Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box3_tetra.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # Tetrahedrization of the geometry union of 3 boxes aligned where the middle
23 # one has a race in common with the two others.
24 # Hypothesis and algorithms for the mesh generation are global
25 #
26 import salome
27 import geompy
28 import smesh
29
30
31 # ---- define 3 boxes box1, box2 and box3
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 box3 = geompy.MakeBox(0., 0., 300., 200., 200., 500.)
60
61 idbox3 = geompy.addToStudy(box3, "box3")
62
63 print "Analysis of the geometry box3 :"
64 subShellList = geompy.SubShapeAll(box3, geompy.ShapeType["SHELL"])
65 subFaceList  = geompy.SubShapeAll(box3, geompy.ShapeType["FACE"])
66 subEdgeList  = geompy.SubShapeAll(box3, geompy.ShapeType["EDGE"])
67
68 print "number of Shells in box3 : ", len(subShellList)
69 print "number of Faces  in box3 : ", len(subFaceList)
70 print "number of Edges  in box3 : ", len(subEdgeList)
71
72 shell = geompy.MakePartition([box1, box2, box3])
73 idshell = geompy.addToStudy(shell,"shell")
74
75 print "Analysis of the geometry shell (union of box1, box2 and box3) :"
76 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
77 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
78 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
79
80 print "number of Shells in shell : ", len(subShellList)
81 print "number of Faces  in shell : ", len(subFaceList)
82 print "number of Edges  in shell : ", len(subEdgeList)
83
84
85 ### ---------------------------- SMESH --------------------------------------
86
87
88 # ---- init a Mesh with the shell
89
90 mesh = smesh.Mesh(shell, "MeshBox3")
91
92
93 # ---- set Hypothesis and Algorithm
94
95 print "-------------------------- NumberOfSegments"
96
97 numberOfSegments = 10
98
99 regular1D = mesh.Segment()
100 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
101 print hypNbSeg.GetName()
102 print hypNbSeg.GetId()
103 print hypNbSeg.GetNumberOfSegments()
104 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
105
106 print "-------------------------- MaxElementArea"
107
108 maxElementArea = 500
109
110 mefisto2D = mesh.Triangle()
111 hypArea = mefisto2D.MaxElementArea(maxElementArea)
112 print hypArea.GetName()
113 print hypArea.GetId()
114 print hypArea.GetMaxElementArea()
115 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
116
117 print "-------------------------- MaxElementVolume"
118
119 maxElementVolume = 500
120
121 netgen3D = mesh.Tetrahedron(smesh.NETGEN)
122 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
123 print hypVolume.GetName()
124 print hypVolume.GetId()
125 print hypVolume.GetMaxElementVolume()
126 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
127
128
129 salome.sg.updateObjBrowser(1)
130
131 print "-------------------------- compute shell"
132 ret = mesh.Compute()
133 print ret
134 if ret != 0:
135     log = mesh.GetLog(0) # no erase trace
136     for linelog in log:
137         print linelog
138     print "Information about the MeshBox3:"
139     print "Number of nodes       : ", mesh.NbNodes()
140     print "Number of edges       : ", mesh.NbEdges()
141     print "Number of faces       : ", mesh.NbFaces()
142     print "Number of triangles   : ", mesh.NbTriangles()
143     print "Number of volumes     : ", mesh.NbVolumes()
144     print "Number of tetrahedrons: ", mesh.NbTetras()
145 else:
146     print "probleme when computing the mesh"