1 # Copyright (C) 2014-2022 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
27 import sys, math, subprocess
28 CWD = subprocess.getoutput('pwd')
31 from MacObject import *
32 import Config, GenFunctions
34 def CentralUnrefine (X0 , Y0 , DX , DY , Orientation, **args ) :
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]()
41 CoefVer = {'SN' : lambda : 1.,
44 'WE' : lambda : 0., }[Orientation]()
46 CoefHor = {'SN' : lambda : 0.,
49 'WE' : lambda : 1., }[Orientation]()
52 MacObject('CompBoxF',[(X0+CoefHor*DX/2,Y0+CoefVer*DY/2),(DX,DY)],['auto'],publish=0)
53 ToLook1 = {'SN' : lambda : 2,
56 'WE' : lambda : 0, }[Orientation]()
58 ToLook2 = {'SN' : lambda : 0,
61 'WE' : lambda : 2, }[Orientation]()
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]()
68 if args.__contains__('groups') :
69 GroupNames = args['groups']
70 else : GroupNames = [None, None, None, None, None, None]
72 ExistingSegments = Config.ListObj[-1].DirectionalMeshParams[ToLook1]
73 ObjIDs = Config.Connections[-1][ToLook1]
76 ExtensionSegments = math.ceil(ExistingSegments/12.)*12.
80 Boundaries = Config.ListObj[ObjID].Boundaries()
81 if Boundaries[ToLook2] < Dmin : Dmin = Boundaries[ToLook2]
82 if Boundaries[ToLook2+1] > Dmax : Dmax = Boundaries[ToLook2+1]
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)
90 BoxSide = (Dmax-Dmin+2*dx)/2.
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])))
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 :
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
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
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])
120 GN10 = [None,None,None,None]
121 GN11 = [None,None,None,None]
122 GN20 = [None,None,None,None]
124 GN10 = GroupArray(ToLook3[1],GroupNames[3])
125 GN11 = GroupArray(ToLook3[1],GroupNames[3])
126 GN20 = GroupArray(ToLook3[1],GroupNames[3])
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]])
133 GN10 = GroupArray(ToLook3[2],GroupNames[4])
134 GN11 = GroupArray(ToLook3[3],GroupNames[5])
135 GN20 = [None,None,None,None]
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])
141 for N in range (1,NLevOpt+1):
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))
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))
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]])))
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]])))
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])))
176 def RemoveLastObj() :
177 Config.ListObj = Config.ListObj[:-1]
178 Config.Connections = Config.Connections[:-1]
180 def GroupArray(indices, GroupNames) :
181 if isinstance(indices, int) :
183 GroupNames = [GroupNames]
184 Output = [None,None,None,None]
185 for i, ind in enumerate(indices) :
186 Output[ind] = GroupNames[i]