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