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