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