Salome HOME
Increment version number (prepare SALOME version 7.0.0)
[modules/hexablock.git] / src / TEST_PY / test_HEXABLOCK.py
1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2012  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import hexablock
22
23
24 # ======================================================== test_sphere
25 def test_sphere ():
26   doc = hexablock.addDocument ("default")
27   orig = doc.addVertex (0,0,0)
28
29   ncouches = 1
30   k = 0.8
31   decal  = doc.addVector (1,1,1)
32   sphere = doc.makeSpherical (orig, decal, ncouches, k)
33
34   for nc in range(ncouches):
35     cell = sphere.getStrate (nc, Q_A)
36     cell.remove ()
37
38   sphere.saveVtk ("sphere.vtk")
39   print "test_sphere OK"
40
41 # ======================================================== test_cartesi1
42 def test_cartesi1 ():
43   size_x = 15
44   size_y = 12
45   size_z = 8
46
47   doc = hexablock.addDocument ()
48   orig = doc.addVertex (0,0,0)
49
50   dirVr = doc.addVector (1,1,1)
51   grid  = doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 ) #CS_NOT_SPEC (makeCartesian1)
52
53    #for (int nz=0 nz<size_z  nz++)
54        #for (int ny=nz+1 ny<size_y-nz-1  ny++)
55            #for (int nx=nz+1 nx<size_x-nz-1  nx++)
56                
57                ##  grid.getHexa (nx, ny, nz).remove ()
58                #Hexa* cell = grid.getHexa (nx, ny, nz)
59                #cell.remove ()
60
61   grid.saveVtk ("hexa1.vtk")
62   print "test_cartesi1 OK"
63   # doc.dump ()
64
65 ## ======================================================== afficher
66 ##define Afficher(elt) afficher (#elt, elt)
67 #def afficher (cpchar nom, EltBase* elt):
68
69    #if (elt==NULL)
70       
71       #printf (" .... %s = 0x0\n", nom)
72       #return HOK
73       
74
75    #printf (" .... %s = 0x%08lx = %03d\n", nom, (unsigned long) elt, elt.getId())
76    #return HOK
77
78 # ======================================================== test_find
79 def test_find ():
80    size_x = 2
81    size_y = 2
82    size_z = 2
83
84    doc = hexablock.addDocument ()
85
86    orig = doc.addVertex (0,0,0)
87    dirVr  = doc.addVector (1,1,1)
88    grid = doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
89
90    grid.saveVtk ("mini1.vtk")
91    #doc.dump()
92
93    v00 = doc.findVertex (0, 0, 0)
94    v02 = doc.findVertex (1, 1, 0)
95    v06 = doc.findVertex (1, 1, 1)
96    v08 = doc.findVertex (2, 1, 0)
97    v10 = doc.findVertex (2, 1, 1)
98    v22 = doc.findVertex (2, 1, 2)
99    v26 = doc.findVertex (2, 2, 2)
100
101    assert v00
102    assert v02
103    assert v06
104    assert v08
105    assert v10
106    assert v22
107    assert v26
108
109    assert doc.findEdge (v06, v10)
110    assert doc.findEdge (v10, v06)
111
112
113    assert doc.findQuad (v02, v10)
114    assert doc.findQuad (v06, v08)
115    assert not doc.findQuad (v02, v06)
116
117
118    assert doc.findHexa (v00, v06)
119    assert doc.findHexa (v06, v26)
120    assert doc.findHexa (v26, v06)
121    print "test_find OK"
122
123 # ======================================================== test_joint
124 def test_joint ():
125   dimx = 11
126   dimy = 11
127   dimz = 2
128   doc = hexablock.addDocument ()
129
130   orig1 = doc.addVertex (0,0,0)
131   dirVr = doc.addVector (1,1,1)
132
133   grid1 = doc.makeCartesian1(orig1, dirVr, dimx,dimy,dimz , 0, 0, 0 )
134
135   orig2 = doc.addVertex  (dimx/2.0,0,8)
136   vectj = doc.addVector (0,1,0)
137   vecti = doc.addVector (1,0,0)
138   grid2 = doc.makeCylindrical (orig2, vecti, vectj, 1, 180, 1,dimz,dimy,dimx, False)
139   
140   mx = dimx/2
141   my = dimy/2
142   prems = grid1.getQuad1 (hexablock.DIR_Z, mx, my, dimz)
143   cible = grid2.getQuad1 (hexablock.DIR_X, dimz, mx, my)
144
145   v1 = prems.getVertex (0)
146   v2 = cible.getVertex (0)
147   v3 = prems.getVertex (1)
148   v4 = cible.getVertex (3)
149
150   liste  = []
151   miroir = []
152
153   liste += [prems]
154   for nx in range (dimx):
155     if ( nx != mx ):
156       liste += [grid1.getQuad1 (hexablock.DIR_Z, nx, my, dimz)]
157
158   for ny in range (dimy):
159     if ( ny != my ):
160       liste += [grid1.getQuad1 (hexablock.DIR_Z, mx, ny, dimz)]
161
162    # Elements* joint = 
163    #
164   doc.joinQuads(liste, cible, v1, v2, v3, v4, 5)
165   doc.saveVtk ("joint.vtk")
166   print "test_joint OK"
167
168 # ======================================================== test_hexa1
169 def test_hexa1 ():
170    size_x = 1
171    size_y = 1
172    size_z = 1
173
174    doc = hexablock.addDocument ()
175    orig  = doc.addVertex (0,0,0)
176    dirVr = doc.addVector (1,1,1)
177    #  Elements*  grid = 
178    doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
179
180    #doc.dump ()
181    print "test_hexa1 OK"
182
183 # ======================================================== test_decoupage
184 def test_decoupage ():
185   size_x = 2
186   size_y = 1
187   size_z = 1
188
189   doc = hexablock.addDocument ()
190
191   orig = doc.addVertex (0,0,0)
192   dirVr = doc.addVector (1,1,1)
193
194   grid  = doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
195   #arete = grid.getEdge ( HEXA_ORB.hexablock.DIR_Z, 0, 0, 0)
196   arete = grid.getEdge1( hexablock.DIR_Z, 0, 0, 0 )
197
198   #doc.dump()
199   doc.saveVtk ("no_decoupe.vtk")
200   doc.cut (arete, 1)
201
202   #doc .dump ()
203   doc .saveVtk ("decoupe.vtk")
204   # doc .saveFile ()
205   print "test_decoupage OK"
206
207 # ======================================================== test_gen_xml
208 def test_gen_xml ():
209
210   size_x = 2
211   size_y = 2
212   size_z = 2
213
214   doc = hexablock.addDocument ()
215
216   orig  = doc.addVertex (0,0,0)
217   dirVr = doc.addVector (1,1,1)
218   grid  = doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
219
220   cell    = grid.getHexa (0)
221   face    = cell.getQuad (0)
222   arete   = cell.getEdge (0)
223   noeud   = cell.getVertex (0)
224
225   #CS_TODO?
226   #shape1 = Shape()
227   #shape2 = Shape()
228   #shape3 = Shape()
229
230   #noeud.setAssociation (shape1)
231   #arete.setAssociation (shape2)
232   #face .setAssociation (shape3)
233
234   law1 = doc.addLaw("loi1", 1)
235   law2 = doc.addLaw("loi2", 2)
236   law3 = doc.addLaw("loi3", 3)
237
238   law1.setKind (hexablock.UNIFORM)
239   law2.setKind (hexablock.ARITHMETIC)
240   law3.setKind (hexablock.GEOMETRIC)
241
242   prop1 = doc.getPropagation (0)
243   prop2 = doc.getPropagation (1)
244   prop3 = doc.getPropagation (2)
245
246   prop1.setLaw (law1)
247   prop2.setLaw (law2)
248   prop3.setLaw (law3)
249
250   prop1.setWay (True)
251   prop2.setWay (False)
252   prop3.setWay (True)
253
254   doc .saveVtk ("mini.vtk")
255   doc .setFile ("Essai")
256   doc .saveFile ()
257   print "test_gen_xml OK"
258
259
260
261 # ======================================================== test_relecture
262 def test_relecture ():
263   doc = hexablock.loadDocument ("Essai")
264
265   #doc .dump ()
266   doc .saveVtk ("restore.vtk")
267   print "test_relecture OK"
268
269 # ======================================================== test_clone
270 def test_clone ():
271   size_x = 2
272   size_y = 2
273   size_z = 2
274   doc = hexablock.addDocument ()
275
276   orig = doc.addVertex (0,0,0)
277   dirVr = doc.addVector (1,1,1)
278   grid  = doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
279
280   bond  = doc.addVector (0, 0, 7)
281   #  Elements* grid2 = doc.makeTranslation (grid, bond)
282   doc.makeTranslation (grid, bond)
283
284   doc.saveVtk ("clonage.vtk")
285   #doc.dump()
286   print "test_clone OK"
287
288 # ======================================================== test_separ
289 def test_separ ():
290   size_x = 2
291   size_y = 2
292   size_z = 2
293
294   doc = hexablock.addDocument ()
295
296   orig  = doc.addVertex (0,0,0)
297   dirVr = doc.addVector (1,1,1)
298
299   doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
300
301   doc .saveVtk ("separ.vtk")
302   #doc .dump()
303   print "test_separ OK"
304
305
306 # ======================================================== test_cyl
307 def test_cyl ():
308   doc = hexablock.addDocument ()
309
310   orig = doc.addVertex (0,0,0)
311   haut = doc.addVector (0,0,1)
312   base = doc.addVector (1,0,0)
313
314   dr = 1
315   # double da = 360 # degres
316   dl = 1
317   nr = 2
318   na = 9
319   nl = 5
320
321   cyl1 = doc.makeCylindrical(orig,base,haut,dr, 360,dl,nr,na,nl)
322   cyl1.saveVtk ("cylindre_full.vtk")
323
324   cyl2 = doc.makeCylindrical(orig,haut,base,dr, 270,dl,nr,na,nl)
325   cyl2.saveVtk ("cylindre_34.vtk")
326
327   # doc.dump ()
328   print "test_cyl OK"
329
330 # ======================================================== test_propagation
331 def test_propagation ():
332   size_x = 2
333   size_y = 1
334   size_z = 1
335
336   doc = hexablock.addDocument ()
337
338   orig = doc.addVertex (0,0,0)
339   dirVr = doc.addVector (1,1,1)
340
341   doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
342
343   nb = doc.countPropagation ()
344
345   for nro in range(nb):
346     prop  = doc .getPropagation (nro)
347     edges = prop.getEdges ()
348     print " ____________________________________ Prop nro %s\n"%nro
349     for e in edges:
350       way = e.getWay ()
351       if (way):
352         print "     (%s,%s)\n"%( e.getVertex(0).name, e.getVertex(1).name )
353       else:
354         print "     (%s,%s)\n"%( e.getVertex(1).name, e.getVertex(0).name )
355
356   #doc.dump  ()
357   doc.saveVtk ("test_propagation.vtk")
358   doc.setFile ("test_propagation")
359   doc.saveFile ()
360   print "test_propagation OK"
361
362
363 # ======================================================== test_move
364 def test_move ():
365   size_x = 1
366   size_y = 1
367   size_z = 2
368
369   doc = hexablock.addDocument ()
370
371   orig  = doc.addVertex (0,0,0)
372   dirVr = doc.addVector (1,1,1)
373   grid  = doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
374
375   enhaut = doc.addVector (0, 0, 5)
376   devant = doc.addVector (5, 0, 0)
377   agauche = doc.addVector (0, 5, 0)
378
379   #CS_TODO?
380   #matrice = Matrix() 
381   #matrice.defTranslation (enhaut)
382
383   cube    = grid.getHexa (1)
384   dessous = cube.getQuad (0)#(Q_A) #CS_TODO?
385   #dessous.dump()
386
387   grid2 = doc.makeTranslation (grid, devant)
388   doc.makeTranslation (grid, agauche)
389   cube2 = grid2.getHexa (1)
390
391   cube .disconnectQuad (dessous)
392   
393   #CS_TODO?
394   #cube .transform( matrice )
395   #cube2.transform( matrice )
396
397
398   doc .saveVtk ("move.vtk")
399   #doc .dump()
400   print "test_move OK, CS_TODO?"
401
402
403
404
405 #test_sphere () KO
406 test_cartesi1 ()
407 test_find ()
408 test_joint ()
409 test_hexa1 ()
410 test_decoupage ()
411 test_gen_xml ()
412 #test_relecture () KO
413 #test_clone ()
414 #test_separ ()
415 #test_cyl ()
416 #test_propagation ()
417 #test_move ()
418