Salome HOME
Porting Python3: Encode URL
[modules/smesh.git] / src / SMESH_SWIG / SMESH_mechanic.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 #
30 import salome
31 salome.salome_init()
32 import GEOM
33 from salome.geom import geomBuilder
34 geompy = geomBuilder.New(salome.myStudy)
35
36 import SMESH, SALOMEDS
37 from salome.smesh import smeshBuilder
38 smesh =  smeshBuilder.New(salome.myStudy)
39
40 from salome.StdMeshers import StdMeshersBuilder
41
42 # ---------------------------- GEOM --------------------------------------
43
44 # ---- define contigous arcs and segment to define a closed wire
45 p1   = geompy.MakeVertex( 100.0,   0.0,  0.0 )
46 p2   = geompy.MakeVertex(  50.0,  50.0,  0.0 )
47 p3   = geompy.MakeVertex( 100.0, 100.0,  0.0 )
48 arc1 = geompy.MakeArc( p1, p2, p3 )
49
50 p4   = geompy.MakeVertex( 170.0, 100.0, 0.0 )
51 seg1 = geompy.MakeVector( p3, p4 )
52
53 p5   = geompy.MakeVertex( 200.0, 70.0, 0.0 )
54 p6   = geompy.MakeVertex( 170.0, 40.0, 0.0 )
55 arc2 = geompy.MakeArc( p4, p5, p6 )
56
57 p7   = geompy.MakeVertex( 120.0, 30.0, 0.0 )
58 arc3 = geompy.MakeArc( p6, p7, p1 )
59
60 # ---- define a closed wire with arcs and segment
61 List1 = []
62 List1.append( arc1 )
63 List1.append( seg1 )
64 List1.append( arc2 )
65 List1.append( arc3 )
66
67 wire1 = geompy.MakeWire( List1 )
68 Id_wire1 = geompy.addToStudy( wire1, "wire1" )
69
70 # ---- define a planar face with wire
71 WantPlanarFace = 1 #True
72 face1 = geompy.MakeFace( wire1, WantPlanarFace )
73 Id_face1 = geompy.addToStudy( face1, "face1" )
74
75 # ---- create a shape by extrusion
76 pO = geompy.MakeVertex( 0.0, 0.0,   0.0 )
77 pz = geompy.MakeVertex( 0.0, 0.0, 100.0 )
78 vz = geompy.MakeVector( pO, pz )
79
80 prism1 = geompy.MakePrismVecH( face1, vz, 100.0 )
81 Id_prism1 = geompy.addToStudy( prism1, "prism1" )
82
83 # ---- create two cylinders
84 pc1 = geompy.MakeVertex(  90.0, 50.0, -40.0 )
85 pc2 = geompy.MakeVertex( 170.0, 70.0, -40.0 )
86
87 radius = 20.0
88 height = 180.0
89 cyl1 = geompy.MakeCylinder( pc1, vz, radius, height )
90 cyl2 = geompy.MakeCylinder( pc2, vz, radius, height )
91
92 Id_Cyl1 = geompy.addToStudy( cyl1, "cyl1" )
93 Id_Cyl2 = geompy.addToStudy( cyl2, "cyl2" )
94
95 # ---- cut with cyl1
96 shape = geompy.MakeBoolean( prism1, cyl1, 2 )
97
98 # ---- fuse with cyl2 to obtain the final mechanic piece :)
99 mechanic = geompy.MakeBoolean( shape, cyl2, 3 )
100 Id_mechanic = geompy.addToStudy( mechanic, "mechanic" )
101
102 # ---- explode on faces
103 SubFaceL = geompy.SubShapeAllSorted(mechanic, geompy.ShapeType["FACE"])
104
105 # ---- add a face sub-shape in study to be meshed different
106 sub_face1 = SubFaceL[0]
107 name      = geompy.SubShapeName( sub_face1, mechanic )
108
109 Id_SubFace1 = geompy.addToStudyInFather( mechanic, sub_face1, name )
110
111 # ---- add a face sub-shape in study to be meshed different
112 sub_face2 = SubFaceL[4]
113 name      = geompy.SubShapeName( sub_face2, mechanic )
114
115 Id_SubFace2 = geompy.addToStudyInFather( mechanic, sub_face2, name )
116
117 # ---- add a face sub-shape in study to be meshed different
118 sub_face3 = SubFaceL[5]
119 name      = geompy.SubShapeName( sub_face3, mechanic )
120
121 Id_SubFace3 = geompy.addToStudyInFather( mechanic, sub_face3, name )
122
123 # ---- add a face sub-shape in study to be meshed different
124 sub_face4 = SubFaceL[10]
125 name      = geompy.SubShapeName( sub_face4, mechanic )
126
127 Id_SubFace4 = geompy.addToStudyInFather( mechanic, sub_face4, name )
128
129 # ---------------------------- SMESH --------------------------------------
130 smesh.SetCurrentStudy(salome.myStudy)
131
132 # -- Init --
133 shape_mesh = salome.IDToObject( Id_mechanic )
134
135 mesh = smesh.Mesh(shape_mesh, "Mesh_mechanic")
136
137 print("-------------------------- NumberOfSegments")
138
139 numberOfSegment = 10
140
141 algo = mesh.Segment()
142 hypNbSeg = algo.NumberOfSegments(numberOfSegment)
143 print(hypNbSeg.GetName())
144 print(hypNbSeg.GetId())
145 print(hypNbSeg.GetNumberOfSegments())
146 smesh.SetName(hypNbSeg, "NumberOfSegments_10")
147
148 print("-------------------------- MaxElementArea")
149
150 maxElementArea = 25
151
152 algo = mesh.Triangle()
153 hypArea25 = algo.MaxElementArea(maxElementArea)
154 print(hypArea25.GetName())
155 print(hypArea25.GetId())
156 print(hypArea25.GetMaxElementArea())
157 smesh.SetName(hypArea25, "MaxElementArea_25")
158
159 # Create submesh on sub_face1 - sub_face4
160 # ---------------------------------------
161
162 # Set 2D algorithm to submesh on sub_face1
163 algo = mesh.Quadrangle(sub_face1)
164 smesh.SetName(algo.GetSubMesh(), "SubMeshFace1")
165
166 # Set 2D algorithm to submesh on sub_face2
167 algo = mesh.Quadrangle(sub_face2)
168 smesh.SetName(algo.GetSubMesh(), "SubMeshFace2")
169
170 # Set 2D algorithm to submesh on sub_face3
171 algo = mesh.Quadrangle(sub_face3)
172 smesh.SetName(algo.GetSubMesh(), "SubMeshFace3")
173
174 # Set 2D algorithm to submesh on sub_face4
175 algo = mesh.Quadrangle(sub_face4)
176 smesh.SetName(algo.GetSubMesh(), "SubMeshFace4")
177
178 print("-------------------------- compute the mesh of the mechanic piece")
179
180 mesh.Compute()
181
182 print("Information about the Mesh_mechanic:")
183 print("Number of nodes       : ", mesh.NbNodes())
184 print("Number of edges       : ", mesh.NbEdges())
185 print("Number of faces       : ", mesh.NbFaces())
186 print("Number of triangles   : ", mesh.NbTriangles())
187 print("Number of quadrangles : ", mesh.NbQuadrangles())
188 print("Number of volumes     : ", mesh.NbVolumes())
189 print("Number of tetrahedrons: ", mesh.NbTetras())
190
191 salome.sg.updateObjBrowser(True)