Salome HOME
[PY3] 2to3 results
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box2_tetra.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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 2 boxes having a face in common
25 # Hypothesis and algorithms for the mesh generation are global
26 #
27 import salome
28 salome.salome_init()
29 import GEOM
30 from salome.geom import geomBuilder
31 geompy = geomBuilder.New(salome.myStudy)
32
33 import SMESH, SALOMEDS
34 from salome.smesh import smeshBuilder
35 smesh =  smeshBuilder.New(salome.myStudy)
36
37
38 # ---- define 2 boxes box1 and box2
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 # append the tow boxes to make ine shel, referrencing only once
67 # the internal interface
68
69 shell = geompy.MakePartition([box1, box2])
70 idshell = geompy.addToStudy(shell, "shell")
71
72 print("Analysis of the geometry shell (union of box1 and box2) :")
73 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
74 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
75 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
76
77 print("number of Shells in shell : ", len(subShellList))
78 print("number of Faces  in shell : ", len(subFaceList))
79 print("number of Edges  in shell : ", len(subEdgeList))
80
81
82 ### ---------------------------- SMESH --------------------------------------
83
84 # ---- init a Mesh with the shell
85
86 mesh = smesh.Mesh(shell, "MeshBox2")
87
88
89 # ---- set Hypothesis and Algorithm
90
91 print("-------------------------- NumberOfSegments")
92
93 numberOfSegments = 10
94
95 regular1D = mesh.Segment()
96 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
97 print(hypNbSeg.GetName())
98 print(hypNbSeg.GetId())
99 print(hypNbSeg.GetNumberOfSegments())
100 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
101
102 print("-------------------------- MaxElementArea")
103
104 maxElementArea = 500
105
106 mefisto2D = mesh.Triangle()
107 hypArea = mefisto2D.MaxElementArea(maxElementArea)
108 print(hypArea.GetName())
109 print(hypArea.GetId())
110 print(hypArea.GetMaxElementArea())
111 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
112
113 print("-------------------------- MaxElementVolume")
114
115 maxElementVolume = 500
116
117 netgen3D = mesh.Tetrahedron(smeshBuilder.NETGEN)
118 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
119 print(hypVolume.GetName())
120 print(hypVolume.GetId())
121 print(hypVolume.GetMaxElementVolume())
122 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
123
124 print("-------------------------- compute shell")
125 ret = mesh.Compute()
126 print(ret)
127 if ret != 0:
128     log = mesh.GetLog(0) # no erase trace
129     for linelog in log:
130         print(linelog)
131     print("Information about the MeshBox2:")
132     print("Number of nodes       : ", mesh.NbNodes())
133     print("Number of edges       : ", mesh.NbEdges())
134     print("Number of faces       : ", mesh.NbFaces())
135     print("Number of triangles   : ", mesh.NbTriangles())
136     print("Number of volumes     : ", mesh.NbVolumes())
137     print("Number of tetrahedrons: ", mesh.NbTetras())
138 else:
139     print("probleme when computing the mesh")
140
141 salome.sg.updateObjBrowser(True)