Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 import smesh
30
31 geom  = geompy.geom
32
33 # ---------------------------- GEOM --------------------------------------
34
35 # ---- define contigous arcs and segment to define a closed wire
36 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
37 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
38 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
39 arc1 = geompy.MakeArc( p1, p2, p3 )
40
41 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
42 seg1 = geompy.MakeVector( p3, p4 )
43
44 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
45 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
46 arc2 = geompy.MakeArc( p4, p5, p6 )
47
48 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
49 arc3 = geompy.MakeArc( p6, p7, p1 )
50
51 # ---- define a closed wire with arcs and segment
52 List1 = []
53 List1.append( arc1 )
54 List1.append( seg1 )
55 List1.append( arc2 )
56 List1.append( arc3 )
57
58 wire1 = geompy.MakeWire( List1 )
59 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
60
61 # ---- define a planar face with wire
62 WantPlanarFace = 1 #True
63 face1 = geompy.MakeFace( wire1, WantPlanarFace )
64 Id_face1 = geompy.addToStudy( face1, "face1" )
65
66 # ---- create a shape by extrusion
67 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
68 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
69 vz = geompy.MakeVector( pO, pz )
70
71 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
72 Id_prism1 = geompy.addToStudy( prism1, "prism1")
73
74 # ---- create two cylinders
75
76 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
77 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
78 radius = 20.0
79 height = 180.0
80 cyl1  = geompy.MakeCylinder( pc1, vz, radius, height )
81 cyl2  = geompy.MakeCylinder( pc2, vz, radius, height )
82
83 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
84 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
85
86 # ---- cut with cyl1
87 shape  = geompy.MakeBoolean( prism1, cyl1, 2 )
88
89 # ---- fuse with cyl2 to obtain the final mechanic piece :)
90 mechanic =  geompy.MakeBoolean( shape, cyl2, 3 )
91 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
92
93 # ---- Analysis of the geometry
94
95 print "Analysis of the geometry mechanic :"
96
97 subShellList = geompy.SubShapeAll(mechanic,geompy.ShapeType["SHELL"])
98 subFaceList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["FACE"])
99 subEdgeList  = geompy.SubShapeAll(mechanic,geompy.ShapeType["EDGE"])
100
101 print "number of Shells in mechanic : ",len(subShellList)
102 print "number of Faces in mechanic : ",len(subFaceList)
103 print "number of Edges in mechanic : ",len(subEdgeList)
104
105 ### ---------------------------- SMESH --------------------------------------
106
107 shape_mesh = salome.IDToObject( Id_mechanic  )
108
109 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic_tetra")
110
111 print "-------------------------- add hypothesis to main mechanic"
112
113 numberOfSegment = 10
114
115 algo1 = mesh.Segment()
116 hypNbSeg = algo1.NumberOfSegments(numberOfSegment)
117 print hypNbSeg.GetName()
118 print hypNbSeg.GetId()
119 print hypNbSeg.GetNumberOfSegments()
120 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegment))
121
122
123 maxElementArea = 20
124
125 algo2 = mesh.Triangle(smesh.MEFISTO)
126 hypArea = algo2.MaxElementArea(maxElementArea)
127 print hypArea.GetName()
128 print hypArea.GetId()
129 print hypArea.GetMaxElementArea()
130 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
131
132
133 maxElementVolume = 20
134
135 algo3 = mesh.Tetrahedron(smesh.NETGEN)
136 hypVolume = algo3.MaxElementVolume(maxElementVolume)
137 print hypVolume.GetName()
138 print hypVolume.GetId()
139 print hypVolume.GetMaxElementVolume()
140 smesh.SetName(hypVolume, "maxElementVolume_" + str(maxElementVolume))
141
142
143 print "-------------------------- compute the mesh of the mechanic piece"
144 mesh.Compute()
145
146 print "Information about the Mesh_mechanic_tetra:"
147 print "Number of nodes       : ", mesh.NbNodes()
148 print "Number of edges       : ", mesh.NbEdges()
149 print "Number of faces       : ", mesh.NbFaces()
150 print "Number of triangles   : ", mesh.NbTriangles()
151 print "Number of quadrangles: ", mesh.NbQuadrangles()
152 print "Number of volumes     : ", mesh.NbVolumes()
153 print "Number of tetrahedrons: ", mesh.NbTetras()
154
155 salome.sg.updateObjBrowser(1)