Back to index

salome-smesh  6.5.0
SMESH_mechanic.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 #  File   : SMESH_withHole.py
00025 #  Author : Lucien PIGNOLONI
00026 #  Module : SMESH
00027 #  $Header: /home/server/cvs/SMESH/SMESH_SRC/src/SMESH_SWIG/SMESH_mechanic.py,v 1.11.2.3.6.3.2.1 2012-04-13 09:31:18 vsr Exp $
00028 #-------------------------------------------------------------------------
00029 #
00030 import salome
00031 import geompy
00032 import smesh
00033 
00034 import StdMeshers
00035 
00036 # ---------------------------- GEOM --------------------------------------
00037 
00038 # ---- define contigous arcs and segment to define a closed wire
00039 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
00040 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
00041 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
00042 arc1 = geompy.MakeArc( p1, p2, p3 )
00043 
00044 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
00045 seg1 = geompy.MakeVector( p3, p4 )
00046 
00047 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
00048 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
00049 arc2 = geompy.MakeArc( p4, p5, p6 )
00050 
00051 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
00052 arc3 = geompy.MakeArc( p6, p7, p1 )
00053 
00054 # ---- define a closed wire with arcs and segment
00055 List1 = []
00056 List1.append( arc1 )
00057 List1.append( seg1 )
00058 List1.append( arc2 )
00059 List1.append( arc3 )
00060 
00061 wire1 = geompy.MakeWire( List1 )
00062 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
00063 
00064 # ---- define a planar face with wire
00065 WantPlanarFace = 1 #True
00066 face1 = geompy.MakeFace( wire1, WantPlanarFace )
00067 Id_face1 = geompy.addToStudy( face1, "face1" )
00068 
00069 # ---- create a shape by extrusion
00070 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
00071 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
00072 vz = geompy.MakeVector( pO, pz )
00073 
00074 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
00075 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
00076 
00077 # ---- create two cylinders
00078 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
00079 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
00080 
00081 radius = 20.0
00082 height = 180.0
00083 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
00084 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
00085 
00086 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
00087 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
00088 
00089 # ---- cut with cyl1
00090 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
00091 
00092 # ---- fuse with cyl2 to obtain the final mechanic piece :)
00093 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
00094 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
00095 
00096 # ---- explode on faces
00097 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
00098 
00099 # ---- add a face sub-shape in study to be meshed different
00100 sub_face1 = SubFaceL[0]
00101 name      = geompy.SubShapeName( sub_face1, mechanic )
00102 
00103 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
00104 
00105 # ---- add a face sub-shape in study to be meshed different
00106 sub_face2 = SubFaceL[4]
00107 name      = geompy.SubShapeName( sub_face2, mechanic )
00108 
00109 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
00110 
00111 # ---- add a face sub-shape in study to be meshed different
00112 sub_face3 = SubFaceL[5]
00113 name      = geompy.SubShapeName( sub_face3, mechanic )
00114 
00115 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
00116 
00117 # ---- add a face sub-shape in study to be meshed different
00118 sub_face4 = SubFaceL[10]
00119 name      = geompy.SubShapeName( sub_face4, mechanic )
00120 
00121 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
00122 
00123 # ---------------------------- SMESH --------------------------------------
00124 smesh.SetCurrentStudy(salome.myStudy)
00125 
00126 # -- Init --
00127 shape_mesh = salome.IDToObject( Id_mechanic )
00128 
00129 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic")
00130 
00131 print "-------------------------- NumberOfSegments"
00132 
00133 numberOfSegment = 10
00134 
00135 algo = mesh.Segment()
00136 hypNbSeg = algo.NumberOfSegments(numberOfSegment)
00137 print hypNbSeg.GetName()
00138 print hypNbSeg.GetId()
00139 print hypNbSeg.GetNumberOfSegments()
00140 smesh.SetName(hypNbSeg, "NumberOfSegments_10")
00141 
00142 print "-------------------------- MaxElementArea"
00143 
00144 maxElementArea = 25
00145 
00146 algo = mesh.Triangle()
00147 hypArea25 = algo.MaxElementArea(maxElementArea)
00148 print hypArea25.GetName()
00149 print hypArea25.GetId()
00150 print hypArea25.GetMaxElementArea()
00151 smesh.SetName(hypArea25, "MaxElementArea_25")
00152 
00153 # Create submesh on sub_face1 - sub_face4
00154 # ---------------------------------------
00155 
00156 # Set 2D algorithm to submesh on sub_face1
00157 algo = mesh.Quadrangle(sub_face1)
00158 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
00159 
00160 # Set 2D algorithm to submesh on sub_face2
00161 algo = mesh.Quadrangle(sub_face2)
00162 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
00163 
00164 # Set 2D algorithm to submesh on sub_face3
00165 algo = mesh.Quadrangle(sub_face3)
00166 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
00167 
00168 # Set 2D algorithm to submesh on sub_face4
00169 algo = mesh.Quadrangle(sub_face4)
00170 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
00171 
00172 print "-------------------------- compute the mesh of the mechanic piece"
00173 
00174 mesh.Compute()
00175 
00176 print "Information about the Mesh_mechanic:"
00177 print "Number of nodes       : ", mesh.NbNodes()
00178 print "Number of edges       : ", mesh.NbEdges()
00179 print "Number of faces       : ", mesh.NbFaces()
00180 print "Number of triangles   : ", mesh.NbTriangles()
00181 print "Number of quadrangles : ", mesh.NbQuadrangles()
00182 print "Number of volumes     : ", mesh.NbVolumes()
00183 print "Number of tetrahedrons: ", mesh.NbTetras()
00184 
00185 salome.sg.updateObjBrowser(1)