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()
13 import SMESH, SALOMEDS
14 from salome.smesh import smeshBuilder
15 smesh = smeshBuilder.New()
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 group_a = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
62 geompy.addToStudyInFather(blocks, group_a, "baseA")
63 items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base, GEOM.ST_ON)
64 geompy.UnionIDs(group_a, items)
66 base_b = geompy.MakeVertex(0, 0, height)
67 group_b = geompy.CreateGroup(blocks, geompy.ShapeType["FACE"])
68 geompy.addToStudyInFather(blocks, group_b, "baseB")
69 items = geompy.GetShapesOnPlaneWithLocationIDs(blocks, geompy.ShapeType["FACE"], direction, base_b, GEOM.ST_ON)
70 geompy.UnionIDs(group_b, items)
72 group_1 = geompy.CreateGroup(blocks, geompy.ShapeType["SOLID"])
73 geompy.addToStudyInFather(blocks, group_1, "limit")
74 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
75 geompy.UnionIDs(group_1, group_1_all)
76 group_1_box = geompy.GetBlockNearPoint(blocks, base)
77 geompy.DifferenceList(group_1, [group_1_box])
79 # Mesh the blocks with hexahedral
80 # -------------------------------
84 hexa = smesh.Mesh(blocks)
86 hexa_1d = hexa.Segment()
87 hexa_1d.NumberOfSegments(1)
89 vertex = geompy.MakeVertex(+radius, +radius, 0)
90 edge = geompy.GetEdgeNearPoint(blocks, vertex)
91 algo = hexa.Segment(edge)
92 algo.NumberOfSegments(5)
95 vertex = geompy.MakeVertex(-radius, +radius, 0)
96 edge = geompy.GetEdgeNearPoint(blocks, vertex)
97 algo = hexa.Segment(edge)
98 algo.NumberOfSegments(8)
101 vertex = geompy.MakeVertex((radius+size)/2, 0, 0)
102 edge = geompy.GetEdgeNearPoint(blocks, vertex)
103 algo = hexa.Segment(edge)
104 algo.NumberOfSegments(10)
107 vertex = geompy.MakeVertex(+radius, 0, height/2)
108 edge = geompy.GetEdgeNearPoint(blocks, vertex)
109 algo = hexa.Segment(edge)
110 algo.NumberOfSegments(20)