Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic_tetra.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
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.
11 #
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.
16 #
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
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 #  File   : SMESH_withHole.py
24 #  Author : Lucien PIGNOLONI
25 #  Module : SMESH
26 #  $Header$
27 #
28 import salome
29 import geompy
30 import smesh
31
32 geom  = geompy.geom
33
34 # ---------------------------- GEOM --------------------------------------
35
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 )
41
42 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
43 seg1 = geompy.MakeVector( p3, p4 )
44
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 )
48
49 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
50 arc3 = geompy.MakeArc( p6, p7, p1 )
51
52 # ---- define a closed wire with arcs and segment
53 List1 = []
54 List1.append( arc1 )
55 List1.append( seg1 )
56 List1.append( arc2 )
57 List1.append( arc3 )
58
59 wire1 = geompy.MakeWire( List1 )
60 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
61
62 # ---- define a planar face with wire
63 WantPlanarFace = 1 #True
64 face1 = geompy.MakeFace( wire1, WantPlanarFace )
65 Id_face1 = geompy.addToStudy( face1, "face1" )
66
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 )
71
72 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
73 Id_prism1 = geompy.addToStudy( prism1, "prism1")
74
75 # ---- create two cylinders
76
77 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
78 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
79 radius = 20.0
80 height = 180.0
81 cyl1  = geompy.MakeCylinder( pc1, vz, radius, height )
82 cyl2  = geompy.MakeCylinder( pc2, vz, radius, height )
83
84 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
85 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
86
87 # ---- cut with cyl1
88 shape  = geompy.MakeBoolean( prism1, cyl1, 2 )
89
90 # ---- fuse with cyl2 to obtain the final mechanic piece :)
91 mechanic =  geompy.MakeBoolean( shape, cyl2, 3 )
92 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
93
94 # ---- Analysis of the geometry
95
96 print "Analysis of the geometry mechanic :"
97
98 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
99 subFaceList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
100 subEdgeList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
101
102 print "number of Shells in mechanic : ",len(subShellList)
103 print "number of Faces in mechanic : ",len(subFaceList)
104 print "number of Edges in mechanic : ",len(subEdgeList)
105
106 ### ---------------------------- SMESH --------------------------------------
107
108 shape_mesh = salome.IDToObject( Id_mechanic  )
109
110 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic_tetra")
111
112 print "-------------------------- add hypothesis to main mechanic"
113
114 numberOfSegment = 10
115
116 algo1 = mesh.Segment()
117 hypNbSeg = algo1.NumberOfSegments(numberOfSegment)
118 print hypNbSeg.GetName()
119 print hypNbSeg.GetId()
120 print hypNbSeg.GetNumberOfSegments()
121 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
122
123
124 maxElementArea = 20
125
126 algo2 = mesh.Triangle(smesh.MEFISTO)
127 hypArea = algo2.MaxElementArea(maxElementArea)
128 print hypArea.GetName()
129 print hypArea.GetId()
130 print hypArea.GetMaxElementArea()
131 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
132
133
134 maxElementVolume = 20
135
136 algo3 = mesh.Tetrahedron(smesh.NETGEN)
137 hypVolume = algo3.MaxElementVolume(maxElementVolume)
138 print hypVolume.GetName()
139 print hypVolume.GetId()
140 print hypVolume.GetMaxElementVolume()
141 smesh.SetName(hypVolume, "maxElementVolume_" + str(maxElementVolume))
142
143
144 print "-------------------------- compute the mesh of the mechanic piece"
145 mesh.Compute()
146
147 print "Information about the Mesh_mechanic_tetra:"
148 print "Number of nodes       : ", mesh.NbNodes()
149 print "Number of edges       : ", mesh.NbEdges()
150 print "Number of faces       : ", mesh.NbFaces()
151 print "Number of triangles   : ", mesh.NbTriangles()
152 print "Number of quadrangles: ", mesh.NbQuadrangles()
153 print "Number of volumes     : ", mesh.NbVolumes()
154 print "Number of tetrahedrons: ", mesh.NbTetras()
155
156 salome.sg.updateObjBrowser(1)