Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 salome
28 import geompy
29
30 geom  = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
31 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
32
33 geom.GetCurrentStudy(salome.myStudy._get_StudyId())
34 smesh.SetCurrentStudy(salome.myStudy)
35
36 smeshgui = salome.ImportComponentGUI("SMESH")
37 smeshgui.Init(salome.myStudyId);
38
39 import StdMeshers
40
41 # ---------------------------- GEOM --------------------------------------
42 ShapeTypeCompSolid = 1
43 ShapeTypeSolid     = 2
44 ShapeTypeShell     = 3
45 ShapeTypeFace      = 4
46 ShapeTypeWire      = 5
47 ShapeTypeEdge      = 6
48 ShapeTypeVertex    = 7
49
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 )
55
56 p4   = geom.MakePointStruct( 170.0, 100.0, 0.0 )
57 seg1 = geom.MakeVector( p3, p4 )
58
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 )
62
63 p7   = geom.MakePointStruct( 120.0, 30.0, 0.0 )
64 arc3 = geom.MakeArc( p6, p7, p1 )
65
66 # ---- define a closed wire with arcs and segment
67 List1 = []
68 List1.append( arc1 )
69 List1.append( seg1 )
70 List1.append( arc2 )
71 List1.append( arc3 )
72
73 ListIOR1 = []
74 for S in List1 :
75     ListIOR1.append( S._get_Name() )
76 wire1 = geom.MakeWire( ListIOR1 )
77
78 Id_wire1 = geompy.addToStudy( wire1, "wire1")
79
80 # ---- define a planar face with wire
81 WantPlanarFace = 1 #True
82 face1 = geom.MakeFace( wire1, WantPlanarFace )
83 Id_face1 = geompy.addToStudy( face1, "face1")
84
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 )
88
89 prism1    = geom.MakePrism( face1, pO, pz )
90 Id_prism1 = geompy.addToStudy( prism1, "prism1")
91
92 # ---- create two cylinders
93
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 )
97 radius = 20.0
98 height = 180.0
99 cyl1  = geom.MakeCylinder( pc1, vz, radius, height )
100 cyl2  = geom.MakeCylinder( pc2, vz, radius, height )
101
102 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
103 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
104
105 # ---- cut with cyl1 
106 shape  = geom.MakeBoolean( prism1, cyl1, 2 )
107
108 # ---- fuse with cyl2 
109 shape1 =  geom.MakeBoolean( shape, cyl2, 3 )
110
111 Id_shape1 = geompy.addToStudy( shape1, "shape1")
112
113 #faces = geompy.SubShapeAllSorted( shape1, ShapeTypeFace)
114 #i = 0
115 #for face in faces:
116 #    geompy.addToStudy(face,"face_" + str(i))
117 #    i = i+1
118     
119 # ---- add a face sub shape in study to be meshed different
120 IdSubFaceList = []
121 IdSubFaceList.append(1)
122 sub_face = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceList )
123 name     = geompy.SubShapeName( sub_face._get_Name(), shape1._get_Name() )
124
125 Id_SubFace = geompy.addToStudyInFather( shape1, sub_face, name )
126
127 # ---- add a face sub shape in study to be meshed different
128 IdSubFaceL = []
129 IdSubFaceL.append(2)
130 sub_face2 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
131 name      = geompy.SubShapeName( sub_face2._get_Name(), shape1._get_Name() )
132
133 Id_SubFace2 = geompy.addToStudyInFather( shape1, sub_face2, name )
134
135 # ---- add a face sub shape in study to be meshed different
136 IdSubFaceL = []
137 IdSubFaceL.append(3)
138 sub_face3 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
139 name      = geompy.SubShapeName( sub_face3._get_Name(), shape1._get_Name() )
140
141 Id_SubFace3 = geompy.addToStudyInFather( shape1, sub_face3, name )
142
143 # ---- add a face sub shape in study to be meshed different
144 IdSubFaceL = []
145 IdSubFaceL.append(6)
146 sub_face4 = geompy.SubShapeSorted( shape1, ShapeTypeFace, IdSubFaceL )
147 name      = geompy.SubShapeName( sub_face4._get_Name(), shape1._get_Name() )
148
149 Id_SubFace4 = geompy.addToStudyInFather( shape1, sub_face4, name )
150
151
152 # ---------------------------- SMESH --------------------------------------
153
154 # ------------------------------ Length Hypothesis
155
156 print "-------------------------- create Hypothesis"
157 print "-------------------------- LocalLength"
158 hyp1 = smesh.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
159 hyp1.SetLength( 100.0 )
160 print hyp1.GetName()
161 print hyp1.GetId()
162 print hyp1.GetLength()
163
164 idlength = salome.ObjectToID(hyp1)
165 smeshgui.SetName(idlength, "Local_Length_100");
166
167 print "-------------------------- NumberOfSegments"
168
169 hyp2 = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
170 hyp2.SetNumberOfSegments( 10 )
171 print hyp2.GetName()
172 print hyp2.GetId()
173 print hyp2.GetNumberOfSegments()
174
175 idseg = salome.ObjectToID(hyp2)
176 smeshgui.SetName(idseg, "NumberOfSegments_12");
177
178 print "-------------------------- MaxElementArea"
179
180 hyp3 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
181 hyp3.SetMaxElementArea( 25 )
182 print hyp3.GetName()
183 print hyp3.GetId()
184 print hyp3.GetMaxElementArea()
185
186 idarea1 = salome.ObjectToID(hyp3)
187 smeshgui.SetName(idarea1, "MaxElementArea_20");
188
189 print "-------------------------- MaxElementArea"
190
191 hyp4 = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
192 hyp4.SetMaxElementArea( 35 )
193 print hyp4.GetName()
194 print hyp4.GetId()
195 print hyp4.GetMaxElementArea()
196
197 idarea2 = salome.ObjectToID(hyp4)
198 smeshgui.SetName(idarea2, "MaxElementArea_30");
199
200
201 print "-------------------------- Regular_1D"
202
203 alg1 = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
204 listHyp =alg1.GetCompatibleHypothesis()
205 for hyp in listHyp:
206     print hyp
207 print alg1.GetName()
208 print alg1.GetId()
209
210 idreg1d = salome.ObjectToID(alg1)
211 smeshgui.SetName( idreg1d, "Regular_1D" );
212
213 print "-------------------------- MEFISTO_2D"
214
215 alg2 = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
216 listHyp = alg2.GetCompatibleHypothesis()
217 for hyp in listHyp:
218     print hyp
219 print alg2.GetName()
220 print alg2.GetId()
221
222 idmef = salome.ObjectToID(alg2)
223 smeshgui.SetName( idmef, "MEFISTO_2D" );
224
225 print "-------------------------- SMESH_Quadrangle_2D"
226
227 alg3 = smesh.CreateHypothesis( "Quadrangle_2D", "libStdMeshersEngine.so" )
228 listHyp = alg3.GetCompatibleHypothesis()
229 for hyp in listHyp:
230     print hyp
231 print alg3.GetName()
232 print alg3.GetId()
233
234 idqad2 =  salome.ObjectToID(alg3)
235 smeshgui.SetName( idqad2, "SMESH_Quadrangle_2D" );
236
237
238 print "-------------------------- add hypothesis to main shape1"
239
240 shape_mesh = salome.IDToObject( Id_shape1  )
241
242 mesh = smesh.CreateMesh(shape_mesh)
243
244 idmesh = salome.ObjectToID(mesh) 
245 smeshgui.SetName( idmesh, "Mesh_mechanic" );
246
247 mesh.AddHypothesis( shape_mesh, alg1 )   # Regular 1D/wire discretisation
248 mesh.AddHypothesis( shape_mesh, alg2 )     # MEFISTO 2D
249
250 ret = mesh.AddHypothesis( shape_mesh, hyp2 )   # nb segments
251 ret = mesh.AddHypothesis( shape_mesh, hyp3 )    # max area
252
253 print "--------Add hypothesis and algorith to sub face"        
254
255 #sub_face  = salome.IDToObject( Id_SubFace )
256 submesh   = mesh.GetSubMesh(sub_face, "SubMeshFace")
257
258 mesh.AddHypothesis( sub_face, alg3 )  # Quadrangle 2D
259 mesh.AddHypothesis( sub_face, hyp4 )  # max area
260
261 print "--------Add hypothesis and algorith to sub face 2"        
262
263 #sub_face2  = salome.IDToObject( Id_SubFace2 )
264 submesh    = mesh.GetSubMesh(sub_face2, "SubMeshFace2")
265
266 mesh.AddHypothesis( sub_face2, alg3 )  # Quadrangle 2D
267 ret = mesh.AddHypothesis( sub_face2, hyp4 )  # max area
268
269 print "--------Add hypothesis and algorith to sub face 3"        
270
271 #sub_face3  = salome.IDToObject( Id_SubFace3 )
272 submesh    = mesh.GetSubMesh(sub_face3, "SubMeshFace3")
273
274 mesh.AddHypothesis( sub_face3, alg3 )  # Quadrangle 2D
275 ret = mesh.AddHypothesis( sub_face3, hyp4 )  # max area
276
277 print "--------Add hypothesis and algorith to sub face 4"        
278
279 #sub_face4  = salome.IDToObject( Id_SubFace4 )
280 submesh    = mesh.GetSubMesh(sub_face4, "SubMeshFace4")
281
282 mesh.AddHypothesis( sub_face4, alg3 )  # Quadrangle 2D
283 ret = mesh.AddHypothesis( sub_face4, hyp4 )  # max area
284
285 smesh.Compute(mesh,shape_mesh)
286
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()
293
294 salome.sg.updateObjBrowser(1);