Salome HOME
Copyright update: 2016
[modules/smesh.git] / src / Tools / MacMesh / MacMesh / CentralUnrefine.py
1 # Copyright (C) 2014-2016  EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20
21
22 # This object allows unrefining from a central point (actually, a line) to the exterior
23 # X0 and Y0 are the center points of the origin point and not those of the center of the generated block
24
25
26
27 import sys, math, commands
28 CWD = commands.getoutput('pwd')
29 sys.path.append(CWD)
30
31 from MacObject import *
32 import Config, GenFunctions
33
34 def CentralUnrefine (X0 , Y0 , DX , DY , Orientation, **args ) : 
35
36         DirPar =     {'SN' : lambda : ['NW', 'NE', 'EW', 'NW', 'SN', 'SN', 'NE', 'WE'],
37                       'NS' : lambda : ['SE', 'SW', 'WE', 'SE', 'NS', 'NS', 'SW', 'EW'],
38                       'EW' : lambda : ['NW', 'SW', 'SN', 'NW', 'EW', 'EW', 'SW', 'NS'],
39                       'WE' : lambda : ['SE', 'NE', 'NS', 'SE', 'WE', 'WE', 'NE', 'SN'], }[Orientation]()
40
41         CoefVer =   {'SN' : lambda :  1.,
42                      'NS' : lambda : -1.,
43                      'EW' : lambda :  0.,
44                      'WE' : lambda :  0., }[Orientation]()
45
46         CoefHor =   {'SN' : lambda :  0.,
47                      'NS' : lambda :  0.,
48                      'EW' : lambda : -1.,
49                      'WE' : lambda :  1., }[Orientation]()
50
51
52         MacObject('CompBoxF',[(X0+CoefHor*DX/2,Y0+CoefVer*DY/2),(DX,DY)],['auto'],publish=0)
53         ToLook1 = {'SN' : lambda : 2,
54                    'NS' : lambda : 3,
55                    'EW' : lambda : 1,
56                    'WE' : lambda : 0, }[Orientation]()
57
58         ToLook2 = {'SN' : lambda : 0,
59                    'NS' : lambda : 0,
60                    'EW' : lambda : 2,
61                    'WE' : lambda : 2, }[Orientation]()
62                    
63         ToLook3 = {'SN' : lambda : [0,1,2,3],
64                    'NS' : lambda : [1,0,3,2],
65                    'EW' : lambda : [3,2,1,0],
66                    'WE' : lambda : [2,3,0,1], }[Orientation]() 
67                                      
68         if args.__contains__('groups') :
69                 GroupNames = args['groups']
70         else : GroupNames = [None, None, None, None, None, None]
71                 
72         ExistingSegments = Config.ListObj[-1].DirectionalMeshParams[ToLook1]
73         ObjIDs = Config.Connections[-1][ToLook1]
74         RemoveLastObj()
75         
76         ExtensionSegments = math.ceil(ExistingSegments/12.)*12.
77         Dmin = 1.E50
78         Dmax = -1.E50
79         for ObjID in ObjIDs : 
80                 Boundaries = Config.ListObj[ObjID].Boundaries()
81                 if Boundaries[ToLook2] < Dmin : Dmin = Boundaries[ToLook2]
82                 if Boundaries[ToLook2+1] > Dmax : Dmax = Boundaries[ToLook2+1]
83         dx = 0                    
84         if ExtensionSegments > ExistingSegments :
85                 dn = (ExtensionSegments-ExistingSegments)/2.
86                 dx = dn*(Dmax-Dmin)/ExistingSegments
87                 #MacObject('CompBoxF',[(X0-CoefHor*dx/2+CoefVer*(-X0+Dmin-dx/2),Y0-CoefVer*dx/2+CoefHor*(-Y0+Dmin-dx/2)),(dx,dx)],[(dn,dn)],publish=0)
88                 #MacObject('CompBoxF',[(X0-CoefHor*dx/2+CoefVer*(-X0+Dmax+dx/2),Y0-CoefVer*dx/2+CoefHor*(-Y0+Dmax+dx/2)),(dx,dx)],[(dn,dn)],publish=0)
89         
90         BoxSide = (Dmax-Dmin+2*dx)/2.
91         
92         Obj = []
93         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(BoxSide/2)+CoefVer*(-BoxSide/2),Y0+CoefVer*(BoxSide/2)+CoefHor*(-BoxSide/2)),(BoxSide,BoxSide)],[int(ExtensionSegments/6),DirPar[0]],groups=GroupArray(ToLook3[0],GroupNames[0])))       
94         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(BoxSide/2)+CoefVer*(BoxSide/2),Y0+CoefVer*(BoxSide/2)+CoefHor*(BoxSide/2)),(BoxSide,BoxSide)],[int(ExtensionSegments/6),DirPar[1]],groups=GroupArray(ToLook3[0],GroupNames[0])))        
95
96         NLevOpt = 0
97         for NLevels in range (1,100) : 
98                 DX1 = abs(CoefVer)*BoxSide*2.**(NLevels+1)+abs(CoefHor)*BoxSide*2.**(NLevels)
99                 DY1 = abs(CoefHor)*BoxSide*2.**(NLevels+1)+abs(CoefVer)*BoxSide*2.**(NLevels)
100                 if DX1 > DX or DY1 > DY :
101                         NLevOpt = NLevels-1
102                         DXinner = DX1/2.
103                         DYinner = DY1/2.
104                         break
105                         
106         dummyArray = [DXinner,DYinner,DYinner,DXinner]                 
107         D1inner = dummyArray[ToLook2]           # = DXinner for SN and NS orientations
108         D2inner = dummyArray[ToLook2+1]         # = DYinner for SN and NS orientations
109          
110         dummyArray = [DX,DY,DY,DX]                 
111         D1 = dummyArray[ToLook2]                # = DX for SN and NS orientations
112         D2 = dummyArray[ToLook2+1]              # = DY for SN and NS orientations
113                        
114         if D1inner < D1 : 
115                 GN0a = GroupArray(ToLook3[0],GroupNames[1])
116                 GN0b = GroupArray(ToLook3[0],GroupNames[2])              
117                 GN01 = GroupArray(ToLook3[0],GroupNames[1])
118                 GN02 = GroupArray(ToLook3[0],GroupNames[2])
119                 if D2inner < D2 : 
120                         GN10 = [None,None,None,None]
121                         GN11 = [None,None,None,None]
122                         GN20 = [None,None,None,None]
123                 else : 
124                         GN10 = GroupArray(ToLook3[1],GroupNames[3])
125                         GN11 = GroupArray(ToLook3[1],GroupNames[3])
126                         GN20 = GroupArray(ToLook3[1],GroupNames[3]) 
127         else : 
128                 GN0a = GroupArray(ToLook3[0],GroupNames[1])
129                 GN0b = GroupArray(ToLook3[0],GroupNames[2])
130                 GN01 = GroupArray([ToLook3[0],ToLook3[2]],[GroupNames[1],GroupNames[4]]) 
131                 GN02 = GroupArray([ToLook3[0],ToLook3[3]],[GroupNames[2],GroupNames[5]]) 
132                 if D2inner < D2 : 
133                         GN10 = GroupArray(ToLook3[2],GroupNames[4])
134                         GN11 = GroupArray(ToLook3[3],GroupNames[5])
135                         GN20 = [None,None,None,None]
136                 else : 
137                         GN10 = GroupArray([ToLook3[1],ToLook3[2]],[GroupNames[3],GroupNames[4]])
138                         GN11 = GroupArray([ToLook3[1],ToLook3[3]],[GroupNames[3],GroupNames[5]])
139                         GN20 = GroupArray(ToLook3[1],GroupNames[3]) 
140                                               
141         for N in range (1,NLevOpt+1):
142                 n=N-1
143                 D = BoxSide*(2.**n)
144                 if N < NLevOpt : 
145                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*1/2-CoefVer*3/2)  , Y0+D*(CoefVer*1/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[2]], groups=GN0a))
146                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefHor*3/2-CoefVer*3/2)  , Y0+D*(CoefVer*3/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[3]]))
147                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2-CoefVer*1/2)  , Y0+D*(CoefVer*3/2-CoefHor*1/2) )          , (D,D)],['auto',DirPar[4]]))
148                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2+CoefVer*1/2)  , Y0+D*(CoefHor*1/2+CoefVer*3/2) )          , (D,D)],['auto',DirPar[5]]))
149                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefVer*3/2+CoefHor*3/2)  , Y0+D*(CoefVer*3/2+CoefHor*3/2) )          , (D,D)],['auto',DirPar[6]]))
150                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefVer*3/2+CoefHor*1/2)  , Y0+D*(CoefHor*3/2+CoefVer*1/2) )          , (D,D)],['auto',DirPar[7]], groups=GN0b))
151                 else :
152                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*1/2-CoefVer*3/2)  , Y0+D*(CoefVer*1/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[2]], groups=GN01))
153                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefHor*3/2-CoefVer*3/2)  , Y0+D*(CoefVer*3/2-CoefHor*3/2) )          , (D,D)],['auto',DirPar[3]], groups=GN10))
154                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2-CoefVer*1/2)  , Y0+D*(CoefVer*3/2-CoefHor*1/2) )          , (D,D)],['auto',DirPar[4]], groups=GN20))
155                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefHor*3/2+CoefVer*1/2)  , Y0+D*(CoefHor*1/2+CoefVer*3/2) )          , (D,D)],['auto',DirPar[5]], groups=GN20))
156                         Obj.append(MacObject('BoxAng32',[(X0+D*(CoefVer*3/2+CoefHor*3/2)  , Y0+D*(CoefVer*3/2+CoefHor*3/2) )          , (D,D)],['auto',DirPar[6]], groups=GN11))
157                         Obj.append(MacObject('Box42'   ,[(X0+D*(CoefVer*3/2+CoefHor*1/2)  , Y0+D*(CoefHor*3/2+CoefVer*1/2) )          , (D,D)],['auto',DirPar[7]], groups=GN02))
158
159         
160         if CoefVer and DX>DXinner : 
161                 Obj.append(MacObject('CompBoxF',[(X0-CoefVer*0.25*(DX+DXinner),Y0+CoefVer*DYinner/2),((DX-DXinner)/2,DYinner)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[2]],[GroupNames[1],GroupNames[4]])))
162                 Obj.append(MacObject('CompBoxF',[(X0+CoefVer*0.25*(DX+DXinner),Y0+CoefVer*DYinner/2),((DX-DXinner)/2,DYinner)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[3]],[GroupNames[2],GroupNames[5]])))
163                 if DY>DYinner : 
164                         Obj.append(MacObject('CompBoxF',[(X0-CoefVer*0.25*(DX+DXinner),Y0+CoefVer*(DY+DYinner)/2.),((DX-DXinner)/2,DY-DYinner)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[2]],[GroupNames[3],GroupNames[4]])))
165                         Obj.append(MacObject('CompBoxF',[(X0+CoefVer*0.25*(DX+DXinner),Y0+CoefVer*(DY+DYinner)/2.),((DX-DXinner)/2,DY-DYinner)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[3]],[GroupNames[3],GroupNames[5]])))
166                         Obj.append(MacObject('CompBoxF',[(X0,Y0+CoefVer*(DY+DYinner)/2.),(DXinner,DY-DYinner)],['auto'], groups = GroupArray(ToLook3[1],GroupNames[3])))
167         elif CoefHor and DY>DYinner : 
168                 Obj.append(MacObject('CompBoxF',[(X0+CoefHor*DXinner/2,Y0-CoefHor*0.25*(DY+DYinner)),(DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[2]],[GroupNames[1],GroupNames[4]])))
169                 Obj.append(MacObject('CompBoxF',[(X0+CoefHor*DXinner/2,Y0+CoefHor*0.25*(DY+DYinner)),(DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[0],ToLook3[3]],[GroupNames[2],GroupNames[5]])))
170                 if DX>DXinner : 
171                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX+DXinner)/2.,Y0-CoefHor*0.25*(DY+DYinner)),(DX-DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[2]],[GroupNames[3],GroupNames[4]])))
172                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX+DXinner)/2.,Y0+CoefHor*0.25*(DY+DYinner)),(DX-DXinner,(DY-DYinner)/2)],['auto'], groups = GroupArray([ToLook3[1],ToLook3[3]],[GroupNames[3],GroupNames[5]])))
173                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX+DXinner)/2.,Y0),(DX-DXinner,DYinner)],['auto'], groups = GroupArray(ToLook3[1],GroupNames[3])))
174         return Obj
175
176 def RemoveLastObj() : 
177         Config.ListObj = Config.ListObj[:-1]
178         Config.Connections = Config.Connections[:-1]
179  
180 def GroupArray(indices, GroupNames) :
181         if type(indices) is int : 
182                 indices = [indices]
183                 GroupNames = [GroupNames]
184         Output = [None,None,None,None]
185         for i, ind in enumerate(indices) : 
186                 Output[ind] = GroupNames[i]
187         return Output