Salome HOME
sources v1.2
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic.py
1 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3
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. 
8
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. 
13
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 
17
18 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 #
20 #
21 #
22 #  File   : SMESH_withHole.py
23 #  Author : Lucien PIGNOLONI
24 #  Module : SMESH
25 #  $Header$
26
27 import SMESH
28 import smeshpy
29 import salome
30 from salome import sg
31 import math
32 #import SMESH_BasicHypothesis_idl
33
34 import geompy
35
36
37
38 # ---------------------------- GEOM --------------------------------------
39 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "Geometry")
40 myBuilder = salome.myStudy.NewBuilder()
41 #from geompy import gg
42
43 smeshgui = salome.ImportComponentGUI("SMESH")
44 smeshgui.Init(salome.myStudyId);
45
46 ShapeTypeCompSolid = 1
47 ShapeTypeSolid     = 2
48 ShapeTypeShell     = 3
49 ShapeTypeFace      = 4
50 ShapeTypeWire      = 5
51 ShapeTypeEdge      = 6
52 ShapeTypeVertex    = 7
53
54
55 # ---- define contigous arcs and segment to define a closed wire
56
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 )
61
62 p4   = geom.MakePointStruct( 170.0, 100.0, 0.0 )
63 seg1 = geom.MakeVector( p3, p4 )
64
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 )
68
69 p7   = geom.MakePointStruct( 120.0, 30.0, 0.0 )
70 arc3 = geom.MakeArc( p6, p7, p1 )
71
72
73 # ---- define a closed wire with arcs and segment
74
75 List1 = []
76 List1.append( arc1 )
77 List1.append( seg1 )
78 List1.append( arc2 )
79 List1.append( arc3 )
80
81 ListIOR1 = []
82 for S in List1 :
83     ListIOR1.append( S._get_Name() )
84 wire1 = geom.MakeWire( ListIOR1 )
85
86 Id_wire1 = geompy.addToStudy( wire1, "wire1")
87
88
89 # ---- define a planar face with wire
90 WantPlanarFace = 1 #True
91 face1 = geom.MakeFace( wire1, WantPlanarFace )
92 Id_face1 = geompy.addToStudy( face1, "face1")
93
94
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 )
98
99 prism1    = geom.MakePrism( face1, pO, pz )
100 Id_prism1 = geompy.addToStudy( prism1, "prism1")
101
102
103
104 # ---- create two cylinders
105
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 )
109 radius = 20.0
110 height = 180.0
111 cyl1  = geom.MakeCylinder( pc1, vz, radius, height )
112 cyl2  = geom.MakeCylinder( pc2, vz, radius, height )
113
114 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
115 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
116
117
118 # ---- cut with cyl1 
119 shape  = geom.MakeBoolean( prism1, cyl1, 2 )
120
121 # ---- fuse with cyl2 
122 shape1 =  geom.MakeBoolean( shape, cyl2, 3 )
123
124 Id_shape1 = geompy.addToStudy( shape1, "shape1")
125
126
127 # ---- add a face sub shape in study to be meshed different
128 IdSubFaceList = []
129 IdSubFaceList.append(10)
130 sub_face = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceList )
131 name     = geompy.SubShapeName( sub_face._get_Name(), shape1._get_Name() )
132
133 Id_SubFace = geompy.addToStudyInFather( shape1, sub_face, name )
134
135
136 # ---- add a face sub shape in study to be meshed different
137 IdSubFaceL = []
138 IdSubFaceL.append(7)
139 sub_face2 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
140 name      = geompy.SubShapeName( sub_face2._get_Name(), shape1._get_Name() )
141
142 Id_SubFace2 = geompy.addToStudyInFather( shape1, sub_face2, name )
143
144
145
146
147 # ---------------------------- SMESH --------------------------------------
148
149 # ---- launch SMESH, init a Mesh with shape 'shape1'
150 gen  = smeshpy.smeshpy()
151 mesh = gen.Init( Id_shape1 )
152
153 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
154 smeshgui.SetName( idmesh, "Mesh_meca" );
155 smeshgui.SetShape( Id_shape1, idmesh );
156
157
158 # ------------------------------ Length Hypothesis
159
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()
168
169 idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) );
170 smeshgui.SetName(idlength, "Local_Length_100");
171
172
173 print "-------------------------- NumberOfSegments"
174
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()
181
182 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) );
183 smeshgui.SetName(idseg, "NumberOfSegments_12");
184
185
186 print "-------------------------- MaxElementArea"
187
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()
194
195 idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) );
196 smeshgui.SetName(idarea1, "MaxElementArea_20");
197
198
199
200 print "-------------------------- MaxElementArea"
201
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()
208
209 idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) );
210 smeshgui.SetName(idarea2, "MaxElementArea_30");
211
212
213 print "-------------------------- Regular_1D"
214
215 alg1    = gen.CreateHypothesis( "Regular_1D" )
216 algo1   = alg1._narrow( SMESH.SMESH_Algo )
217 listHyp =algo1.GetCompatibleHypothesis()
218 for hyp in listHyp:
219     print hyp
220 algoReg1d = alg1._narrow( SMESH.SMESH_Regular_1D )
221 print algoReg1d.GetName()
222 print algoReg1d.GetId()
223
224 idreg1d = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg1d) );
225 smeshgui.SetName( idreg1d, "Regular_1D" );
226
227
228
229 print "-------------------------- MEFISTO_2D"
230
231 alg2    = gen.CreateHypothesis( "MEFISTO_2D" )
232 algo2   = alg2._narrow( SMESH.SMESH_Algo )
233 listHyp = algo2.GetCompatibleHypothesis()
234 for hyp in listHyp:
235     print hyp
236 algoMef = alg2._narrow( SMESH.SMESH_MEFISTO_2D )
237 print algoMef.GetName()
238 print algoMef.GetId()
239
240 idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) );
241 smeshgui.SetName( idmef, "MEFISTO_2D" );
242
243
244
245 print "-------------------------- SMESH_Quadrangle_2D"
246
247 alg3    = gen.CreateHypothesis( "Quadrangle_2D" )
248 algo3   = alg3._narrow( SMESH.SMESH_2D_Algo )
249 listHyp = algo3.GetCompatibleHypothesis()
250 for hyp in listHyp:
251     print hyp
252 algoQad2 = alg3._narrow( SMESH.SMESH_Quadrangle_2D )
253 print algoQad2.GetName()
254 print algoQad2.GetId()
255
256 idqad2 = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoQad2) );
257 smeshgui.SetName( idqad2, "SMESH_Quadrangle_2D" );
258
259
260
261 print "-------------------------- add hypothesis to main shape1"
262
263 shape_mesh = salome.IDToObject( Id_shape1  )
264 submesh    = mesh.GetElementsOnShape( shape_mesh )
265
266 ret = mesh.AddHypothesis( shape_mesh, algoReg1d )   # Regular 1D/wire discretisation
267 print ret
268 ret = mesh.AddHypothesis( shape_mesh, algoMef )     # MEFISTO 2D
269 print ret
270 ret = mesh.AddHypothesis( shape_mesh, hypNbSeg1 )   # nb segments
271 print ret
272 ret = mesh.AddHypothesis( shape_mesh, hypArea1 )    # max area
273 print ret
274
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
279
280
281
282 print "-------------------------- add hypothesis and algorith to sub face"        
283
284 sub_face  = salome.IDToObject( Id_SubFace )
285 submesh   = mesh.GetElementsOnShape( sub_face )
286
287 ret = mesh.AddHypothesis( sub_face, algoQad2 )  # Quadrangle 2D
288 print ret
289 ret = mesh.AddHypothesis( sub_face, hypArea2 )  # max area
290 print ret
291
292 idsm2 = smeshgui.AddSubMeshOnShape( idmesh,
293                                     Id_SubFace,
294                                     salome.orb.object_to_string(submesh),
295                                     ShapeTypeFace )
296
297 smeshgui.SetName(idsm2, "SubMeshFace")
298 smeshgui.SetAlgorithms( idsm2, idqad2 );  # Quadrangle 2D
299 smeshgui.SetHypothesis( idsm2, idarea2 ); # max area
300
301
302
303 print "-------------------------- add hypothesis and algorith to sub face"        
304
305 sub_face2  = salome.IDToObject( Id_SubFace2 )
306 submesh    = mesh.GetElementsOnShape( sub_face2 )
307
308 ret = mesh.AddHypothesis( sub_face2, algoQad2 )  # Quadrangle 2D
309 print ret
310 ret = mesh.AddHypothesis( sub_face2, hypArea2 )  # max area
311 print ret
312
313 idsm3 = smeshgui.AddSubMeshOnShape( idmesh,
314                                     Id_SubFace2,
315                                     salome.orb.object_to_string(submesh),
316                                     ShapeTypeFace )
317
318 smeshgui.SetName(idsm3, "SubMeshFace2")
319 smeshgui.SetAlgorithms( idsm3, idqad2 );  # Quadrangle 2D
320 smeshgui.SetHypothesis( idsm3, idarea2 ); # max area
321
322
323
324
325 sg.updateObjBrowser(1);