1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # File : SMESH_withHole.py
25 # Author : Lucien PIGNOLONI
28 #-------------------------------------------------------------------------
34 # ---------------------------- GEOM --------------------------------------
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 )
42 p4 = geompy.MakeVertex( 170.0, 100.0, 0.0 )
43 seg1 = geompy.MakeVector( p3, p4 )
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 )
49 p7 = geompy.MakeVertex( 120.0, 30.0, 0.0 )
50 arc3 = geompy.MakeArc( p6, p7, p1 )
52 # ---- define a closed wire with arcs and segment
59 wire1 = geompy.MakeWire( List1 )
60 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
62 # ---- define a planar face with wire
63 WantPlanarFace = 1 #True
64 face1 = geompy.MakeFace( wire1, WantPlanarFace )
65 Id_face1 = geompy.addToStudy( face1, "face1" )
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 )
72 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
73 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
75 # ---- create two cylinders
76 pc1 = geompy.MakeVertex( 90.0, 50.0, -40.0 )
77 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
81 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
82 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
84 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
85 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
88 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
90 # ---- fuse with cyl2 to obtain the final mechanic piece :)
91 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
92 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
94 # ---- explode on faces
95 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
97 # ---- add a face sub shape in study to be meshed different
98 sub_face1 = SubFaceL[0]
99 name = geompy.SubShapeName( sub_face1, mechanic )
101 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
103 # ---- add a face sub shape in study to be meshed different
104 sub_face2 = SubFaceL[4]
105 name = geompy.SubShapeName( sub_face2, mechanic )
107 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
109 # ---- add a face sub shape in study to be meshed different
110 sub_face3 = SubFaceL[5]
111 name = geompy.SubShapeName( sub_face3, mechanic )
113 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
115 # ---- add a face sub shape in study to be meshed different
116 sub_face4 = SubFaceL[10]
117 name = geompy.SubShapeName( sub_face4, mechanic )
119 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
121 # ---------------------------- SMESH --------------------------------------
122 smesh.SetCurrentStudy(salome.myStudy)
125 shape_mesh = salome.IDToObject( Id_mechanic )
127 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic")
129 print "-------------------------- NumberOfSegments"
133 algo = mesh.Segment()
134 hypNbSeg = algo.NumberOfSegments(numberOfSegment)
135 print hypNbSeg.GetName()
136 print hypNbSeg.GetId()
137 print hypNbSeg.GetNumberOfSegments()
138 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
141 print "-------------------------- MaxElementArea"
145 algo = mesh.Triangle()
146 hypArea25 = algo.MaxElementArea(maxElementArea)
147 print hypArea25.GetName()
148 print hypArea25.GetId()
149 print hypArea25.GetMaxElementArea()
150 smesh.SetName(hypArea25, "MaxElementArea_" + str(maxElementArea))
153 # Create submesh on sub_face1 - sub_face4
154 # ---------------------------------------
156 # Set 2D algorithm to submesh on sub_face1
157 algo = mesh.Quadrangle(sub_face1)
158 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
159 submesh1 = algo.GetSubMesh()
161 # Set 2D algorithm to submesh on sub_face2
162 algo = mesh.Quadrangle(sub_face2)
163 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
164 submesh2 = algo.GetSubMesh()
166 # Set 2D algorithm to submesh on sub_face3
167 algo = mesh.Quadrangle(sub_face3)
168 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
169 submesh3 = algo.GetSubMesh()
171 # Set 2D algorithm to submesh on sub_face4
172 algo = mesh.Quadrangle(sub_face4)
173 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
174 submesh4 = algo.GetSubMesh()
177 print "-------------------------- compute the mesh of the mechanic piece"
181 print "Information about the Mesh_mechanic:"
182 print "Number of nodes : ", mesh.NbNodes()
183 print "Number of edges : ", mesh.NbEdges()
184 print "Number of faces : ", mesh.NbFaces()
185 print "Number of triangles : ", mesh.NbTriangles()
186 print "Number of quadrangles : ", mesh.NbQuadrangles()
187 print "Number of volumes : ", mesh.NbVolumes()
188 print "Number of tetrahedrons: ", mesh.NbTetras()
191 #1 cutting of quadrangles of the 'SubMeshFace2' submesh
192 mesh.SplitQuadObject(submesh2, 1)
194 #2 cutting of triangles of the group
195 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]
196 GroupTriToQuad = mesh.MakeGroupByIds("Group of faces (quad)", smesh.FACE, FacesTriToQuad)
197 mesh.TriToQuadObject(GroupTriToQuad, None , 1.57)
199 #3 extrusion of the group
200 point = smesh.PointStruct(0, 0, 5)
201 vector = smesh.DirStruct(point)
202 mesh.ExtrusionSweepObject(GroupTriToQuad, vector, 5)
205 mesh.Mirror([], smesh.AxisStruct(0, 0, 0, 0, 0, 0), smesh.POINT, 0)
208 point = smesh.PointStruct(10, 10, 10)
209 vector = smesh.DirStruct(point)
210 mesh.Translate([], vector, 0)
213 axisXYZ = smesh.AxisStruct(0, 0, 0, 10, 10, 10)
214 angle180 = 180*3.141/180
215 mesh.Rotate([], axisXYZ, angle180, 0)
218 FacesSmooth = [864, 933, 941, 950, 1005, 1013]
219 GroupSmooth = mesh.MakeGroupByIds("Group of faces (smooth)", smesh.FACE, FacesSmooth)
220 mesh.SmoothObject(GroupSmooth, [], 20, 2, smesh.CENTROIDAL_SMOOTH)
222 #8 rotation sweep object
223 FacesRotate = [492, 493, 502, 503]
224 GroupRotate = mesh.MakeGroupByIds("Group of faces (rotate)", smesh.FACE, FacesRotate)
225 angle45 = 45*3.141/180
226 axisXYZ = smesh.AxisStruct(-38.3128, -73.3658, -133.321, -13.3402, -13.3265, 6.66632)
227 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
229 #9 reorientation of the submesh1
230 mesh.ReorientObject(submesh1)
232 salome.sg.updateObjBrowser(1)