Salome HOME
3ddc895821b0410d902259d484fa039319adbe19
[modules/smesh.git] / src / Tools / MacMesh / MacMesh / SharpAngle.py
1 # This is an automation of the sharp angle object, with a corner at (X0,Y0), side length : Extension and a fine local meshing : LocalMeshing
2 # The corner orientation is defined as NE (North-East) , NW (North-West), SE, or SW. The object's "arm" is 8/14 of Extension
3 #                       |      |     8      6
4 #                -------        ---------
5 #       ---->   |                        |   <----
6 #               |   NW             NE    |  oo
7 #          _____|                        |_____
8
9 import sys, salome, geompy, smesh, SMESH, math, commands
10 CWD = commands.getoutput('pwd')
11 sys.path.append(CWD)
12
13 from MacObject import *
14 from CompositeBox import *
15 import Config, GenFunctions
16
17 def SharpAngleOut (X0 , Y0 , DX , DY , DLocal, LocalMeshing , CornerOrientation , NLevels, **args) : 
18         if DLocal == 'auto' : DLocal = float(min(DX,DY))
19
20         BoxSide = DLocal/(2.**(NLevels+1))
21         InternalMeshing = int(math.ceil(BoxSide/(3*LocalMeshing)))
22         InternalMeshing = InternalMeshing+InternalMeshing%2     # An even number is needed, otherwise the objects would not be compatible once created
23         if InternalMeshing == 0 : InternalMeshing = 2           # This sets a minimum meshing condition in order to avoid an error. The user is notified of the value considered for the local meshing
24         print "Possible Local meshing is :", BoxSide/(3*InternalMeshing), "\nThis value is returned by this function for your convenience"
25
26         DirPar =     {'NE' : lambda : ['NE', 'NW', 'SE', 'EW', 'NW', 'SN', 'SN', 'NE', 'WE', 'WE', 'SE', 'NS'],
27                       'NW' : lambda : ['NW', 'NE', 'SW', 'WE', 'NE', 'SN', 'SN', 'NW', 'EW', 'EW', 'SW', 'NS'],
28                       'SE' : lambda : ['SE', 'SW', 'NE', 'EW', 'SW', 'NS', 'NS', 'SE', 'WE', 'WE', 'NE', 'SN'],
29                       'SW' : lambda : ['SW', 'SE', 'NW', 'WE', 'SE', 'NS', 'NS', 'SW', 'EW', 'EW', 'NW', 'SN'], }[CornerOrientation]()
30
31         CoefVer =   {'NE' : lambda :  1,
32                      'NW' : lambda :  1,
33                      'SE' : lambda : -1,
34                      'SW' : lambda : -1, }[CornerOrientation]()
35
36         CoefHor =   {'NE' : lambda :  1,
37                      'NW' : lambda : -1,
38                      'SE' : lambda :  1,
39                      'SW' : lambda : -1, }[CornerOrientation]()
40                      
41         ToLook  = {'NE' : lambda : [0,2,1,3],
42                    'NW' : lambda : [0,3,1,2],
43                    'SE' : lambda : [1,2,0,3],
44                    'SW' : lambda : [1,3,0,2], }[CornerOrientation]()        
45        
46         if args.__contains__('groups') :
47                 GroupNames = args['groups']
48         else : GroupNames = [None, None, None, None, None, None]
49         
50         GN00 = GroupArray(ToLook[0],GroupNames[0])
51         GN01 = GroupArray(ToLook[1],GroupNames[1])
52         
53         GN1 = GroupArray([ToLook[0],ToLook[1]],[GroupNames[0],GroupNames[5]])
54         GN7 = GroupArray([ToLook[0],ToLook[1]],[GroupNames[4],GroupNames[1]])
55         
56         if DY == DLocal :
57                 GN2 = GroupArray([ToLook[1],ToLook[2]],[GroupNames[5],GroupNames[2]])
58                 GN3 = GroupArray(ToLook[2],GroupNames[2])
59                 if DX == DLocal:
60                         GN4 = GroupArray([ToLook[2],ToLook[3]],[GroupNames[2],GroupNames[3]])
61                         GN5 = GroupArray(ToLook[3],GroupNames[3])
62                         GN6 = GroupArray([ToLook[3],ToLook[0]],[GroupNames[3],GroupNames[4]])
63                 else :
64                         GN4 = GroupArray(ToLook[2],GroupNames[2])
65                         GN5 = [None,None,None,None]
66                         GN6 = GroupArray(ToLook[0],GroupNames[4])
67                         GN21 = GroupArray([ToLook[3],ToLook[0],ToLook[2]],[GroupNames[3],GroupNames[4],GroupNames[2]])
68         else :
69                 GN2 = GroupArray(ToLook[1],GroupNames[5])
70                 GN3 = [None,None,None,None]
71                 if DX == DLocal:
72                         GN4 = GroupArray(ToLook[3],GroupNames[3])
73                         GN5 = GroupArray(ToLook[3],GroupNames[3])
74                         GN6 = GroupArray([ToLook[3],ToLook[0]],[GroupNames[3],GroupNames[4]])
75                         GN22 = GroupArray([ToLook[1],ToLook[2],ToLook[3]],[GroupNames[5],GroupNames[2],GroupNames[3]])
76                 else :
77                         GN4 = [None,None,None,None]
78                         GN5 = [None,None,None,None]
79                         GN6 = GroupArray(ToLook[0],GroupNames[4])
80                         GN21 = GroupArray([ToLook[3],ToLook[0]],[GroupNames[3],GroupNames[4]])
81                         GN22 = GroupArray([ToLook[1],ToLook[2]],[GroupNames[5],GroupNames[2]])
82                         GN23 = GroupArray([ToLook[2],ToLook[3]],[GroupNames[2],GroupNames[3]])
83                         
84         Obj = []
85
86         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*BoxSide/2,Y0+CoefVer*BoxSide/2),(BoxSide,BoxSide)],[InternalMeshing,DirPar[0]]))
87         Obj.append(MacObject('BoxAng32',[(X0-CoefHor*BoxSide/2,Y0+CoefVer*BoxSide/2),(BoxSide,BoxSide)],['auto',DirPar[1]], groups = GroupArray(ToLook[0],GroupNames[0])))
88         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*BoxSide/2,Y0-CoefVer*BoxSide/2),(BoxSide,BoxSide)],['auto',DirPar[2]], groups = GroupArray(ToLook[1],GroupNames[1])))
89         
90         for N in range (1,NLevels+1):
91                 n = N-1
92                 if N < NLevels : 
93                        Obj.append(MacObject('Box42',[(X0-CoefHor*BoxSide*(2**n)*3/2,Y0+CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[3]]      , groups = GN00))
94                        Obj.append(MacObject('BoxAng32',[(X0-CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[4]]               ))
95                        Obj.append(MacObject('Box42',[(X0-CoefHor*(2**n)*BoxSide/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[5]]                    ))
96                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[6]]                    ))
97                        Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[7]]               ))
98                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[8]]                    ))
99                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0-CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[9]]                    ))
100                        Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0-CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[10]]              ))
101                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide/2,Y0-CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[11]]     , groups = GN01))
102                 else :
103                        Obj.append(MacObject('Box42',[(X0-CoefHor*BoxSide*(2**n)*3/2,Y0+CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[3]]      , groups = GN1))
104                        Obj.append(MacObject('BoxAng32',[(X0-CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[4]] , groups = GN2))
105                        Obj.append(MacObject('Box42',[(X0-CoefHor*(2**n)*BoxSide/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[5]]      , groups = GN3))
106                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[6]]      , groups = GN3))
107                        Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[7]] , groups = GN4))
108                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[8]]      , groups = GN5))
109                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0-CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[9]]      , groups = GN5))
110                        Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0-CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[10]], groups = GN6))
111                        Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide/2,Y0-CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[11]]     , groups = GN7))
112                        
113         OuterMeshing = (3/2)*InternalMeshing*2**(NLevels-1)
114         OuterSegLength = (DLocal/OuterMeshing)
115
116         if DX > DLocal :
117                 dX = DX - DLocal
118                 Obj.append(MacObject('CompBoxF',[(X0+CoefHor*(DX)/2.,Y0),(dX,DLocal)],['auto'], groups = GN21))
119         if DY > DLocal :
120                 dY = DY - DLocal
121                 if DX > DLocal : 
122                         Obj.append(MacObject('CompBoxF',[(X0+CoefHor*DX/2.,Y0+CoefVer*(DY)/2.),(DX-DLocal,dY)],['auto'], groups = GN23))
123
124                 Obj.append(MacObject('CompBoxF',[(X0,Y0+CoefVer*(DY)/2.),(DLocal,dY)],['auto'], groups = GN22))
125                 
126         return Obj
127
128 def SharpAngleIn (X0 , Y0 , DX , DY , DLocal, LocalMeshing , CornerOrientation , NLevels, **args) : 
129         if DLocal == 'auto' : DLocal = float(min(DX,DY))
130
131         BoxSide = DLocal/(2.**(NLevels))
132         InternalMeshing = int(math.ceil(BoxSide/(3*LocalMeshing)))
133         InternalMeshing = InternalMeshing+InternalMeshing%2     # An even number is needed, otherwise the objects would not be compatible once created
134         if InternalMeshing == 0 : InternalMeshing = 2           # This sets a minimum meshing condition in order to avoid an error. The user is notified of the value considered for the local meshing
135         print "Possible Local meshing is :", BoxSide/(3*InternalMeshing), "\nThis value is returned by this function for your convenience..."
136
137         DirPar =     {'NE' : lambda : ['NE', 'SN', 'NE', 'WE'],
138                       'NW' : lambda : ['NW', 'SN', 'NW', 'EW'],
139                       'SE' : lambda : ['SE', 'NS', 'SE', 'WE'],
140                       'SW' : lambda : ['SW', 'NS', 'SW', 'EW'], }[CornerOrientation]()
141
142         CoefVer =   {'NE' : lambda :  1,
143                      'NW' : lambda :  1,
144                      'SE' : lambda : -1,
145                      'SW' : lambda : -1, }[CornerOrientation]()
146
147         CoefHor =   {'NE' : lambda :  1,
148                      'NW' : lambda : -1,
149                      'SE' : lambda :  1,
150                      'SW' : lambda : -1, }[CornerOrientation]()
151                      
152         ToLook  = {'NE' : lambda : [0,2,1,3],
153                    'NW' : lambda : [0,3,1,2],
154                    'SE' : lambda : [1,2,0,3],
155                    'SW' : lambda : [1,3,0,2], }[CornerOrientation]()
156                                                
157         if args.__contains__('groups') :
158                 GroupNames = args['groups']
159         else : GroupNames = [None, None, None, None]
160         
161         GN01 = GroupArray([ToLook[0],ToLook[1]],[GroupNames[ToLook[0]],GroupNames[ToLook[1]]])
162         GN02 = GroupArray(ToLook[1],GroupNames[ToLook[1]])        
163         GN03 = [None, None, None, None]
164         GN04 = GroupArray(ToLook[0],GroupNames[ToLook[0]])  
165
166         if DY == DLocal :
167                 GN05 = GroupArray([ToLook[1],ToLook[2]],[GroupNames[ToLook[1]],GroupNames[ToLook[2]]])
168                 GN08 = GroupArray([ToLook[0],ToLook[2],ToLook[3]],[GroupNames[ToLook[0]],GroupNames[ToLook[2]],GroupNames[ToLook[3]]])
169                 if DX == DLocal:
170                         GN06 = GroupArray([ToLook[2],ToLook[3]],[GroupNames[ToLook[2]],GroupNames[ToLook[3]]])
171                         GN07 = GroupArray([ToLook[0],ToLook[3]],[GroupNames[ToLook[0]],GroupNames[ToLook[3]]])
172                 else :
173                         GN06 = GroupArray(ToLook[2],GroupNames[ToLook[2]])
174                         GN07 = GroupArray(ToLook[0],GroupNames[ToLook[0]])
175         else :
176                 GN05 = GroupArray(ToLook[1],GroupNames[ToLook[1]])
177                 if DX == DLocal : 
178                         GN06 = GroupArray(ToLook[3],GroupNames[ToLook[3]])
179                         GN07 = GroupArray([ToLook[0],ToLook[3]],[GroupNames[ToLook[0]],GroupNames[ToLook[3]]])
180                         GN10 = GroupArray([ToLook[1],ToLook[2],ToLook[3]],[GroupNames[ToLook[1]],GroupNames[ToLook[2]],GroupNames[ToLook[3]]])
181                 else :
182                         GN06 = [None, None, None, None]
183                         GN07 = GroupArray(ToLook[0],GroupNames[ToLook[0]])
184                         GN08 = GroupArray([ToLook[0],ToLook[3]],[GroupNames[ToLook[0]],GroupNames[ToLook[3]]])
185                         GN09 = GroupArray([ToLook[2],ToLook[3]],[GroupNames[ToLook[2]],GroupNames[ToLook[3]]])
186                         GN10 = GroupArray([ToLook[1],ToLook[2]],[GroupNames[ToLook[1]],GroupNames[ToLook[2]]])
187          
188         Obj = []
189
190         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*BoxSide/2,Y0+CoefVer*BoxSide/2),(BoxSide,BoxSide)],[InternalMeshing,DirPar[0]],groups = GN01))
191         
192         for N in range (1,NLevels+1):
193                 n = N-1
194                 if N < NLevels : 
195                         Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[1]],groups = GN02))
196                         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[2]],groups = GN03))
197                         Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[3]],groups = GN04))
198                 else :
199                         Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[1]],groups = GN05))
200                         Obj.append(MacObject('BoxAng32',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide*3/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[2]],groups = GN06))
201                         Obj.append(MacObject('Box42',[(X0+CoefHor*(2**n)*BoxSide*3/2,Y0+CoefVer*(2**n)*BoxSide/2),((2**n)*BoxSide,(2**n)*BoxSide)],['auto',DirPar[3]],groups = GN07))
202  
203         OuterMeshing = (3/2)*InternalMeshing*2**(NLevels-1)
204         OuterSegLength = (DLocal/OuterMeshing)
205
206         if DX > DLocal :
207                 dX = DX - DLocal
208                 Obj = Obj + CompositeBox(X0+CoefHor*(DLocal+dX/2.),Y0+CoefVer*(DLocal)/2.,dX,DLocal, groups = GN08)
209         if DY > DLocal :
210                 dY = DY - DLocal
211
212                 if DX > DLocal : 
213                         Obj = Obj + CompositeBox(X0+CoefHor*(DLocal+(DX-DLocal)/2.),Y0+CoefVer*(DLocal+dY/2.),DX-DLocal,dY, groups = GN09)
214
215                 Obj = Obj + CompositeBox(X0+CoefHor*DLocal/2,Y0+CoefVer*(DLocal+dY/2.),DLocal,dY,groups = GN10)
216
217         return Obj
218
219 def GroupArray(indices, GroupNames) :
220         if type(indices) is int : 
221                 indices = [indices]
222                 GroupNames = [GroupNames]
223         Output = [None,None,None,None]
224         for i, ind in enumerate(indices) : 
225                 Output[ind] = GroupNames[i]
226         return Output