1 # Creating a hexahedral mesh on a cylinder.
3 # This example uses Partition to divide the cylinder into blocks, which is
4 # a general approach. But for the case of cylinder there is a dedicated
5 # command creating a blocked cylinder: geompy.MakeDividedCylinder()
10 from salome.geom import geomBuilder
11 geompy = geomBuilder.New(salome.myStudy)
13 import SMESH, SALOMEDS
14 from salome.smesh import smeshBuilder
15 smesh = smeshBuilder.New(salome.myStudy)
28 base = geompy.MakeVertex(0, 0, 0)
29 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
31 cylinder = geompy.MakeCylinder(base, direction, radius, height)
33 geompy.addToStudy(cylinder, "cylinder")
40 box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
41 box_axis = geompy.MakeLine(base, direction)
42 box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
44 hole = geompy.MakeCut(cylinder, box)
48 plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
49 plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
51 blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
52 blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
53 blocks_all = geompy.MakeCompound(blocks_list)
54 blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
56 geompy.addToStudy(blocks, "cylinder:blocks")
58 # Build geometric groups
59 # ----------------------
61 def group(name, shape, type, base=None, direction=None):
62 t = geompy.ShapeType[type]
63 g = geompy.CreateGroup(shape, t)
65 geompy.addToStudy(g, name)
69 l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
74 group_a = group("baseA", blocks, "FACE", base, direction)
76 base_b = geompy.MakeVertex(0, 0, height)
77 group_b = group("baseB", blocks, "FACE", base_b, direction)
79 group_1 = group("limit", blocks, "SOLID")
80 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
81 geompy.UnionIDs(group_1, group_1_all)
82 group_1_box = geompy.GetBlockNearPoint(blocks, base)
83 geompy.DifferenceList(group_1, [group_1_box])
85 # Mesh the blocks with hexahedral
86 # -------------------------------
88 smesh.SetCurrentStudy(salome.myStudy)
90 def discretize(x, y, z, n, s=blocks):
91 p = geompy.MakeVertex(x, y, z)
92 e = geompy.GetEdgeNearPoint(s, p)
97 hexa = smesh.Mesh(blocks)
99 hexa_1d = hexa.Segment()
100 hexa_1d.NumberOfSegments(1)
102 discretize(+radius , +radius, 0, 5)
103 discretize(-radius , +radius, 0, 8)
104 discretize((radius+size)/2, 0, 0, 10)
105 discretize( +radius, 0, height/2, 20)