Back to index

salome-smesh  6.5.0
ex15_cyl2geometry.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 # =======================================
00025 #
00026 from geompy import *
00027 
00028 import smesh
00029 
00030 # Geometrie
00031 # =========
00032 
00033 # Construire avec des hexahedres une piece faite de 2 cylindres de diametre different
00034 # et dont les axes se coupent orthogonalement, puis mailler.
00035 
00036 # Valeurs
00037 # -------
00038 
00039 cx = 0
00040 cy = 0
00041 cz = 0
00042 
00043 g_rayon   = 100.0
00044 g_hauteur = 500
00045 
00046 p_rayon   =  50.0
00047 p_hauteur = 500
00048 
00049 g_trim = 1000
00050 
00051 # Gros cylindre
00052 # -------------
00053 
00054 cpd = []
00055 
00056 g_base = MakeVertex(cx, cy, cz)
00057 g_dir  = MakeVectorDXDYDZ(0, 0, 1)
00058 t_hauteur = p_rayon+10.0
00059 
00060 g_cyl = MakeCylinder(g_base, g_dir, g_rayon, g_hauteur)
00061 
00062 g_coupe   = MakeVectorDXDYDZ(1, 0, 0)
00063 
00064 g_tools = []
00065 g_tools.append(MakePlane(MakeVertex(cx+t_hauteur, cy, cz), g_coupe, g_trim))
00066 g_tools.append(MakePlane(MakeVertex(cx-t_hauteur, cy, cz), g_coupe, g_trim))
00067 
00068 g_partie = MakePartition([g_cyl], g_tools, [], [], ShapeType["SOLID"])
00069 g_bas, g_centre, g_haut = SubShapeAllSorted(g_partie, ShapeType["SOLID"])
00070 
00071 # Partie basse du gros cylindre
00072 # -----------------------------
00073 
00074 b_hauteur = 10
00075 b_base    = 20
00076 
00077 b_boite = MakeBox(cx-t_hauteur, cy-b_base, cz,  cx-t_hauteur-b_hauteur, cy+b_base, cz+g_hauteur)
00078 cpd.append(b_boite)
00079 
00080 b_cyl = MakeCut(g_bas, b_boite)
00081 
00082 b_tools = []
00083 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy+b_base, cz), MakeVectorDXDYDZ( 1, 1, 0), g_trim))
00084 b_tools.append(MakePlane(MakeVertex(cx-t_hauteur-b_hauteur, cy-b_base, cz), MakeVectorDXDYDZ(-1, 1, 0), g_trim))
00085 
00086 b_partie = MakePartition([b_cyl], b_tools, [], [], ShapeType["SOLID"])
00087 b_element = SubShapeAll(b_partie, ShapeType["SOLID"])
00088 cpd = cpd + b_element
00089 
00090 # Partie haute du gros cylindre
00091 # -----------------------------
00092 
00093 h_plan = MakePlane(g_base, g_coupe, g_trim)
00094 
00095 cpd.append(MakeMirrorByPlane(b_boite, h_plan))
00096 
00097 for h in b_element:
00098     h_symetrie = MakeMirrorByPlane(h, h_plan)
00099     cpd.append(h_symetrie)
00100 
00101 # Petit cylindre
00102 # --------------
00103 
00104 z_arete = p_rayon/2
00105 x_arete = z_arete*t_hauteur*2/g_hauteur
00106 
00107 px = cx-x_arete
00108 py = cy-1.5*g_rayon
00109 pz = cz+g_hauteur/2
00110 
00111 p_base = MakeVertex(cx, py, pz)
00112 p_dir  = MakeVectorDXDYDZ(0, 1, 0)
00113 p_cyl  = MakeCylinder(p_base, p_dir, p_rayon, p_hauteur)
00114 
00115 p_boite = MakeBox(px, py, pz-z_arete,  cx+x_arete, py+p_hauteur, pz+z_arete)
00116 
00117 # Partie interieure du petit cylindre
00118 # -----------------------------------
00119 
00120 i_cyl   = MakeCommon(p_cyl, g_cyl)
00121 i_tuyau = MakeCut(i_cyl, p_boite)
00122 i_boite = MakeCommon(p_boite, g_cyl)
00123 
00124 # Partie exterieure du petit cylindre
00125 # -----------------------------------
00126 
00127 e_cyl0 = MakeCut(p_cyl, g_cyl)
00128 e_cyl  = SubShapeAllSorted(e_cyl0, ShapeType["SOLID"])
00129 
00130 e_tuyau = MakeCut(e_cyl[1], p_boite)
00131 
00132 e_boite0 = MakeCut(p_boite, g_cyl)
00133 e_boite  = SubShapeAllSorted(e_boite0, ShapeType["SOLID"])
00134 
00135 cpd.append(e_boite[1])
00136 
00137 # Partie centrale du gros cylindre
00138 # --------------------------------
00139 
00140 c_cyl = MakeCut(g_centre, p_cyl)
00141 
00142 # Partitionner
00143 # ------------
00144 
00145 p_tools = []
00146 p_tools.append(MakePlane(MakeVertex(px, py, pz-z_arete), MakeVectorDXDYDZ(-z_arete, 0, x_arete), g_trim))
00147 p_tools.append(MakePlane(MakeVertex(px, py, pz+z_arete), MakeVectorDXDYDZ( z_arete, 0, x_arete), g_trim))
00148 
00149 p_partie = MakePartition([e_tuyau], p_tools, [], [], ShapeType["SOLID"])
00150 p_element = SubShapeAll(p_partie, ShapeType["SOLID"])
00151 cpd = cpd + p_element
00152 
00153 q_partie = MakePartition([i_tuyau, c_cyl], p_tools, [], [], ShapeType["SOLID"])
00154 q_element = SubShapeAll(q_partie, ShapeType["SOLID"])
00155 
00156 q_element = q_element + [i_boite]
00157 
00158 q_tools = []
00159 q_tools.append(MakePlane(MakeVertex(cx, cy-b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
00160 q_tools.append(MakePlane(MakeVertex(cx, cy+b_base, cz), MakeVectorDXDYDZ(0, 1, 0), g_trim))
00161 
00162 r_element = []
00163 for e in q_element:
00164     r_partie = MakePartition([e], q_tools, [], [], ShapeType["SOLID"])
00165     r_element = r_element + SubShapeAll(r_partie, ShapeType["SOLID"])
00166 
00167 cpd = cpd + r_element
00168 
00169 # Compound
00170 # --------
00171 
00172 piece = RemoveExtraEdges(MakeCompound(cpd), True)
00173 
00174 # Ajouter la piece dans l'etude
00175 # -----------------------------
00176 
00177 piece_id = addToStudy(piece, "ex15_cyl2geometry")
00178 
00179 # Meshing
00180 # =======
00181 
00182 smesh.SetCurrentStudy(salome.myStudy)
00183 
00184 # Create a hexahedral mesh
00185 # ------------------------
00186 
00187 hexa = smesh.Mesh(piece, "ex15_cyl2geometry:hexa")
00188 
00189 algo = hexa.Segment()
00190 algo.NumberOfSegments(12)
00191 
00192 hexa.Quadrangle()
00193 
00194 hexa.Hexahedron()
00195 
00196 # Mesh calculus
00197 # -------------
00198 
00199 hexa.Compute()