Salome HOME
2bcba7195620e6003e07508d3950e37d623a6126
[modules/smesh.git] / src / SMESH_SWIG / ex15_cyl2geometry.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # =======================================
23 #
24 from geompy import *
25
26 import smesh
27
28 # Geometrie
29 # =========
30
31 # Construire avec des hexahedres une piece faite de 2 cylindres de diametre different
32 # et dont les axes se coupent orthogonalement, puis mailler.
33
34 # Valeurs
35 # -------
36
37 cx = 0
38 cy = 0
39 cz = 0
40
41 g_rayon   = 100.0
42 g_hauteur = 500
43
44 p_rayon   =  50.0
45 p_hauteur = 500
46
47 g_trim = 1000
48
49 # Gros cylindre
50 # -------------
51
52 cpd = []
53
54 g_base = MakeVertex(cx, cy, cz)
55 g_dir  = MakeVectorDXDYDZ(0, 0, 1)
56 t_hauteur = p_rayon+10.0
57
58 g_cyl = MakeCylinder(g_base, g_dir, g_rayon, g_hauteur)
59
60 g_coupe   = MakeVectorDXDYDZ(1, 0, 0)
61
62 g_tools = []
63 g_tools.append(MakePlane(MakeVertex(cx+t_hauteur, cy, cz), g_coupe, g_trim))
64 g_tools.append(MakePlane(MakeVertex(cx-t_hauteur, cy, cz), g_coupe, g_trim))
65
66 g_partie = MakePartition([g_cyl], g_tools, [], [], ShapeType["SOLID"])
67 g_bas, g_centre, g_haut = SubShapeAllSorted(g_partie, ShapeType["SOLID"])
68
69 # Partie basse du gros cylindre
70 # -----------------------------
71
72 b_hauteur = 10
73 b_base    = 20
74
75 b_boite = MakeBox(cx-t_hauteur, cy-b_base, cz,  cx-t_hauteur-b_hauteur, cy+b_base, cz+g_hauteur)
76 cpd.append(b_boite)
77
78 b_cyl = MakeCut(g_bas, b_boite)
79
80 b_tools = []
81 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy+b_base, cz), MakeVectorDXDYDZ( 1, 1, 0), g_trim))
82 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy-b_base, cz), MakeVectorDXDYDZ(-1, 1, 0), g_trim))
83
84 b_partie = MakePartition([b_cyl], b_tools, [], [], ShapeType["SOLID"])
85 b_element = SubShapeAll(b_partie, ShapeType["SOLID"])
86 cpd = cpd + b_element
87
88 # Partie haute du gros cylindre
89 # -----------------------------
90
91 h_plan = MakePlane(g_base, g_coupe, g_trim)
92
93 cpd.append(MakeMirrorByPlane(b_boite, h_plan))
94
95 for h in b_element:
96     h_symetrie = MakeMirrorByPlane(h, h_plan)
97     cpd.append(h_symetrie)
98
99 # Petit cylindre
100 # --------------
101
102 z_arete = p_rayon/2
103 x_arete = z_arete*t_hauteur*2/g_hauteur
104
105 px = cx-x_arete
106 py = cy-1.5*g_rayon
107 pz = cz+g_hauteur/2
108
109 p_base = MakeVertex(cx, py, pz)
110 p_dir  = MakeVectorDXDYDZ(0, 1, 0)
111 p_cyl  = MakeCylinder(p_base, p_dir, p_rayon, p_hauteur)
112
113 p_boite = MakeBox(px, py, pz-z_arete,  cx+x_arete, py+p_hauteur, pz+z_arete)
114
115 # Partie interieure du petit cylindre
116 # -----------------------------------
117
118 i_cyl   = MakeCommon(p_cyl, g_cyl)
119 i_tuyau = MakeCut(i_cyl, p_boite)
120 i_boite = MakeCommon(p_boite, g_cyl)
121
122 # Partie exterieure du petit cylindre
123 # -----------------------------------
124
125 e_cyl0 = MakeCut(p_cyl, g_cyl)
126 e_cyl  = SubShapeAllSorted(e_cyl0, ShapeType["SOLID"])
127
128 e_tuyau = MakeCut(e_cyl[1], p_boite)
129
130 e_boite0 = MakeCut(p_boite, g_cyl)
131 e_boite  = SubShapeAllSorted(e_boite0, ShapeType["SOLID"])
132
133 cpd.append(e_boite[1])
134
135 # Partie centrale du gros cylindre
136 # --------------------------------
137
138 c_cyl = MakeCut(g_centre, p_cyl)
139
140 # Partitionner
141 # ------------
142
143 p_tools = []
144 p_tools.append(MakePlane(MakeVertex(px, py, pz-z_arete), MakeVectorDXDYDZ(-z_arete, 0, x_arete), g_trim))
145 p_tools.append(MakePlane(MakeVertex(px, py, pz+z_arete), MakeVectorDXDYDZ( z_arete, 0, x_arete), g_trim))
146
147 p_partie = MakePartition([e_tuyau], p_tools, [], [], ShapeType["SOLID"])
148 p_element = SubShapeAll(p_partie, ShapeType["SOLID"])
149 cpd = cpd + p_element
150
151 q_partie = MakePartition([i_tuyau, c_cyl], p_tools, [], [], ShapeType["SOLID"])
152 q_element = SubShapeAll(q_partie, ShapeType["SOLID"])
153
154 q_element = q_element + [i_boite]
155
156 q_tools = []
157 q_tools.append(MakePlane(MakeVertex(cx, cy-b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
158 q_tools.append(MakePlane(MakeVertex(cx, cy+b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
159
160 r_element = []
161 for e in q_element:
162     r_partie = MakePartition([e], q_tools, [], [], ShapeType["SOLID"])
163     r_element = r_element + SubShapeAll(r_partie, ShapeType["SOLID"])
164
165 cpd = cpd + r_element
166
167 # Compound
168 # --------
169
170 piece = RemoveExtraEdges(MakeCompound(cpd), 0)
171
172 # Ajouter la piece dans l'etude
173 # -----------------------------
174
175 piece_id = addToStudy(piece, "ex15_cyl2geometry")
176
177 # Meshing
178 # =======
179
180 # Create a hexahedral mesh
181 # ------------------------
182
183 hexa = smesh.Mesh(piece, "ex15_cyl2geometry:hexa")
184
185 algo = hexa.Segment()
186 algo.NumberOfSegments(12)
187
188 hexa.Quadrangle()
189
190 hexa.Hexahedron()
191
192 # Mesh calculus
193 # -------------
194
195 hexa.Compute()