Salome HOME
721d6f2a22c2237ccaa0a3711dbeaf3abd1c900e
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic.py
1 #! /usr/bin/python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 #  This library is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU Lesser General Public
10 #  License as published by the Free Software Foundation; either
11 #  version 2.1 of the License.
12 #
13 #  This library is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  Lesser General Public License for more details.
17 #
18 #  You should have received a copy of the GNU Lesser General Public
19 #  License along with this library; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 import StdMeshers
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 # -- 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_10")
140
141 print "-------------------------- MaxElementArea"
142
143 maxElementArea = 25
144
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_25")
151
152 # Create submesh on sub_face1 - sub_face4
153 # ---------------------------------------
154
155 # Set 2D algorithm to submesh on sub_face1
156 algo = mesh.Quadrangle(sub_face1)
157 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
158
159 # Set 2D algorithm to submesh on sub_face2
160 algo = mesh.Quadrangle(sub_face2)
161 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
162
163 # Set 2D algorithm to submesh on sub_face3
164 algo = mesh.Quadrangle(sub_face3)
165 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
166
167 # Set 2D algorithm to submesh on sub_face4
168 algo = mesh.Quadrangle(sub_face4)
169 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
170
171 print "-------------------------- compute the mesh of the mechanic piece"
172
173 mesh.Compute()
174
175 print "Information about the Mesh_mechanic:"
176 print "Number of nodes       : ", mesh.NbNodes()
177 print "Number of edges       : ", mesh.NbEdges()
178 print "Number of faces       : ", mesh.NbFaces()
179 print "Number of triangles   : ", mesh.NbTriangles()
180 print "Number of quadrangles : ", mesh.NbQuadrangles()
181 print "Number of volumes     : ", mesh.NbVolumes()
182 print "Number of tetrahedrons: ", mesh.NbTetras()
183
184 salome.sg.updateObjBrowser(1)