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