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
30 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
31 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
33 geom.GetCurrentStudy(salome.myStudy._get_StudyId())
34 smesh.SetCurrentStudy(salome.myStudy)
36 smeshgui = salome.ImportComponentGUI("SMESH")
37 smeshgui.Init(salome.myStudyId);
41 # ---------------------------- GEOM --------------------------------------
42 ShapeTypeCompSolid = 1
50 # ---- define contigous arcs and segment to define a closed wire
51 p1 = geom.MakePointStruct( 100.0, 0.0, 0.0 )
52 p2 = geom.MakePointStruct( 50.0, 50.0, 0.0 )
53 p3 = geom.MakePointStruct( 100.0, 100.0, 0.0 )
54 arc1 = geom.MakeArc( p1, p2, p3 )
56 p4 = geom.MakePointStruct( 170.0, 100.0, 0.0 )
57 seg1 = geom.MakeVector( p3, p4 )
59 p5 = geom.MakePointStruct( 200.0, 70.0, 0.0 )
60 p6 = geom.MakePointStruct( 170.0, 40.0, 0.0 )
61 arc2 = geom.MakeArc( p4, p5, p6 )
63 p7 = geom.MakePointStruct( 120.0, 30.0, 0.0 )
64 arc3 = geom.MakeArc( p6, p7, p1 )
66 # ---- define a closed wire with arcs and segment
75 ListIOR1.append( S._get_Name() )
76 wire1 = geom.MakeWire( ListIOR1 )
78 Id_wire1 = geompy.addToStudy( wire1, "wire1")
80 # ---- define a planar face with wire
81 WantPlanarFace = 1 #True
82 face1 = geom.MakeFace( wire1, WantPlanarFace )
83 Id_face1 = geompy.addToStudy( face1, "face1")
85 # ---- create a shape by extrusion
86 pO = geom.MakePointStruct( 0.0, 0.0, 0.0 )
87 pz = geom.MakePointStruct( 0.0, 0.0, 100.0 )
89 prism1 = geom.MakePrism( face1, pO, pz )
90 Id_prism1 = geompy.addToStudy( prism1, "prism1")
92 # ---- create two cylinders
94 pc1 = geom.MakePointStruct( 90.0, 50.0, -40.0 )
95 pc2 = geom.MakePointStruct( 170.0, 70.0, -40.0 )
96 vz = geom.MakeDirection( pz )
99 cyl1 = geom.MakeCylinder( pc1, vz, radius, height )
100 cyl2 = geom.MakeCylinder( pc2, vz, radius, height )
102 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
103 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
106 shape = geom.MakeBoolean( prism1, cyl1, 2 )
108 # ---- fuse with cyl2
109 shape1 = geom.MakeBoolean( shape, cyl2, 3 )
111 Id_shape1 = geompy.addToStudy( shape1, "shape1")
113 #faces = geompy.SubShapeAllSorted( shape1, ShapeTypeFace)
116 # geompy.addToStudy(face,"face_" + str(i))
119 # ---- add a face sub shape in study to be meshed different
121 IdSubFaceList.append(1)
122 sub_face = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceList )
123 name = geompy.SubShapeName( sub_face._get_Name(), shape1._get_Name() )
125 Id_SubFace = geompy.addToStudyInFather( shape1, sub_face, name )
127 # ---- add a face sub shape in study to be meshed different
130 sub_face2 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
131 name = geompy.SubShapeName( sub_face2._get_Name(), shape1._get_Name() )
133 Id_SubFace2 = geompy.addToStudyInFather( shape1, sub_face2, name )
135 # ---- add a face sub shape in study to be meshed different
138 sub_face3 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
139 name = geompy.SubShapeName( sub_face3._get_Name(), shape1._get_Name() )
141 Id_SubFace3 = geompy.addToStudyInFather( shape1, sub_face3, name )
143 # ---- add a face sub shape in study to be meshed different
146 sub_face4 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
147 name = geompy.SubShapeName( sub_face4._get_Name(), shape1._get_Name() )
149 Id_SubFace4 = geompy.addToStudyInFather( shape1, sub_face4, name )
152 # ---------------------------- SMESH --------------------------------------
154 # ------------------------------ Length Hypothesis
156 print "-------------------------- create Hypothesis"
157 print "-------------------------- LocalLength"
158 hyp1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
159 hyp1.SetLength( 100.0 )
162 print hyp1.GetLength()
164 idlength = salome.ObjectToID(hyp1)
165 smeshgui.SetName(idlength, "Local_Length_100");
167 print "-------------------------- NumberOfSegments"
169 hyp2 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
170 hyp2.SetNumberOfSegments( 10 )
173 print hyp2.GetNumberOfSegments()
175 idseg = salome.ObjectToID(hyp2)
176 smeshgui.SetName(idseg, "NumberOfSegments_12");
178 print "-------------------------- MaxElementArea"
180 hyp3 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
181 hyp3.SetMaxElementArea( 25 )
184 print hyp3.GetMaxElementArea()
186 idarea1 = salome.ObjectToID(hyp3)
187 smeshgui.SetName(idarea1, "MaxElementArea_20");
189 print "-------------------------- MaxElementArea"
191 hyp4 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
192 hyp4.SetMaxElementArea( 35 )
195 print hyp4.GetMaxElementArea()
197 idarea2 = salome.ObjectToID(hyp4)
198 smeshgui.SetName(idarea2, "MaxElementArea_30");
201 print "-------------------------- Regular_1D"
203 alg1 = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
204 listHyp =alg1.GetCompatibleHypothesis()
210 idreg1d = salome.ObjectToID(alg1)
211 smeshgui.SetName( idreg1d, "Regular_1D" );
213 print "-------------------------- MEFISTO_2D"
215 alg2 = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
216 listHyp = alg2.GetCompatibleHypothesis()
222 idmef = salome.ObjectToID(alg2)
223 smeshgui.SetName( idmef, "MEFISTO_2D" );
225 print "-------------------------- SMESH_Quadrangle_2D"
227 alg3 = smesh.CreateHypothesis( "Quadrangle_2D", "libStdMeshersEngine.so" )
228 listHyp = alg3.GetCompatibleHypothesis()
234 idqad2 = salome.ObjectToID(alg3)
235 smeshgui.SetName( idqad2, "SMESH_Quadrangle_2D" );
238 print "-------------------------- add hypothesis to main shape1"
240 shape_mesh = salome.IDToObject( Id_shape1 )
242 mesh = smesh.CreateMesh(shape_mesh)
244 idmesh = salome.ObjectToID(mesh)
245 smeshgui.SetName( idmesh, "Mesh_mechanic" );
247 mesh.AddHypothesis( shape_mesh, alg1 ) # Regular 1D/wire discretisation
248 mesh.AddHypothesis( shape_mesh, alg2 ) # MEFISTO 2D
250 ret = mesh.AddHypothesis( shape_mesh, hyp2 ) # nb segments
251 ret = mesh.AddHypothesis( shape_mesh, hyp3 ) # max area
253 print "--------Add hypothesis and algorith to sub face"
255 #sub_face = salome.IDToObject( Id_SubFace )
256 submesh = mesh.GetSubMesh(sub_face, "SubMeshFace")
258 mesh.AddHypothesis( sub_face, alg3 ) # Quadrangle 2D
259 mesh.AddHypothesis( sub_face, hyp4 ) # max area
261 print "--------Add hypothesis and algorith to sub face 2"
263 #sub_face2 = salome.IDToObject( Id_SubFace2 )
264 submesh = mesh.GetSubMesh(sub_face2, "SubMeshFace2")
266 mesh.AddHypothesis( sub_face2, alg3 ) # Quadrangle 2D
267 ret = mesh.AddHypothesis( sub_face2, hyp4 ) # max area
269 print "--------Add hypothesis and algorith to sub face 3"
271 #sub_face3 = salome.IDToObject( Id_SubFace3 )
272 submesh = mesh.GetSubMesh(sub_face3, "SubMeshFace3")
274 mesh.AddHypothesis( sub_face3, alg3 ) # Quadrangle 2D
275 ret = mesh.AddHypothesis( sub_face3, hyp4 ) # max area
277 print "--------Add hypothesis and algorith to sub face 4"
279 #sub_face4 = salome.IDToObject( Id_SubFace4 )
280 submesh = mesh.GetSubMesh(sub_face4, "SubMeshFace4")
282 mesh.AddHypothesis( sub_face4, alg3 ) # Quadrangle 2D
283 ret = mesh.AddHypothesis( sub_face4, hyp4 ) # max area
285 smesh.Compute(mesh,shape_mesh)
287 print "Information about the Mesh_mechanic:"
288 print "Number of nodes : ", mesh.NbNodes()
289 print "Number of edges : ", mesh.NbEdges()
290 print "Number of faces : ", mesh.NbFaces()
291 print "Number of triangles : ", mesh.NbTriangles()
292 print "Number of quadrangles: ", mesh.NbQuadrangles()
294 salome.sg.updateObjBrowser(1);