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