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
33 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
34 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
36 smeshgui = salome.ImportComponentGUI("SMESH")
37 smeshgui.Init(salome.myStudyId);
39 # ---------------------------- GEOM --------------------------------------
40 ShapeTypeCompSolid = 1
48 # ---- define contigous arcs and segment to define a closed wire
50 p1 = geom.MakePointStruct( 100.0, 0.0, 0.0 )
51 p2 = geom.MakePointStruct( 50.0, 50.0, 0.0 )
52 p3 = geom.MakePointStruct( 100.0, 100.0, 0.0 )
53 arc1 = geom.MakeArc( p1, p2, p3 )
55 p4 = geom.MakePointStruct( 170.0, 100.0, 0.0 )
56 seg1 = geom.MakeVector( p3, p4 )
58 p5 = geom.MakePointStruct( 200.0, 70.0, 0.0 )
59 p6 = geom.MakePointStruct( 170.0, 40.0, 0.0 )
60 arc2 = geom.MakeArc( p4, p5, p6 )
62 p7 = geom.MakePointStruct( 120.0, 30.0, 0.0 )
63 arc3 = geom.MakeArc( p6, p7, p1 )
65 # ---- define a closed wire with arcs and segment
75 ListIOR1.append( S._get_Name() )
76 wire1 = geom.MakeWire( ListIOR1 )
78 # ---- define a planar face with wire
80 WantPlanarFace = 1 #True
81 face1 = geom.MakeFace( wire1, WantPlanarFace )
83 # ---- create a shape by extrusion
85 pO = geom.MakePointStruct( 0.0, 0.0, 0.0 )
86 pz = geom.MakePointStruct( 0.0, 0.0, 100.0 )
88 prism1 = geom.MakePrism( face1, pO, pz )
90 # ---- create two cylinders
92 pc1 = geom.MakePointStruct( 90.0, 50.0, -40.0 )
93 pc2 = geom.MakePointStruct( 170.0, 70.0, -40.0 )
94 vz = geom.MakeDirection( pz )
97 cyl1 = geom.MakeCylinder( pc1, vz, radius, height )
98 cyl2 = geom.MakeCylinder( pc2, vz, radius, height )
102 shape = geom.MakeBoolean( prism1, cyl1, 2 )
104 # ---- fuse with cyl2 to obtain the final mechanic piece :)
106 mechanic = geom.MakeBoolean( shape, cyl2, 3 )
108 idMechanic = geompy.addToStudy( mechanic, "mechanic")
110 # ---- Analysis of the geometry
112 print "Analysis of the geometry mechanic :"
114 subShellList=geompy.SubShapeAll(mechanic,ShapeTypeShell)
115 subFaceList=geompy.SubShapeAll(mechanic,ShapeTypeFace)
116 subEdgeList=geompy.SubShapeAll(mechanic,ShapeTypeEdge)
118 print "number of Shells in mechanic : ",len(subShellList)
119 print "number of Faces in mechanic : ",len(subFaceList)
120 print "number of Edges in mechanic : ",len(subEdgeList)
122 ### ---------------------------- SMESH --------------------------------------
124 print "-------------------------- NumberOfSegments"
128 hypNbSeg = smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" )
129 hypNbSeg.SetNumberOfSegments(numberOfSegment)
130 print hypNbSeg.GetName()
131 print hypNbSeg.GetId()
132 print hypNbSeg.GetNumberOfSegments()
134 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
136 print "-------------------------- MaxElementArea"
140 hypArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
141 hypArea.SetMaxElementArea(maxElementArea)
142 print hypArea.GetName()
143 print hypArea.GetId()
144 print hypArea.GetMaxElementArea()
146 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_20")
148 print "-------------------------- MaxElementVolume"
150 maxElementVolume = 20
152 hypVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
153 hypVolume.SetMaxElementVolume(maxElementVolume)
154 print hypVolume.GetName()
155 print hypVolume.GetId()
156 print hypVolume.GetMaxElementVolume()
158 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_20")
160 print "-------------------------- Regular_1D"
162 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
163 listHyp =algoReg1D.GetCompatibleHypothesis()
166 print algoReg1D.GetName()
167 print algoReg1D.GetId()
169 smeshgui.SetName(salome.ObjectToID(algoReg1D), "Regular_1D" )
171 print "-------------------------- MEFISTO_2D"
173 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
174 listHyp = algoMef.GetCompatibleHypothesis()
177 print algoMef.GetName()
178 print algoMef.GetId()
180 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" )
182 print "-------------------------- NETGEN_3D"
184 algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
185 listHyp = algoNg.GetCompatibleHypothesis()
188 print algoNg.GetName()
191 smeshgui.SetName(salome.ObjectToID(algoNg), "NETGEN_3D" )
193 print "-------------------------- add hypothesis to main mechanic"
195 shape_mesh = salome.IDToObject( idMechanic )
197 mesh = smesh.CreateMesh(shape_mesh)
198 smeshgui.SetName(salome.ObjectToID(mesh), "Mesh_mechanic_tetra" );
200 mesh.AddHypothesis( shape_mesh, algoReg1D ) # Regular 1D/wire discretisation
201 mesh.AddHypothesis( shape_mesh, algoMef ) # MEFISTO 2D
202 mesh.AddHypothesis( shape_mesh, algoNg ) # NETGEN 3D
204 mesh.AddHypothesis( shape_mesh, hypNbSeg ) # nb segments
205 mesh.AddHypothesis( shape_mesh, hypArea ) # max area
206 mesh.AddHypothesis( shape_mesh, hypVolume ) # max volume
208 print "-------------------------- compute the mesh of the mechanic piece"
209 smesh.Compute(mesh,shape_mesh)
211 print "Information about the Mesh_mechanic_tetra:"
212 print "Number of nodes : ", mesh.NbNodes()
213 print "Number of edges : ", mesh.NbEdges()
214 print "Number of faces : ", mesh.NbFaces()
215 print "Number of triangles : ", mesh.NbTriangles()
216 print "Number of volumes: ", mesh.NbVolumes()
217 print "Number of tetrahedrons: ", mesh.NbTetras()
219 salome.sg.updateObjBrowser(1);