Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESH_SWIG / ex24_cylinder.py
1 # CEA/LGLS 2007, Francis KLOSS (OCC)
2 # ==================================
3
4 import math
5
6 import geompy
7 import smesh
8
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 def discretize(x, y, z,  n, s=blocks):
81     p = geo.MakeVertex(x, y, z)
82     e = geo.GetEdgeNearPoint(s, p)
83     a = hexa.Segment(e)
84     a.NumberOfSegments(n)
85     a.Propagation()
86
87 hexa = smesh.Mesh(blocks)
88
89 hexa_1d = hexa.Segment()
90 hexa_1d.NumberOfSegments(1)
91
92 discretize(+radius        , +radius,        0,   5)
93 discretize(-radius        , +radius,        0,   8)
94 discretize((radius+size)/2,       0,        0,  10)
95 discretize(        +radius,       0, height/2,  20)
96
97 hexa.Quadrangle()
98 hexa.Hexahedron()
99
100 hexa.Compute()
101
102 hexa.Group(group_a)
103 hexa.Group(group_b)
104 hexa.Group(group_1)