]> SALOME platform Git repositories - modules/smesh.git/blob - doc/salome/examples/creating_meshes_ex06.py
Salome HOME
update of messages
[modules/smesh.git] / doc / salome / examples / creating_meshes_ex06.py
1 # Creating a hexahedral mesh on a cylinder.
2 # Note: it is a copy of 'ex24_cylinder.py' from SMESH_SWIG
3
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh =  smeshBuilder.New(salome.myStudy)
13
14 import math
15
16 # Parameters
17 # ----------
18
19 radius =  50
20 height = 200
21
22 # Build a cylinder
23 # ----------------
24
25 base = geompy.MakeVertex(0, 0, 0)
26 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
27
28 cylinder = geompy.MakeCylinder(base, direction, radius, height)
29
30 geompy.addToStudy(cylinder, "cylinder")
31
32 # Build blocks
33 # ------------
34
35 size = radius/2.0
36
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)
40
41 hole = geompy.MakeCut(cylinder, box)
42
43 plane_trim = 2000
44
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)
47
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)
52
53 geompy.addToStudy(blocks, "cylinder:blocks")
54
55 # Build geometric groups
56 # ----------------------
57
58 def group(name, shape, type, base=None, direction=None):
59     t = geompy.ShapeType[type]
60     g = geompy.CreateGroup(shape, t)
61
62     geompy.addToStudy(g, name)
63     g.SetName(name)
64
65     if base!=None:
66         l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
67         geompy.UnionIDs(g, l)
68
69     return g
70
71 group_a = group("baseA", blocks, "FACE", base, direction)
72
73 base_b  = geompy.MakeVertex(0, 0, height)
74 group_b = group("baseB", blocks, "FACE", base_b, direction)
75
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])
81
82 # Mesh the blocks with hexahedral
83 # -------------------------------
84
85 smesh.SetCurrentStudy(salome.myStudy)
86
87 def discretize(x, y, z,  n, s=blocks):
88     p = geompy.MakeVertex(x, y, z)
89     e = geompy.GetEdgeNearPoint(s, p)
90     a = hexa.Segment(e)
91     a.NumberOfSegments(n)
92     a.Propagation()
93
94 hexa = smesh.Mesh(blocks)
95
96 hexa_1d = hexa.Segment()
97 hexa_1d.NumberOfSegments(1)
98
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)
103
104 hexa.Quadrangle()
105 hexa.Hexahedron()
106
107 hexa.Compute()
108
109 hexa.Group(group_a)
110 hexa.Group(group_b)
111 hexa.Group(group_1)