Salome HOME
Add support for tetra, pyramid and prism
[modules/smesh.git] / src / SMESH_I / 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 SMESH
28 import smeshpy
29 import salome
30 from salome import sg
31 import math
32 #import SMESH_BasicHypothesis_idl
33
34 import geompy
35
36 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
37 myBuilder = salome.myStudy.NewBuilder()
38 from geompy import gg
39
40 ShapeTypeCompSolid = 1
41 ShapeTypeSolid = 2
42 ShapeTypeShell = 3
43 ShapeTypeFace = 4
44 ShapeTypeWire = 5
45 ShapeTypeEdge = 6
46 ShapeTypeVertex = 7
47
48 # ---- define a box
49
50 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
51 idb = geompy.addToStudy(box,"box")
52
53 # ---- add first face of box in study
54
55 subShapeList=geompy.SubShapeAll(box,ShapeTypeFace)
56 face=subShapeList[0]
57 name = geompy.SubShapeName( face._get_Name(), box._get_Name() )
58 print name
59 idf=geompy.addToStudyInFather(box,face,name)
60
61 # ---- add shell from box  in study
62
63 subShellList=geompy.SubShapeAll(box,ShapeTypeShell)
64 shell = subShellList[0]
65 name = geompy.SubShapeName( shell._get_Name(), box._get_Name() )
66 print name
67 ids=geompy.addToStudyInFather(box,shell,name)
68
69 # ---- add first edge of face in study
70
71 edgeList = geompy.SubShapeAll(face,ShapeTypeEdge)
72 edge=edgeList[0];
73 name = geompy.SubShapeName( edge._get_Name(), face._get_Name() )
74 print name
75 ide=geompy.addToStudyInFather(face,edge,name)
76
77 # ---- launch SMESH, init a Mesh with the box
78 gen=smeshpy.smeshpy()
79 mesh=gen.Init(idb)
80
81 # ---- create Hypothesis
82
83 print "-------------------------- create Hypothesis"
84 print "-------------------------- LocalLength"
85 hyp1=gen.CreateHypothesis("LocalLength")
86 print hyp1.GetName()
87 print hyp1.GetId()
88 hypo1 = hyp1._narrow(SMESH.SMESH_LocalLength)
89 print hypo1.GetLength()
90 hypo1.SetLength(100)
91 print hypo1.GetLength()
92
93 print "-------------------------- bidon"
94 hyp3=gen.CreateHypothesis("bidon")
95
96 print "-------------------------- NumberOfSegments"
97 hyp3=gen.CreateHypothesis("NumberOfSegments")
98 hypo3=hyp3._narrow(SMESH.SMESH_NumberOfSegments)
99 hypo3.SetNumberOfSegments(7)
100 print hypo3.GetName()
101 print hypo3.GetNumberOfSegments()
102 print hypo3.GetId()
103
104 print "-------------------------- MaxElementArea"
105 hyp4=gen.CreateHypothesis("MaxElementArea")
106 hypo4=hyp4._narrow(SMESH.SMESH_MaxElementArea)
107 hypo4.SetMaxElementArea(5000)
108 print hypo4.GetName()
109 print hypo4.GetMaxElementArea()
110 print hypo4.GetId()
111
112 print "-------------------------- Regular_1D"
113 alg1=gen.CreateHypothesis("Regular_1D")
114 print alg1.GetName()
115 print alg1.GetId()
116 algo1=alg1._narrow(SMESH.SMESH_Algo)
117 listHyp=algo1.GetCompatibleHypothesis()
118 for hyp in listHyp:
119     print hyp
120     
121 algo_1=alg1._narrow(SMESH.SMESH_Regular_1D)
122 print algo_1.GetId()
123
124 print "-------------------------- MEFISTO_2D"
125 alg2=gen.CreateHypothesis("MEFISTO_2D")
126 print alg2.GetName()
127 print alg2.GetId()
128 algo2=alg2._narrow(SMESH.SMESH_Algo)
129 listHyp=algo2.GetCompatibleHypothesis()
130 for hyp in listHyp:
131     print hyp
132 algo_2=alg2._narrow(SMESH.SMESH_MEFISTO_2D)
133 print algo_2.GetId()
134
135 # ---- add hypothesis to edge
136
137 print "-------------------------- add hypothesis to edge"
138 edge=salome.IDToObject(ide)
139 submesh=mesh.GetElementsOnShape(edge)
140 ret=mesh.AddHypothesis(edge,algo_1)
141 print ret
142 ret=mesh.AddHypothesis(edge,hypo1)
143 print ret
144
145 # ---- compute edge
146
147 ##print "-------------------------- compute edge"
148 ##ret=gen.Compute(mesh,ide)
149 ##print ret
150 ##log=mesh.GetLog(1);
151 ##for a in log:
152 ##    print a
153
154 # ---- add hypothesis to box
155
156 print "-------------------------- add hypothesis to box"
157 box=salome.IDToObject(idb)
158 submesh=mesh.GetElementsOnShape(box)
159 ret=mesh.AddHypothesis(box,algo_1)
160 print ret
161 ret=mesh.AddHypothesis(box,hypo1)
162 print ret
163 ret=mesh.AddHypothesis(box,algo_2)
164 print ret
165 ret=mesh.AddHypothesis(box,hypo4)
166 print ret
167
168 # ---- compute face
169
170 print "-------------------------- compute face"
171 ret=gen.Compute(mesh,idf)
172 print ret
173 log=mesh.GetLog(1);
174 for a in log:
175     print "-------"
176     ii = 0
177     ir = 0
178     comType = a.commandType
179     if comType == 0:
180         for i in range(a.number):
181             ind = a.indexes[ii]
182             ii = ii+1
183             r1 = a.coords[ir]
184             ir = ir+1
185             r2 = a.coords[ir]
186             ir = ir+1
187             r3 = a.coords[ir]
188             ir = ir+1
189             print "AddNode %i - %g %g %g" % (ind, r1, r2, r3)
190     elif comType == 1:
191         for i in range(a.number):
192             ind = a.indexes[ii]
193             ii = ii+1
194             i1 = a.indexes[ii]
195             ii = ii+1
196             i2 = a.indexes[ii]
197             ii = ii+1
198             print "AddEdge %i - %i %i" % (ind, i1, i2)
199     elif comType == 2:
200         for i in range(a.number):
201             ind = a.indexes[ii]
202             ii = ii+1
203             i1 = a.indexes[ii]
204             ii = ii+1
205             i2 = a.indexes[ii]
206             ii = ii+1
207             i3 = a.indexes[ii]
208             ii = ii+1
209             print "AddTriangle %i - %i %i %i" % (ind, i1, i2, i3)
210
211 # ---- compute box
212
213 ##print "-------------------------- compute box"
214 ##ret=gen.Compute(mesh,idb)
215 ##print ret
216 ##log=mesh.GetLog(1);
217 ##print log
218
219 ##shell=salome.IDToObject(ids)
220 ##submesh=mesh.GetElementsOnShape(shell)
221 ##ret=mesh.AddHypothesis(shell,algo_1)
222 ##print ret
223 ##ret=mesh.AddHypothesis(shell,hypo1)
224 ##print ret
225 ##ret=gen.Compute(mesh,ids)
226 ##print ret
227