Salome HOME
Mesh redesine. New fields added to specify whether hypothesis is main or additional...
[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 #-------------------------------------------------------------------------
28
29 import salome
30 import geompy
31
32 import StdMeshers
33
34 # ---------------------------- GEOM --------------------------------------
35
36 # ---- define contigous arcs and segment to define a closed wire
37 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
38 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
39 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
40 arc1 = geompy.MakeArc( p1, p2, p3 )
41
42 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
43 seg1 = geompy.MakeVector( p3, p4 )
44
45 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
46 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
47 arc2 = geompy.MakeArc( p4, p5, p6 )
48
49 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
50 arc3 = geompy.MakeArc( p6, p7, p1 )
51
52 # ---- define a closed wire with arcs and segment
53 List1 = []
54 List1.append( arc1 )
55 List1.append( seg1 )
56 List1.append( arc2 )
57 List1.append( arc3 )
58
59 wire1 = geompy.MakeWire( List1 )
60 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
61
62 # ---- define a planar face with wire
63 WantPlanarFace = 1 #True
64 face1 = geompy.MakeFace( wire1, WantPlanarFace )
65 Id_face1 = geompy.addToStudy( face1, "face1" )
66
67 # ---- create a shape by extrusion
68 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
69 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
70 vz = geompy.MakeVector( pO, pz )
71
72 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
73 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
74
75 # ---- create two cylinders
76 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
77 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
78
79 radius = 20.0
80 height = 180.0
81 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
82 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
83
84 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
85 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
86
87 # ---- cut with cyl1
88 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
89
90 # ---- fuse with cyl2 to obtain the final mechanic piece :)
91 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
92 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
93
94 # ---- explode on faces
95 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
96
97 # ---- add a face sub shape in study to be meshed different
98 sub_face1 = SubFaceL[0]
99 name      = geompy.SubShapeName( sub_face1, mechanic )
100
101 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
102
103 # ---- add a face sub shape in study to be meshed different
104 sub_face2 = SubFaceL[4]
105 name      = geompy.SubShapeName( sub_face2, mechanic )
106
107 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
108
109 # ---- add a face sub shape in study to be meshed different
110 sub_face3 = SubFaceL[5]
111 name      = geompy.SubShapeName( sub_face3, mechanic )
112
113 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
114
115 # ---- add a face sub shape in study to be meshed different
116 sub_face4 = SubFaceL[10]
117 name      = geompy.SubShapeName( sub_face4, mechanic )
118
119 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
120
121 # ---------------------------- SMESH --------------------------------------
122
123 # ---- launch SMESH, init a Mesh with shape 'mechanic'
124
125 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
126
127 # -- Init --
128 shape_mesh = salome.IDToObject( Id_mechanic )
129 smesh.SetCurrentStudy(salome.myStudy)
130
131 mesh = smesh.CreateMesh(shape_mesh)
132
133 smeshgui = salome.ImportComponentGUI("SMESH")
134 smeshgui.Init(salome.myStudyId)
135
136 idmesh = salome.ObjectToID(mesh)
137 smeshgui.SetName( idmesh, "Mesh_mechanic" )
138
139 print "-------------------------- NumberOfSegments"
140
141 numberOfSegment = 10
142
143 hypNbSeg = smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" )
144 hypNbSeg.SetNumberOfSegments( numberOfSegment )
145 print hypNbSeg.GetName()
146 print hypNbSeg.GetId()
147 print hypNbSeg.GetNumberOfSegments()
148
149 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
150
151 print "-------------------------- MaxElementArea"
152
153 maxElementArea = 25
154
155 hypArea25 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
156 hypArea25.SetMaxElementArea( maxElementArea )
157 print hypArea25.GetName()
158 print hypArea25.GetId()
159 print hypArea25.GetMaxElementArea()
160
161 smeshgui.SetName(salome.ObjectToID(hypArea25), "MaxElementArea_25")
162
163 print "-------------------------- MaxElementArea"
164
165 maxElementArea = 35
166
167 hypArea35 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
168 hypArea35.SetMaxElementArea( maxElementArea )
169 print hypArea35.GetName()
170 print hypArea35.GetId()
171 print hypArea35.GetMaxElementArea()
172
173 smeshgui.SetName(salome.ObjectToID(hypArea35), "MaxElementArea_35")
174
175 print "-------------------------- Regular_1D"
176
177 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
178 listHyp = algoReg1D.GetCompatibleHypothesis()
179 for hyp in listHyp:
180     print hyp
181 print algoReg1D.GetName()
182 print algoReg1D.GetId()
183
184 smeshgui.SetName(salome.ObjectToID(algoReg1D), "Regular_1D")
185
186 print "-------------------------- MEFISTO_2D"
187
188 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
189 listHyp = algoMef.GetCompatibleHypothesis()
190 for hyp in listHyp:
191     print hyp
192 print algoMef.GetName()
193 print algoMef.GetId()
194
195 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D")
196
197 print "-------------------------- SMESH_Quadrangle_2D"
198
199 algoQuad = smesh.CreateHypothesis( "Quadrangle_2D", "libStdMeshersEngine.so" )
200 listHyp = algoQuad.GetCompatibleHypothesis()
201 for hyp in listHyp:
202     print hyp
203 print algoQuad.GetName()
204 print algoQuad.GetId()
205
206 smeshgui.SetName(salome.ObjectToID(algoQuad), "SMESH_Quadrangle_2D")
207
208 print "-------------------------- add hypothesis to main shape"
209
210 mesh.AddHypothesis( shape_mesh, hypNbSeg )   # nb segments
211 mesh.AddHypothesis( shape_mesh, hypArea25 )  # max area
212
213 mesh.AddHypothesis( shape_mesh, algoReg1D )  # Regular 1D/wire discretisation
214 mesh.AddHypothesis( shape_mesh, algoMef )    # MEFISTO 2D
215
216 print "-------------------------- add hypothesis and algorithm to sub face 1"
217
218 submesh = mesh.GetSubMesh(sub_face1, "SubMeshFace1")
219
220 mesh.AddHypothesis( sub_face1, algoQuad )   # Quadrangle 2D
221 mesh.AddHypothesis( sub_face1, hypArea35 )  # max area
222
223 print "-------------------------- add hypothesis and algorithm to sub face 2"
224
225 submesh = mesh.GetSubMesh(sub_face2, "SubMeshFace2")
226
227 mesh.AddHypothesis( sub_face2, algoQuad )   # Quadrangle 2D
228 mesh.AddHypothesis( sub_face2, hypArea35 )  # max area
229
230 print "-------------------------- add hypothesis and algorith to sub face 3"
231
232 submesh = mesh.GetSubMesh(sub_face3, "SubMeshFace3")
233
234 mesh.AddHypothesis( sub_face3, algoQuad )   # Quadrangle 2D
235 mesh.AddHypothesis( sub_face3, hypArea35 )  # max area
236
237 print "-------------------------- add hypothesis and algorith to sub face 4"
238
239 submesh = mesh.GetSubMesh(sub_face4, "SubMeshFace4")
240
241 mesh.AddHypothesis( sub_face4, algoQuad )   # Quadrangle 2D
242 mesh.AddHypothesis( sub_face4, hypArea35 )  # max area
243
244 print "-------------------------- compute the mesh of the mechanic piece"
245
246 smesh.Compute(mesh, shape_mesh)
247
248 print "Information about the Mesh_mechanic:"
249 print "Number of nodes       : ", mesh.NbNodes()
250 print "Number of edges       : ", mesh.NbEdges()
251 print "Number of faces       : ", mesh.NbFaces()
252 print "Number of triangles   : ", mesh.NbTriangles()
253 print "Number of quadrangles : ", mesh.NbQuadrangles()
254 print "Number of volumes     : ", mesh.NbVolumes()
255 print "Number of tetrahedrons: ", mesh.NbTetras()
256
257 salome.sg.updateObjBrowser(1)