1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # =======================================
29 from salome.geom import geomBuilder
30 geompy = geomBuilder.New()
32 import SMESH, SALOMEDS
33 from salome.smesh import smeshBuilder
34 smesh = smeshBuilder.New()
39 # Construire avec des hexahedres une piece faite de 2 cylindres de diametre different
40 # et dont les axes se coupent orthogonalement, puis mailler.
62 g_base = geompy.MakeVertex(cx, cy, cz)
63 g_dir = geompy.MakeVectorDXDYDZ(0, 0, 1)
64 t_hauteur = p_rayon+10.0
66 g_cyl = geompy.MakeCylinder(g_base, g_dir, g_rayon, g_hauteur)
68 g_coupe = geompy.MakeVectorDXDYDZ(1, 0, 0)
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))
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"])
77 # Partie basse du gros cylindre
78 # -----------------------------
83 b_boite = geompy.MakeBox(cx-t_hauteur, cy-b_base, cz, cx-t_hauteur-b_hauteur, cy+b_base, cz+g_hauteur)
86 b_cyl = geompy.MakeCut(g_bas, b_boite)
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))
92 b_partie = geompy.MakePartition([b_cyl], b_tools, [], [], geompy.ShapeType["SOLID"])
93 b_element = geompy.SubShapeAll(b_partie, geompy.ShapeType["SOLID"])
96 # Partie haute du gros cylindre
97 # -----------------------------
99 h_plan = geompy.MakePlane(g_base, g_coupe, g_trim)
101 cpd.append(geompy.MakeMirrorByPlane(b_boite, h_plan))
104 h_symetrie = geompy.MakeMirrorByPlane(h, h_plan)
105 cpd.append(h_symetrie)
111 x_arete = z_arete*t_hauteur*2/g_hauteur
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)
121 p_boite = geompy.MakeBox(px, py, pz-z_arete, cx+x_arete, py+p_hauteur, pz+z_arete)
123 # Partie interieure du petit cylindre
124 # -----------------------------------
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)
130 # Partie exterieure du petit cylindre
131 # -----------------------------------
133 e_cyl0 = geompy.MakeCut(p_cyl, g_cyl)
134 e_cyl = geompy.SubShapeAllSorted(e_cyl0, geompy.ShapeType["SOLID"])
136 e_tuyau = geompy.MakeCut(e_cyl[1], p_boite)
138 e_boite0 = geompy.MakeCut(p_boite, g_cyl)
139 e_boite = geompy.SubShapeAllSorted(e_boite0, geompy.ShapeType["SOLID"])
141 cpd.append(e_boite[1])
143 # Partie centrale du gros cylindre
144 # --------------------------------
146 c_cyl = geompy.MakeCut(g_centre, p_cyl)
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))
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
159 q_partie = geompy.MakePartition([i_tuyau, c_cyl], p_tools, [], [], geompy.ShapeType["SOLID"])
160 q_element = geompy.SubShapeAll(q_partie, geompy.ShapeType["SOLID"])
162 q_element = q_element + [i_boite]
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))
170 r_partie = geompy.MakePartition([e], q_tools, [], [], geompy.ShapeType["SOLID"])
171 r_element = r_element + geompy.SubShapeAll(r_partie, geompy.ShapeType["SOLID"])
173 cpd = cpd + r_element
178 piece = geompy.RemoveExtraEdges(geompy.MakeCompound(cpd), True)
180 # Ajouter la piece dans l'etude
181 # -----------------------------
183 piece_id = geompy.addToStudy(piece, "ex15_cyl2geometry")
188 # Create a hexahedral mesh
189 # ------------------------
191 hexa = smesh.Mesh(piece, "ex15_cyl2geometry:hexa")
193 algo = hexa.Segment()
194 algo.NumberOfSegments(12)
205 # Update object browser
206 # ---------------------
208 salome.sg.updateObjBrowser()