Salome HOME
Fix regression of SALOME_TESTS/Grids/smesh/3D_submesh_00/A6
[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.addToStudy(g, name)
66     g.SetName(name)
67
68     if base!=None:
69         l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
70         geompy.UnionIDs(g, l)
71
72     return g
73
74 group_a = group("baseA", blocks, "FACE", base, direction)
75
76 base_b  = geompy.MakeVertex(0, 0, height)
77 group_b = group("baseB", blocks, "FACE", base_b, direction)
78
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])
84
85 # Mesh the blocks with hexahedral
86 # -------------------------------
87
88 smesh.SetCurrentStudy(salome.myStudy)
89
90 def discretize(x, y, z,  n, s=blocks):
91     p = geompy.MakeVertex(x, y, z)
92     e = geompy.GetEdgeNearPoint(s, p)
93     a = hexa.Segment(e)
94     a.NumberOfSegments(n)
95     a.Propagation()
96
97 hexa = smesh.Mesh(blocks)
98
99 hexa_1d = hexa.Segment()
100 hexa_1d.NumberOfSegments(1)
101
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)
106
107 hexa.Quadrangle()
108 hexa.Hexahedron()
109
110 hexa.Compute()
111
112 hexa.Group(group_a)
113 hexa.Group(group_b)
114 hexa.Group(group_1)