Salome HOME
Passage des cas-tests en moins de 1mn chacun
[modules/smesh.git] / doc / salome / examples / creating_meshes_ex06.py
index d16e067d34f2aa6152bad601e78a13a5320e9544..20b8a043446a54a3dc776bd14da8e30e976c769e 100644 (file)
@@ -1,15 +1,18 @@
 # Creating a hexahedral mesh on a cylinder.
-# Note: it is a copy of 'ex24_cylinder.py' from SMESH_SWIG
+#
+# This example uses Partition to divide the cylinder into blocks, which is
+# a general approach. But for the case of cylinder there is a dedicated
+# command creating a blocked cylinder: geompy.MakeDividedCylinder()
 
 import salome
 salome.salome_init()
 import GEOM
 from salome.geom import geomBuilder
-geompy = geomBuilder.New(salome.myStudy)
+geompy = geomBuilder.New()
 
 import SMESH, SALOMEDS
 from salome.smesh import smeshBuilder
-smesh =  smeshBuilder.New(salome.myStudy)
+smesh =  smeshBuilder.New()
 
 import math
 
@@ -22,7 +25,7 @@ height = 200
 # Build a cylinder
 # ----------------
 
-base = geompy.MakeVertex(0, 0, 0)
+base      = geompy.MakeVertex(0, 0, 0)
 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
 
 cylinder = geompy.MakeCylinder(base, direction, radius, height)
@@ -34,9 +37,9 @@ geompy.addToStudy(cylinder, "cylinder")
 
 size = radius/2.0
 
-box_rot = geompy.MakeBox(-size, -size, 0,  +size, +size, height)
+box_rot  = geompy.MakeBox(-size, -size, 0,  +size, +size, height)
 box_axis = geompy.MakeLine(base, direction)
-box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
+box      = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
 
 hole = geompy.MakeCut(cylinder, box)
 
@@ -47,33 +50,27 @@ plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
 
 blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
 blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
-blocks_all = geompy.MakeCompound(blocks_list)
-blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
+blocks_all  = geompy.MakeCompound(blocks_list)
+blocks      = geompy.MakeGlueFaces(blocks_all, 0.0001)
 
 geompy.addToStudy(blocks, "cylinder:blocks")
 
 # Build geometric groups
 # ----------------------
 
-def group(name, shape, type, base=None, direction=None):
-    t = geompy.ShapeType[type]
-    g = geompy.CreateGroup(shape, t)
+group_a = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
+geompy.addToStudyInFather(blocks, group_a, "baseA")
+items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base, GEOM.ST_ON)
+geompy.UnionIDs(group_a, items)
 
-    geompy.addToStudy(g, name)
-    g.SetName(name)
+base_b = geompy.MakeVertex(0, 0, height)
+group_b = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
+geompy.addToStudyInFather(blocks, group_b, "baseB")
+items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base_b, GEOM.ST_ON)
+geompy.UnionIDs(group_b, items)
 
-    if base!=None:
-        l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
-        geompy.UnionIDs(g, l)
-
-    return g
-
-group_a = group("baseA", blocks, "FACE", base, direction)
-
-base_b  = geompy.MakeVertex(0, 0, height)
-group_b = group("baseB", blocks, "FACE", base_b, direction)
-
-group_1 = group("limit", blocks, "SOLID")
+group_1 = geompy.CreateGroup(blocks, geompy.ShapeType["SOLID"])
+geompy.addToStudyInFather(blocks, group_1, "limit")
 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
 geompy.UnionIDs(group_1, group_1_all)
 group_1_box = geompy.GetBlockNearPoint(blocks, base)
@@ -82,24 +79,36 @@ geompy.DifferenceList(group_1, [group_1_box])
 # Mesh the blocks with hexahedral
 # -------------------------------
 
-smesh.SetCurrentStudy(salome.myStudy)
-
-def discretize(x, y, z,  n, s=blocks):
-    p = geompy.MakeVertex(x, y, z)
-    e = geompy.GetEdgeNearPoint(s, p)
-    a = hexa.Segment(e)
-    a.NumberOfSegments(n)
-    a.Propagation()
+smesh.UpdateStudy()
 
 hexa = smesh.Mesh(blocks)
 
 hexa_1d = hexa.Segment()
 hexa_1d.NumberOfSegments(1)
 
-discretize(+radius        , +radius,        0,   5)
-discretize(-radius        , +radius,        0,   8)
-discretize((radius+size)/2,       0,        0,  10)
-discretize(        +radius,       0, height/2,  20)
+vertex = geompy.MakeVertex(+radius, +radius, 0)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(5)
+algo.Propagation()
+
+vertex = geompy.MakeVertex(-radius, +radius, 0)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(8)
+algo.Propagation()
+
+vertex = geompy.MakeVertex((radius+size)/2, 0, 0)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(10)
+algo.Propagation()
+
+vertex = geompy.MakeVertex(+radius, 0, height/2)
+edge = geompy.GetEdgeNearPoint(blocks, vertex)
+algo = hexa.Segment(edge)
+algo.NumberOfSegments(20)
+algo.Propagation()
 
 hexa.Quadrangle()
 hexa.Hexahedron()