Salome HOME
Copyright update 2020
[modules/smesh.git] / src / Tools / ZCracksPlug / casTests / launchCas.py
1 # Copyright (C) 2016-2020  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 from Zcracks import genereCrack, Zset
21 from Zcracks import utilityFunctions as uF
22 from . import genereCube
23
24 from math import sqrt
25
26
27 if False:
28   import Zcracks
29   from Zcracks import casTests
30   from Zcracks.casTests import launchCas
31   launchCas.LAUNCH(['10'])
32
33 import os, shutil
34 import tempfile
35 import string
36
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)
41
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)
46
47 def LAUNCH(listCas=[]):
48   if not isinstance(listCas, list): listCas=[listCas]
49
50   N=20
51   L=1.
52   te=L/N
53   offset=te/2.
54   genereCube.cube3D(L, N, os.path.join(tmpdir,'cube3D.med'))
55   genereCube.cube2D(L, N, os.path.join(tmpdir,'cube2D.med'))
56   crack={}
57   synthese={}
58
59   # -------- #
60   #  CAS 2D  #
61   # -------- #
62   data={'minSize':[te/10.], 'maxSize':[te], 'extractLength':[2.*te], 'is2D':True, 'crack':crack,
63         'grEdge':['EDGEXP EDGEXM EDGEYP EDGEYM']}
64
65   cas='1'
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)
70
71   cas='2'
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)
76
77   cas='3'
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)
82
83   cas='4'
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)
88
89   data['grFace']=['FACEXM FACEXP']
90   cas='5'
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)
94
95   cas='6'
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)
100
101
102   data['grFace']=['']
103   cas='7'
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)
108
109   cas='8'
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)
114
115   data['grFace']=['FACEXM FACEXP']
116   cas='9'
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)
121
122   # -------- #
123   #  CAS 3D  #
124   # -------- #
125   data['grEdge']=['']
126   data['grFace']=['FACEXP FACEXM FACEYP FACEYM FACEZP FACEZM']
127   data['is2D']=False
128
129   cas='10'
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)
134
135   cas='11'
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)
140
141   cas='12'
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)
146
147   cas='13'
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)
152
153   cas='14'
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)
158
159   cas='15'
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)
165
166   cas='16'
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)
172
173   cas='17'
174   crack['actif']='Rectangle'
175   crack[crack['actif']]={'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
176                          'Longueur':[L/4.]}
177   if cas in listCas or listCas==[]:
178     synthese[cas]=execute3D(data, cas)
179
180   cas='18'
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)
186
187
188   data['grVol']=['VOLYP VOLYM']
189
190   cas='19'
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)
196
197   data['grVol']=['VOLXP VOLXM']
198
199   cas='20'
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)
204
205   data['grVol']=['VOLYP VOLYM']
206
207   cas='21'
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)
212
213   OK=[]
214   NOOK=[]
215   for s in synthese:
216     if synthese[s]:
217       OK.append(s)
218     else:
219       NOOK.append(s)
220
221   print('OK:')
222   print(OK)
223   print(' ')
224   print('NOOK:')
225   print(NOOK)
226   print(' ')
227
228   return(synthese)
229
230
231
232 def execute3D(data, cas):
233   names={'saneGeoName':'cube3D', 'crackGeoName':'crack'+cas, 'crackedGeoName':'cracked'+cas}
234
235   crackMed=os.path.join(tmpdir,'crack'+cas+'.med')
236   crackedMed=os.path.join(tmpdir,'cracked'+cas+'.med')
237
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')
241
242   for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
243     if os.path.isfile(f): os.remove(f)
244
245   genereCrack.main(data, crackMed)
246
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'))
252
253   Zset.geoToMed(crackedMed, names['crackedGeoName'], tmpdir)
254
255   if os.path.isfile(crackedMed):
256     uF.extendElsets(crackedMed)
257     maxAR=uF.getMaxAspectRatio(tmpdir)
258     return(maxAR<30. and maxAR>=1.)
259   else:
260     return(False)
261
262
263
264 def execute2D(data, cas):
265   names={'saneGeoName':'cube2D', 'crackGeoName':'crack'+cas, 'crackedGeoName':'cracked'+cas}
266
267   crackMed=os.path.join(tmpdir,'crack'+cas+'.med')
268   crackedMed=os.path.join(tmpdir,'cracked'+cas+'.med')
269
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')
273
274   for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
275     if os.path.isfile(f): os.remove(f)
276
277   genereCrack.main(data, crackMed)
278
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)
285
286   if os.path.isfile(crackedMed):
287     uF.extendElsets(crackedMed)
288     maxAR=uF.getMaxAspectRatio(tmpdir)
289     return(maxAR<30. and maxAR>=1.)
290   else:
291     return(False)
292
293
294
295