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