Back to index

salome-smesh  6.5.0
SMESH_Partition1_tetra.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 # Tetrahedrization of the geometry generated by the Python script GEOM_Partition1.py
00025 # Hypothesis and algorithms for the mesh generation are global
00026 # -- Rayon de la bariere
00027 #
00028 import salome
00029 import geompy
00030 import smesh
00031 from math import sqrt
00032 
00033 
00034 #---------------------------------------------------------------
00035 
00036 barier_height = 7.0
00037 barier_radius = 5.6 / 2 # Rayon de la bariere
00038 colis_radius = 1.0 / 2  # Rayon du colis
00039 colis_step = 2.0        # Distance s‰parant deux colis
00040 cc_width = 0.11         # Epaisseur du complement de colisage
00041 
00042 # --
00043 
00044 cc_radius = colis_radius + cc_width
00045 colis_center = sqrt(2.0)*colis_step/2
00046 
00047 # --
00048 
00049 boolean_common  = 1
00050 boolean_cut     = 2
00051 boolean_fuse    = 3
00052 boolean_section = 4
00053 
00054 # --
00055 
00056 p0 = geompy.MakeVertex(0.,0.,0.)
00057 vz = geompy.MakeVectorDXDYDZ(0.,0.,1.)
00058 
00059 # --
00060 
00061 barier = geompy.MakeCylinder(p0, vz, barier_radius, barier_height)
00062 
00063 # --
00064 
00065 colis = geompy.MakeCylinder(p0, vz, colis_radius, barier_height)
00066 cc    = geompy.MakeCylinder(p0, vz,    cc_radius, barier_height)
00067 
00068 colis_cc = geompy.MakeCompound([colis, cc])
00069 colis_cc = geompy.MakeTranslation(colis_cc, colis_center, 0.0, 0.0)
00070 
00071 colis_cc_multi = geompy.MultiRotate1D(colis_cc, vz, 4)
00072 
00073 # --
00074 
00075 Compound1 = geompy.MakeCompound([colis_cc_multi, barier])
00076 SubShape_theShape = geompy.SubShapeAll(Compound1,geompy.ShapeType["SOLID"])
00077 alveole = geompy.MakePartition(SubShape_theShape)
00078 
00079 print "Analysis of the geometry to mesh (right after the Partition) :"
00080 
00081 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
00082 subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
00083 subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
00084 
00085 print "number of Shells in alveole : ", len(subShellList)
00086 print "number of Faces  in alveole : ", len(subFaceList)
00087 print "number of Edges  in alveole : ", len(subEdgeList)
00088 
00089 subshapes = geompy.SubShapeAll(alveole, geompy.ShapeType["SHAPE"])
00090 
00091 ## there are 9 sub-shapes
00092 
00093 comp1 = geompy.MakeCompound( [ subshapes[0], subshapes[1] ] )
00094 comp2 = geompy.MakeCompound( [ subshapes[2], subshapes[3] ] )
00095 comp3 = geompy.MakeCompound( [ subshapes[4], subshapes[5] ] )
00096 comp4 = geompy.MakeCompound( [ subshapes[6], subshapes[7] ] )
00097 
00098 compGOs = []
00099 compGOs.append( comp1 )
00100 compGOs.append( comp2 )
00101 compGOs.append( comp3 )
00102 compGOs.append( comp4 )
00103 comp = geompy.MakeCompound( compGOs )
00104 
00105 alveole = geompy.MakeCompound( [ comp, subshapes[8] ])
00106 
00107 idalveole = geompy.addToStudy(alveole, "alveole")
00108 
00109 print "Analysis of the geometry to mesh (right after the MakeCompound) :"
00110 
00111 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
00112 subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
00113 subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
00114 
00115 print "number of Shells in alveole : ", len(subShellList)
00116 print "number of Faces  in alveole : ", len(subFaceList)
00117 print "number of Edges  in alveole : ", len(subEdgeList)
00118 
00119 status = geompy.CheckShape(alveole)
00120 print " check status ", status
00121 
00122 # ---- launch SMESH
00123 smesh.SetCurrentStudy(salome.myStudy)
00124 
00125 # ---- init a Mesh with the alveole
00126 shape_mesh = salome.IDToObject( idalveole )
00127 
00128 mesh = smesh.Mesh(shape_mesh, "MeshAlveole")
00129 
00130 print "-------------------------- create Hypothesis (In this case global hypothesis are used)"
00131 
00132 print "-------------------------- NumberOfSegments"
00133 
00134 numberOfSegments = 10
00135 
00136 regular1D = mesh.Segment()
00137 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
00138 print hypNbSeg.GetName()
00139 print hypNbSeg.GetId()
00140 print hypNbSeg.GetNumberOfSegments()
00141 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
00142 
00143 print "-------------------------- MaxElementArea"
00144 
00145 maxElementArea = 0.1
00146 
00147 mefisto2D = mesh.Triangle()
00148 hypArea = mefisto2D.MaxElementArea(maxElementArea)
00149 print hypArea.GetName()
00150 print hypArea.GetId()
00151 print hypArea.GetMaxElementArea()
00152 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
00153 
00154 print "-------------------------- MaxElementVolume"
00155 
00156 maxElementVolume = 0.5
00157 
00158 netgen3D = mesh.Tetrahedron(smesh.NETGEN)
00159 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
00160 print hypVolume.GetName()
00161 print hypVolume.GetId()
00162 print hypVolume.GetMaxElementVolume()
00163 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
00164 
00165 print "-------------------------- compute the mesh of alveole "
00166 ret = mesh.Compute()
00167 
00168 if ret != 0:
00169     log=mesh.GetLog(0) # no erase trace
00170     for linelog in log:
00171         print linelog
00172     print "Information about the Mesh_mechanic:"
00173     print "Number of nodes       : ", mesh.NbNodes()
00174     print "Number of edges       : ", mesh.NbEdges()
00175     print "Number of faces       : ", mesh.NbFaces()
00176     print "Number of triangles   : ", mesh.NbTriangles()
00177     print "Number of volumes     : ", mesh.NbVolumes()
00178     print "Number of tetrahedrons: ", mesh.NbTetras()
00179 else:
00180     print "problem when computing the mesh"
00181 
00182 salome.sg.updateObjBrowser(1)