From a507bbc954994ebabdc91141619465ced04c75fe Mon Sep 17 00:00:00 2001 From: abuhsing Date: Tue, 28 Jan 2014 11:31:53 +0000 Subject: [PATCH] Ajout de cas-tests unitaires --- src/TEST_PY/test_v6/makeCartesianTop.py | 8 ++ src/TEST_PY/test_v6/makeCylinderTop.py | 31 +++++ src/TEST_PY/test_v6/makePipeTop.py | 8 ++ src/TEST_PY/test_v6/makeRindTop.py | 8 ++ src/TEST_PY/test_v6/makeRindUni.py | 23 ++++ src/TEST_PY/test_v6/makeSphere.py | 20 +++ src/TEST_PY/test_v6/makeSphereTop.py | 8 ++ src/TEST_PY/test_v6/makeSphereUni.py | 22 +++ src/TEST_PY/test_v6/monica.py | 174 ++++++++++++++++++++++++ src/TEST_PY/test_v6/test_cone.py | 80 +++++++++++ 10 files changed, 382 insertions(+) create mode 100644 src/TEST_PY/test_v6/makeCartesianTop.py create mode 100644 src/TEST_PY/test_v6/makeCylinderTop.py create mode 100644 src/TEST_PY/test_v6/makePipeTop.py create mode 100644 src/TEST_PY/test_v6/makeRindTop.py create mode 100644 src/TEST_PY/test_v6/makeRindUni.py create mode 100644 src/TEST_PY/test_v6/makeSphere.py create mode 100644 src/TEST_PY/test_v6/makeSphereTop.py create mode 100644 src/TEST_PY/test_v6/makeSphereUni.py create mode 100755 src/TEST_PY/test_v6/monica.py create mode 100644 src/TEST_PY/test_v6/test_cone.py diff --git a/src/TEST_PY/test_v6/makeCartesianTop.py b/src/TEST_PY/test_v6/makeCartesianTop.py new file mode 100644 index 0000000..4fbc0fd --- /dev/null +++ b/src/TEST_PY/test_v6/makeCartesianTop.py @@ -0,0 +1,8 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +doc.makeCartesianTop (6, 4, 2) + +doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/makeCylinderTop.py b/src/TEST_PY/test_v6/makeCylinderTop.py new file mode 100644 index 0000000..030719a --- /dev/null +++ b/src/TEST_PY/test_v6/makeCylinderTop.py @@ -0,0 +1,31 @@ + +import hexablock + +# ================================================ rename +def rename (elt, pref, indices) : + if elt == None : return + elt.setName (pref + indices) +# ================================================ begin +doc = hexablock.addDocument ("model") +nr = 3 +na = 8 +nh = 3 + +grid = doc.makeCylinderTop (nr, na, nh) +for i in range (nr+1) : + for j in range (na) : + for k in range (nh+1) : + name = "(%d,%d,%d)" % (i,j,k) + vertex = grid.getVertexIJK (i,j,k) + ei = grid.getEdgeI (i,j,k) + ej = grid.getEdgeJ (i,j,k) + ek = grid.getEdgeK (i,j,k) + rename (vertex, 'v', name) + rename (ei, 'ei', name) + rename (ej, 'ej', name) + rename (ek, 'ek', name) + +doc.save ("cylinder") +doc.saveVtk ("cylinder.vtk") +doc.addLaws (1, True) +mesh_hexas = hexablock.mesh(doc) diff --git a/src/TEST_PY/test_v6/makePipeTop.py b/src/TEST_PY/test_v6/makePipeTop.py new file mode 100644 index 0000000..917d6a1 --- /dev/null +++ b/src/TEST_PY/test_v6/makePipeTop.py @@ -0,0 +1,8 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +doc.makePipeTop (3, 8, 3) + +### doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/makeRindTop.py b/src/TEST_PY/test_v6/makeRindTop.py new file mode 100644 index 0000000..bd86360 --- /dev/null +++ b/src/TEST_PY/test_v6/makeRindTop.py @@ -0,0 +1,8 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +doc.makeRindTop (3, 8, 6) + +## doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/makeRindUni.py b/src/TEST_PY/test_v6/makeRindUni.py new file mode 100644 index 0000000..41738ea --- /dev/null +++ b/src/TEST_PY/test_v6/makeRindUni.py @@ -0,0 +1,23 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +center = doc.addVertex (0,0,0) +vx = doc.addVector (1,0,0) +vz = doc.addVector (0,0,1) + +rhole = 1.0 +rint = 3.0 +rext = 4.0 +angle = 180.0 + +nr = 3 +na = 8 +nh = 6 + +vplan = doc.addVertex (0, 0, -rext*0.7) + +doc.makeRindUni (center,vx,vz, rhole,rint,rext, angle,vplan,nr,na,nh) + +## doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/makeSphere.py b/src/TEST_PY/test_v6/makeSphere.py new file mode 100644 index 0000000..eb3343d --- /dev/null +++ b/src/TEST_PY/test_v6/makeSphere.py @@ -0,0 +1,20 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +center = doc.addVertex (0,0,0) +vx = doc.addVector (1,0,0) +vz = doc.addVector (0,0,1) + +rhole = 1.0 +rext = 4.0 +angle = 260.0 + +trayons = [ 1, 2, 3 , 4 ] +tangles = [ 0, 30, 60, 90, 120, 150, 180] +tphi = [ -30, -10, 0, 10, 30, 45, 60, 75, 80 ] + +doc.makeSphere (center,vx,vz, trayons, tangles, tphi) + +doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/makeSphereTop.py b/src/TEST_PY/test_v6/makeSphereTop.py new file mode 100644 index 0000000..639fb38 --- /dev/null +++ b/src/TEST_PY/test_v6/makeSphereTop.py @@ -0,0 +1,8 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +doc.makeSphereTop (3, 8, 6) + +doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/makeSphereUni.py b/src/TEST_PY/test_v6/makeSphereUni.py new file mode 100644 index 0000000..9abb8ee --- /dev/null +++ b/src/TEST_PY/test_v6/makeSphereUni.py @@ -0,0 +1,22 @@ + +import hexablock + +doc = hexablock.addDocument ("model") + +center = doc.addVertex (0,0,0) +vx = doc.addVector (1,0,0) +vz = doc.addVector (0,0,1) + +rhole = 1.0 +rext = 4.0 +angle = 260.0 + +nr = 3 +na = 8 +nh = 6 + +vplan = doc.addVertex (0, 0, -rext*0.5) + +doc.makeSphereUni (center,vx,vz, rhole,rext,angle,vplan, nr,na,nh) + +doc.saveVtk ("model1.vtk") diff --git a/src/TEST_PY/test_v6/monica.py b/src/TEST_PY/test_v6/monica.py new file mode 100755 index 0000000..2fb80ba --- /dev/null +++ b/src/TEST_PY/test_v6/monica.py @@ -0,0 +1,174 @@ +# !/bin/python +# -*- coding: latin-1 -*- +# Hexa : Creation d'hexaedres + +import hexablock +import os + +#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 + +doc = hexablock.addDocument ("default") +vx = doc.addVector (1,0,0) +vy = doc.addVector (0,1,0) +vz = doc.addVector (0,0,1) + +vxy = doc.addVector (1,1,0) + +nbr_files = 0 + + +# ======================================================= save_vtk +def save_vtk () : + + global nbr_files + nom = "monica%d.vtk" % nbr_files + nbr_files += 1 + doc.saveVtk (nom) + +# ======================================================= carre +def carre (x) : + return x*x + +# ======================================================= get_center +def get_center (quad) : + px = 0 + py = 0 + pz = 0 + for nv in range (4) : + vertex = quad.getVertex (nv) + px += vertex.getX() / 4 + py += vertex.getY() / 4 + pz += vertex.getZ() / 4 + return [ px, py, pz ] +# ======================================================= nearest +def nearest (grid, vertex) : + nbre = grid.countVertex() + dmin = 1e+6 + result = None + px = vertex.getX() + py = vertex.getY() + pz = vertex.getZ() + for nro in range (nbre) : + v1 = grid.getVertex (nro) + d2 = carre(px-v1.getX()) + carre(py-v1.getY()) + carre(pz-v1.getZ()) + if (d2 < dmin) : + result = v1 + dmin = d2 + + print vertex.getName () , px, py, pz, " -> ", result.getName() + return result + +# ======================================================= nearest_quad +def nearest_quad (grid, quad) : + dmin = 1e+16 + result = None + [ox, oy, oz] = get_center (quad) + nbre = grid.countQuad () + for nro in range (nbre) : + q1 = grid.getQuad (nro) + if q1 != None : + [px, py, pz] = get_center (q1) + d2 = carre(px-ox) + carre(py-oy) + carre(pz-oz) + if (d2 < dmin) : + result = q1 + dmin = d2 + + print quad.getName () , px, py, pz, " -> ", result.getName() + return result + +# ======================================================= insert_cylinder +def insert_cylinder (plaque, nx, ny) : + + hexa = plaque.getHexaIJK (nx, ny, 0) + xmin = 666 ; ymin = xmin ; zmin = xmin + xmax = -666 ; ymax = xmax ; zmax = xmax + + tabv1 = [] + for nv in range (8) : + node = hexa.getVertex (nv) + xmin = min (xmin, node.getX()) ; xmax = max (xmax, node.getX()) + ymin = min (ymin, node.getY()) ; ymax = max (ymax, node.getY()) + zmin = min (zmin, node.getZ()) ; zmax = max (zmax, node.getZ()) + tabv1.append (node) + + doc.removeHexa (hexa) + save_vtk () + + dx = (xmax - xmin)/2 + dz = (zmax - zmin)/2 + xorig = (xmin + xmax)/2 + yorig = (ymin + ymax)/2 + zorig = (zmin + zmax)/2 - 3*dz + + orig = doc.addVertex (xorig, yorig, zorig) + nr = 1 + na = 4 + nh = 3 + rext = dx + rint = rext/3 + haut = 3 + angle = 360 + pipe = doc.makePipeUni (orig, vxy,vz, rint,rext,angle,haut, nr,na,nh) + + hexablock.what () + + tabquad = [] + tabv0 = [] + for nq in range (4) : + quad = pipe.getQuadJK (1, nq, 1) + tabquad.append (quad) + + print " .. tabquad[0] = ", tabquad[0].getName () + cible = nearest_quad (plaque, tabquad[0]) + tabquad[0]. setColor (5) + cible . setColor (5) + save_vtk () + + va1 = tabquad[0].getVertex (0) + va2 = tabquad[0].getVertex (1) + vb1 = cible.nearestVertex (va1) + vb2 = cible.nearestVertex (va2) + doc.setLevel (1) + doc.joinQuadsUni (tabquad, cible, va1, vb1, va2, vb2, 1) + hexablock.what () + save_vtk () + + return + doc.setLevel (1) + for nv in range (8) : + ier = doc.mergeVertices (tabv0[nv], tabv1[nv]) + print "ier = ", ier + save_vtk () + + +# ======================================================= test_monica +def test_monica () : + + orig = doc.addVertex (0,0,0) + + lx = 1 + ly = lx + lz = lx + nx = 3 + ny = nx + nz = 1 + + plaque = doc.makeCartesianUni (orig, vx,vy,vz, lx, ly, lz, nx,ny,nz) + save_vtk () + + insert_cylinder (plaque, 1, 1) + ## hexa = plaque.getHexaIJK (1,1,0) + ## doc.removeHexa (hexa) + return doc + +# ================================================================= Begin + +doc = test_monica () + +law = doc.addLaw("Uniform", 4) + +for j in range(doc.countPropagation()): + propa = doc.getPropagation(j) + propa.setLaw(law) + +mesh_hexas = hexablock.mesh (doc) diff --git a/src/TEST_PY/test_v6/test_cone.py b/src/TEST_PY/test_v6/test_cone.py new file mode 100644 index 0000000..1e6e2ff --- /dev/null +++ b/src/TEST_PY/test_v6/test_cone.py @@ -0,0 +1,80 @@ +# -*- coding: latin-1 -*- +# Hexa : Creation d'hexaedres + +# Copyright (C) 2009-2012 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ +# or email : webmaster.salome@opencascade.com +# + +import hexablock +### import os +### import geompy +geompy = hexablock.geompy + +#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 + + +doc = hexablock.addDocument ("test_cone") + +orig = doc.addVertex (0, 0, 0) +ori2 = doc.addVertex (0, 0, 10) +vz = doc.addVector (0, 0, 1) +vx = doc.addVector (1 ,0, 0) + +rad1 = 4.0 +rad2 = 2.0 +height = 5.0 +angle = 270.0 +hollow = False + +nr = 2 +na = 8 +nl = 1 + +c1 = doc.makePipeUni (orig, vx,vz, rad1/2, rad1, angle, height, nr,na,nl) +c2 = doc.makePipeUni (ori2, vx,vz, rad2/2, rad2, angle, height, nr,na,nl) + + ### -------- We prepare a joint .... +vh0 = c2.getVertexIJK (0, 0, 0) +vh1 = c2.getVertexIJK (1, 0, 0) + +vb0 = c1.getVertexIJK (0, 0, nl) +vb1 = c1.getVertexIJK (1, 0, nl) + +qcible = c2.getQuadIJ (0, 0, 0) +qliste = [] +for ni in range (nr) : + for nj in range (na) : + quad = c1.getQuadIJ (ni, nj, nl) + qliste.append (quad) + + ### -------- Join quads to make a cone between the 2 cylinders +doc.joinQuadsUni (qliste, qcible, vb0, vh0, vb1, vh1, 1) + + ### -------------------- Mesh + +doc.save ("test_cones") + +law = doc.addLaw ("Uniform", 4) + +for np in range(doc.countPropagation()): + propa = doc.getPropagation (np) + propa.setLaw (law) + +mesh_hexas = hexablock.mesh(doc) + -- 2.39.2