1 #==============================================================================
2 # File : SMESH_withHole.py
3 # Created : 26 august 2002
4 # Author : Lucien PIGNOLONI
6 # Copyright : Open CASCADE, 2002
8 #==============================================================================
15 #import SMESH_BasicHypothesis_idl
21 # ---------------------------- GEOM --------------------------------------
22 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "Geometry")
23 myBuilder = salome.myStudy.NewBuilder()
24 #from geompy import gg
26 smeshgui = salome.ImportComponentGUI("SMESH")
27 smeshgui.Init(salome.myStudyId);
29 ShapeTypeCompSolid = 1
38 # ---- define contigous arcs and segment to define a closed wire
40 p1 = geom.MakePointStruct( 100.0, 0.0, 0.0 )
41 p2 = geom.MakePointStruct( 50.0, 50.0, 0.0 )
42 p3 = geom.MakePointStruct( 100.0, 100.0, 0.0 )
43 arc1 = geom.MakeArc( p1, p2, p3 )
45 p4 = geom.MakePointStruct( 170.0, 100.0, 0.0 )
46 seg1 = geom.MakeVector( p3, p4 )
48 p5 = geom.MakePointStruct( 200.0, 70.0, 0.0 )
49 p6 = geom.MakePointStruct( 170.0, 40.0, 0.0 )
50 arc2 = geom.MakeArc( p4, p5, p6 )
52 p7 = geom.MakePointStruct( 120.0, 30.0, 0.0 )
53 arc3 = geom.MakeArc( p6, p7, p1 )
56 # ---- define a closed wire with arcs and segment
66 ListIOR1.append( S._get_Name() )
67 wire1 = geom.MakeWire( ListIOR1 )
69 Id_wire1 = geompy.addToStudy( wire1, "wire1")
72 # ---- define a planar face with wire
73 WantPlanarFace = 1 #True
74 face1 = geom.MakeFace( wire1, WantPlanarFace )
75 Id_face1 = geompy.addToStudy( face1, "face1")
78 # ---- create a shape by extrusion
79 pO = geom.MakePointStruct( 0.0, 0.0, 0.0 )
80 pz = geom.MakePointStruct( 0.0, 0.0, 100.0 )
82 prism1 = geom.MakePrism( face1, pO, pz )
83 Id_prism1 = geompy.addToStudy( prism1, "prism1")
87 # ---- create two cylinders
89 pc1 = geom.MakePointStruct( 90.0, 50.0, -40.0 )
90 pc2 = geom.MakePointStruct( 170.0, 70.0, -40.0 )
91 vz = geom.MakeDirection( pz )
94 cyl1 = geom.MakeCylinder( pc1, vz, radius, height )
95 cyl2 = geom.MakeCylinder( pc2, vz, radius, height )
97 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
98 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
102 shape = geom.MakeBoolean( prism1, cyl1, 2 )
104 # ---- fuse with cyl2
105 shape1 = geom.MakeBoolean( shape, cyl2, 3 )
107 Id_shape1 = geompy.addToStudy( shape1, "shape1")
110 # ---- add a face sub shape in study to be meshed different
112 IdSubFaceList.append(10)
113 sub_face = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceList )
114 name = geompy.SubShapeName( sub_face._get_Name(), shape1._get_Name() )
116 Id_SubFace = geompy.addToStudyInFather( shape1, sub_face, name )
119 # ---- add a face sub shape in study to be meshed different
122 sub_face2 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
123 name = geompy.SubShapeName( sub_face2._get_Name(), shape1._get_Name() )
125 Id_SubFace2 = geompy.addToStudyInFather( shape1, sub_face2, name )
130 # ---------------------------- SMESH --------------------------------------
132 # ---- launch SMESH, init a Mesh with shape 'shape1'
133 gen = smeshpy.smeshpy()
134 mesh = gen.Init( Id_shape1 )
136 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
137 smeshgui.SetName( idmesh, "Mesh_meca" );
138 smeshgui.SetShape( Id_shape1, idmesh );
141 # ------------------------------ Length Hypothesis
143 print "-------------------------- create Hypothesis"
144 print "-------------------------- LocalLength"
145 hyp1 = gen.CreateHypothesis( "LocalLength" )
146 hypLen1 = hyp1._narrow( SMESH.SMESH_LocalLength )
147 hypLen1.SetLength( 100.0 )
148 print hypLen1.GetName()
149 print hypLen1.GetId()
150 print hypLen1.GetLength()
152 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
153 smeshgui.SetName(idlength, "Local_Length_100");
156 print "-------------------------- NumberOfSegments"
158 hyp2 = gen.CreateHypothesis( "NumberOfSegments" )
159 hypNbSeg1 = hyp2._narrow( SMESH.SMESH_NumberOfSegments )
160 hypNbSeg1.SetNumberOfSegments( 10 )
161 print hypNbSeg1.GetName()
162 print hypNbSeg1.GetId()
163 print hypNbSeg1.GetNumberOfSegments()
165 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
166 smeshgui.SetName(idseg, "NumberOfSegments_12");
169 print "-------------------------- MaxElementArea"
171 hyp3 = gen.CreateHypothesis( "MaxElementArea" )
172 hypArea1 = hyp3._narrow( SMESH.SMESH_MaxElementArea )
173 hypArea1.SetMaxElementArea( 25 )
174 print hypArea1.GetName()
175 print hypArea1.GetId()
176 print hypArea1.GetMaxElementArea()
178 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
179 smeshgui.SetName(idarea1, "MaxElementArea_20");
183 print "-------------------------- MaxElementArea"
185 hyp4 = gen.CreateHypothesis( "MaxElementArea" )
186 hypArea2 = hyp4._narrow( SMESH.SMESH_MaxElementArea )
187 hypArea2.SetMaxElementArea( 35 )
188 print hypArea2. GetName()
189 print hypArea2.GetId()
190 print hypArea2.GetMaxElementArea()
192 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
193 smeshgui.SetName(idarea2, "MaxElementArea_30");
196 print "-------------------------- Regular_1D"
198 alg1 = gen.CreateHypothesis( "Regular_1D" )
199 algo1 = alg1._narrow( SMESH.SMESH_Algo )
200 listHyp =algo1.GetCompatibleHypothesis()
203 algoReg1d = alg1._narrow( SMESH.SMESH_Regular_1D )
204 print algoReg1d.GetName()
205 print algoReg1d.GetId()
207 idreg1d = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg1d) );
208 smeshgui.SetName( idreg1d, "Regular_1D" );
212 print "-------------------------- MEFISTO_2D"
214 alg2 = gen.CreateHypothesis( "MEFISTO_2D" )
215 algo2 = alg2._narrow( SMESH.SMESH_Algo )
216 listHyp = algo2.GetCompatibleHypothesis()
219 algoMef = alg2._narrow( SMESH.SMESH_MEFISTO_2D )
220 print algoMef.GetName()
221 print algoMef.GetId()
223 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
224 smeshgui.SetName( idmef, "MEFISTO_2D" );
228 print "-------------------------- SMESH_Quadrangle_2D"
230 alg3 = gen.CreateHypothesis( "Quadrangle_2D" )
231 algo3 = alg3._narrow( SMESH.SMESH_2D_Algo )
232 listHyp = algo3.GetCompatibleHypothesis()
235 algoQad2 = alg3._narrow( SMESH.SMESH_Quadrangle_2D )
236 print algoQad2.GetName()
237 print algoQad2.GetId()
239 idqad2 = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoQad2) );
240 smeshgui.SetName( idqad2, "SMESH_Quadrangle_2D" );
244 print "-------------------------- add hypothesis to main shape1"
246 shape_mesh = salome.IDToObject( Id_shape1 )
247 submesh = mesh.GetElementsOnShape( shape_mesh )
249 ret = mesh.AddHypothesis( shape_mesh, algoReg1d ) # Regular 1D/wire discretisation
251 ret = mesh.AddHypothesis( shape_mesh, algoMef ) # MEFISTO 2D
253 ret = mesh.AddHypothesis( shape_mesh, hypNbSeg1 ) # nb segments
255 ret = mesh.AddHypothesis( shape_mesh, hypArea1 ) # max area
258 smeshgui.SetAlgorithms( idmesh, idreg1d ); # Regular 1D/wire discretisation
259 smeshgui.SetAlgorithms( idmesh, idmef ); # MEFISTO 2D
260 smeshgui.SetHypothesis( idmesh, idseg ); # nb segments
261 smeshgui.SetHypothesis( idmesh, idarea1 ); # max area
265 print "-------------------------- add hypothesis and algorith to sub face"
267 sub_face = salome.IDToObject( Id_SubFace )
268 submesh = mesh.GetElementsOnShape( sub_face )
270 ret = mesh.AddHypothesis( sub_face, algoQad2 ) # Quadrangle 2D
272 ret = mesh.AddHypothesis( sub_face, hypArea2 ) # max area
275 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
277 salome.orb.object_to_string(submesh),
280 smeshgui.SetName(idsm2, "SubMeshFace")
281 smeshgui.SetAlgorithms( idsm2, idqad2 ); # Quadrangle 2D
282 smeshgui.SetHypothesis( idsm2, idarea2 ); # max area
286 print "-------------------------- add hypothesis and algorith to sub face"
288 sub_face2 = salome.IDToObject( Id_SubFace2 )
289 submesh = mesh.GetElementsOnShape( sub_face2 )
291 ret = mesh.AddHypothesis( sub_face2, algoQad2 ) # Quadrangle 2D
293 ret = mesh.AddHypothesis( sub_face2, hypArea2 ) # max area
296 idsm3 = smeshgui.AddSubMeshOnShape( idmesh,
298 salome.orb.object_to_string(submesh),
301 smeshgui.SetName(idsm3, "SubMeshFace2")
302 smeshgui.SetAlgorithms( idsm3, idqad2 ); # Quadrangle 2D
303 smeshgui.SetHypothesis( idsm3, idarea2 ); # max area
308 sg.updateObjBrowser(1);