Salome HOME
PR: needed by merge C. CAREMOLI branch CCAR_br1
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic.py
1 #==============================================================================
2 #  File      : SMESH_withHole.py
3 #  Created   : 26 august 2002
4 #  Author    : Lucien PIGNOLONI
5 #  Project   : SALOME
6 #  Copyright : Open CASCADE, 2002
7 #  $Header$
8 #==============================================================================
9
10 import SMESH
11 import smeshpy
12 import salome
13 from salome import sg
14 import math
15 #import SMESH_BasicHypothesis_idl
16
17 import geompy
18
19
20
21 # ---------------------------- GEOM --------------------------------------
22 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
23 myBuilder = salome.myStudy.NewBuilder()
24 #from geompy import gg
25
26 smeshgui = salome.ImportComponentGUI("SMESH")
27 smeshgui.Init(salome.myStudyId);
28
29 ShapeTypeCompSolid = 1
30 ShapeTypeSolid     = 2
31 ShapeTypeShell     = 3
32 ShapeTypeFace      = 4
33 ShapeTypeWire      = 5
34 ShapeTypeEdge      = 6
35 ShapeTypeVertex    = 7
36
37
38 # ---- define contigous arcs and segment to define a closed wire
39
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 )
44
45 p4   = geom.MakePointStruct( 170.0, 100.0, 0.0 )
46 seg1 = geom.MakeVector( p3, p4 )
47
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 )
51
52 p7   = geom.MakePointStruct( 120.0, 30.0, 0.0 )
53 arc3 = geom.MakeArc( p6, p7, p1 )
54
55
56 # ---- define a closed wire with arcs and segment
57
58 List1 = []
59 List1.append( arc1 )
60 List1.append( seg1 )
61 List1.append( arc2 )
62 List1.append( arc3 )
63
64 ListIOR1 = []
65 for S in List1 :
66     ListIOR1.append( S._get_Name() )
67 wire1 = geom.MakeWire( ListIOR1 )
68
69 Id_wire1 = geompy.addToStudy( wire1, "wire1")
70
71
72 # ---- define a planar face with wire
73 WantPlanarFace = 1 #True
74 face1 = geom.MakeFace( wire1, WantPlanarFace )
75 Id_face1 = geompy.addToStudy( face1, "face1")
76
77
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 )
81
82 prism1    = geom.MakePrism( face1, pO, pz )
83 Id_prism1 = geompy.addToStudy( prism1, "prism1")
84
85
86
87 # ---- create two cylinders
88
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 )
92 radius = 20.0
93 height = 180.0
94 cyl1  = geom.MakeCylinder( pc1, vz, radius, height )
95 cyl2  = geom.MakeCylinder( pc2, vz, radius, height )
96
97 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
98 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
99
100
101 # ---- cut with cyl1 
102 shape  = geom.MakeBoolean( prism1, cyl1, 2 )
103
104 # ---- fuse with cyl2 
105 shape1 =  geom.MakeBoolean( shape, cyl2, 3 )
106
107 Id_shape1 = geompy.addToStudy( shape1, "shape1")
108
109
110 # ---- add a face sub shape in study to be meshed different
111 IdSubFaceList = []
112 IdSubFaceList.append(10)
113 sub_face = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceList )
114 name     = geompy.SubShapeName( sub_face._get_Name(), shape1._get_Name() )
115
116 Id_SubFace = geompy.addToStudyInFather( shape1, sub_face, name )
117
118
119 # ---- add a face sub shape in study to be meshed different
120 IdSubFaceL = []
121 IdSubFaceL.append(7)
122 sub_face2 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
123 name      = geompy.SubShapeName( sub_face2._get_Name(), shape1._get_Name() )
124
125 Id_SubFace2 = geompy.addToStudyInFather( shape1, sub_face2, name )
126
127
128
129
130 # ---------------------------- SMESH --------------------------------------
131
132 # ---- launch SMESH, init a Mesh with shape 'shape1'
133 gen  = smeshpy.smeshpy()
134 mesh = gen.Init( Id_shape1 )
135
136 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
137 smeshgui.SetName( idmesh, "Mesh_meca" );
138 smeshgui.SetShape( Id_shape1, idmesh );
139
140
141 # ------------------------------ Length Hypothesis
142
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()
151
152 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
153 smeshgui.SetName(idlength, "Local_Length_100");
154
155
156 print "-------------------------- NumberOfSegments"
157
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()
164
165 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
166 smeshgui.SetName(idseg, "NumberOfSegments_12");
167
168
169 print "-------------------------- MaxElementArea"
170
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()
177
178 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
179 smeshgui.SetName(idarea1, "MaxElementArea_20");
180
181
182
183 print "-------------------------- MaxElementArea"
184
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()
191
192 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
193 smeshgui.SetName(idarea2, "MaxElementArea_30");
194
195
196 print "-------------------------- Regular_1D"
197
198 alg1    = gen.CreateHypothesis( "Regular_1D" )
199 algo1   = alg1._narrow( SMESH.SMESH_Algo )
200 listHyp =algo1.GetCompatibleHypothesis()
201 for hyp in listHyp:
202     print hyp
203 algoReg1d = alg1._narrow( SMESH.SMESH_Regular_1D )
204 print algoReg1d.GetName()
205 print algoReg1d.GetId()
206
207 idreg1d = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg1d) );
208 smeshgui.SetName( idreg1d, "Regular_1D" );
209
210
211
212 print "-------------------------- MEFISTO_2D"
213
214 alg2    = gen.CreateHypothesis( "MEFISTO_2D" )
215 algo2   = alg2._narrow( SMESH.SMESH_Algo )
216 listHyp = algo2.GetCompatibleHypothesis()
217 for hyp in listHyp:
218     print hyp
219 algoMef = alg2._narrow( SMESH.SMESH_MEFISTO_2D )
220 print algoMef.GetName()
221 print algoMef.GetId()
222
223 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
224 smeshgui.SetName( idmef, "MEFISTO_2D" );
225
226
227
228 print "-------------------------- SMESH_Quadrangle_2D"
229
230 alg3    = gen.CreateHypothesis( "Quadrangle_2D" )
231 algo3   = alg3._narrow( SMESH.SMESH_2D_Algo )
232 listHyp = algo3.GetCompatibleHypothesis()
233 for hyp in listHyp:
234     print hyp
235 algoQad2 = alg3._narrow( SMESH.SMESH_Quadrangle_2D )
236 print algoQad2.GetName()
237 print algoQad2.GetId()
238
239 idqad2 = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoQad2) );
240 smeshgui.SetName( idqad2, "SMESH_Quadrangle_2D" );
241
242
243
244 print "-------------------------- add hypothesis to main shape1"
245
246 shape_mesh = salome.IDToObject( Id_shape1  )
247 submesh    = mesh.GetElementsOnShape( shape_mesh )
248
249 ret = mesh.AddHypothesis( shape_mesh, algoReg1d )   # Regular 1D/wire discretisation
250 print ret
251 ret = mesh.AddHypothesis( shape_mesh, algoMef )     # MEFISTO 2D
252 print ret
253 ret = mesh.AddHypothesis( shape_mesh, hypNbSeg1 )   # nb segments
254 print ret
255 ret = mesh.AddHypothesis( shape_mesh, hypArea1 )    # max area
256 print ret
257
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
262
263
264
265 print "-------------------------- add hypothesis and algorith to sub face"        
266
267 sub_face  = salome.IDToObject( Id_SubFace )
268 submesh   = mesh.GetElementsOnShape( sub_face )
269
270 ret = mesh.AddHypothesis( sub_face, algoQad2 )  # Quadrangle 2D
271 print ret
272 ret = mesh.AddHypothesis( sub_face, hypArea2 )  # max area
273 print ret
274
275 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
276                                     Id_SubFace,
277                                     salome.orb.object_to_string(submesh),
278                                     ShapeTypeFace )
279
280 smeshgui.SetName(idsm2, "SubMeshFace")
281 smeshgui.SetAlgorithms( idsm2, idqad2 );  # Quadrangle 2D
282 smeshgui.SetHypothesis( idsm2, idarea2 ); # max area
283
284
285
286 print "-------------------------- add hypothesis and algorith to sub face"        
287
288 sub_face2  = salome.IDToObject( Id_SubFace2 )
289 submesh    = mesh.GetElementsOnShape( sub_face2 )
290
291 ret = mesh.AddHypothesis( sub_face2, algoQad2 )  # Quadrangle 2D
292 print ret
293 ret = mesh.AddHypothesis( sub_face2, hypArea2 )  # max area
294 print ret
295
296 idsm3 = smeshgui.AddSubMeshOnShape( idmesh,
297                                     Id_SubFace2,
298                                     salome.orb.object_to_string(submesh),
299                                     ShapeTypeFace )
300
301 smeshgui.SetName(idsm3, "SubMeshFace2")
302 smeshgui.SetAlgorithms( idsm3, idqad2 );  # Quadrangle 2D
303 smeshgui.SetHypothesis( idsm3, idarea2 ); # max area
304
305
306
307
308 sg.updateObjBrowser(1);