Salome HOME
2b11455a817c2a08729b2101b83ed0c5be74683a
[modules/smesh.git] / src / SMESH_SWIG / SMESH_demo_hexa2_upd.py
1 #! /usr/bin/python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 #  This library is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU Lesser General Public
10 #  License as published by the Free Software Foundation; either
11 #  version 2.1 of the License.
12 #
13 #  This library is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  Lesser General Public License for more details.
17 #
18 #  You should have received a copy of the GNU Lesser General Public
19 #  License along with this library; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
129 # ---- init a Mesh with the volume
130
131 mesh = smesh.Mesh(vol, "meshVolume")
132
133 # ---- set Hypothesis and Algorithm to main shape
134
135 print "-------------------------- NumberOfSegments the global one"
136
137 numberOfSegments = 10
138
139 regular1D = mesh.Segment()
140 regular1D.SetName("Wire Discretisation")
141 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
142 print hypNbSeg.GetName()
143 print hypNbSeg.GetId()
144 print hypNbSeg.GetNumberOfSegments()
145 smesh.SetName(hypNbSeg, "NumberOfSegments")
146
147
148 print "-------------------------- Quadrangle_2D"
149
150 quad2D=mesh.Quadrangle()
151 quad2D.SetName("Quadrangle_2D")
152
153 print "-------------------------- Hexa_3D"
154
155 hexa3D=mesh.Hexahedron()
156 hexa3D.SetName("Hexa_3D")
157
158
159 print "-------------------------- NumberOfSegments in the Z direction"
160
161 numberOfSegmentsZ = 40
162
163 for i in range(8):
164     print "-------------------------- add hypothesis to edge in the Z directions", (i+1)
165
166     algo = mesh.Segment(edgeZ[i])
167     hyp = algo.NumberOfSegments(numberOfSegmentsZ)
168     smesh.SetName(hyp, "NumberOfSegmentsZ")
169     smesh.SetName(algo.GetSubMesh(), "SubMeshEdgeZ_"+str(i+1))
170   
171
172 salome.sg.updateObjBrowser(1)
173
174 print "-------------------------- compute the mesh of the volume"
175
176 ret=mesh.Compute()
177
178 print ret
179 if ret != 0:
180 ##    log=mesh.GetLog(0) # no erase trace
181 ##    for linelog in log:
182 ##        print linelog
183     print "Information about the MeshBox :"
184     print "Number of nodes       : ", mesh.NbNodes()
185     print "Number of edges       : ", mesh.NbEdges()
186     print "Number of faces       : ", mesh.NbFaces()
187     print "Number of triangles   : ", mesh.NbTriangles()
188     print "Number of volumes     : ", mesh.NbVolumes()
189     print "Number of tetrahedrons: ", mesh.NbTetras()
190 else:
191     print "problem when Computing the mesh"
192
193 salome.sg.updateObjBrowser(1)