Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box2_tetra.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 #
21 # Tetrahedrization of the geometry union of 2 boxes having a face in common
22 # Hypothesis and algorithms for the mesh generation are global
23 #
24
25 import salome
26 import geompy
27
28 import StdMeshers
29 import NETGENPlugin
30
31 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
32
33 smeshgui = salome.ImportComponentGUI("SMESH")
34 smeshgui.Init(salome.myStudyId);
35
36 # ---- define 2 boxes box1 and box2
37
38 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
39
40 idbox1 = geompy.addToStudy(box1, "box1")
41
42 print "Analysis of the geometry box1 :"
43 subShellList = geompy.SubShapeAll(box1, geompy.ShapeType["SHELL"])
44 subFaceList  = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
45 subEdgeList  = geompy.SubShapeAll(box1, geompy.ShapeType["EDGE"])
46
47 print "number of Shells in box1 : ", len(subShellList)
48 print "number of Faces  in box1 : ", len(subFaceList)
49 print "number of Edges  in box1 : ", len(subEdgeList)
50
51 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
52
53 idbox2 = geompy.addToStudy(box2, "box2")
54
55 print "Analysis of the geometry box2 :"
56 subShellList = geompy.SubShapeAll(box2, geompy.ShapeType["SHELL"])
57 subFaceList  = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
58 subEdgeList  = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
59
60 print "number of Shells in box2 : ", len(subShellList)
61 print "number of Faces  in box2 : ", len(subFaceList)
62 print "number of Edges  in box2 : ", len(subEdgeList)
63
64 # append the tow boxes to make ine shel, referrencing only once
65 # the internal interface
66
67 shell = geompy.MakePartition([box1, box2])
68 idshell = geompy.addToStudy(shell, "shell")
69
70 print "Analysis of the geometry shell (union of box1 and box2) :"
71 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
72 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
73 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
74
75 print "number of Shells in shell : ", len(subShellList)
76 print "number of Faces  in shell : ", len(subFaceList)
77 print "number of Edges  in shell : ", len(subEdgeList)
78
79
80 ### ---------------------------- SMESH --------------------------------------
81
82 # ---- create Hypothesis
83
84 print "-------------------------- create Hypothesis"
85
86 print "-------------------------- NumberOfSegments"
87
88 numberOfSegments = 10
89
90 hypNbSeg = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
91 hypNbSeg.SetNumberOfSegments(numberOfSegments)
92
93 print hypNbSeg.GetName()
94 print hypNbSeg.GetId()
95 print hypNbSeg.GetNumberOfSegments()
96
97 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
98
99 print "-------------------------- MaxElementArea"
100
101 maxElementArea = 500
102
103 hypArea = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
104 hypArea.SetMaxElementArea(maxElementArea)
105
106 print hypArea.GetName()
107 print hypArea.GetId()
108 print hypArea.GetMaxElementArea()
109
110 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_500")
111
112 print "-------------------------- MaxElementVolume"
113
114 maxElementVolume = 500
115
116 hypVolume = smesh.CreateHypothesis("MaxElementVolume", "libStdMeshersEngine.so")
117 hypVolume.SetMaxElementVolume(maxElementVolume)
118
119 print hypVolume.GetName()
120 print hypVolume.GetId()
121 print hypVolume.GetMaxElementVolume()
122
123 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_500")
124
125 # ---- create Algorithms
126
127 print "-------------------------- create Algorithms"
128
129 print "-------------------------- Regular_1D"
130
131 regular1D = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
132 smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")
133
134 print "-------------------------- MEFISTO_2D"
135
136 mefisto2D = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
137 smeshgui.SetName(salome.ObjectToID(mefisto2D), "MEFISTO_2D")
138
139 print "-------------------------- NETGEN_3D"
140
141 netgen3D = smesh.CreateHypothesis("NETGEN_3D", "libNETGENEngine.so")
142 smeshgui.SetName(salome.ObjectToID(netgen3D), "NETGEN_3D")
143
144 # ---- init a Mesh with the shell
145
146 mesh = smesh.CreateMesh(shell)
147 smeshgui.SetName(salome.ObjectToID(mesh), "MeshBox2")
148
149 # ---- add hypothesis to shell
150
151 print "-------------------------- add hypothesis to shell"
152
153 mesh.AddHypothesis(shell,regular1D)
154 mesh.AddHypothesis(shell,hypNbSeg)
155
156 mesh.AddHypothesis(shell,mefisto2D)
157 mesh.AddHypothesis(shell,hypArea)
158
159 mesh.AddHypothesis(shell,netgen3D)
160 mesh.AddHypothesis(shell,hypVolume)
161
162 salome.sg.updateObjBrowser(1)
163
164 print "-------------------------- compute shell"
165 ret = smesh.Compute(mesh,shell)
166 print ret
167 if ret != 0:
168     log = mesh.GetLog(0) # no erase trace
169     for linelog in log:
170         print linelog
171     print "Information about the MeshBox2:"
172     print "Number of nodes       : ", mesh.NbNodes()
173     print "Number of edges       : ", mesh.NbEdges()
174     print "Number of faces       : ", mesh.NbFaces()
175     print "Number of triangles   : ", mesh.NbTriangles()
176     print "Number of volumes     : ", mesh.NbVolumes()
177     print "Number of tetrahedrons: ", mesh.NbTetras()
178 else:
179     print "probleme when computing the mesh"