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
32 #import SMESH_BasicHypothesis_idl
38 # ---------------------------- GEOM --------------------------------------
39 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
40 myBuilder = salome.myStudy.NewBuilder()
41 #from geompy import gg
43 smeshgui = salome.ImportComponentGUI("SMESH")
44 smeshgui.Init(salome.myStudyId);
46 ShapeTypeCompSolid = 1
55 # ---- define contigous arcs and segment to define a closed wire
57 p1 = geom.MakePointStruct( 100.0, 0.0, 0.0 )
58 p2 = geom.MakePointStruct( 50.0, 50.0, 0.0 )
59 p3 = geom.MakePointStruct( 100.0, 100.0, 0.0 )
60 arc1 = geom.MakeArc( p1, p2, p3 )
62 p4 = geom.MakePointStruct( 170.0, 100.0, 0.0 )
63 seg1 = geom.MakeVector( p3, p4 )
65 p5 = geom.MakePointStruct( 200.0, 70.0, 0.0 )
66 p6 = geom.MakePointStruct( 170.0, 40.0, 0.0 )
67 arc2 = geom.MakeArc( p4, p5, p6 )
69 p7 = geom.MakePointStruct( 120.0, 30.0, 0.0 )
70 arc3 = geom.MakeArc( p6, p7, p1 )
73 # ---- define a closed wire with arcs and segment
83 ListIOR1.append( S._get_Name() )
84 wire1 = geom.MakeWire( ListIOR1 )
86 Id_wire1 = geompy.addToStudy( wire1, "wire1")
89 # ---- define a planar face with wire
90 WantPlanarFace = 1 #True
91 face1 = geom.MakeFace( wire1, WantPlanarFace )
92 Id_face1 = geompy.addToStudy( face1, "face1")
95 # ---- create a shape by extrusion
96 pO = geom.MakePointStruct( 0.0, 0.0, 0.0 )
97 pz = geom.MakePointStruct( 0.0, 0.0, 100.0 )
99 prism1 = geom.MakePrism( face1, pO, pz )
100 Id_prism1 = geompy.addToStudy( prism1, "prism1")
104 # ---- create two cylinders
106 pc1 = geom.MakePointStruct( 90.0, 50.0, -40.0 )
107 pc2 = geom.MakePointStruct( 170.0, 70.0, -40.0 )
108 vz = geom.MakeDirection( pz )
111 cyl1 = geom.MakeCylinder( pc1, vz, radius, height )
112 cyl2 = geom.MakeCylinder( pc2, vz, radius, height )
114 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
115 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
119 shape = geom.MakeBoolean( prism1, cyl1, 2 )
121 # ---- fuse with cyl2
122 shape1 = geom.MakeBoolean( shape, cyl2, 3 )
124 Id_shape1 = geompy.addToStudy( shape1, "shape1")
127 # ---- add a face sub shape in study to be meshed different
129 IdSubFaceList.append(10)
130 sub_face = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceList )
131 name = geompy.SubShapeName( sub_face._get_Name(), shape1._get_Name() )
133 Id_SubFace = geompy.addToStudyInFather( shape1, sub_face, name )
136 # ---- add a face sub shape in study to be meshed different
139 sub_face2 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
140 name = geompy.SubShapeName( sub_face2._get_Name(), shape1._get_Name() )
142 Id_SubFace2 = geompy.addToStudyInFather( shape1, sub_face2, name )
147 # ---------------------------- SMESH --------------------------------------
149 # ---- launch SMESH, init a Mesh with shape 'shape1'
150 gen = smeshpy.smeshpy()
151 mesh = gen.Init( Id_shape1 )
153 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
154 smeshgui.SetName( idmesh, "Mesh_meca" );
155 smeshgui.SetShape( Id_shape1, idmesh );
158 # ------------------------------ Length Hypothesis
160 print "-------------------------- create Hypothesis"
161 print "-------------------------- LocalLength"
162 hyp1 = gen.CreateHypothesis( "LocalLength" )
163 hypLen1 = hyp1._narrow( SMESH.SMESH_LocalLength )
164 hypLen1.SetLength( 100.0 )
165 print hypLen1.GetName()
166 print hypLen1.GetId()
167 print hypLen1.GetLength()
169 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
170 smeshgui.SetName(idlength, "Local_Length_100");
173 print "-------------------------- NumberOfSegments"
175 hyp2 = gen.CreateHypothesis( "NumberOfSegments" )
176 hypNbSeg1 = hyp2._narrow( SMESH.SMESH_NumberOfSegments )
177 hypNbSeg1.SetNumberOfSegments( 10 )
178 print hypNbSeg1.GetName()
179 print hypNbSeg1.GetId()
180 print hypNbSeg1.GetNumberOfSegments()
182 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
183 smeshgui.SetName(idseg, "NumberOfSegments_12");
186 print "-------------------------- MaxElementArea"
188 hyp3 = gen.CreateHypothesis( "MaxElementArea" )
189 hypArea1 = hyp3._narrow( SMESH.SMESH_MaxElementArea )
190 hypArea1.SetMaxElementArea( 25 )
191 print hypArea1.GetName()
192 print hypArea1.GetId()
193 print hypArea1.GetMaxElementArea()
195 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
196 smeshgui.SetName(idarea1, "MaxElementArea_20");
200 print "-------------------------- MaxElementArea"
202 hyp4 = gen.CreateHypothesis( "MaxElementArea" )
203 hypArea2 = hyp4._narrow( SMESH.SMESH_MaxElementArea )
204 hypArea2.SetMaxElementArea( 35 )
205 print hypArea2. GetName()
206 print hypArea2.GetId()
207 print hypArea2.GetMaxElementArea()
209 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
210 smeshgui.SetName(idarea2, "MaxElementArea_30");
213 print "-------------------------- Regular_1D"
215 alg1 = gen.CreateHypothesis( "Regular_1D" )
216 algo1 = alg1._narrow( SMESH.SMESH_Algo )
217 listHyp =algo1.GetCompatibleHypothesis()
220 algoReg1d = alg1._narrow( SMESH.SMESH_Regular_1D )
221 print algoReg1d.GetName()
222 print algoReg1d.GetId()
224 idreg1d = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg1d) );
225 smeshgui.SetName( idreg1d, "Regular_1D" );
229 print "-------------------------- MEFISTO_2D"
231 alg2 = gen.CreateHypothesis( "MEFISTO_2D" )
232 algo2 = alg2._narrow( SMESH.SMESH_Algo )
233 listHyp = algo2.GetCompatibleHypothesis()
236 algoMef = alg2._narrow( SMESH.SMESH_MEFISTO_2D )
237 print algoMef.GetName()
238 print algoMef.GetId()
240 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
241 smeshgui.SetName( idmef, "MEFISTO_2D" );
245 print "-------------------------- SMESH_Quadrangle_2D"
247 alg3 = gen.CreateHypothesis( "Quadrangle_2D" )
248 algo3 = alg3._narrow( SMESH.SMESH_2D_Algo )
249 listHyp = algo3.GetCompatibleHypothesis()
252 algoQad2 = alg3._narrow( SMESH.SMESH_Quadrangle_2D )
253 print algoQad2.GetName()
254 print algoQad2.GetId()
256 idqad2 = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoQad2) );
257 smeshgui.SetName( idqad2, "SMESH_Quadrangle_2D" );
261 print "-------------------------- add hypothesis to main shape1"
263 shape_mesh = salome.IDToObject( Id_shape1 )
264 submesh = mesh.GetElementsOnShape( shape_mesh )
266 ret = mesh.AddHypothesis( shape_mesh, algoReg1d ) # Regular 1D/wire discretisation
268 ret = mesh.AddHypothesis( shape_mesh, algoMef ) # MEFISTO 2D
270 ret = mesh.AddHypothesis( shape_mesh, hypNbSeg1 ) # nb segments
272 ret = mesh.AddHypothesis( shape_mesh, hypArea1 ) # max area
275 smeshgui.SetAlgorithms( idmesh, idreg1d ); # Regular 1D/wire discretisation
276 smeshgui.SetAlgorithms( idmesh, idmef ); # MEFISTO 2D
277 smeshgui.SetHypothesis( idmesh, idseg ); # nb segments
278 smeshgui.SetHypothesis( idmesh, idarea1 ); # max area
282 print "-------------------------- add hypothesis and algorith to sub face"
284 sub_face = salome.IDToObject( Id_SubFace )
285 submesh = mesh.GetElementsOnShape( sub_face )
287 ret = mesh.AddHypothesis( sub_face, algoQad2 ) # Quadrangle 2D
289 ret = mesh.AddHypothesis( sub_face, hypArea2 ) # max area
292 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
294 salome.orb.object_to_string(submesh),
297 smeshgui.SetName(idsm2, "SubMeshFace")
298 smeshgui.SetAlgorithms( idsm2, idqad2 ); # Quadrangle 2D
299 smeshgui.SetHypothesis( idsm2, idarea2 ); # max area
303 print "-------------------------- add hypothesis and algorith to sub face"
305 sub_face2 = salome.IDToObject( Id_SubFace2 )
306 submesh = mesh.GetElementsOnShape( sub_face2 )
308 ret = mesh.AddHypothesis( sub_face2, algoQad2 ) # Quadrangle 2D
310 ret = mesh.AddHypothesis( sub_face2, hypArea2 ) # max area
313 idsm3 = smeshgui.AddSubMeshOnShape( idmesh,
315 salome.orb.object_to_string(submesh),
318 smeshgui.SetName(idsm3, "SubMeshFace2")
319 smeshgui.SetAlgorithms( idsm3, idqad2 ); # Quadrangle 2D
320 smeshgui.SetHypothesis( idsm3, idarea2 ); # max area
325 sg.updateObjBrowser(1);