Salome HOME
52977: Find Element by Point does not find supporting node of Ball element at group...
[modules/smesh.git] / doc / salome / examples / creating_meshes_ex06.py
1 # Creating a hexahedral mesh on a cylinder.
2 #
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()
6
7 import salome
8 salome.salome_init()
9 import GEOM
10 from salome.geom import geomBuilder
11 geompy = geomBuilder.New(salome.myStudy)
12
13 import SMESH, SALOMEDS
14 from salome.smesh import smeshBuilder
15 smesh =  smeshBuilder.New(salome.myStudy)
16
17 import math
18
19 # Parameters
20 # ----------
21
22 radius =  50
23 height = 200
24
25 # Build a cylinder
26 # ----------------
27
28 base      = geompy.MakeVertex(0, 0, 0)
29 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
30
31 cylinder = geompy.MakeCylinder(base, direction, radius, height)
32
33 geompy.addToStudy(cylinder, "cylinder")
34
35 # Build blocks
36 # ------------
37
38 size = radius/2.0
39
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)
43
44 hole = geompy.MakeCut(cylinder, box)
45
46 plane_trim = 2000
47
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)
50
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)
55
56 geompy.addToStudy(blocks, "cylinder:blocks")
57
58 # Build geometric groups
59 # ----------------------
60
61 def group(name, shape, type, base=None, direction=None):
62     t = geompy.ShapeType[type]
63     g = geompy.CreateGroup(shape, t)
64
65     geompy.addToStudyInFather(shape, g, name)
66
67     if base!=None:
68         l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
69         geompy.UnionIDs(g, l)
70
71     return g
72
73 group_a = group("baseA", blocks, "FACE", base, direction)
74
75 base_b  = geompy.MakeVertex(0, 0, height)
76 group_b = group("baseB", blocks, "FACE", base_b, direction)
77
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])
83
84 # Mesh the blocks with hexahedral
85 # -------------------------------
86
87 smesh.SetCurrentStudy(salome.myStudy)
88
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 )
94     algo.Propagation()
95
96 hexa = smesh.Mesh(blocks)
97
98 hexa_1d = hexa.Segment()
99 hexa_1d.NumberOfSegments(1)
100
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)
105
106 hexa.Quadrangle()
107 hexa.Hexahedron()
108
109 hexa.Compute()
110
111 hexa.Group(group_a)
112 hexa.Group(group_b)
113 hexa.Group(group_1)