Salome HOME
6d9f3077dac394051f92470e79350e97c96a7614
[modules/smesh.git] / src / SMESH_SWIG / ex24_cylinder.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # ==================================
23 #
24 import math
25
26 import geompy
27 import smesh
28
29 geo = geompy
30
31 # Parameters
32 # ----------
33
34 radius =  50
35 height = 200
36
37 # Build a cylinder
38 # ----------------
39
40 base = geo.MakeVertex(0, 0, 0)
41 direction = geo.MakeVectorDXDYDZ(0, 0, 1)
42
43 cylinder = geo.MakeCylinder(base, direction, radius, height)
44
45 geo.addToStudy(cylinder, "cylinder")
46
47 # Build blocks
48 # ------------
49
50 size = radius/2.0
51
52 box_rot = geo.MakeBox(-size, -size, 0,  +size, +size, height)
53 box_axis = geo.MakeLine(base, direction)
54 box = geo.MakeRotation(box_rot, box_axis, math.pi/4)
55
56 hole = geo.MakeCut(cylinder, box)
57
58 plane_trim = 2000
59
60 plane_a = geo.MakePlane(base, geo.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
61 plane_b = geo.MakePlane(base, geo.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
62
63 blocks_part = geo.MakePartition([hole], [plane_a, plane_b], [], [], geo.ShapeType["SOLID"])
64 blocks_list = [box] + geo.SubShapeAll(blocks_part, geo.ShapeType["SOLID"])
65 blocks_all = geo.MakeCompound(blocks_list)
66 blocks = geo.MakeGlueFaces(blocks_all, 0.0001)
67
68 geo.addToStudy(blocks, "cylinder:blocks")
69
70 # Build geometric groups
71 # ----------------------
72
73 def group(name, shape, type, base=None, direction=None):
74     t = geo.ShapeType[type]
75     g = geo.CreateGroup(shape, t)
76
77     geo.addToStudy(g, name)
78     g.SetName(name)
79
80     if base!=None:
81         l = geo.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, geo.GEOM.ST_ON)
82         geo.UnionIDs(g, l)
83
84     return g
85
86 group_a = group("baseA", blocks, "FACE", base, direction)
87
88 base_b  = geo.MakeVertex(0, 0, height)
89 group_b = group("baseB", blocks, "FACE", base_b, direction)
90
91 group_1 = group("limit", blocks, "SOLID")
92 group_1_all = geo.SubShapeAllIDs(blocks, geo.ShapeType["SOLID"])
93 geo.UnionIDs(group_1, group_1_all)
94 group_1_box = geo.GetBlockNearPoint(blocks, base)
95 geo.DifferenceList(group_1, [group_1_box])
96
97 # Mesh the blocks with hexahedral
98 # -------------------------------
99
100 def discretize(x, y, z,  n, s=blocks):
101     p = geo.MakeVertex(x, y, z)
102     e = geo.GetEdgeNearPoint(s, p)
103     a = hexa.Segment(e)
104     a.NumberOfSegments(n)
105     a.Propagation()
106
107 hexa = smesh.Mesh(blocks)
108
109 hexa_1d = hexa.Segment()
110 hexa_1d.NumberOfSegments(1)
111
112 discretize(+radius        , +radius,        0,   5)
113 discretize(-radius        , +radius,        0,   8)
114 discretize((radius+size)/2,       0,        0,  10)
115 discretize(        +radius,       0, height/2,  20)
116
117 hexa.Quadrangle()
118 hexa.Hexahedron()
119
120 hexa.Compute()
121
122 hexa.Group(group_a)
123 hexa.Group(group_b)
124 hexa.Group(group_1)