Back to index

salome-smesh  6.5.0
SMESH_mechanic_netgen.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 # Quadrangulation of the geometry generated by the Python script
00025 # SMESH_mechanic.py
00026 # The new Netgen algorithm is used that discretizes baoundaries itself
00027 #
00028 import salome
00029 import geompy
00030 
00031 geom  = geompy.geom
00032 
00033 import smesh
00034 
00035 # ---------------------------- GEOM --------------------------------------
00036 
00037 # ---- define contigous arcs and segment to define a closed wire
00038 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
00039 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
00040 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
00041 arc1 = geompy.MakeArc( p1, p2, p3 )
00042 
00043 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
00044 seg1 = geompy.MakeVector( p3, p4 )
00045 
00046 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
00047 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
00048 arc2 = geompy.MakeArc( p4, p5, p6 )
00049 
00050 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
00051 arc3 = geompy.MakeArc( p6, p7, p1 )
00052 
00053 # ---- define a closed wire with arcs and segment
00054 List1 = []
00055 List1.append( arc1 )
00056 List1.append( seg1 )
00057 List1.append( arc2 )
00058 List1.append( arc3 )
00059 
00060 wire1 = geompy.MakeWire( List1 )
00061 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
00062 
00063 # ---- define a planar face with wire
00064 WantPlanarFace = 1 #True
00065 face1 = geompy.MakeFace( wire1, WantPlanarFace )
00066 Id_face1 = geompy.addToStudy( face1, "face1" )
00067 
00068 # ---- create a shape by extrusion
00069 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
00070 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
00071 vz = geompy.MakeVector( pO, pz )
00072 
00073 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
00074 Id_prism1 = geompy.addToStudy( prism1, "prism1")
00075 
00076 # ---- create two cylinders
00077 
00078 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
00079 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
00080 radius = 20.0
00081 height = 180.0
00082 cyl1  = geompy.MakeCylinder( pc1, vz, radius, height )
00083 cyl2  = geompy.MakeCylinder( pc2, vz, radius, height )
00084 
00085 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
00086 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
00087 
00088 # ---- cut with cyl1
00089 shape  = geompy.MakeBoolean( prism1, cyl1, 2 )
00090 
00091 # ---- fuse with cyl2 to obtain the final mechanic piece :)
00092 mechanic =  geompy.MakeBoolean( shape, cyl2, 3 )
00093 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
00094 
00095 # ---- Analysis of the geometry
00096 
00097 print "Analysis of the geometry mechanic :"
00098 
00099 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
00100 subFaceList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
00101 subEdgeList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
00102 
00103 print "number of Shells in mechanic : ",len(subShellList)
00104 print "number of Faces in mechanic : ",len(subFaceList)
00105 print "number of Edges in mechanic : ",len(subEdgeList)
00106 
00107 ### ---------------------------- SMESH --------------------------------------
00108 smesh.SetCurrentStudy(salome.myStudy)
00109 
00110 print "-------------------------- create Mesh, algorithm, hypothesis"
00111 
00112 mesh = smesh.Mesh(mechanic, "Mesh_mechanic");
00113 netgen = mesh.Triangle(smesh.NETGEN)
00114 netgen.SetMaxSize( 50 )
00115 #netgen.SetSecondOrder( 0 )
00116 netgen.SetFineness( smesh.Fine )
00117 netgen.SetQuadAllowed( 1 )
00118 #netgen.SetOptimize( 1 )
00119 
00120 salome.sg.updateObjBrowser(1)
00121 
00122 print "-------------------------- compute mesh"
00123 ret = mesh.Compute()
00124 print ret
00125 if ret != 0:
00126     print "Information about the MeshcompShel:"
00127     print "Number of nodes        : ", mesh.NbNodes()
00128     print "Number of edges        : ", mesh.NbEdges()
00129     print "Number of faces        : ", mesh.NbFaces()
00130     print "Number of triangles    : ", mesh.NbTriangles()
00131     print "Number of quadrangles  : ", mesh.NbQuadrangles()
00132     print "Number of volumes      : ", mesh.NbVolumes()
00133     print "Number of tetrahedrons : ", mesh.NbTetras()
00134     
00135 else:
00136     print "problem when computing the mesh"