Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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
35 import StdMeshers
36 import NETGENPlugin
37
38 geom  = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
39 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
40
41 smeshgui = salome.ImportComponentGUI("SMESH")
42 smeshgui.Init(salome.myStudyId);
43
44 import math
45
46 # -----------------------------------------------------------------------------
47
48 ShapeTypeShell     = 3
49 ShapeTypeFace      = 4
50 ShapeTypeEdge      = 6
51
52 a = math.sqrt(2.)/4.
53 ma = - a
54 zero = 0.
55 un = 1.
56 mun= - un
57 demi = 1./2.
58
59 Orig = geompy.MakeVertex(zero,zero,zero)
60 P0 = geompy.MakeVertex(a,a,zero)
61 P1 = geompy.MakeVertex(zero,demi,zero)
62 P2 = geompy.MakeVertex(ma,a,zero)
63 P3 = geompy.MakeVertex(mun,un,zero)
64 P4 = geompy.MakeVertex(un,un,zero)
65 P5 = geompy.MakeVertex(zero,zero,un)
66
67 arc = geompy.MakeArc(P0,P1,P2)
68 e1 = geompy.MakeEdge(P2,P3)
69 e2 = geompy.MakeEdge(P3,P4)
70 e3 = geompy.MakeEdge(P4,P0)
71
72 list = []
73 list.append(arc)
74 list.append(e1)
75 list.append(e2)
76 list.append(e3)
77
78 wire = geompy.MakeWire(list)
79 face = geompy.MakeFace(wire,1)
80
81 dir = geompy.MakeVector(Orig,P5)
82 vol1 = geompy.MakePipe(face,dir)
83
84 angle = math.pi/2.
85 #dir = geom.MakeVector(Orig,P5)
86 vol2 = geompy.MakeRotation(vol1,dir,angle)
87
88 vol3 = geompy.MakeRotation(vol2,dir,angle)
89
90 vol4 = geompy.MakeRotation(vol3,dir,angle)
91
92 list = []
93 list.append(vol1)
94 list.append(vol2)
95 list.append(vol3)
96 list.append(vol4)
97
98 volComp = geompy.MakeCompound(list)
99
100 tol3d = 1.e-3
101 vol = geompy.MakeGlueFaces(volComp,tol3d)
102 idVol = geompy.addToStudy(vol,"volume")
103
104 print "Analysis of the final volume:"
105 subShellList = geompy.SubShapeAllSorted(vol,ShapeTypeShell)
106 subFaceList = geompy.SubShapeAllSorted(vol,ShapeTypeFace)
107 subEdgeList = geompy.SubShapeAllSorted(vol,ShapeTypeEdge)
108
109 print "number of Shells in the volume : ",len(subShellList)
110 print "number of Faces in the volume : ",len(subFaceList)
111 print "number of Edges in the volume : ",len(subEdgeList)
112
113 idSubEdge = []
114 for k in range(len(subEdgeList)):
115     idSubEdge.append(geompy.addToStudyInFather(vol,subEdgeList[k],"SubEdge"+str(k)))
116
117 edgeZ = []
118 edgeZ.append(subEdgeList[0])
119 edgeZ.append(subEdgeList[3])
120 edgeZ.append(subEdgeList[10])
121 edgeZ.append(subEdgeList[11])
122 edgeZ.append(subEdgeList[20])
123 edgeZ.append(subEdgeList[21])
124 edgeZ.append(subEdgeList[28])
125 edgeZ.append(subEdgeList[31])
126
127 idEdgeZ = []
128 for i in range(8):
129     idEdgeZ.append(geompy.addToStudyInFather(vol,edgeZ[i],"EdgeZ"+str(i+1)))
130
131 ### ---------------------------- SMESH --------------------------------------
132
133 # ---- create Hypothesis
134
135 print "-------------------------- create Hypothesis"
136
137 print "-------------------------- NumberOfSegments the global one"
138
139 numberOfSegments = 10
140
141 hypNbSeg=smesh.CreateHypothesis("NumberOfSegments","libStdMeshersEngine.so")
142 hypNbSeg.SetNumberOfSegments(numberOfSegments)
143 hypNbSegID = hypNbSeg.GetId()
144 print hypNbSeg.GetName()
145 print hypNbSegID
146 print hypNbSeg.GetNumberOfSegments()
147
148 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments")
149
150 print "-------------------------- NumberOfSegments in the Z direction"
151
152 numberOfSegmentsZ = 40
153
154 hypNbSegZ=smesh.CreateHypothesis("NumberOfSegments","libStdMeshersEngine.so")
155 hypNbSegZ.SetNumberOfSegments(numberOfSegmentsZ)
156 hypNbSegZID = hypNbSegZ.GetId()
157 print hypNbSegZ.GetName()
158 print hypNbSegZID
159 print hypNbSegZ.GetNumberOfSegments()
160
161 smeshgui.SetName(salome.ObjectToID(hypNbSegZ), "NumberOfSegmentsZ")
162
163 # ---- create Algorithms
164
165 print "-------------------------- create Algorithms"
166
167 print "-------------------------- Regular_1D"
168
169 regular1D=smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
170 smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")
171
172 print "-------------------------- Quadrangle_2D"
173
174 quad2D=smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")
175 smeshgui.SetName(salome.ObjectToID(quad2D), "Quadrangle_2D")
176
177 print "-------------------------- Hexa_3D"
178
179 hexa3D=smesh.CreateHypothesis("Hexa_3D", "libStdMeshersEngine.so")
180 smeshgui.SetName(salome.ObjectToID(hexa3D), "Hexa_3D")
181
182 # ---- init a Mesh with the volume
183
184 mesh = smesh.CreateMesh(vol)
185 smeshgui.SetName(salome.ObjectToID(mesh), "meshVolume")
186
187 # ---- add hypothesis to the volume
188
189 print "-------------------------- add hypothesis to the volume"
190
191 ret=mesh.AddHypothesis(vol,regular1D)
192 print ret
193 ret=mesh.AddHypothesis(vol,hypNbSeg)
194 print ret
195 ret=mesh.AddHypothesis(vol,quad2D)
196 print ret
197 ret=mesh.AddHypothesis(vol,hexa3D)
198 print ret
199
200 for i in range(8):
201     print "-------------------------- add hypothesis to edge in the Z directions", (i+1)
202
203     subMeshEdgeZ = mesh.GetSubMesh(edgeZ[i],"SubMeshEdgeZ_"+str(i+1))
204
205     retZ = mesh.AddHypothesis(edgeZ[i],hypNbSegZ)
206     print " add hyp Z ", retZ
207
208 salome.sg.updateObjBrowser(1)
209
210 print "-------------------------- compute the mesh of the volume"
211
212 ret=smesh.Compute(mesh,vol)
213
214 print ret
215 if ret != 0:
216 ##    log=mesh.GetLog(0) # no erase trace
217 ##    for linelog in log:
218 ##        print linelog
219     print "Information about the MeshBox :"
220     print "Number of nodes       : ", mesh.NbNodes()
221     print "Number of edges       : ", mesh.NbEdges()
222     print "Number of faces       : ", mesh.NbFaces()
223     print "Number of triangles   : ", mesh.NbTriangles()
224     print "Number of volumes     : ", mesh.NbVolumes()
225     print "Number of tetrahedrons: ", mesh.NbTetras()
226 else:
227     print "problem when Computing the mesh"
228
229 salome.sg.updateObjBrowser(1)