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