Salome HOME
Merge remote-tracking branch 'origin/V8_3_BR' into ngr/python3_dev
[modules/smesh.git] / src / Tools / ZCracksPlug / casTests / launchCas.py
1
2 from Zcracks import genereCrack, Zset
3 from Zcracks import utilityFunctions as uF
4 from . import genereCube
5
6 from math import sqrt
7
8
9 if False:
10   import Zcracks
11   from Zcracks import casTests
12   from Zcracks.casTests import launchCas
13   launchCas.LAUNCH(['10'])
14
15 import os, shutil
16 import tempfile
17 import string
18
19 #tmpdir = "/local00/home/B27118/projets/Zcracks/Zcracks/casTests/tmpdir"
20 #if not os.path.isdir(tmpdir): os.mkdir(tmpdir)
21 tmpdir=tempfile.mkdtemp(prefix='tmpZcracks')
22 print("tmpdir=", tmpdir)
23
24 #meshgemsdir=os.environ('MESHGEMSHOME')
25 #if len(meshgemsdir) > 0:
26   #meshgems=string.split(meshgemsdir,os.sep)[-1]
27   #uF.removeFromSessionPath('LD_LIBRARY_PATH', meshgems)
28
29 def LAUNCH(listCas=[]):
30   if not isinstance(listCas, list): listCas=[listCas]
31
32   N=20
33   L=1.
34   te=L/N
35   offset=te/2.
36   genereCube.cube3D(L, N, os.path.join(tmpdir,'cube3D.med'))
37   genereCube.cube2D(L, N, os.path.join(tmpdir,'cube2D.med'))
38   crack={}
39   synthese={}
40
41   # -------- #
42   #  CAS 2D  #
43   # -------- #
44   data={'minSize':[te/10.], 'maxSize':[te], 'extractLength':[2.*te], 'is2D':True, 'crack':crack,
45         'grEdge':['EDGEXP EDGEXM EDGEYP EDGEYM']}
46
47   cas='1'
48   crack['actif']='Ellipse'
49   crack[crack['actif']]={'Rayon':[L/2.], 'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.]}
50   if cas in listCas or listCas==[]:
51     synthese[cas]=execute2D(data, cas)
52
53   cas='2'
54   crack['actif']='Ellipse'
55   crack[crack['actif']]={'Rayon':[L], 'Centre':[L/2., 0., 0.], 'Normale':[1., 1., 0.]}
56   if cas in listCas or listCas==[]:
57     synthese[cas]=execute2D(data, cas)
58
59   cas='3'
60   crack['actif']='Ellipse'
61   crack[crack['actif']]={'Rayon':[L*sqrt(2.)], 'Centre':[-L/2., L/2., 0.], 'Normale':[1., 1., 0.]}
62   if cas in listCas or listCas==[]:
63     synthese[cas]=execute2D(data, cas)
64
65   cas='4'
66   crack['actif']='Ellipse'
67   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.]}
68   if cas in listCas or listCas==[]:
69     synthese[cas]=execute2D(data, cas)
70
71   data['grFace']=['FACEXM FACEXP']
72   cas='5'
73   crack['actif']='Ellipse'; crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.]}
74   if cas in listCas or listCas==[]:
75     synthese[cas]=execute2D(data, cas)
76
77   cas='6'
78   crack['actif']='Ellipse'
79   crack[crack['actif']]={'Rayon':[L/8.], 'Centre':[-L/16., offset, 0.], 'Normale':[0., 1., 0.]}
80   if cas in listCas or listCas==[]:
81     synthese[cas]=execute2D(data, cas)
82
83
84   data['grFace']=['']
85   cas='7'
86   crack['actif']='Sphere'
87   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
88   if cas in listCas or listCas==[]:
89     synthese[cas]=execute2D(data, cas)
90
91   cas='8'
92   crack['actif']='Sphere'
93   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., 0., 0.]}
94   if cas in listCas or listCas==[]:
95     synthese[cas]=execute2D(data, cas)
96
97   data['grFace']=['FACEXM FACEXP']
98   cas='9'
99   crack['actif']='Sphere'
100   crack['Sphere']={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
101   if cas in listCas or listCas==[]:
102     synthese[cas]=execute2D(data, cas)
103
104   # -------- #
105   #  CAS 3D  #
106   # -------- #
107   data['grEdge']=['']
108   data['grFace']=['FACEXP FACEXM FACEYP FACEYM FACEZP FACEZM']
109   data['is2D']=False
110
111   cas='10'
112   crack['actif']='Rectangle'
113   crack[crack['actif']]={'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.], 'Longueur':[L/2.], 'Largeur':[L]}
114   if cas in listCas or listCas==[]:
115     synthese[cas]=execute3D(data, cas)
116
117   cas='11'
118   crack['actif']='Sphere'
119   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
120   if cas in listCas or listCas==[]:
121     synthese[cas]=execute3D(data, cas)
122
123   cas='12'
124   crack['actif']='Ellipse'
125   crack[crack['actif']]={'Centre':[L/4., L/4., L/4.], 'Normale':[1., 1., 1.], 'Rayon':[L]}
126   if cas in listCas or listCas==[]:
127     synthese[cas]=execute3D(data, cas)
128
129   cas='13'
130   crack['actif']='Sphere'
131   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., 0., 0.]}
132   if cas in listCas or listCas==[]:
133     synthese[cas]=execute3D(data, cas)
134
135   cas='14'
136   crack['actif']='Ellipse'
137   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.]}
138   if cas in listCas or listCas==[]:
139     synthese[cas]=execute3D(data, cas)
140
141   cas='15'
142   crack['actif']='Rectangle'
143   crack[crack['actif']]={'Centre':[L/2., 0., 0.], 'Normale':[0., 1., 0.], 'Direction':[-1., 0., 0.],
144                          'Longueur':[L/2.], 'Largeur':[L], 'Rayon entaille':[te*1.5]}
145   if cas in listCas or listCas==[]:
146     synthese[cas]=execute3D(data, cas)
147
148   cas='16'
149   crack['actif']='Rectangle'
150   crack[crack['actif']]={'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
151                          'Longueur':[L/2.], 'Largeur':[L/4.], 'Rayon':[2.*te]}
152   if cas in listCas or listCas==[]:
153     synthese[cas]=execute3D(data, cas)
154
155   cas='17'
156   crack['actif']='Rectangle'
157   crack[crack['actif']]={'Centre':[0., offset, 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
158                          'Longueur':[L/4.]}
159   if cas in listCas or listCas==[]:
160     synthese[cas]=execute3D(data, cas)
161
162   cas='18'
163   crack['actif']='Rectangle'
164   crack[crack['actif']]={'Centre':[0., 0., 0.], 'Normale':[1., 1., 0.], 'Direction':[1., -1., 0.],
165                          'Longueur':[L], 'Angle':[180.]}
166   if cas in listCas or listCas==[]:
167     synthese[cas]=execute3D(data, cas)
168
169
170   data['grVol']=['VOLYP VOLYM']
171
172   cas='19'
173   crack['actif']='Rectangle'
174   crack[crack['actif']]={'Centre':[0., 0., 0.], 'Normale':[0., 1., 0.], 'Direction':[1., 0., 0.],
175                          'Longueur':[L], 'Angle':[180.]}
176   if cas in listCas or listCas==[]:
177     synthese[cas]=execute3D(data, cas)
178
179   data['grVol']=['VOLXP VOLXM']
180
181   cas='20'
182   crack['actif']='Sphere'
183   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[0., 0., 0.]}
184   if cas in listCas or listCas==[]:
185     synthese[cas]=execute3D(data, cas)
186
187   data['grVol']=['VOLYP VOLYM']
188
189   cas='21'
190   crack['actif']='Ellipse'
191   crack[crack['actif']]={'Rayon':[L/4.], 'Centre':[L/2., offset, 0.], 'Normale':[0., 1., 0.]}
192   if cas in listCas or listCas==[]:
193     synthese[cas]=execute3D(data, cas)
194
195   OK=[]
196   NOOK=[]
197   for s in synthese:
198     if synthese[s]:
199       OK.append(s)
200     else:
201       NOOK.append(s)
202
203   print('OK:')
204   print(OK)
205   print(' ')
206   print('NOOK:')
207   print(NOOK)
208   print(' ')
209
210   return(synthese)
211
212
213
214 def execute3D(data, cas):
215   names={'saneGeoName':'cube3D', 'crackGeoName':'crack'+cas, 'crackedGeoName':'cracked'+cas}
216
217   crackMed=os.path.join(tmpdir,'crack'+cas+'.med')
218   crackedMed=os.path.join(tmpdir,'cracked'+cas+'.med')
219
220   saneGeo=os.path.join(tmpdir,names['saneGeoName'],'.geo')
221   crackGeo=os.path.join(tmpdir,names['crackGeoName'],'.geo')
222   crackedGeo=os.path.join(tmpdir,names['crackedGeoName'],'.geo')
223
224   for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
225     if os.path.isfile(f): os.remove(f)
226
227   genereCrack.main(data, crackMed)
228
229   Zset.medToGeo(os.path.join(tmpdir,names['saneGeoName']),names['saneGeoName'], tmpdir)
230   Zset.medToGeo(crackMed, names['crackGeoName'], tmpdir)
231   Zset.insertCrack(data, names, tmpdir)
232   shutil.copy(os.path.join(tmpdir,'_mesh_out_to_ghs3d.mesh'),os.path.join(tmpdir,'mesh'+cas+'.mesh'))
233   shutil.copy(os.path.join(tmpdir,'insert.z7p'),os.path.join(tmpdir,'insert'+cas+'.z7p'))
234
235   Zset.geoToMed(crackedMed, names['crackedGeoName'], tmpdir)
236
237   if os.path.isfile(crackedMed):
238     uF.extendElsets(crackedMed)
239     maxAR=uF.getMaxAspectRatio(tmpdir)
240     return(maxAR<30. and maxAR>=1.)
241   else:
242     return(False)
243
244
245
246 def execute2D(data, cas):
247   names={'saneGeoName':'cube2D', 'crackGeoName':'crack'+cas, 'crackedGeoName':'cracked'+cas}
248
249   crackMed=os.path.join(tmpdir,'crack'+cas+'.med')
250   crackedMed=os.path.join(tmpdir,'cracked'+cas+'.med')
251
252   saneGeo=os.path.join(tmpdir,names['saneGeoName'],'.geo')
253   crackGeo=os.path.join(tmpdir,names['crackGeoName'],'.geo')
254   crackedGeo=os.path.join(tmpdir,names['crackedGeoName'],'.geo')
255
256   for f in [crackMed, crackedMed, saneGeo, crackGeo, crackedGeo]:
257     if os.path.isfile(f): os.remove(f)
258
259   genereCrack.main(data, crackMed)
260
261   Zset.medToGeo(os.path.join(tmpdir,names['saneGeoName']),names['saneGeoName'], tmpdir, opt=['  **to_3d'])
262   Zset.medToGeo(crackMed, names['crackGeoName'], tmpdir)
263   Zset.insertCrack(data, names, tmpdir)
264   shutil.copy(os.path.join(tmpdir,'_mesh_out_.mesh'),os.path.join(tmpdir,'mesh'+cas+'.mesh'))
265   shutil.copy(os.path.join(tmpdir,'insert.z7p'),os.path.join(tmpdir,'insert'+cas+'.z7p'))
266   Zset.geoToMed(crackedMed, names['crackedGeoName'], tmpdir)
267
268   if os.path.isfile(crackedMed):
269     uF.extendElsets(crackedMed)
270     maxAR=uF.getMaxAspectRatio(tmpdir)
271     return(maxAR<30. and maxAR>=1.)
272   else:
273     return(False)
274
275
276
277