Salome HOME
IPAL9381: replace import of smeshpy by import of smesh
[modules/smesh.git] / src / SMESH_SWIG / SMESH_test.py
1 #  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 #
3 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 #
22 #
23 #
24 #  File   : SMESH_test.py
25 #  Module : SMESH
26
27 import salome
28 import geompy
29 import smesh
30
31 import SMESH
32 import StdMeshers
33
34 # ---- define a box
35
36 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
37 idb = geompy.addToStudy(box, "box")
38
39 # ---- add first face of box in study
40
41 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
42 face = subShapeList[0]
43 name = geompy.SubShapeName(face, box)
44 idf = geompy.addToStudyInFather(box, face, name)
45
46 # ---- add shell from box  in study
47
48 subShellList = geompy.SubShapeAll(box, geompy.ShapeType["SHELL"])
49 shell = subShellList[0]
50 name = geompy.SubShapeName(shell, box)
51 ids = geompy.addToStudyInFather(box, shell, name)
52
53 # ---- add first edge of face in study
54
55 edgeList = geompy.SubShapeAll(face, geompy.ShapeType["EDGE"])
56 edge = edgeList[0];
57 name = geompy.SubShapeName(edge, face)
58 ide = geompy.addToStudyInFather(face, edge, name)
59
60 # ---- launch SMESH, init a Mesh with the box
61
62 gen = smesh.smesh()
63 mesh = gen.CreateMesh(idb)
64
65 print "-------------------------- create Hypothesis"
66
67 print "-------------------------- LocalLength"
68
69 hypo1 = gen.CreateHypothesis("LocalLength", "libStdMeshersEngine.so")
70 print hypo1.GetName()
71 print hypo1.GetId()
72 print hypo1.GetLength()
73 hypo1.SetLength(100)
74 print hypo1.GetLength()
75
76 print "-------------------------- bidon"
77
78 hyp3 = gen.CreateHypothesis("bidon", "")
79
80 print "-------------------------- NumberOfSegments"
81
82 hypo3 = gen.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
83 hypo3.SetNumberOfSegments(7)
84 print hypo3.GetName()
85 print hypo3.GetNumberOfSegments()
86 print hypo3.GetId()
87
88 print "-------------------------- MaxElementArea"
89
90 hypo4 = gen.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
91 hypo4.SetMaxElementArea(5000)
92 print hypo4.GetName()
93 print hypo4.GetMaxElementArea()
94 print hypo4.GetId()
95
96 print "-------------------------- Regular_1D"
97
98 algo_1 = gen.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
99 print algo_1.GetName()
100 print algo_1.GetId()
101 listHyp = algo_1.GetCompatibleHypothesis()
102 for hyp in listHyp:
103     print hyp
104 print algo_1.GetId()
105
106 print "-------------------------- MEFISTO_2D"
107
108 algo_2 = gen.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
109 print algo_2.GetName()
110 print algo_2.GetId()
111 listHyp = algo_2.GetCompatibleHypothesis()
112 for hyp in listHyp:
113     print hyp
114 print algo_2.GetId()
115
116 print "-------------------------- add hypothesis to edge"
117
118 edge = salome.IDToObject(ide)
119 submesh = mesh.GetSubMesh(edge, "SubMeshEdge")
120 ret = mesh.AddHypothesis(edge,algo_1)
121 print ret
122 ret = mesh.AddHypothesis(edge,hypo1)
123 print ret
124
125 ##print "-------------------------- compute edge"
126 ##ret=gen.Compute(mesh,ide)
127 ##print ret
128 ##log=mesh.GetLog(1);
129 ##for a in log:
130 ##    print a
131
132 print "-------------------------- add hypothesis to box"
133
134 box = salome.IDToObject(idb)
135 submesh = mesh.GetSubMesh(box, "SubMeshBox")
136 ret = mesh.AddHypothesis(box,algo_1)
137 print ret
138 ret = mesh.AddHypothesis(box,hypo1)
139 print ret
140 ret = mesh.AddHypothesis(box,algo_2)
141 print ret
142 ret = mesh.AddHypothesis(box,hypo4)
143 print ret
144
145 print "-------------------------- compute face"
146
147 ret = gen.Compute(mesh,idf)
148 print ret
149 log = mesh.GetLog(0) # 0 - GetLog without ClearLog after, else if 1 - ClearLog after
150 for a in log:
151     print "-------"
152     ii = 0
153     ir = 0
154     comType = a.commandType
155     if comType == 0:
156         for i in range(a.number):
157             ind = a.indexes[ii]
158             ii = ii+1
159             r1 = a.coords[ir]
160             ir = ir+1
161             r2 = a.coords[ir]
162             ir = ir+1
163             r3 = a.coords[ir]
164             ir = ir+1
165             print "AddNode %i - %g %g %g" % (ind, r1, r2, r3)
166     elif comType == 1:
167         for i in range(a.number):
168             ind = a.indexes[ii]
169             ii = ii+1
170             i1 = a.indexes[ii]
171             ii = ii+1
172             i2 = a.indexes[ii]
173             ii = ii+1
174             print "AddEdge %i - %i %i" % (ind, i1, i2)
175     elif comType == 2:
176         for i in range(a.number):
177             ind = a.indexes[ii]
178             ii = ii+1
179             i1 = a.indexes[ii]
180             ii = ii+1
181             i2 = a.indexes[ii]
182             ii = ii+1
183             i3 = a.indexes[ii]
184             ii = ii+1
185             print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3)
186
187 ##print "-------------------------- compute box"
188 ##ret=gen.Compute(mesh,idb)
189 ##print ret
190 ##log=mesh.GetLog(1);
191 ##print log
192
193 ##shell=salome.IDToObject(ids)
194 ##submesh=mesh.GetElementsOnShape(shell)
195 ##ret=mesh.AddHypothesis(shell,algo_1)
196 ##print ret
197 ##ret=mesh.AddHypothesis(shell,hypo1)
198 ##print ret
199 ##ret=gen.Compute(mesh,ids)
200 ##print ret