Salome HOME
4628ce987b82f3ded06d38adfd25a6584a304b82
[modules/smesh.git] / src / SMESH_SWIG / ex24_cylinder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  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, or (at your option) any later version.
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 salome
26 salome.salome_init()
27 import GEOM
28 from salome.geom import geomBuilder
29 geompy = geomBuilder.New(salome.myStudy)
30
31 import SMESH, SALOMEDS
32 from salome.smesh import smeshBuilder
33 smesh =  smeshBuilder.New(salome.myStudy)
34
35 geo = geompy
36
37 # Parameters
38 # ----------
39
40 radius =  50
41 height = 200
42
43 # Build a cylinder
44 # ----------------
45
46 base = geompy.MakeVertex(0, 0, 0)
47 direction = geompy.MakeVectorDXDYDZ(0, 0, 1)
48
49 cylinder = geompy.MakeCylinder(base, direction, radius, height)
50
51 geompy.addToStudy(cylinder, "cylinder")
52
53 # Build blocks
54 # ------------
55
56 size = radius/2.0
57
58 box_rot = geompy.MakeBox(-size, -size, 0,  +size, +size, height)
59 box_axis = geompy.MakeLine(base, direction)
60 box = geompy.MakeRotation(box_rot, box_axis, math.pi/4)
61
62 hole = geompy.MakeCut(cylinder, box)
63
64 plane_trim = 2000
65
66 plane_a = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
67 plane_b = geompy.MakePlane(base, geompy.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
68
69 blocks_part = geompy.MakePartition([hole], [plane_a, plane_b], [], [], geompy.ShapeType["SOLID"])
70 blocks_list = [box] + geompy.SubShapeAll(blocks_part, geompy.ShapeType["SOLID"])
71 blocks_all = geompy.MakeCompound(blocks_list)
72 blocks = geompy.MakeGlueFaces(blocks_all, 0.0001)
73
74 geompy.addToStudy(blocks, "cylinder:blocks")
75
76 # Build geometric groups
77 # ----------------------
78
79 def group(name, shape, type, base=None, direction=None):
80     t = geompy.ShapeType[type]
81     g = geompy.CreateGroup(shape, t)
82
83     geompy.addToStudy(g, name)
84     g.SetName(name)
85
86     if base!=None:
87         l = geompy.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, GEOM.ST_ON)
88         geompy.UnionIDs(g, l)
89
90     return g
91
92 group_a = group("baseA", blocks, "FACE", base, direction)
93
94 base_b  = geompy.MakeVertex(0, 0, height)
95 group_b = group("baseB", blocks, "FACE", base_b, direction)
96
97 group_1 = group("limit", blocks, "SOLID")
98 group_1_all = geompy.SubShapeAllIDs(blocks, geompy.ShapeType["SOLID"])
99 geompy.UnionIDs(group_1, group_1_all)
100 group_1_box = geompy.GetBlockNearPoint(blocks, base)
101 geompy.DifferenceList(group_1, [group_1_box])
102
103 # Mesh the blocks with hexahedral
104 # -------------------------------
105
106 smesh.SetCurrentStudy(salome.myStudy)
107
108 def discretize(x, y, z,  n, s=blocks):
109     p = geompy.MakeVertex(x, y, z)
110     e = geompy.GetEdgeNearPoint(s, p)
111     a = hexa.Segment(e)
112     a.NumberOfSegments(n)
113     a.Propagation()
114
115 hexa = smesh.Mesh(blocks)
116
117 hexa_1d = hexa.Segment()
118 hexa_1d.NumberOfSegments(1)
119
120 discretize(+radius        , +radius,        0,   5)
121 discretize(-radius        , +radius,        0,   8)
122 discretize((radius+size)/2,       0,        0,  10)
123 discretize(        +radius,       0, height/2,  20)
124
125 hexa.Quadrangle()
126 hexa.Hexahedron()
127
128 hexa.Compute()
129
130 hexa.Group(group_a)
131 hexa.Group(group_b)
132 hexa.Group(group_1)