Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box2_tetra.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 # Tetrahedrization of the geometry union of 2 boxes having a face in common
24 # Hypothesis and algorithms for the mesh generation are global
25 #
26 import salome
27 import geompy
28 import smesh
29
30
31 # ---- define 2 boxes box1 and box2
32
33 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
34
35 idbox1 = geompy.addToStudy(box1, "box1")
36
37 print "Analysis of the geometry box1 :"
38 subShellList = geompy.SubShapeAll(box1, geompy.ShapeType["SHELL"])
39 subFaceList  = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
40 subEdgeList  = geompy.SubShapeAll(box1, geompy.ShapeType["EDGE"])
41
42 print "number of Shells in box1 : ", len(subShellList)
43 print "number of Faces  in box1 : ", len(subFaceList)
44 print "number of Edges  in box1 : ", len(subEdgeList)
45
46 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
47
48 idbox2 = geompy.addToStudy(box2, "box2")
49
50 print "Analysis of the geometry box2 :"
51 subShellList = geompy.SubShapeAll(box2, geompy.ShapeType["SHELL"])
52 subFaceList  = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
53 subEdgeList  = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
54
55 print "number of Shells in box2 : ", len(subShellList)
56 print "number of Faces  in box2 : ", len(subFaceList)
57 print "number of Edges  in box2 : ", len(subEdgeList)
58
59 # append the tow boxes to make ine shel, referrencing only once
60 # the internal interface
61
62 shell = geompy.MakePartition([box1, box2])
63 idshell = geompy.addToStudy(shell, "shell")
64
65 print "Analysis of the geometry shell (union of box1 and box2) :"
66 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
67 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
68 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
69
70 print "number of Shells in shell : ", len(subShellList)
71 print "number of Faces  in shell : ", len(subFaceList)
72 print "number of Edges  in shell : ", len(subEdgeList)
73
74
75 ### ---------------------------- SMESH --------------------------------------
76
77 # ---- init a Mesh with the shell
78
79 mesh = smesh.Mesh(shell, "MeshBox2")
80
81
82 # ---- set Hypothesis and Algorithm
83
84 print "-------------------------- NumberOfSegments"
85
86 numberOfSegments = 10
87
88 regular1D = mesh.Segment()
89 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
90 print hypNbSeg.GetName()
91 print hypNbSeg.GetId()
92 print hypNbSeg.GetNumberOfSegments()
93 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
94
95 print "-------------------------- MaxElementArea"
96
97 maxElementArea = 500
98
99 mefisto2D = mesh.Triangle()
100 hypArea = mefisto2D.MaxElementArea(maxElementArea)
101 print hypArea.GetName()
102 print hypArea.GetId()
103 print hypArea.GetMaxElementArea()
104 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
105
106 print "-------------------------- MaxElementVolume"
107
108 maxElementVolume = 500
109
110 netgen3D = mesh.Tetrahedron(smesh.NETGEN)
111 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
112 print hypVolume.GetName()
113 print hypVolume.GetId()
114 print hypVolume.GetMaxElementVolume()
115 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
116
117
118 salome.sg.updateObjBrowser(1)
119
120 print "-------------------------- compute shell"
121 ret = mesh.Compute()
122 print ret
123 if ret != 0:
124     log = mesh.GetLog(0) # no erase trace
125     for linelog in log:
126         print linelog
127     print "Information about the MeshBox2:"
128     print "Number of nodes       : ", mesh.NbNodes()
129     print "Number of edges       : ", mesh.NbEdges()
130     print "Number of faces       : ", mesh.NbFaces()
131     print "Number of triangles   : ", mesh.NbTriangles()
132     print "Number of volumes     : ", mesh.NbVolumes()
133     print "Number of tetrahedrons: ", mesh.NbTetras()
134 else:
135     print "probleme when computing the mesh"