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