Salome HOME
Merge branch merge_1_2_d
[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 SMESH
28 import smeshpy
29 import salome
30 from salome import sg
31 import math
32
33 import geompy
34
35 # ---------------------------- GEOM --------------------------------------
36 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
37 myBuilder = salome.myStudy.NewBuilder()
38 #from geompy import gg
39
40 smeshgui = salome.ImportComponentGUI("SMESH")
41 smeshgui.Init(salome.myStudyId)
42
43 ShapeTypeCompSolid = 1
44 ShapeTypeSolid     = 2
45 ShapeTypeShell     = 3
46 ShapeTypeFace      = 4
47 ShapeTypeWire      = 5
48 ShapeTypeEdge      = 6
49 ShapeTypeVertex    = 7
50
51 # ---- define contigous arcs and segment to define a closed wire
52
53 p1   = geom.MakePointStruct( 100.0,   0.0,  0.0 )
54 p2   = geom.MakePointStruct(  50.0,  50.0,  0.0 )
55 p3   = geom.MakePointStruct( 100.0, 100.0,  0.0 ) 
56 arc1 = geom.MakeArc( p1, p2, p3 )
57
58 p4   = geom.MakePointStruct( 170.0, 100.0, 0.0 )
59 seg1 = geom.MakeVector( p3, p4 )
60
61 p5   = geom.MakePointStruct( 200.0, 70.0, 0.0 )
62 p6   = geom.MakePointStruct( 170.0, 40.0, 0.0 )
63 arc2 = geom.MakeArc( p4, p5, p6 )
64
65 p7   = geom.MakePointStruct( 120.0, 30.0, 0.0 )
66 arc3 = geom.MakeArc( p6, p7, p1 )
67
68 # ---- define a closed wire with arcs and segment
69
70 List1 = []
71 List1.append( arc1 )
72 List1.append( seg1 )
73 List1.append( arc2 )
74 List1.append( arc3 )
75
76 ListIOR1 = []
77 for S in List1 :
78     ListIOR1.append( S._get_Name() )
79 wire1 = geom.MakeWire( ListIOR1 )
80
81 # ---- define a planar face with wire
82
83 WantPlanarFace = 1 #True
84 face1 = geom.MakeFace( wire1, WantPlanarFace )
85
86 # ---- create a shape by extrusion
87
88 pO = geom.MakePointStruct( 0.0, 0.0,   0.0 )
89 pz = geom.MakePointStruct( 0.0, 0.0, 100.0 )
90
91 prism1    = geom.MakePrism( face1, pO, pz )
92
93 # ---- create two cylinders
94
95 pc1 = geom.MakePointStruct(  90.0, 50.0, -40.0 )
96 pc2 = geom.MakePointStruct( 170.0, 70.0, -40.0 )
97 vz  = geom.MakeDirection( pz )
98 radius = 20.0
99 height = 180.0
100 cyl1  = geom.MakeCylinder( pc1, vz, radius, height )
101 cyl2  = geom.MakeCylinder( pc2, vz, radius, height )
102
103 # ---- cut with cyl1 
104
105 shape  = geom.MakeBoolean( prism1, cyl1, 2 )
106
107 # ---- fuse with cyl2 to obtain the final mechanic piece :)
108
109 mechanic =  geom.MakeBoolean( shape, cyl2, 3 )
110
111 idMechanic = geompy.addToStudy( mechanic, "mechanic")
112
113 # ---- Analysis of the geometry
114
115 print "Analysis of the geometry mechanic :"
116
117 subShellList=geompy.SubShapeAll(mechanic,ShapeTypeShell)
118 subFaceList=geompy.SubShapeAll(mechanic,ShapeTypeFace)
119 subEdgeList=geompy.SubShapeAll(mechanic,ShapeTypeEdge)
120
121 print "number of Shells in mechanic : ",len(subShellList)
122 print "number of Faces in mechanic : ",len(subFaceList)
123 print "number of Edges in mechanic : ",len(subEdgeList)
124
125 ### ---------------------------- SMESH --------------------------------------
126
127 # ---- launch SMESH, init a Mesh with shape 'mechanic'
128
129 gen  = smeshpy.smeshpy()
130 mesh = gen.Init( idMechanic )
131
132 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
133 smeshgui.SetName( idmesh, "Mesh_mechanic" )
134 smeshgui.SetShape( idMechanic, idmesh )
135
136 print "-------------------------- NumberOfSegments"
137
138 numberOfSegment = 10
139
140 hypNumberOfSegment = gen.CreateHypothesis( "NumberOfSegments" )
141 hypNbSeg = hypNumberOfSegment._narrow( SMESH.SMESH_NumberOfSegments )
142 hypNbSeg.SetNumberOfSegments(numberOfSegment)
143 print hypNbSeg.GetName()
144 print hypNbSeg.GetId()
145 print hypNbSeg.GetNumberOfSegments()
146
147 idSeg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )
148 smeshgui.SetName(idSeg, "NumberOfSegments")
149
150 print "-------------------------- MaxElementArea"
151
152 maxElementArea = 20
153
154 hypMaxElementArea = gen.CreateHypothesis( "MaxElementArea" )
155 hypArea = hypMaxElementArea._narrow( SMESH.SMESH_MaxElementArea )
156 hypArea.SetMaxElementArea(maxElementArea)
157 print hypArea.GetName()
158 print hypArea.GetId()
159 print hypArea.GetMaxElementArea()
160
161 idArea = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea) )
162 smeshgui.SetName(idArea, "MaxElementArea")
163
164 print "-------------------------- MaxElementVolume"
165
166 maxElementVolume = 20
167
168 hypMaxElementVolume = gen.CreateHypothesis( "MaxElementVolume" )
169 hypVolume = hypMaxElementVolume._narrow( SMESH.SMESH_MaxElementVolume )
170 hypVolume.SetMaxElementVolume(maxElementVolume)
171 print hypVolume.GetName()
172 print hypVolume.GetId()
173 print hypVolume.GetMaxElementVolume()
174
175 idVolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )
176 smeshgui.SetName(idVolume, "MaxElementArea")
177
178 print "-------------------------- Regular_1D"
179
180 alg1D = gen.CreateHypothesis( "Regular_1D" )
181 algo1D   = alg1D._narrow( SMESH.SMESH_Algo )
182 listHyp =algo1D.GetCompatibleHypothesis()
183 for hyp in listHyp:
184     print hyp
185 algoReg1D = alg1D._narrow( SMESH.SMESH_Regular_1D )
186 print algoReg1D.GetName()
187 print algoReg1D.GetId()
188
189 idReg1D = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg1D) )
190 smeshgui.SetName( idReg1D, "Regular_1D" )
191
192 print "-------------------------- MEFISTO_2D"
193
194 alg2D = gen.CreateHypothesis( "MEFISTO_2D" )
195 algo2D = alg2D._narrow( SMESH.SMESH_Algo )
196 listHyp = algo2D.GetCompatibleHypothesis()
197 for hyp in listHyp:
198     print hyp
199 algoMef = alg2D._narrow( SMESH.SMESH_MEFISTO_2D )
200 print algoMef.GetName()
201 print algoMef.GetId()
202
203 idMef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) )
204 smeshgui.SetName( idMef, "MEFISTO_2D" )
205
206 print "-------------------------- NETGEN_3D"
207
208 alg3D = gen.CreateHypothesis( "NETGEN_3D" )
209 algo3D = alg3D._narrow( SMESH.SMESH_Algo )
210 listHyp = algo3D.GetCompatibleHypothesis()
211 for hyp in listHyp:
212     print hyp
213 algoNg = alg3D._narrow( SMESH.SMESH_NETGEN_3D )
214 print algoNg.GetName()
215 print algoNg.GetId()
216
217 idNg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoNg) )
218 smeshgui.SetName( idNg, "NETGEN_2D" )
219
220 print "-------------------------- add hypothesis to main mechanic"
221
222 shape_mesh = salome.IDToObject( idMechanic  )
223 submesh    = mesh.GetElementsOnShape( shape_mesh )
224
225 ret = mesh.AddHypothesis( shape_mesh, algoReg1D )   # Regular 1D/wire discretisation
226 print ret
227 ret = mesh.AddHypothesis( shape_mesh, algoMef )     # MEFISTO 2D
228 print ret
229 ret = mesh.AddHypothesis( shape_mesh, algoNg )     # NETGEN 3D
230 print ret
231 ret = mesh.AddHypothesis( shape_mesh, hypNbSeg )   # nb segments
232 print ret
233 ret = mesh.AddHypothesis( shape_mesh, hypArea )    # max area
234 print ret
235 ret = mesh.AddHypothesis( shape_mesh, hypVolume )    # max volume
236 print ret
237
238 smeshgui.SetAlgorithms( idmesh, idReg1D );  # Regular 1D/wire discretisation
239 smeshgui.SetAlgorithms( idmesh, idMef );    # MEFISTO 2D
240 smeshgui.SetAlgorithms( idmesh, idNg );    # NETGEN 3D
241 smeshgui.SetHypothesis( idmesh, idSeg );    # nb segments
242 smeshgui.SetHypothesis( idmesh, idArea );  # max area
243 smeshgui.SetHypothesis( idmesh, idVolume );  # max volume
244
245 sg.updateObjBrowser(1);
246
247 print "-------------------------- compute the mesh of the mechanic piece"
248 ret=gen.Compute(mesh,idMechanic)
249 print ret
250 log=mesh.GetLog(0) # no erase trace
251 for linelog in log:
252     print linelog
253
254 sg.updateObjBrowser(1)