Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box3_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 3 boxes aligned where the middle
22 # one has a race in common with the two others.
23 # Hypothesis and algorithms for the mesh generation are global
24 #
25
26 import salome
27 import geompy
28
29 import StdMeshers
30 import NETGENPlugin
31
32 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
33
34 smeshgui = salome.ImportComponentGUI("SMESH")
35 smeshgui.Init(salome.myStudyId);
36
37 # ---- define 3 boxes box1, box2 and box3
38
39 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
40
41 idbox1 = geompy.addToStudy(box1, "box1")
42
43 print "Analysis of the geometry box1 :"
44 subShellList = geompy.SubShapeAll(box1, geompy.ShapeType["SHELL"])
45 subFaceList  = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
46 subEdgeList  = geompy.SubShapeAll(box1, geompy.ShapeType["EDGE"])
47
48 print "number of Shells in box1 : ", len(subShellList)
49 print "number of Faces  in box1 : ", len(subFaceList)
50 print "number of Edges  in box1 : ", len(subEdgeList)
51
52 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
53
54 idbox2 = geompy.addToStudy(box2, "box2")
55
56 print "Analysis of the geometry box2 :"
57 subShellList = geompy.SubShapeAll(box2, geompy.ShapeType["SHELL"])
58 subFaceList  = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
59 subEdgeList  = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
60
61 print "number of Shells in box2 : ", len(subShellList)
62 print "number of Faces  in box2 : ", len(subFaceList)
63 print "number of Edges  in box2 : ", len(subEdgeList)
64
65 box3 = geompy.MakeBox(0., 0., 300., 200., 200., 500.)
66
67 idbox3 = geompy.addToStudy(box3, "box3")
68
69 print "Analysis of the geometry box3 :"
70 subShellList = geompy.SubShapeAll(box3, geompy.ShapeType["SHELL"])
71 subFaceList  = geompy.SubShapeAll(box3, geompy.ShapeType["FACE"])
72 subEdgeList  = geompy.SubShapeAll(box3, geompy.ShapeType["EDGE"])
73
74 print "number of Shells in box3 : ", len(subShellList)
75 print "number of Faces  in box3 : ", len(subFaceList)
76 print "number of Edges  in box3 : ", len(subEdgeList)
77
78 shell = geompy.MakePartition([box1, box2, box3])
79 idshell = geompy.addToStudy(shell,"shell")
80
81 print "Analysis of the geometry shell (union of box1, box2 and box3) :"
82 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
83 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
84 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
85
86 print "number of Shells in shell : ", len(subShellList)
87 print "number of Faces  in shell : ", len(subFaceList)
88 print "number of Edges  in shell : ", len(subEdgeList)
89
90
91 ### ---------------------------- SMESH --------------------------------------
92
93 # ---- create Hypothesis
94
95 print "-------------------------- create Hypothesis"
96
97 print "-------------------------- NumberOfSegments"
98
99 numberOfSegments = 10
100
101 hypNbSeg = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
102 hypNbSeg.SetNumberOfSegments(numberOfSegments)
103
104 print hypNbSeg.GetName()
105 print hypNbSeg.GetId()
106 print hypNbSeg.GetNumberOfSegments()
107
108 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
109
110 print "-------------------------- MaxElementArea"
111
112 maxElementArea = 500
113
114 hypArea = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
115 hypArea.SetMaxElementArea(maxElementArea)
116
117 print hypArea.GetName()
118 print hypArea.GetId()
119 print hypArea.GetMaxElementArea()
120
121 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_500")
122
123 print "-------------------------- MaxElementVolume"
124
125 maxElementVolume = 500
126
127 hypVolume = smesh.CreateHypothesis("MaxElementVolume", "libStdMeshersEngine.so")
128 hypVolume.SetMaxElementVolume(maxElementVolume)
129
130 print hypVolume.GetName()
131 print hypVolume.GetId()
132 print hypVolume.GetMaxElementVolume()
133
134 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_500")
135
136 # ---- create Algorithms
137
138 print "-------------------------- create Algorithms"
139
140 print "-------------------------- Regular_1D"
141
142 regular1D = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
143 smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")
144
145 print "-------------------------- MEFISTO_2D"
146
147 mefisto2D = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
148 smeshgui.SetName(salome.ObjectToID(mefisto2D), "MEFISTO_2D")
149
150 print "-------------------------- NETGEN_3D"
151
152 netgen3D = smesh.CreateHypothesis("NETGEN_3D", "libNETGENEngine.so")
153 smeshgui.SetName(salome.ObjectToID(netgen3D), "NETGEN_3D")
154
155 # ---- init a Mesh with the shell
156
157 mesh = smesh.CreateMesh(shell)
158 smeshgui.SetName(salome.ObjectToID(mesh), "MeshBox3")
159
160 # ---- add hypothesis to shell
161
162 print "-------------------------- add hypothesis to shell"
163
164 mesh.AddHypothesis(shell,regular1D)
165 mesh.AddHypothesis(shell,hypNbSeg)
166
167 mesh.AddHypothesis(shell,mefisto2D)
168 mesh.AddHypothesis(shell,hypArea)
169
170 mesh.AddHypothesis(shell,netgen3D)
171 mesh.AddHypothesis(shell,hypVolume)
172
173 salome.sg.updateObjBrowser(1)
174
175 print "-------------------------- compute shell"
176 ret = smesh.Compute(mesh,shell)
177 print ret
178 if ret != 0:
179     log = mesh.GetLog(0) # no erase trace
180     for linelog in log:
181         print linelog
182     print "Information about the MeshBox3:"
183     print "Number of nodes       : ", mesh.NbNodes()
184     print "Number of edges       : ", mesh.NbEdges()
185     print "Number of faces       : ", mesh.NbFaces()
186     print "Number of triangles   : ", mesh.NbTriangles()
187     print "Number of volumes     : ", mesh.NbVolumes()
188     print "Number of tetrahedrons: ", mesh.NbTetras()
189 else:
190     print "probleme when computing the mesh"