1 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 # File : SMESH_withHole.py
23 # Author : Lucien PIGNOLONI
31 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
32 smesh.SetCurrentStudy(salome.myStudy)
34 smeshgui = salome.ImportComponentGUI("SMESH")
35 smeshgui.Init(salome.myStudyId)
40 # ---------------------------- GEOM --------------------------------------
42 # ---- define contigous arcs and segment to define a closed wire
43 p1 = geompy.MakeVertex( 100.0, 0.0, 0.0 )
44 p2 = geompy.MakeVertex( 50.0, 50.0, 0.0 )
45 p3 = geompy.MakeVertex( 100.0, 100.0, 0.0 )
46 arc1 = geompy.MakeArc( p1, p2, p3 )
48 p4 = geompy.MakeVertex( 170.0, 100.0, 0.0 )
49 seg1 = geompy.MakeVector( p3, p4 )
51 p5 = geompy.MakeVertex( 200.0, 70.0, 0.0 )
52 p6 = geompy.MakeVertex( 170.0, 40.0, 0.0 )
53 arc2 = geompy.MakeArc( p4, p5, p6 )
55 p7 = geompy.MakeVertex( 120.0, 30.0, 0.0 )
56 arc3 = geompy.MakeArc( p6, p7, p1 )
58 # ---- define a closed wire with arcs and segment
65 wire1 = geompy.MakeWire( List1 )
66 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
68 # ---- define a planar face with wire
69 WantPlanarFace = 1 #True
70 face1 = geompy.MakeFace( wire1, WantPlanarFace )
71 Id_face1 = geompy.addToStudy( face1, "face1" )
73 # ---- create a shape by extrusion
74 pO = geompy.MakeVertex( 0.0, 0.0, 0.0 )
75 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
76 vz = geompy.MakeVector( pO, pz )
78 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
79 Id_prism1 = geompy.addToStudy( prism1, "prism1")
81 # ---- create two cylinders
83 pc1 = geompy.MakeVertex( 90.0, 50.0, -40.0 )
84 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
87 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
88 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
90 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
91 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
94 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
96 # ---- fuse with cyl2 to obtain the final mechanic piece :)
97 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
98 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
100 # ---- Analysis of the geometry
102 print "Analysis of the geometry mechanic :"
104 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
105 subFaceList = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
106 subEdgeList = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
108 print "number of Shells in mechanic : ",len(subShellList)
109 print "number of Faces in mechanic : ",len(subFaceList)
110 print "number of Edges in mechanic : ",len(subEdgeList)
112 ### ---------------------------- SMESH --------------------------------------
114 print "-------------------------- NumberOfSegments"
118 hypNbSeg = smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" )
119 hypNbSeg.SetNumberOfSegments( numberOfSegment )
120 print hypNbSeg.GetName()
121 print hypNbSeg.GetId()
122 print hypNbSeg.GetNumberOfSegments()
124 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
126 print "-------------------------- MaxElementArea"
130 hypArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
131 hypArea.SetMaxElementArea( maxElementArea )
132 print hypArea.GetName()
133 print hypArea.GetId()
134 print hypArea.GetMaxElementArea()
136 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_20")
138 print "-------------------------- MaxElementVolume"
140 maxElementVolume = 20
142 hypVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
143 hypVolume.SetMaxElementVolume( maxElementVolume )
144 print hypVolume.GetName()
145 print hypVolume.GetId()
146 print hypVolume.GetMaxElementVolume()
148 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_20")
150 print "-------------------------- Regular_1D"
152 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
153 listHyp =algoReg1D.GetCompatibleHypothesis()
156 print algoReg1D.GetName()
157 print algoReg1D.GetId()
159 smeshgui.SetName(salome.ObjectToID(algoReg1D), "Regular_1D")
161 print "-------------------------- MEFISTO_2D"
163 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
164 listHyp = algoMef.GetCompatibleHypothesis()
167 print algoMef.GetName()
168 print algoMef.GetId()
170 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D")
172 print "-------------------------- NETGEN_3D"
174 algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
175 listHyp = algoNg.GetCompatibleHypothesis()
178 print algoNg.GetName()
181 smeshgui.SetName(salome.ObjectToID(algoNg), "NETGEN_3D")
183 print "-------------------------- add hypothesis to main mechanic"
185 shape_mesh = salome.IDToObject( Id_mechanic )
187 mesh = smesh.CreateMesh(shape_mesh)
189 idmesh = salome.ObjectToID(mesh)
190 smeshgui.SetName( idmesh, "Mesh_mechanic_tetra" )
192 mesh.AddHypothesis( shape_mesh, hypNbSeg ) # nb segments
193 mesh.AddHypothesis( shape_mesh, hypArea ) # max area
194 mesh.AddHypothesis( shape_mesh, hypVolume ) # max volume
196 mesh.AddHypothesis( shape_mesh, algoReg1D ) # Regular 1D/wire discretisation
197 mesh.AddHypothesis( shape_mesh, algoMef ) # MEFISTO 2D
198 mesh.AddHypothesis( shape_mesh, algoNg ) # NETGEN 3D
200 print "-------------------------- compute the mesh of the mechanic piece"
201 smesh.Compute(mesh,shape_mesh)
203 print "Information about the Mesh_mechanic_tetra:"
204 print "Number of nodes : ", mesh.NbNodes()
205 print "Number of edges : ", mesh.NbEdges()
206 print "Number of faces : ", mesh.NbFaces()
207 print "Number of triangles : ", mesh.NbTriangles()
208 print "Number of quadrangles: ", mesh.NbQuadrangles()
209 print "Number of volumes : ", mesh.NbVolumes()
210 print "Number of tetrahedrons: ", mesh.NbTetras()
212 salome.sg.updateObjBrowser(1)