Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / TEST_PY / recettes / troisCylindres.py
index 3fcf56ea71acdec5127d5a2b092073138a2e4023..80ffbbe00b8cda5c0327d8a1e8ba6cdd1cca74d3 100644 (file)
@@ -1,10 +1,10 @@
 # -*- coding: latin-1 -*-
-# Copyright (C) 2009-2012  CEA/DEN, EDF R&D
+# Copyright (C) 2009-2024  CEA, EDF
 #
 # 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.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # Francis KLOSS : 2012 : CEA-Saclay, DEN, DM2S, SFME, LGLS, F-91191 Gif-sur-Yvette, France
 # ========================================================================================
 
-import geompy
 import hexablock
+#### import geompy
+geompy = hexablock.geompy
 
-# Charger la géométrie
+# Charger la geometrie
 # ====================
 
 nom = "troisCylindres"
 
 piece = geompy.ImportBREP(nom+".brep")
 
-# Sélectionner des sous-parties de la géométrie
+# Selectionner des sous-parties de la geometrie
 # ---------------------------------------------
 
 sommets = geompy.SubShapeAllSortedCentres(piece, geompy.ShapeType["VERTEX"])
@@ -49,12 +50,12 @@ moyen0, moyen_x , moyen_y , moyen_z ,  moyen1, moyen2, moyen3,  moyen_rayon = ge
 petit0, petit_xb, petit_yb, petit_zb,  petit1, petit2, petit3,  petit_rayon = geompy.KindOfShape(aretes[12])
 petit4, petit_xh, petit_yh, petit_zh,  petit5, petit6, petit7,  petit8      = geompy.KindOfShape(aretes[13])
 
-# Construire le modèle de bloc
+# Construire le modele de bloc
 # ============================
 
 doc = hexablock.addDocument(nom)
 
-doc.setShape(piece)
+### doc.addShape(piece,nom)
 
 # Construire le grand cylindre
 # ----------------------------
@@ -66,9 +67,9 @@ grand_dir = doc.addVectorVertices(grand_base, grand_oppo)
 
 grand_hauteur = grand_dir.getNorm()
 
-grand_cylindre = doc.addCylinder(grand_base, grand_dir, grand_rayon, grand_hauteur)
+###  grand_cylindre = doc.addCylinder(grand_base, grand_dir, grand_rayon, grand_hauteur)
 
-# Construire le moyen cylindre coté grand
+# Construire le moyen cylindre cote grand
 # ---------------------------------------
 
 moy_g_r1 = 0.8
@@ -85,9 +86,9 @@ moy_g_dir = doc.addVectorVertices(moy_g_base, moy_g_oppo)
 
 moy_g_hauteur = moy_g_dir.getNorm()
 
-moy_g_cylindre = doc.addCylinder(moy_g_base, moy_g_dir, moyen_rayon, moy_g_hauteur)
+###  moy_g_cylindre = doc.addCylinder(moy_g_base, moy_g_dir, moyen_rayon, moy_g_hauteur)
 
-# Construire le moyen cylindre coté petit
+# Construire le moyen cylindre cote petit
 # ---------------------------------------
 
 moy_p_r = 0.18
@@ -98,9 +99,9 @@ moy_p_oppo = doc.addVertex( moy_p_x+(moy_g_x-moy_p_x) * moy_p_r, moy_p_y+(moy_g_
 
 moy_p_dir = doc.addVectorVertices(moy_b_base, moy_p_oppo)
 
-moy_p_hauteur = moy_p_dir.getNorm()
+moy_p_hauteur = moy_p_dir.getNorm()*1.2
 
-moy_p_cylindre = doc.addCylinder(moy_p_base, moy_p_dir, moyen_rayon, moy_p_hauteur)
+###  moy_p_cylindre = doc.addCylinder(moy_p_base, moy_p_dir, moyen_rayon, moy_p_hauteur)
 
 # Construire le petit cylindre
 # ----------------------------
@@ -108,100 +109,73 @@ moy_p_cylindre = doc.addCylinder(moy_p_base, moy_p_dir, moyen_rayon, moy_p_haute
 petit_base = doc.addVertex(petit_xb, petit_yb, petit_zb)
 petit_oppo = doc.addVertex(petit_xh, petit_yh, petit_zh)
 
-petit_dir = doc.addVectorVertices(petit_base, petit_oppo)
+petit_dir  = doc.addVectorVertices(petit_base, petit_oppo)
 
 petit_hauteur = petit_dir.getNorm()
 
-petit_cylindre = doc.addCylinder(petit_base, petit_dir, petit_rayon, petit_hauteur)
+###  petit_cylindre = doc.addCylinder(petit_base, petit_dir, petit_rayon, petit_hauteur)
 
 # Construire le T et la X
 # -----------------------
 
-en_te = doc.makeCylinders(grand_cylindre, moy_g_cylindre)
-croix = doc.makeCylinders(moy_p_cylindre, petit_cylindre)
+en_te = doc.makeCylinders (grand_base, grand_dir, grand_rayon, grand_hauteur, 
+                           moy_g_base, moy_g_dir, moyen_rayon, moy_g_hauteur)
 
-# Relier le T et la X
-# -------------------
-
-croix_quads = []
-
-for i in xrange(1, -1, -1):
-    for j in xrange( [hexablock.CV_MAXI_INT, hexablock.CV_MAXI_EXT][i] ):
-        quad = croix.getQuadIJ(hexablock.CYL_BIG, i, j, hexablock.CYL_BIG_SLICES)
-        croix_quads.append(quad)
-
-en_te_q = en_te.getQuadIJ(hexablock.CYL_SMALL, 1, hexablock.V_N, 0)
+hexablock.what ()
 
-en_te_v0 = en_te.getVertexIJK(hexablock.CYL_SMALL, 2, hexablock.V_N , 0)
-en_te_v1 = en_te.getVertexIJK(hexablock.CYL_SMALL, 2, hexablock.V_NW, 0)
+croix = doc.makeCylinders (moy_p_base, moy_p_dir, moyen_rayon, moy_p_hauteur,
+                           petit_base, petit_dir, petit_rayon, petit_hauteur)
 
-croix_v0 = croix.getVertexIJK(hexablock.CYL_BIG, 2, hexablock.V_E , hexablock.CYL_BIG_SLICES)
-croix_v1 = croix.getVertexIJK(hexablock.CYL_BIG, 2, hexablock.V_NE, hexablock.CYL_BIG_SLICES)
-
-prisme = doc.joinQuads(croix_quads, en_te_q,  croix_v0, en_te_v0,  croix_v1, en_te_v1,  1)
-
-# Associer
-# ========
+hexablock.what ()
 
-# fkl: comme pour la tuyauterie: associer pour le prisme (sauf si item 142 et 146 de Taches.ods)
-
-# Mailler le modèle de bloc
-# =========================
+# Relier le T et la X
+# -------------------
 
-# Définir 5 groupes de faces
-# --------------------------
+CYL_SMALL  = 0
+CYL_BIG    = 1
+CYL_KMAX   = 3
+CYL_JMAX   = 4
 
-groupe_grand_a = doc.addQuadGroup("Grand_A")
-groupe_grand_b = doc.addQuadGroup("Grand_B")
-groupe_moyen_f = doc.addQuadGroup("Moyen")
-groupe_petit_a = doc.addQuadGroup("Petit_A")
-groupe_petit_b = doc.addQuadGroup("Petit_B")
 
-for i in xrange(2):
-    for j in xrange( [hexablock.CV_MAXI_INT, hexablock.CV_MAXI_EXT][i] ):
-        quad = en_te.getQuadIJ(hexablock.CYL_BIG  , i, j, 0)
-        groupe_grand_a.addElement(quad)
+qstart = croix.getQuadIJ (CYL_BIG, 0,0,CYL_KMAX)
+##  qstart.setColor(5)
+croix_quads = [qstart]
 
-        quad = en_te.getQuadIJ(hexablock.CYL_BIG  , i, j, hexablock.CYL_BIG_SLICES)
-        groupe_grand_b.addElement(quad)
+for nj in range (CYL_JMAX) :
+    quad = croix.getQuadIJ (CYL_BIG, 1,nj, CYL_KMAX)
+    quad.setColor(5)
+    croix_quads.append (quad)
 
-        quad = croix.getQuadIJ(hexablock.CYL_BIG  , i, j, 0)
-        groupe_moyen_f.addElement(quad)
+qdest = en_te.getQuadIJ (CYL_SMALL, 0,0,0)
+qdest.setColor(5)
 
-        quad = croix.getQuadIJ(hexablock.CYL_SMALL, i, j, 0)
-        groupe_petit_a.addElement(quad)
+va1 = qstart.getVertex (0)
+va2 = qstart.getVertex (1)
 
-        quad = croix.getQuadIJ(hexablock.CYL_SMALL, i, j, hexablock.CYL_SMALL_SLICES)
-        groupe_petit_b.addElement(quad)
+vb1 = qdest.nearestVertex (va1)
+vb2 = qdest.nearestVertex (va2)
 
-# Définir 3 groupes de volumes
-# ----------------------------
+prisme = doc.joinQuadsUni (croix_quads, qdest, va1,vb1,va2,vb2, 1)
 
-groupe_grand = doc.addHexaGroup("Grand")
-groupe_moyen = doc.addHexaGroup("Moyen")
-groupe_petit = doc.addHexaGroup("Petit")
+# Associer
+# ========
 
-for i in xrange( doc.countUsedHexa() ):
-    h = doc.getUsedHexa(i)
-    groupe_moyen.addElement(h)
 
-for i in xrange(2):
-    for j in xrange( [hexablock.CV_MAXI_INT, hexablock.CV_MAXI_EXT][i] ):
-        for k in [ 0, hexablock.CYL_BIG_SLICES-1 ]:
-            h = en_te.getHexaIJK(hexablock.CYL_BIG, i, j, k)
-            groupe_grand.addElement(h)
-            groupe_moyen.removeElement(h)
+# Mailler le modele de bloc avec association
+# ------------------------------------------
 
-        for k in [0, hexablock.CYL_SMALL_SLICES-1 ]:
-            h = croix.getHexaIJK(hexablock.CYL_SMALL, i, j, k)
-            groupe_petit.addElement(h)
-            groupe_moyen.removeElement(h)
+doc.addLaws(10, True)
 
-# Mailler le modèle de bloc avec association
-# ------------------------------------------
+law = doc.addLaw("Uniform", 4)
+for j in range(doc.countPropagation()):
+    propa = doc.getPropagation(j)
+    propa.setLaw(law)
 
-hexablock.addLaws(doc, 10, True)
+doc.save("troisCylindres")
+doc.setName("troisCylindres")
+doc.saveVtk("troisCylindres1.vtk")
+hexablock.addToStudy(doc)
 
-blocs = hexablock.mesh(doc)
+blocs = hexablock.mesh(doc, dim=3)
 
 muv, mue, muq, muh = hexablock.dump(doc, blocs)