Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_editor.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #  File   : SMESH_withHole.py
23 #  Author : Lucien PIGNOLONI
24 #  Module : SMESH
25 #  $Header$
26 #-------------------------------------------------------------------------
27 #
28 import salome
29 import geompy
30 import smesh
31
32 # ---------------------------- GEOM --------------------------------------
33
34 # ---- define contigous arcs and segment to define a closed wire
35 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
36 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
37 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
38 arc1 = geompy.MakeArc( p1, p2, p3 )
39
40 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
41 seg1 = geompy.MakeVector( p3, p4 )
42
43 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
44 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
45 arc2 = geompy.MakeArc( p4, p5, p6 )
46
47 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
48 arc3 = geompy.MakeArc( p6, p7, p1 )
49
50 # ---- define a closed wire with arcs and segment
51 List1 = []
52 List1.append( arc1 )
53 List1.append( seg1 )
54 List1.append( arc2 )
55 List1.append( arc3 )
56
57 wire1 = geompy.MakeWire( List1 )
58 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
59
60 # ---- define a planar face with wire
61 WantPlanarFace = 1 #True
62 face1 = geompy.MakeFace( wire1, WantPlanarFace )
63 Id_face1 = geompy.addToStudy( face1, "face1" )
64
65 # ---- create a shape by extrusion
66 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
67 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
68 vz = geompy.MakeVector( pO, pz )
69
70 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
71 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
72
73 # ---- create two cylinders
74 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
75 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
76
77 radius = 20.0
78 height = 180.0
79 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
80 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
81
82 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
83 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
84
85 # ---- cut with cyl1
86 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
87
88 # ---- fuse with cyl2 to obtain the final mechanic piece :)
89 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
90 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
91
92 # ---- explode on faces
93 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
94
95 # ---- add a face sub shape in study to be meshed different
96 sub_face1 = SubFaceL[0]
97 name      = geompy.SubShapeName( sub_face1, mechanic )
98
99 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
100
101 # ---- add a face sub shape in study to be meshed different
102 sub_face2 = SubFaceL[4]
103 name      = geompy.SubShapeName( sub_face2, mechanic )
104
105 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
106
107 # ---- add a face sub shape in study to be meshed different
108 sub_face3 = SubFaceL[5]
109 name      = geompy.SubShapeName( sub_face3, mechanic )
110
111 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
112
113 # ---- add a face sub shape in study to be meshed different
114 sub_face4 = SubFaceL[10]
115 name      = geompy.SubShapeName( sub_face4, mechanic )
116
117 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
118
119 # ---------------------------- SMESH --------------------------------------
120
121 # -- Init --
122 shape_mesh = salome.IDToObject( Id_mechanic )
123
124 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic")
125
126 print "-------------------------- NumberOfSegments"
127
128 numberOfSegment = 10
129
130 algo = mesh.Segment()
131 hypNbSeg = algo.NumberOfSegments(numberOfSegment)
132 print hypNbSeg.GetName()
133 print hypNbSeg.GetId()
134 print hypNbSeg.GetNumberOfSegments()
135 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
136
137
138 print "-------------------------- MaxElementArea"
139
140 maxElementArea = 25
141
142 algo = mesh.Triangle()
143 hypArea25 = algo.MaxElementArea(maxElementArea)
144 print hypArea25.GetName()
145 print hypArea25.GetId()
146 print hypArea25.GetMaxElementArea()
147 smesh.SetName(hypArea25, "MaxElementArea_" + str(maxElementArea))
148
149
150 # Create submesh on sub_face1 - sub_face4
151 # ---------------------------------------
152
153 # Set 2D algorithm to submesh on sub_face1
154 algo = mesh.Quadrangle(sub_face1)
155 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
156 submesh1 = algo.GetSubMesh()
157
158 # Set 2D algorithm to submesh on sub_face2
159 algo = mesh.Quadrangle(sub_face2)
160 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
161 submesh2 = algo.GetSubMesh()
162
163 # Set 2D algorithm to submesh on sub_face3
164 algo = mesh.Quadrangle(sub_face3)
165 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
166 submesh3 = algo.GetSubMesh()
167
168 # Set 2D algorithm to submesh on sub_face4
169 algo = mesh.Quadrangle(sub_face4)
170 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
171 submesh4 = algo.GetSubMesh()
172
173
174 print "-------------------------- compute the mesh of the mechanic piece"
175
176 mesh.Compute()
177
178 print "Information about the Mesh_mechanic:"
179 print "Number of nodes       : ", mesh.NbNodes()
180 print "Number of edges       : ", mesh.NbEdges()
181 print "Number of faces       : ", mesh.NbFaces()
182 print "Number of triangles   : ", mesh.NbTriangles()
183 print "Number of quadrangles : ", mesh.NbQuadrangles()
184 print "Number of volumes     : ", mesh.NbVolumes()
185 print "Number of tetrahedrons: ", mesh.NbTetras()
186
187
188 #1 cutting of quadrangles of the 'SubMeshFace2' submesh
189 mesh.SplitQuadObject(submesh2, 1)
190
191 #2 cutting of triangles of the group
192 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]
193 GroupTriToQuad = mesh.MakeGroupByIds("Group of faces (quad)", smesh.FACE, FacesTriToQuad)
194 mesh.TriToQuadObject(GroupTriToQuad, None , 1.57)
195
196 #3 extrusion of the group
197 point = smesh.PointStruct(0, 0, 5)
198 vector = smesh.DirStruct(point) 
199 mesh.ExtrusionSweepObject(GroupTriToQuad, vector, 5)
200
201 #4 mirror object
202 mesh.Mirror([], smesh.AxisStruct(0, 0, 0, 0, 0, 0), smesh.POINT, 0) 
203
204 #5 mesh translation
205 point = smesh.PointStruct(10, 10, 10)
206 vector = smesh.DirStruct(point) 
207 mesh.Translate([], vector, 0)
208
209 #6 mesh rotation
210 axisXYZ = smesh.AxisStruct(0, 0, 0, 10, 10, 10)
211 angle180 =  180*3.141/180
212 mesh.Rotate([], axisXYZ, angle180, 0)
213
214 #7 group smoothing
215 FacesSmooth = [864, 933, 941, 950, 1005, 1013]
216 GroupSmooth = mesh.MakeGroupByIds("Group of faces (smooth)", smesh.FACE, FacesSmooth)
217 mesh.SmoothObject(GroupSmooth, [], 20, 2, smesh.CENTROIDAL_SMOOTH)
218
219 #8 rotation sweep object
220 FacesRotate = [492, 493, 502, 503]
221 GroupRotate = mesh.MakeGroupByIds("Group of faces (rotate)", smesh.FACE, FacesRotate)
222 angle45 =  45*3.141/180
223 axisXYZ = smesh.AxisStruct(-38.3128, -73.3658, -133.321, -13.3402, -13.3265, 6.66632)
224 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
225
226 #9 reorientation of the submesh1
227 mesh.ReorientObject(submesh1)
228
229 salome.sg.updateObjBrowser(1)