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