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