Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / src / SMESH_SWIG / ex15_cyl2geometry.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  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 #
26 from geompy import *
27
28 import smesh
29
30 # Geometrie
31 # =========
32
33 # Construire avec des hexahedres une piece faite de 2 cylindres de diametre different
34 # et dont les axes se coupent orthogonalement, puis mailler.
35
36 # Valeurs
37 # -------
38
39 cx = 0
40 cy = 0
41 cz = 0
42
43 g_rayon   = 100.0
44 g_hauteur = 500
45
46 p_rayon   =  50.0
47 p_hauteur = 500
48
49 g_trim = 1000
50
51 # Gros cylindre
52 # -------------
53
54 cpd = []
55
56 g_base = MakeVertex(cx, cy, cz)
57 g_dir  = MakeVectorDXDYDZ(0, 0, 1)
58 t_hauteur = p_rayon+10.0
59
60 g_cyl = MakeCylinder(g_base, g_dir, g_rayon, g_hauteur)
61
62 g_coupe   = MakeVectorDXDYDZ(1, 0, 0)
63
64 g_tools = []
65 g_tools.append(MakePlane(MakeVertex(cx+t_hauteur, cy, cz), g_coupe, g_trim))
66 g_tools.append(MakePlane(MakeVertex(cx-t_hauteur, cy, cz), g_coupe, g_trim))
67
68 g_partie = MakePartition([g_cyl], g_tools, [], [], ShapeType["SOLID"])
69 g_bas, g_centre, g_haut = SubShapeAllSorted(g_partie, ShapeType["SOLID"])
70
71 # Partie basse du gros cylindre
72 # -----------------------------
73
74 b_hauteur = 10
75 b_base    = 20
76
77 b_boite = MakeBox(cx-t_hauteur, cy-b_base, cz,  cx-t_hauteur-b_hauteur, cy+b_base, cz+g_hauteur)
78 cpd.append(b_boite)
79
80 b_cyl = MakeCut(g_bas, b_boite)
81
82 b_tools = []
83 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy+b_base, cz), MakeVectorDXDYDZ( 1, 1, 0), g_trim))
84 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy-b_base, cz), MakeVectorDXDYDZ(-1, 1, 0), g_trim))
85
86 b_partie = MakePartition([b_cyl], b_tools, [], [], ShapeType["SOLID"])
87 b_element = SubShapeAll(b_partie, ShapeType["SOLID"])
88 cpd = cpd + b_element
89
90 # Partie haute du gros cylindre
91 # -----------------------------
92
93 h_plan = MakePlane(g_base, g_coupe, g_trim)
94
95 cpd.append(MakeMirrorByPlane(b_boite, h_plan))
96
97 for h in b_element:
98     h_symetrie = MakeMirrorByPlane(h, h_plan)
99     cpd.append(h_symetrie)
100
101 # Petit cylindre
102 # --------------
103
104 z_arete = p_rayon/2
105 x_arete = z_arete*t_hauteur*2/g_hauteur
106
107 px = cx-x_arete
108 py = cy-1.5*g_rayon
109 pz = cz+g_hauteur/2
110
111 p_base = MakeVertex(cx, py, pz)
112 p_dir  = MakeVectorDXDYDZ(0, 1, 0)
113 p_cyl  = MakeCylinder(p_base, p_dir, p_rayon, p_hauteur)
114
115 p_boite = MakeBox(px, py, pz-z_arete,  cx+x_arete, py+p_hauteur, pz+z_arete)
116
117 # Partie interieure du petit cylindre
118 # -----------------------------------
119
120 i_cyl   = MakeCommon(p_cyl, g_cyl)
121 i_tuyau = MakeCut(i_cyl, p_boite)
122 i_boite = MakeCommon(p_boite, g_cyl)
123
124 # Partie exterieure du petit cylindre
125 # -----------------------------------
126
127 e_cyl0 = MakeCut(p_cyl, g_cyl)
128 e_cyl  = SubShapeAllSorted(e_cyl0, ShapeType["SOLID"])
129
130 e_tuyau = MakeCut(e_cyl[1], p_boite)
131
132 e_boite0 = MakeCut(p_boite, g_cyl)
133 e_boite  = SubShapeAllSorted(e_boite0, ShapeType["SOLID"])
134
135 cpd.append(e_boite[1])
136
137 # Partie centrale du gros cylindre
138 # --------------------------------
139
140 c_cyl = MakeCut(g_centre, p_cyl)
141
142 # Partitionner
143 # ------------
144
145 p_tools = []
146 p_tools.append(MakePlane(MakeVertex(px, py, pz-z_arete), MakeVectorDXDYDZ(-z_arete, 0, x_arete), g_trim))
147 p_tools.append(MakePlane(MakeVertex(px, py, pz+z_arete), MakeVectorDXDYDZ( z_arete, 0, x_arete), g_trim))
148
149 p_partie = MakePartition([e_tuyau], p_tools, [], [], ShapeType["SOLID"])
150 p_element = SubShapeAll(p_partie, ShapeType["SOLID"])
151 cpd = cpd + p_element
152
153 q_partie = MakePartition([i_tuyau, c_cyl], p_tools, [], [], ShapeType["SOLID"])
154 q_element = SubShapeAll(q_partie, ShapeType["SOLID"])
155
156 q_element = q_element + [i_boite]
157
158 q_tools = []
159 q_tools.append(MakePlane(MakeVertex(cx, cy-b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
160 q_tools.append(MakePlane(MakeVertex(cx, cy+b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
161
162 r_element = []
163 for e in q_element:
164     r_partie = MakePartition([e], q_tools, [], [], ShapeType["SOLID"])
165     r_element = r_element + SubShapeAll(r_partie, ShapeType["SOLID"])
166
167 cpd = cpd + r_element
168
169 # Compound
170 # --------
171
172 piece = RemoveExtraEdges(MakeCompound(cpd), True)
173
174 # Ajouter la piece dans l'etude
175 # -----------------------------
176
177 piece_id = addToStudy(piece, "ex15_cyl2geometry")
178
179 # Meshing
180 # =======
181
182 smesh.SetCurrentStudy(salome.myStudy)
183
184 # Create a hexahedral mesh
185 # ------------------------
186
187 hexa = smesh.Mesh(piece, "ex15_cyl2geometry:hexa")
188
189 algo = hexa.Segment()
190 algo.NumberOfSegments(12)
191
192 hexa.Quadrangle()
193
194 hexa.Hexahedron()
195
196 # Mesh calculus
197 # -------------
198
199 hexa.Compute()