Salome HOME
Merge Python 3 porting.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_demo_hexa2_upd.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 #==============================================================================
25 #  Info.
26 #  Bug (from script, bug)   : SMESH_demo_hexa2_upd.py, PAL6781
27 #  Modified                 : 25/11/2004
28 #  Author                   : Kovaltchuk Alexey
29 #  Project                  : PAL/SALOME
30 #==============================================================================
31 # Tetrahedrization of a geometry (box minus a inner cylinder).
32 # Hypothesis and algorithms for the mesh generation are not global:
33 # the mesh of some edges is thinner
34 #
35 import salome
36 salome.salome_init()
37 import GEOM
38 from salome.geom import geomBuilder
39 geompy = geomBuilder.New()
40
41 import SMESH, SALOMEDS
42 from salome.smesh import smeshBuilder
43 smesh =  smeshBuilder.New()
44
45 import math
46
47
48 # -----------------------------------------------------------------------------
49
50 ShapeTypeShell     = 3
51 ShapeTypeFace      = 4
52 ShapeTypeEdge      = 6
53
54 a = math.sqrt(2.)/4.
55 ma = - a
56 zero = 0.
57 un = 1.
58 mun= - un
59 demi = 1./2.
60
61 Orig = geompy.MakeVertex(zero,zero,zero)
62 P0 = geompy.MakeVertex(a,a,zero)
63 P1 = geompy.MakeVertex(zero,demi,zero)
64 P2 = geompy.MakeVertex(ma,a,zero)
65 P3 = geompy.MakeVertex(mun,un,zero)
66 P4 = geompy.MakeVertex(un,un,zero)
67 P5 = geompy.MakeVertex(zero,zero,un)
68
69 arc = geompy.MakeArc(P0,P1,P2)
70 e1 = geompy.MakeEdge(P2,P3)
71 e2 = geompy.MakeEdge(P3,P4)
72 e3 = geompy.MakeEdge(P4,P0)
73
74 list = []
75 list.append(arc)
76 list.append(e1)
77 list.append(e2)
78 list.append(e3)
79
80 wire = geompy.MakeWire(list)
81 face = geompy.MakeFace(wire,1)
82
83 dir = geompy.MakeVector(Orig,P5)
84 vol1 = geompy.MakePipe(face,dir)
85
86 angle = math.pi/2.
87 #dir = geom.MakeVector(Orig,P5)
88 vol2 = geompy.MakeRotation(vol1,dir,angle)
89
90 vol3 = geompy.MakeRotation(vol2,dir,angle)
91
92 vol4 = geompy.MakeRotation(vol3,dir,angle)
93
94 list = []
95 list.append(vol1)
96 list.append(vol2)
97 list.append(vol3)
98 list.append(vol4)
99
100 volComp = geompy.MakeCompound(list)
101
102 tol3d = 1.e-3
103 vol = geompy.MakeGlueFaces(volComp,tol3d)
104 idVol = geompy.addToStudy(vol,"volume")
105
106 print("Analysis of the final volume:")
107 subShellList = geompy.SubShapeAllSorted(vol,ShapeTypeShell)
108 subFaceList = geompy.SubShapeAllSorted(vol,ShapeTypeFace)
109 subEdgeList = geompy.SubShapeAllSorted(vol,ShapeTypeEdge)
110
111 print("number of Shells in the volume : ",len(subShellList))
112 print("number of Faces in the volume : ",len(subFaceList))
113 print("number of Edges in the volume : ",len(subEdgeList))
114
115 idSubEdge = []
116 for k in range(len(subEdgeList)):
117     idSubEdge.append(geompy.addToStudyInFather(vol,subEdgeList[k],"SubEdge"+str(k)))
118
119 edgeZ = []
120 edgeZ.append(subEdgeList[0])
121 edgeZ.append(subEdgeList[3])
122 edgeZ.append(subEdgeList[10])
123 edgeZ.append(subEdgeList[11])
124 edgeZ.append(subEdgeList[20])
125 edgeZ.append(subEdgeList[21])
126 edgeZ.append(subEdgeList[28])
127 edgeZ.append(subEdgeList[31])
128
129 idEdgeZ = []
130 for i in range(8):
131     idEdgeZ.append(geompy.addToStudyInFather(vol,edgeZ[i],"EdgeZ"+str(i+1)))
132
133 ### ---------------------------- SMESH --------------------------------------
134 smesh.UpdateStudy()
135
136 # ---- init a Mesh with the volume
137
138 mesh = smesh.Mesh(vol, "meshVolume")
139
140 # ---- set Hypothesis and Algorithm to main shape
141
142 print("-------------------------- NumberOfSegments the global one")
143
144 numberOfSegments = 10
145
146 regular1D = mesh.Segment()
147 regular1D.SetName("Wire Discretisation")
148 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
149 print(hypNbSeg.GetName())
150 print(hypNbSeg.GetId())
151 print(hypNbSeg.GetNumberOfSegments())
152 smesh.SetName(hypNbSeg, "NumberOfSegments")
153
154
155 print("-------------------------- Quadrangle_2D")
156
157 quad2D=mesh.Quadrangle()
158 quad2D.SetName("Quadrangle_2D")
159
160 print("-------------------------- Hexa_3D")
161
162 hexa3D=mesh.Hexahedron()
163 hexa3D.SetName("Hexa_3D")
164
165
166 print("-------------------------- NumberOfSegments in the Z direction")
167
168 numberOfSegmentsZ = 40
169
170 for i in range(8):
171     print("-------------------------- add hypothesis to edge in the Z directions", (i+1))
172
173     algo = mesh.Segment(edgeZ[i])
174     hyp = algo.NumberOfSegments(numberOfSegmentsZ)
175     smesh.SetName(hyp, "NumberOfSegmentsZ")
176     smesh.SetName(algo.GetSubMesh(), "SubMeshEdgeZ_"+str(i+1))
177   
178
179 salome.sg.updateObjBrowser()
180
181 print("-------------------------- compute the mesh of the volume")
182
183 ret=mesh.Compute()
184
185 print(ret)
186 if ret != 0:
187 ##    log=mesh.GetLog(0) # no erase trace
188 ##    for linelog in log:
189 ##        print linelog
190     print("Information about the MeshBox :")
191     print("Number of nodes       : ", mesh.NbNodes())
192     print("Number of edges       : ", mesh.NbEdges())
193     print("Number of faces       : ", mesh.NbFaces())
194     print("Number of triangles   : ", mesh.NbTriangles())
195     print("Number of volumes     : ", mesh.NbVolumes())
196     print("Number of tetrahedrons: ", mesh.NbTetras())
197 else:
198     print("problem when Computing the mesh")
199
200 salome.sg.updateObjBrowser()