Salome HOME
245fccec4b652631dff625b1484dcb6d67e0c855
[modules/smesh.git] / src / SMESH_SWIG / SMESH_demo_hexa2_upd.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #==============================================================================
23 #  Info.
24 #  Bug (from script, bug)   : SMESH_demo_hexa2_upd.py, PAL6781
25 #  Modified                 : 25/11/2004
26 #  Author                   : Kovaltchuk Alexey
27 #  Project                  : PAL/SALOME
28 #==============================================================================
29 # Tetrahedrization of a geometry (box minus a inner cylinder).
30 # Hypothesis and algorithms for the mesh generation are not global:
31 # the mesh of some edges is thinner
32 #
33 import salome
34 import geompy
35 import smesh
36
37 import math
38
39
40 # -----------------------------------------------------------------------------
41
42 ShapeTypeShell     = 3
43 ShapeTypeFace      = 4
44 ShapeTypeEdge      = 6
45
46 a = math.sqrt(2.)/4.
47 ma = - a
48 zero = 0.
49 un = 1.
50 mun= - un
51 demi = 1./2.
52
53 Orig = geompy.MakeVertex(zero,zero,zero)
54 P0 = geompy.MakeVertex(a,a,zero)
55 P1 = geompy.MakeVertex(zero,demi,zero)
56 P2 = geompy.MakeVertex(ma,a,zero)
57 P3 = geompy.MakeVertex(mun,un,zero)
58 P4 = geompy.MakeVertex(un,un,zero)
59 P5 = geompy.MakeVertex(zero,zero,un)
60
61 arc = geompy.MakeArc(P0,P1,P2)
62 e1 = geompy.MakeEdge(P2,P3)
63 e2 = geompy.MakeEdge(P3,P4)
64 e3 = geompy.MakeEdge(P4,P0)
65
66 list = []
67 list.append(arc)
68 list.append(e1)
69 list.append(e2)
70 list.append(e3)
71
72 wire = geompy.MakeWire(list)
73 face = geompy.MakeFace(wire,1)
74
75 dir = geompy.MakeVector(Orig,P5)
76 vol1 = geompy.MakePipe(face,dir)
77
78 angle = math.pi/2.
79 #dir = geom.MakeVector(Orig,P5)
80 vol2 = geompy.MakeRotation(vol1,dir,angle)
81
82 vol3 = geompy.MakeRotation(vol2,dir,angle)
83
84 vol4 = geompy.MakeRotation(vol3,dir,angle)
85
86 list = []
87 list.append(vol1)
88 list.append(vol2)
89 list.append(vol3)
90 list.append(vol4)
91
92 volComp = geompy.MakeCompound(list)
93
94 tol3d = 1.e-3
95 vol = geompy.MakeGlueFaces(volComp,tol3d)
96 idVol = geompy.addToStudy(vol,"volume")
97
98 print "Analysis of the final volume:"
99 subShellList = geompy.SubShapeAllSorted(vol,ShapeTypeShell)
100 subFaceList = geompy.SubShapeAllSorted(vol,ShapeTypeFace)
101 subEdgeList = geompy.SubShapeAllSorted(vol,ShapeTypeEdge)
102
103 print "number of Shells in the volume : ",len(subShellList)
104 print "number of Faces in the volume : ",len(subFaceList)
105 print "number of Edges in the volume : ",len(subEdgeList)
106
107 idSubEdge = []
108 for k in range(len(subEdgeList)):
109     idSubEdge.append(geompy.addToStudyInFather(vol,subEdgeList[k],"SubEdge"+str(k)))
110
111 edgeZ = []
112 edgeZ.append(subEdgeList[0])
113 edgeZ.append(subEdgeList[3])
114 edgeZ.append(subEdgeList[10])
115 edgeZ.append(subEdgeList[11])
116 edgeZ.append(subEdgeList[20])
117 edgeZ.append(subEdgeList[21])
118 edgeZ.append(subEdgeList[28])
119 edgeZ.append(subEdgeList[31])
120
121 idEdgeZ = []
122 for i in range(8):
123     idEdgeZ.append(geompy.addToStudyInFather(vol,edgeZ[i],"EdgeZ"+str(i+1)))
124
125 ### ---------------------------- SMESH --------------------------------------
126
127 # ---- init a Mesh with the volume
128
129 mesh = smesh.Mesh(vol, "meshVolume")
130
131 # ---- set Hypothesis and Algorithm to main shape
132
133 print "-------------------------- NumberOfSegments the global one"
134
135 numberOfSegments = 10
136
137 regular1D = mesh.Segment()
138 regular1D.SetName("Wire Discretisation")
139 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
140 print hypNbSeg.GetName()
141 print hypNbSeg.GetId()
142 print hypNbSeg.GetNumberOfSegments()
143 smesh.SetName(hypNbSeg, "NumberOfSegments")
144
145
146 print "-------------------------- Quadrangle_2D"
147
148 quad2D=mesh.Quadrangle()
149 quad2D.SetName("Quadrangle_2D")
150
151 print "-------------------------- Hexa_3D"
152
153 hexa3D=mesh.Hexahedron()
154 hexa3D.SetName("Hexa_3D")
155
156
157 print "-------------------------- NumberOfSegments in the Z direction"
158
159 numberOfSegmentsZ = 40
160
161 for i in range(8):
162     print "-------------------------- add hypothesis to edge in the Z directions", (i+1)
163
164     algo = mesh.Segment(edgeZ[i])
165     hyp = algo.NumberOfSegments(numberOfSegmentsZ)
166     smesh.SetName(hyp, "NumberOfSegmentsZ")
167     smesh.SetName(algo.GetSubMesh(), "SubMeshEdgeZ_"+str(i+1))
168   
169
170 salome.sg.updateObjBrowser(1)
171
172 print "-------------------------- compute the mesh of the volume"
173
174 ret=mesh.Compute()
175
176 print ret
177 if ret != 0:
178 ##    log=mesh.GetLog(0) # no erase trace
179 ##    for linelog in log:
180 ##        print linelog
181     print "Information about the MeshBox :"
182     print "Number of nodes       : ", mesh.NbNodes()
183     print "Number of edges       : ", mesh.NbEdges()
184     print "Number of faces       : ", mesh.NbFaces()
185     print "Number of triangles   : ", mesh.NbTriangles()
186     print "Number of volumes     : ", mesh.NbVolumes()
187     print "Number of tetrahedrons: ", mesh.NbTetras()
188 else:
189     print "problem when Computing the mesh"
190
191 salome.sg.updateObjBrowser(1)