Salome HOME
Merge from V6_main 28/02/2013
[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 math
5
6 import geompy
7 import smesh
8 import salome
9 geo = geompy
10
11 # Parameters
12 # ----------
13
14 radius =  50
15 height = 200
16
17 # Build a cylinder
18 # ----------------
19
20 base = geo.MakeVertex(0, 0, 0)
21 direction = geo.MakeVectorDXDYDZ(0, 0, 1)
22
23 cylinder = geo.MakeCylinder(base, direction, radius, height)
24
25 geo.addToStudy(cylinder, "cylinder")
26
27 # Build blocks
28 # ------------
29
30 size = radius/2.0
31
32 box_rot = geo.MakeBox(-size, -size, 0,  +size, +size, height)
33 box_axis = geo.MakeLine(base, direction)
34 box = geo.MakeRotation(box_rot, box_axis, math.pi/4)
35
36 hole = geo.MakeCut(cylinder, box)
37
38 plane_trim = 2000
39
40 plane_a = geo.MakePlane(base, geo.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
41 plane_b = geo.MakePlane(base, geo.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
42
43 blocks_part = geo.MakePartition([hole], [plane_a, plane_b], [], [], geo.ShapeType["SOLID"])
44 blocks_list = [box] + geo.SubShapeAll(blocks_part, geo.ShapeType["SOLID"])
45 blocks_all = geo.MakeCompound(blocks_list)
46 blocks = geo.MakeGlueFaces(blocks_all, 0.0001)
47
48 geo.addToStudy(blocks, "cylinder:blocks")
49
50 # Build geometric groups
51 # ----------------------
52
53 def group(name, shape, type, base=None, direction=None):
54     t = geo.ShapeType[type]
55     g = geo.CreateGroup(shape, t)
56
57     geo.addToStudy(g, name)
58     g.SetName(name)
59
60     if base!=None:
61         l = geo.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, geo.GEOM.ST_ON)
62         geo.UnionIDs(g, l)
63
64     return g
65
66 group_a = group("baseA", blocks, "FACE", base, direction)
67
68 base_b  = geo.MakeVertex(0, 0, height)
69 group_b = group("baseB", blocks, "FACE", base_b, direction)
70
71 group_1 = group("limit", blocks, "SOLID")
72 group_1_all = geo.SubShapeAllIDs(blocks, geo.ShapeType["SOLID"])
73 geo.UnionIDs(group_1, group_1_all)
74 group_1_box = geo.GetBlockNearPoint(blocks, base)
75 geo.DifferenceList(group_1, [group_1_box])
76
77 # Mesh the blocks with hexahedral
78 # -------------------------------
79
80 smesh.SetCurrentStudy(salome.myStudy)
81
82 def discretize(x, y, z,  n, s=blocks):
83     p = geo.MakeVertex(x, y, z)
84     e = geo.GetEdgeNearPoint(s, p)
85     a = hexa.Segment(e)
86     a.NumberOfSegments(n)
87     a.Propagation()
88
89 hexa = smesh.Mesh(blocks)
90
91 hexa_1d = hexa.Segment()
92 hexa_1d.NumberOfSegments(1)
93
94 discretize(+radius        , +radius,        0,   5)
95 discretize(-radius        , +radius,        0,   8)
96 discretize((radius+size)/2,       0,        0,  10)
97 discretize(        +radius,       0, height/2,  20)
98
99 hexa.Quadrangle()
100 hexa.Hexahedron()
101
102 hexa.Compute()
103
104 hexa.Group(group_a)
105 hexa.Group(group_b)
106 hexa.Group(group_1)