Salome HOME
IPAL9153, IPAL9148, IPAL9150
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_tetra.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 import salome
28 import geompy
29
30 geom  = geompy.geom
31 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
32 smesh.SetCurrentStudy(salome.myStudy)
33
34 smeshgui = salome.ImportComponentGUI("SMESH")
35 smeshgui.Init(salome.myStudyId)
36
37 import StdMeshers
38 import NETGENPlugin
39
40 # ---------------------------- GEOM --------------------------------------
41
42 # ---- define contigous arcs and segment to define a closed wire
43 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
44 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
45 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
46 arc1 = geompy.MakeArc( p1, p2, p3 )
47
48 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
49 seg1 = geompy.MakeVector( p3, p4 )
50
51 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
52 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
53 arc2 = geompy.MakeArc( p4, p5, p6 )
54
55 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
56 arc3 = geompy.MakeArc( p6, p7, p1 )
57
58 # ---- define a closed wire with arcs and segment
59 List1 = []
60 List1.append( arc1 )
61 List1.append( seg1 )
62 List1.append( arc2 )
63 List1.append( arc3 )
64
65 wire1 = geompy.MakeWire( List1 )
66 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
67
68 # ---- define a planar face with wire
69 WantPlanarFace = 1 #True
70 face1 = geompy.MakeFace( wire1, WantPlanarFace )
71 Id_face1 = geompy.addToStudy( face1, "face1" )
72
73 # ---- create a shape by extrusion
74 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
75 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
76 vz = geompy.MakeVector( pO, pz )
77
78 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
79 Id_prism1 = geompy.addToStudy( prism1, "prism1")
80
81 # ---- create two cylinders
82
83 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
84 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
85 radius = 20.0
86 height = 180.0
87 cyl1  = geompy.MakeCylinder( pc1, vz, radius, height )
88 cyl2  = geompy.MakeCylinder( pc2, vz, radius, height )
89
90 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
91 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
92
93 # ---- cut with cyl1
94 shape  = geompy.MakeBoolean( prism1, cyl1, 2 )
95
96 # ---- fuse with cyl2 to obtain the final mechanic piece :)
97 mechanic =  geompy.MakeBoolean( shape, cyl2, 3 )
98 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
99
100 # ---- Analysis of the geometry
101
102 print "Analysis of the geometry mechanic :"
103
104 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
105 subFaceList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
106 subEdgeList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
107
108 print "number of Shells in mechanic : ",len(subShellList)
109 print "number of Faces in mechanic : ",len(subFaceList)
110 print "number of Edges in mechanic : ",len(subEdgeList)
111
112 ### ---------------------------- SMESH --------------------------------------
113
114 print "-------------------------- NumberOfSegments"
115
116 numberOfSegment = 10
117
118 hypNbSeg = smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" )
119 hypNbSeg.SetNumberOfSegments( numberOfSegment )
120 print hypNbSeg.GetName()
121 print hypNbSeg.GetId()
122 print hypNbSeg.GetNumberOfSegments()
123
124 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
125
126 print "-------------------------- MaxElementArea"
127
128 maxElementArea = 20
129
130 hypArea = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" )
131 hypArea.SetMaxElementArea( maxElementArea )
132 print hypArea.GetName()
133 print hypArea.GetId()
134 print hypArea.GetMaxElementArea()
135
136 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_20")
137
138 print "-------------------------- MaxElementVolume"
139
140 maxElementVolume = 20
141
142 hypVolume = smesh.CreateHypothesis( "MaxElementVolume", "libStdMeshersEngine.so" )
143 hypVolume.SetMaxElementVolume( maxElementVolume )
144 print hypVolume.GetName()
145 print hypVolume.GetId()
146 print hypVolume.GetMaxElementVolume()
147
148 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_20")
149
150 print "-------------------------- Regular_1D"
151
152 algoReg1D = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" )
153 listHyp =algoReg1D.GetCompatibleHypothesis()
154 for hyp in listHyp:
155     print hyp
156 print algoReg1D.GetName()
157 print algoReg1D.GetId()
158
159 smeshgui.SetName(salome.ObjectToID(algoReg1D), "Regular_1D")
160
161 print "-------------------------- MEFISTO_2D"
162
163 algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" )
164 listHyp = algoMef.GetCompatibleHypothesis()
165 for hyp in listHyp:
166     print hyp
167 print algoMef.GetName()
168 print algoMef.GetId()
169
170 smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D")
171
172 print "-------------------------- NETGEN_3D"
173
174 algoNg = smesh.CreateHypothesis( "NETGEN_3D", "libNETGENEngine.so" )
175 listHyp = algoNg.GetCompatibleHypothesis()
176 for hyp in listHyp:
177     print hyp
178 print algoNg.GetName()
179 print algoNg.GetId()
180
181 smeshgui.SetName(salome.ObjectToID(algoNg), "NETGEN_3D")
182
183 print "-------------------------- add hypothesis to main mechanic"
184
185 shape_mesh = salome.IDToObject( Id_mechanic  )
186
187 mesh = smesh.CreateMesh(shape_mesh)
188
189 idmesh = salome.ObjectToID(mesh)
190 smeshgui.SetName( idmesh, "Mesh_mechanic_tetra" )
191
192 mesh.AddHypothesis( shape_mesh, hypNbSeg )   # nb segments
193 mesh.AddHypothesis( shape_mesh, hypArea )    # max area
194 mesh.AddHypothesis( shape_mesh, hypVolume )  # max volume
195
196 mesh.AddHypothesis( shape_mesh, algoReg1D )  # Regular 1D/wire discretisation
197 mesh.AddHypothesis( shape_mesh, algoMef )    # MEFISTO 2D
198 mesh.AddHypothesis( shape_mesh, algoNg )     # NETGEN 3D
199
200 print "-------------------------- compute the mesh of the mechanic piece"
201 smesh.Compute(mesh,shape_mesh)
202
203 print "Information about the Mesh_mechanic_tetra:"
204 print "Number of nodes       : ", mesh.NbNodes()
205 print "Number of edges       : ", mesh.NbEdges()
206 print "Number of faces       : ", mesh.NbFaces()
207 print "Number of triangles   : ", mesh.NbTriangles()
208 print "Number of quadrangles: ", mesh.NbQuadrangles()
209 print "Number of volumes     : ", mesh.NbVolumes()
210 print "Number of tetrahedrons: ", mesh.NbTetras()
211
212 salome.sg.updateObjBrowser(1)