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