1 # -*- coding: latin-1 -*-
2 # Copyright (C) 2009-2012 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # ======================================================== test_sphere
26 doc = hexablock.addDocument ("default")
27 orig = doc.addVertex (0,0,0)
31 decal = doc.addVector (1,1,1)
32 sphere = doc.makeSpherical (orig, decal, ncouches, k)
34 for nc in range(ncouches):
35 cell = sphere.getStrate (nc, Q_A)
38 sphere.saveVtk ("sphere.vtk")
39 print "test_sphere OK"
41 # ======================================================== test_cartesi1
47 doc = hexablock.addDocument ()
48 orig = doc.addVertex (0,0,0)
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)
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++)
57 ## grid.getHexa (nx, ny, nz).remove ()
58 #Hexa* cell = grid.getHexa (nx, ny, nz)
61 grid.saveVtk ("hexa1.vtk")
62 print "test_cartesi1 OK"
65 ## ======================================================== afficher
66 ##define Afficher(elt) afficher (#elt, elt)
67 #def afficher (cpchar nom, EltBase* elt):
71 #printf (" .... %s = 0x0\n", nom)
75 #printf (" .... %s = 0x%08lx = %03d\n", nom, (unsigned long) elt, elt.getId())
78 # ======================================================== test_find
84 doc = hexablock.addDocument ()
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 )
90 grid.saveVtk ("mini1.vtk")
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)
109 assert doc.findEdge (v06, v10)
110 assert doc.findEdge (v10, v06)
113 assert doc.findQuad (v02, v10)
114 assert doc.findQuad (v06, v08)
115 assert not doc.findQuad (v02, v06)
118 assert doc.findHexa (v00, v06)
119 assert doc.findHexa (v06, v26)
120 assert doc.findHexa (v26, v06)
123 # ======================================================== test_joint
128 doc = hexablock.addDocument ()
130 orig1 = doc.addVertex (0,0,0)
131 dirVr = doc.addVector (1,1,1)
133 grid1 = doc.makeCartesian1(orig1, dirVr, dimx,dimy,dimz , 0, 0, 0 )
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)
142 prems = grid1.getQuad1 (hexablock.DIR_Z, mx, my, dimz)
143 cible = grid2.getQuad1 (hexablock.DIR_X, dimz, mx, my)
145 v1 = prems.getVertex (0)
146 v2 = cible.getVertex (0)
147 v3 = prems.getVertex (1)
148 v4 = cible.getVertex (3)
154 for nx in range (dimx):
156 liste += [grid1.getQuad1 (hexablock.DIR_Z, nx, my, dimz)]
158 for ny in range (dimy):
160 liste += [grid1.getQuad1 (hexablock.DIR_Z, mx, ny, dimz)]
164 doc.joinQuads(liste, cible, v1, v2, v3, v4, 5)
165 doc.saveVtk ("joint.vtk")
166 print "test_joint OK"
168 # ======================================================== test_hexa1
174 doc = hexablock.addDocument ()
175 orig = doc.addVertex (0,0,0)
176 dirVr = doc.addVector (1,1,1)
178 doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
181 print "test_hexa1 OK"
183 # ======================================================== test_decoupage
184 def test_decoupage ():
189 doc = hexablock.addDocument ()
191 orig = doc.addVertex (0,0,0)
192 dirVr = doc.addVector (1,1,1)
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 )
199 doc.saveVtk ("no_decoupe.vtk")
203 doc .saveVtk ("decoupe.vtk")
205 print "test_decoupage OK"
207 # ======================================================== test_gen_xml
214 doc = hexablock.addDocument ()
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 )
220 cell = grid.getHexa (0)
221 face = cell.getQuad (0)
222 arete = cell.getEdge (0)
223 noeud = cell.getVertex (0)
230 #noeud.setAssociation (shape1)
231 #arete.setAssociation (shape2)
232 #face .setAssociation (shape3)
234 law1 = doc.addLaw("loi1", 1)
235 law2 = doc.addLaw("loi2", 2)
236 law3 = doc.addLaw("loi3", 3)
238 law1.setKind (hexablock.UNIFORM)
239 law2.setKind (hexablock.ARITHMETIC)
240 law3.setKind (hexablock.GEOMETRIC)
242 prop1 = doc.getPropagation (0)
243 prop2 = doc.getPropagation (1)
244 prop3 = doc.getPropagation (2)
254 doc .saveVtk ("mini.vtk")
255 doc .setFile ("Essai")
257 print "test_gen_xml OK"
261 # ======================================================== test_relecture
262 def test_relecture ():
263 doc = hexablock.loadDocument ("Essai")
266 doc .saveVtk ("restore.vtk")
267 print "test_relecture OK"
269 # ======================================================== test_clone
274 doc = hexablock.addDocument ()
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 )
280 bond = doc.addVector (0, 0, 7)
281 # Elements* grid2 = doc.makeTranslation (grid, bond)
282 doc.makeTranslation (grid, bond)
284 doc.saveVtk ("clonage.vtk")
286 print "test_clone OK"
288 # ======================================================== test_separ
294 doc = hexablock.addDocument ()
296 orig = doc.addVertex (0,0,0)
297 dirVr = doc.addVector (1,1,1)
299 doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
301 doc .saveVtk ("separ.vtk")
303 print "test_separ OK"
306 # ======================================================== test_cyl
308 doc = hexablock.addDocument ()
310 orig = doc.addVertex (0,0,0)
311 haut = doc.addVector (0,0,1)
312 base = doc.addVector (1,0,0)
315 # double da = 360 # degres
321 cyl1 = doc.makeCylindrical(orig,base,haut,dr, 360,dl,nr,na,nl)
322 cyl1.saveVtk ("cylindre_full.vtk")
324 cyl2 = doc.makeCylindrical(orig,haut,base,dr, 270,dl,nr,na,nl)
325 cyl2.saveVtk ("cylindre_34.vtk")
330 # ======================================================== test_propagation
331 def test_propagation ():
336 doc = hexablock.addDocument ()
338 orig = doc.addVertex (0,0,0)
339 dirVr = doc.addVector (1,1,1)
341 doc.makeCartesian1 (orig, dirVr, size_x,size_y,size_z, 0, 0, 0 )
343 nb = doc.countPropagation ()
345 for nro in range(nb):
346 prop = doc .getPropagation (nro)
347 edges = prop.getEdges ()
348 print " ____________________________________ Prop nro %s\n"%nro
352 print " (%s,%s)\n"%( e.getVertex(0).name, e.getVertex(1).name )
354 print " (%s,%s)\n"%( e.getVertex(1).name, e.getVertex(0).name )
357 doc.saveVtk ("test_propagation.vtk")
358 doc.setFile ("test_propagation")
360 print "test_propagation OK"
363 # ======================================================== test_move
369 doc = hexablock.addDocument ()
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 )
375 enhaut = doc.addVector (0, 0, 5)
376 devant = doc.addVector (5, 0, 0)
377 agauche = doc.addVector (0, 5, 0)
381 #matrice.defTranslation (enhaut)
383 cube = grid.getHexa (1)
384 dessous = cube.getQuad (0)#(Q_A) #CS_TODO?
387 grid2 = doc.makeTranslation (grid, devant)
388 doc.makeTranslation (grid, agauche)
389 cube2 = grid2.getHexa (1)
391 cube .disconnectQuad (dessous)
394 #cube .transform( matrice )
395 #cube2.transform( matrice )
398 doc .saveVtk ("move.vtk")
400 print "test_move OK, CS_TODO?"
412 #test_relecture () KO