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