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.addToStudyInFather(shape, g, name)
68 l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
73 group_a = group("baseA", blocks, "FACE", base, direction)
75 base_b = geompy.MakeVertex(0, 0, height)
76 group_b = group("baseB", blocks, "FACE", base_b, direction)
78 group_1 = group("limit", blocks, "SOLID")
79 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
80 geompy.UnionIDs(group_1, group_1_all)
81 group_1_box = geompy.GetBlockNearPoint(blocks, base)
82 geompy.DifferenceList(group_1, [group_1_box])
84 # Mesh the blocks with hexahedral
85 # -------------------------------
87 smesh.SetCurrentStudy(salome.myStudy)
89 def discretize(x, y, z, nbSeg, shape=blocks):
90 vert = geompy.MakeVertex( x, y, z )
91 edge = geompy.GetEdgeNearPoint( shape, vert )
92 algo = hexa.Segment( edge )
93 algo.NumberOfSegments( nbSeg )
96 hexa = smesh.Mesh(blocks)
98 hexa_1d = hexa.Segment()
99 hexa_1d.NumberOfSegments(1)
101 discretize(+radius , +radius, 0, 5)
102 discretize(-radius , +radius, 0, 8)
103 discretize((radius+size)/2, 0, 0, 10)
104 discretize( +radius, 0, height/2, 20)