1 # Copyright (C) 2016-2020 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
20 from Zcracks import genereCrack, Zset
21 from Zcracks import utilityFunctions as uF
22 from . import genereCube
29 from Zcracks import casTests
30 from Zcracks.casTests import launchCas
31 launchCas.LAUNCH(['10'])
37 #tmpdir = "/local00/home/B27118/projets/Zcracks/Zcracks/casTests/tmpdir"
38 #if not os.path.isdir(tmpdir): os.mkdir(tmpdir)
39 tmpdir=tempfile.mkdtemp(prefix='tmpZcracks')
40 print("tmpdir=", tmpdir)
42 #meshgemsdir=os.environ('MESHGEMSHOME')
43 #if len(meshgemsdir) > 0:
44 #meshgems=string.split(meshgemsdir,os.sep)[-1]
45 #uF.removeFromSessionPath('LD_LIBRARY_PATH', meshgems)
47 def LAUNCH(listCas=[]):
48 if not isinstance(listCas, list): listCas=[listCas]
54 genereCube.cube3D(L, N, os.path.join(tmpdir,'cube3D.med'))
55 genereCube.cube2D(L, N, os.path.join(tmpdir,'cube2D.med'))
62 data={'minSize':[te/10.], 'maxSize':[te], 'extractLength':[2.*te], 'is2D':True, 'crack':crack,
63 'grEdge':['EDGEXP EDGEXM EDGEYP EDGEYM']}
66 crack['actif']='Ellipse'
67 crack[crack['actif']]={'Rayon':[L/2.], 'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.]}
68 if cas in listCas or listCas==[]:
69 synthese[cas]=execute2D(data, cas)
72 crack['actif']='Ellipse'
73 crack[crack['actif']]={'Rayon':[L], 'Centre':[L/2., 0., 0.], 'Normale':[1., 1., 0.]}
74 if cas in listCas or listCas==[]:
75 synthese[cas]=execute2D(data, cas)
78 crack['actif']='Ellipse'
79 crack[crack['actif']]={'Rayon':[L*sqrt(2.)], 'Centre':[-L/2., L/2., 0.], 'Normale':[1., 1., 0.]}
80 if cas in listCas or listCas==[]:
81 synthese[cas]=execute2D(data, cas)
84 crack['actif']='Ellipse'
85 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.]}
86 if cas in listCas or listCas==[]:
87 synthese[cas]=execute2D(data, cas)
89 data['grFace']=['FACEXM FACEXP']
91 crack['actif']='Ellipse'; crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.]}
92 if cas in listCas or listCas==[]:
93 synthese[cas]=execute2D(data, cas)
96 crack['actif']='Ellipse'
97 crack[crack['actif']]={'Rayon':[L/8.], 'Centre':[-L/16., offset, 0.], 'Normale':[0., 1., 0.]}
98 if cas in listCas or listCas==[]:
99 synthese[cas]=execute2D(data, cas)
104 crack['actif']='Sphere'
105 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
106 if cas in listCas or listCas==[]:
107 synthese[cas]=execute2D(data, cas)
110 crack['actif']='Sphere'
111 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., 0., 0.]}
112 if cas in listCas or listCas==[]:
113 synthese[cas]=execute2D(data, cas)
115 data['grFace']=['FACEXM FACEXP']
117 crack['actif']='Sphere'
118 crack['Sphere']={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
119 if cas in listCas or listCas==[]:
120 synthese[cas]=execute2D(data, cas)
126 data['grFace']=['FACEXP FACEXM FACEYP FACEYM FACEZP FACEZM']
130 crack['actif']='Rectangle'
131 crack[crack['actif']]={'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.], 'Longueur':[L/2.], 'Largeur':[L]}
132 if cas in listCas or listCas==[]:
133 synthese[cas]=execute3D(data, cas)
136 crack['actif']='Sphere'
137 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
138 if cas in listCas or listCas==[]:
139 synthese[cas]=execute3D(data, cas)
142 crack['actif']='Ellipse'
143 crack[crack['actif']]={'Centre':[L/4., L/4., L/4.], 'Normale':[1., 1., 1.], 'Rayon':[L]}
144 if cas in listCas or listCas==[]:
145 synthese[cas]=execute3D(data, cas)
148 crack['actif']='Sphere'
149 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., 0., 0.]}
150 if cas in listCas or listCas==[]:
151 synthese[cas]=execute3D(data, cas)
154 crack['actif']='Ellipse'
155 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.]}
156 if cas in listCas or listCas==[]:
157 synthese[cas]=execute3D(data, cas)
160 crack['actif']='Rectangle'
161 crack[crack['actif']]={'Centre':[L/2., 0., 0.], 'Normale':[0., 1., 0.], 'Direction':[-1., 0., 0.],
162 'Longueur':[L/2.], 'Largeur':[L], 'Rayon entaille':[te*1.5]}
163 if cas in listCas or listCas==[]:
164 synthese[cas]=execute3D(data, cas)
167 crack['actif']='Rectangle'
168 crack[crack['actif']]={'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
169 'Longueur':[L/2.], 'Largeur':[L/4.], 'Rayon':[2.*te]}
170 if cas in listCas or listCas==[]:
171 synthese[cas]=execute3D(data, cas)
174 crack['actif']='Rectangle'
175 crack[crack['actif']]={'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
177 if cas in listCas or listCas==[]:
178 synthese[cas]=execute3D(data, cas)
181 crack['actif']='Rectangle'
182 crack[crack['actif']]={'Centre':[0., 0., 0.], 'Normale':[1., 1., 0.], 'Direction':[1., -1., 0.],
183 'Longueur':[L], 'Angle':[180.]}
184 if cas in listCas or listCas==[]:
185 synthese[cas]=execute3D(data, cas)
188 data['grVol']=['VOLYP VOLYM']
191 crack['actif']='Rectangle'
192 crack[crack['actif']]={'Centre':[0., 0., 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
193 'Longueur':[L], 'Angle':[180.]}
194 if cas in listCas or listCas==[]:
195 synthese[cas]=execute3D(data, cas)
197 data['grVol']=['VOLXP VOLXM']
200 crack['actif']='Sphere'
201 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
202 if cas in listCas or listCas==[]:
203 synthese[cas]=execute3D(data, cas)
205 data['grVol']=['VOLYP VOLYM']
208 crack['actif']='Ellipse'
209 crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.]}
210 if cas in listCas or listCas==[]:
211 synthese[cas]=execute3D(data, cas)
232 def execute3D(data, cas):
233 names={'saneGeoName':'cube3D', 'crackGeoName':'crack'+cas, 'crackedGeoName':'cracked'+cas}
235 crackMed=os.path.join(tmpdir,'crack'+cas+'.med')
236 crackedMed=os.path.join(tmpdir,'cracked'+cas+'.med')
238 saneGeo=os.path.join(tmpdir,names['saneGeoName'],'.geo')
239 crackGeo=os.path.join(tmpdir,names['crackGeoName'],'.geo')
240 crackedGeo=os.path.join(tmpdir,names['crackedGeoName'],'.geo')
242 for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
243 if os.path.isfile(f): os.remove(f)
245 genereCrack.main(data, crackMed)
247 Zset.medToGeo(os.path.join(tmpdir,names['saneGeoName']),names['saneGeoName'], tmpdir)
248 Zset.medToGeo(crackMed, names['crackGeoName'], tmpdir)
249 Zset.insertCrack(data, names, tmpdir)
250 shutil.copy(os.path.join(tmpdir,'_mesh_out_to_ghs3d.mesh'),os.path.join(tmpdir,'mesh'+cas+'.mesh'))
251 shutil.copy(os.path.join(tmpdir,'insert.z7p'),os.path.join(tmpdir,'insert'+cas+'.z7p'))
253 Zset.geoToMed(crackedMed, names['crackedGeoName'], tmpdir)
255 if os.path.isfile(crackedMed):
256 uF.extendElsets(crackedMed)
257 maxAR=uF.getMaxAspectRatio(tmpdir)
258 return(maxAR<30. and maxAR>=1.)
264 def execute2D(data, cas):
265 names={'saneGeoName':'cube2D', 'crackGeoName':'crack'+cas, 'crackedGeoName':'cracked'+cas}
267 crackMed=os.path.join(tmpdir,'crack'+cas+'.med')
268 crackedMed=os.path.join(tmpdir,'cracked'+cas+'.med')
270 saneGeo=os.path.join(tmpdir,names['saneGeoName'],'.geo')
271 crackGeo=os.path.join(tmpdir,names['crackGeoName'],'.geo')
272 crackedGeo=os.path.join(tmpdir,names['crackedGeoName'],'.geo')
274 for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
275 if os.path.isfile(f): os.remove(f)
277 genereCrack.main(data, crackMed)
279 Zset.medToGeo(os.path.join(tmpdir,names['saneGeoName']),names['saneGeoName'], tmpdir, opt=[' **to_3d'])
280 Zset.medToGeo(crackMed, names['crackGeoName'], tmpdir)
281 Zset.insertCrack(data, names, tmpdir)
282 shutil.copy(os.path.join(tmpdir,'_mesh_out_.mesh'),os.path.join(tmpdir,'mesh'+cas+'.mesh'))
283 shutil.copy(os.path.join(tmpdir,'insert.z7p'),os.path.join(tmpdir,'insert'+cas+'.z7p'))
284 Zset.geoToMed(crackedMed, names['crackedGeoName'], tmpdir)
286 if os.path.isfile(crackedMed):
287 uF.extendElsets(crackedMed)
288 maxAR=uF.getMaxAspectRatio(tmpdir)
289 return(maxAR<30. and maxAR>=1.)