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