Salome HOME
Fix wrong comments indentation
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_editor.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 import SMESH
35
36 # ---------------------------- GEOM --------------------------------------
37
38 # ---- define contigous arcs and segment to define a closed wire
39 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
40 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
41 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
42 arc1 = geompy.MakeArc( p1, p2, p3 )
43
44 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
45 seg1 = geompy.MakeVector( p3, p4 )
46
47 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
48 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
49 arc2 = geompy.MakeArc( p4, p5, p6 )
50
51 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
52 arc3 = geompy.MakeArc( p6, p7, p1 )
53
54 # ---- define a closed wire with arcs and segment
55 List1 = []
56 List1.append( arc1 )
57 List1.append( seg1 )
58 List1.append( arc2 )
59 List1.append( arc3 )
60
61 wire1 = geompy.MakeWire( List1 )
62 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
63
64 # ---- define a planar face with wire
65 WantPlanarFace = 1 #True
66 face1 = geompy.MakeFace( wire1, WantPlanarFace )
67 Id_face1 = geompy.addToStudy( face1, "face1" )
68
69 # ---- create a shape by extrusion
70 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
71 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
72 vz = geompy.MakeVector( pO, pz )
73
74 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
75 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
76
77 # ---- create two cylinders
78 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
79 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
80
81 radius = 20.0
82 height = 180.0
83 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
84 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
85
86 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
87 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
88
89 # ---- cut with cyl1
90 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
91
92 # ---- fuse with cyl2 to obtain the final mechanic piece :)
93 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
94 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
95
96 # ---- explode on faces
97 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
98
99 # ---- add a face sub shape in study to be meshed different
100 sub_face1 = SubFaceL[0]
101 name      = geompy.SubShapeName( sub_face1, mechanic )
102
103 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
104
105 # ---- add a face sub shape in study to be meshed different
106 sub_face2 = SubFaceL[4]
107 name      = geompy.SubShapeName( sub_face2, mechanic )
108
109 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
110
111 # ---- add a face sub shape in study to be meshed different
112 sub_face3 = SubFaceL[5]
113 name      = geompy.SubShapeName( sub_face3, mechanic )
114
115 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
116
117 # ---- add a face sub shape in study to be meshed different
118 sub_face4 = SubFaceL[10]
119 name      = geompy.SubShapeName( sub_face4, mechanic )
120
121 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
122
123 # ---------------------------- SMESH --------------------------------------
124
125 # ---- launch SMESH, init a Mesh with shape 'mechanic'
126
127 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
128
129 # -- Init --
130 shape_mesh = salome.IDToObject( Id_mechanic )
131 smesh.SetCurrentStudy(salome.myStudy)
132
133 mesh = smesh.CreateMesh(shape_mesh)
134
135 smeshgui = salome.ImportComponentGUI("SMESH")
136 smeshgui.Init(salome.myStudyId)
137
138 idmesh = salome.ObjectToID(mesh)
139 smeshgui.SetName( idmesh, "Mesh_mechanic" )
140
141 print "-------------------------- NumberOfSegments"
142
143 numberOfSegment = 10
144
145 hypNbSeg = smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" )
146 hypNbSeg.SetNumberOfSegments( numberOfSegment )
147 print hypNbSeg.GetName()
148 print hypNbSeg.GetId()
149 print hypNbSeg.GetNumberOfSegments()
150
151 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
152
153 print "-------------------------- MaxElementArea"
154
155 maxElementArea = 25
156
157 hypArea25 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
158 hypArea25.SetMaxElementArea( maxElementArea )
159 print hypArea25.GetName()
160 print hypArea25.GetId()
161 print hypArea25.GetMaxElementArea()
162
163 smeshgui.SetName(salome.ObjectToID(hypArea25), "MaxElementArea_25")
164
165 print "-------------------------- MaxElementArea"
166
167 maxElementArea = 35
168
169 hypArea35 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
170 hypArea35.SetMaxElementArea( maxElementArea )
171 print hypArea35.GetName()
172 print hypArea35.GetId()
173 print hypArea35.GetMaxElementArea()
174
175 smeshgui.SetName(salome.ObjectToID(hypArea35), "MaxElementArea_35")
176
177 print "-------------------------- Regular_1D"
178
179 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
180 listHyp = algoReg1D.GetCompatibleHypothesis()
181 for hyp in listHyp:
182     print hyp
183 print algoReg1D.GetName()
184 print algoReg1D.GetId()
185
186 smeshgui.SetName(salome.ObjectToID(algoReg1D), "Regular_1D")
187
188 print "-------------------------- MEFISTO_2D"
189
190 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
191 listHyp = algoMef.GetCompatibleHypothesis()
192 for hyp in listHyp:
193     print hyp
194 print algoMef.GetName()
195 print algoMef.GetId()
196
197 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D")
198
199 print "-------------------------- SMESH_Quadrangle_2D"
200
201 algoQuad = smesh.CreateHypothesis( "Quadrangle_2D", "libStdMeshersEngine.so" )
202 listHyp = algoQuad.GetCompatibleHypothesis()
203 for hyp in listHyp:
204     print hyp
205 print algoQuad.GetName()
206 print algoQuad.GetId()
207
208 smeshgui.SetName(salome.ObjectToID(algoQuad), "SMESH_Quadrangle_2D")
209
210 print "-------------------------- add hypothesis to main shape"
211
212 mesh.AddHypothesis( shape_mesh, hypNbSeg )   # nb segments
213 mesh.AddHypothesis( shape_mesh, hypArea25 )  # max area
214
215 mesh.AddHypothesis( shape_mesh, algoReg1D )  # Regular 1D/wire discretisation
216 mesh.AddHypothesis( shape_mesh, algoMef )    # MEFISTO 2D
217
218 print "-------------------------- add hypothesis and algorithm to sub face 1"
219
220 submesh = mesh.GetSubMesh(sub_face1, "SubMeshFace1")
221
222 mesh.AddHypothesis( sub_face1, algoQuad )   # Quadrangle 2D
223 mesh.AddHypothesis( sub_face1, hypArea35 )  # max area
224
225 print "-------------------------- add hypothesis and algorithm to sub face 2"
226
227 submesh = mesh.GetSubMesh(sub_face2, "SubMeshFace2")
228
229 mesh.AddHypothesis( sub_face2, algoQuad )   # Quadrangle 2D
230 mesh.AddHypothesis( sub_face2, hypArea35 )  # max area
231
232 print "-------------------------- add hypothesis and algorith to sub face 3"
233
234 submesh = mesh.GetSubMesh(sub_face3, "SubMeshFace3")
235
236 mesh.AddHypothesis( sub_face3, algoQuad )   # Quadrangle 2D
237 mesh.AddHypothesis( sub_face3, hypArea35 )  # max area
238
239 print "-------------------------- add hypothesis and algorith to sub face 4"
240
241 submesh = mesh.GetSubMesh(sub_face4, "SubMeshFace4")
242
243 mesh.AddHypothesis( sub_face4, algoQuad )   # Quadrangle 2D
244 mesh.AddHypothesis( sub_face4, hypArea35 )  # max area
245
246 print "-------------------------- compute the mesh of the mechanic piece"
247
248 smesh.Compute(mesh, shape_mesh)
249
250 print "Information about the Mesh_mechanic:"
251 print "Number of nodes       : ", mesh.NbNodes()
252 print "Number of edges       : ", mesh.NbEdges()
253 print "Number of faces       : ", mesh.NbFaces()
254 print "Number of triangles   : ", mesh.NbTriangles()
255 print "Number of quadrangles : ", mesh.NbQuadrangles()
256 print "Number of volumes     : ", mesh.NbVolumes()
257 print "Number of tetrahedrons: ", mesh.NbTetras()
258
259
260 MeshEditor = mesh.GetMeshEditor()
261
262 #1 cutting of quadrangles of the 'SubMeshFace2' submesh
263 submesh = mesh.GetSubMesh(sub_face2, "SubMeshFace2")
264 MeshEditor.SplitQuadObject(submesh, 1)
265
266 #2 cutting of triangles of the group
267 FacesTriToQuad = [2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422]
268 GroupTriToQuad = mesh.CreateGroup(SMESH.FACE,"Group of faces (quad)")
269 GroupTriToQuad.Add(FacesTriToQuad)
270 MeshEditor.TriToQuadObject(GroupTriToQuad, None , 1.57)
271
272 #3 extrusion of the group
273 point = SMESH.PointStruct(0, 0, 5)
274 vector = SMESH.DirStruct(point) 
275 MeshEditor.ExtrusionSweepObject(GroupTriToQuad, vector, 5)
276
277 #4 mirror object
278 MeshEditor.MirrorObject(mesh, SMESH.AxisStruct(0, 0, 0, 0, 0, 0), SMESH.SMESH_MeshEditor.POINT, 0) 
279
280 #5 mesh translation
281 point = SMESH.PointStruct(10, 10, 10)
282 vector = SMESH.DirStruct(point) 
283 MeshEditor.TranslateObject(mesh, vector, 0)
284
285 #6 mesh rotation
286 axisXYZ = SMESH.AxisStruct(0, 0, 0, 10, 10, 10)
287 angle180 =  180*3.141/180
288 MeshEditor.RotateObject(mesh, axisXYZ, angle180, 0)
289
290 #7 group smoothing
291 FacesSmooth = [864, 933, 941, 950, 1005, 1013]
292 GroupSmooth = mesh.CreateGroup(SMESH.FACE,"Group of faces (smooth)")
293 GroupSmooth.Add(FacesSmooth)
294 MeshEditor.SmoothObject(GroupSmooth, [], 20, 2, SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH)
295
296 #8 rotation sweep object
297 FacesRotate = [492, 493, 502, 503]
298 GroupRotate = mesh.CreateGroup(SMESH.FACE,"Group of faces (rotate)")
299 GroupRotate.Add(FacesRotate)
300 angle45 =  45*3.141/180
301 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -133.321, -13.3402, -13.3265, 6.66632)
302 MeshEditor.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
303
304 #9 reorientation of the whole mesh
305 submesh = mesh.GetSubMesh(sub_face1, "SubMeshFace1")
306 MeshEditor.ReorientObject(submesh)
307
308 salome.sg.updateObjBrowser(1)