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