1 # Creating a hexahedral mesh on a cylinder.
2 # Note: it is a copy of 'ex24_cylinder.py' from SMESH_SWIG
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
25 base = geompy.MakeVertex(0, 0, 0)
26 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
28 cylinder = geompy.MakeCylinder(base, direction, radius, height)
30 geompy.addToStudy(cylinder, "cylinder")
37 box_rot = geompy.MakeBox(-size, -size, 0, +size, +size, height)
38 box_axis = geompy.MakeLine(base, direction)
39 box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
41 hole = geompy.MakeCut(cylinder, box)
45 plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
46 plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
48 blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
49 blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
50 blocks_all = geompy.MakeCompound(blocks_list)
51 blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
53 geompy.addToStudy(blocks, "cylinder:blocks")
55 # Build geometric groups
56 # ----------------------
58 def group(name, shape, type, base=None, direction=None):
59 t = geompy.ShapeType[type]
60 g = geompy.CreateGroup(shape, t)
62 geompy.addToStudy(g, name)
66 l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
71 group_a = group("baseA", blocks, "FACE", base, direction)
73 base_b = geompy.MakeVertex(0, 0, height)
74 group_b = group("baseB", blocks, "FACE", base_b, direction)
76 group_1 = group("limit", blocks, "SOLID")
77 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
78 geompy.UnionIDs(group_1, group_1_all)
79 group_1_box = geompy.GetBlockNearPoint(blocks, base)
80 geompy.DifferenceList(group_1, [group_1_box])
82 # Mesh the blocks with hexahedral
83 # -------------------------------
85 smesh.SetCurrentStudy(salome.myStudy)
87 def discretize(x, y, z, n, s=blocks):
88 p = geompy.MakeVertex(x, y, z)
89 e = geompy.GetEdgeNearPoint(s, p)
94 hexa = smesh.Mesh(blocks)
96 hexa_1d = hexa.Segment()
97 hexa_1d.NumberOfSegments(1)
99 discretize(+radius , +radius, 0, 5)
100 discretize(-radius , +radius, 0, 8)
101 discretize((radius+size)/2, 0, 0, 10)
102 discretize( +radius, 0, height/2, 20)