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