1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012 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.
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 # File : SMESH_withHole.py
25 # Author : Lucien PIGNOLONI
35 # ---------------------------- GEOM --------------------------------------
37 # ---- define contigous arcs and segment to define a closed wire
38 p1 = geompy.MakeVertex( 100.0, 0.0, 0.0 )
39 p2 = geompy.MakeVertex( 50.0, 50.0, 0.0 )
40 p3 = geompy.MakeVertex( 100.0, 100.0, 0.0 )
41 arc1 = geompy.MakeArc( p1, p2, p3 )
43 p4 = geompy.MakeVertex( 170.0, 100.0, 0.0 )
44 seg1 = geompy.MakeVector( p3, p4 )
46 p5 = geompy.MakeVertex( 200.0, 70.0, 0.0 )
47 p6 = geompy.MakeVertex( 170.0, 40.0, 0.0 )
48 arc2 = geompy.MakeArc( p4, p5, p6 )
50 p7 = geompy.MakeVertex( 120.0, 30.0, 0.0 )
51 arc3 = geompy.MakeArc( p6, p7, p1 )
53 # ---- define a closed wire with arcs and segment
60 wire1 = geompy.MakeWire( List1 )
61 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
63 # ---- define a planar face with wire
64 WantPlanarFace = 1 #True
65 face1 = geompy.MakeFace( wire1, WantPlanarFace )
66 Id_face1 = geompy.addToStudy( face1, "face1" )
68 # ---- create a shape by extrusion
69 pO = geompy.MakeVertex( 0.0, 0.0, 0.0 )
70 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
71 vz = geompy.MakeVector( pO, pz )
73 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
74 Id_prism1 = geompy.addToStudy( prism1, "prism1")
76 # ---- create two cylinders
78 pc1 = geompy.MakeVertex( 90.0, 50.0, -40.0 )
79 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
82 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
83 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
85 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
86 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
89 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
91 # ---- fuse with cyl2 to obtain the final mechanic piece :)
92 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
93 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
95 # ---- Analysis of the geometry
97 print "Analysis of the geometry mechanic :"
99 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
100 subFaceList = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
101 subEdgeList = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
103 print "number of Shells in mechanic : ",len(subShellList)
104 print "number of Faces in mechanic : ",len(subFaceList)
105 print "number of Edges in mechanic : ",len(subEdgeList)
107 ### ---------------------------- SMESH --------------------------------------
108 smesh.SetCurrentStudy(salome.myStudy)
110 shape_mesh = salome.IDToObject( Id_mechanic )
112 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic_tetra")
114 print "-------------------------- add hypothesis to main mechanic"
118 algo1 = mesh.Segment()
119 hypNbSeg = algo1.NumberOfSegments(numberOfSegment)
120 print hypNbSeg.GetName()
121 print hypNbSeg.GetId()
122 print hypNbSeg.GetNumberOfSegments()
123 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
128 algo2 = mesh.Triangle(smesh.MEFISTO)
129 hypArea = algo2.MaxElementArea(maxElementArea)
130 print hypArea.GetName()
131 print hypArea.GetId()
132 print hypArea.GetMaxElementArea()
133 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
136 maxElementVolume = 20
138 algo3 = mesh.Tetrahedron(smesh.NETGEN)
139 hypVolume = algo3.MaxElementVolume(maxElementVolume)
140 print hypVolume.GetName()
141 print hypVolume.GetId()
142 print hypVolume.GetMaxElementVolume()
143 smesh.SetName(hypVolume, "maxElementVolume_" + str(maxElementVolume))
146 print "-------------------------- compute the mesh of the mechanic piece"
149 print "Information about the Mesh_mechanic_tetra:"
150 print "Number of nodes : ", mesh.NbNodes()
151 print "Number of edges : ", mesh.NbEdges()
152 print "Number of faces : ", mesh.NbFaces()
153 print "Number of triangles : ", mesh.NbTriangles()
154 print "Number of quadrangles: ", mesh.NbQuadrangles()
155 print "Number of volumes : ", mesh.NbVolumes()
156 print "Number of tetrahedrons: ", mesh.NbTetras()
158 salome.sg.updateObjBrowser(1)