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