Salome HOME
Merge from V6_main 01/04/2013
[modules/med.git] / src / RENUMBER / testRenumbering.py
1 #!/usr/bin/env python
2 #  -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 from libMEDMEM_Swig import *
23 import os
24 import sys
25
26 ##                                         ***************
27 ##                                         *** TEST 2D ***
28 ##                                         ***************
29 srcdir   = os.getenv("srcdir")
30 med_root = os.getenv("MED_ROOT_DIR")
31 if srcdir:
32     # make check is being performed
33     dir_renumber="./renumber"
34     dir_mesh = os.path.join( srcdir, "../../resources")
35 elif med_root:
36     # hope renumber has been already installed
37     dir_renumber=os.path.join( med_root, "bin/salome/renumber")
38     dir_mesh = os.path.join( med_root, "share/salome/resources/med")
39 else:
40     # initial version
41     dir_renumber="../../../MED_INSTALL/bin/salome/renumber"
42     dir_mesh="../../resources"
43
44 filename="Test2D.med"
45 meshname="Mesh_1"
46
47 print "TEST 2D Boost"
48 method="BOOST"
49 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
50 eval("os.system("+string_to_execute+")")
51 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
52
53 field_ini=[2,3,12,13,14,15,4,5,6,7,8,9,16,17,0,1,10,11]
54 s = m.getSupportOnAll(MED_CELL)
55 f = FIELDDOUBLE(s,2)
56 id=f.addDriver(MED_DRIVER,dir_mesh+"/out_"+filename,"Test field")
57 f.read(id);
58 field=True
59 for i in range(9):
60     field=field&(f.getValueIJ(i+1,1)==field_ini[i*2])
61     field=field&(f.getValueIJ(i+1,2)==field_ini[i*2+1])
62 f.rmDriver(id)
63
64 nbcell2dboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
65 connectivite=[2,6,13,11,11,13,14,12,6,5,15,13,12,14,10,4,13,15,16,14,5,1,7,15,14,16,9,10,15,7,8,16,16,8,3,9]
66 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
67 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_QUAD4)
68 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
69 conn2dboost=(list(conn)==connectivite) # convert numpy.ndarray to list
70 conn_index2dboost=(list(conn_index)==connectivite_index)
71 Boost2D=conn2dboost and conn_index2dboost and (nbcell2dboost==9) and field
72 os.remove(dir_mesh+"/out_"+filename)
73
74
75 print "TEST 2D Metis"
76 method="METIS"
77 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
78 eval("os.system("+string_to_execute+")")
79 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
80 nbcell2dmetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
81 connectivite=[12,14,10,4,2,6,13,11,11,13,14,12,16,8,3,9,5,1,7,15,15,7,8,16,14,16,9,10,6,5,15,13,13,15,16,14]
82 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
83 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_QUAD4)
84 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
85 conn2dmetis=(list(conn)==connectivite)
86 conn_index2dmetis=(list(conn_index)==connectivite_index)
87 Metis2D=conn2dmetis and conn_index2dmetis and (nbcell2dmetis==9)
88 os.remove(dir_mesh+"/out_"+filename)
89
90 ## *** Avec polygone ***
91
92 filename="Test2Dpoly.med"
93 meshname="Mesh_1"
94
95
96 print "TEST 2D Boost with polygons"
97 method="BOOST"
98 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
99 eval("os.system("+string_to_execute+")")
100 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
101 nbcell2dpolyboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
102 connectivite=[2,5,9,10,11,10,9,12,5,6,8,9,4,11,12,16,12,9,8,13,6,1,7,8,16,12,13,15,13,8,7,14,15,13,14,3]
103 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
104 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYGON)
105 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL)
106 conn2dpolyboost=(list(conn)==connectivite)
107 conn_index2dpolyboost=(list(conn_index)==connectivite_index)
108 PolyBoost2D=conn2dpolyboost and conn_index2dpolyboost and (nbcell2dpolyboost==9)
109 os.remove(dir_mesh+"/out_"+filename)
110
111 print "TEST 2D Metis with polygons"
112 method="METIS"
113 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
114 eval("os.system("+string_to_execute+")")
115 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
116 nbcell2dpolymetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
117 connectivite=[6,1,7,8,2,5,9,10,5,6,8,9,15,13,14,3,4,11,12,16,16,12,13,15,11,10,9,12,12,9,8,13,13,8,7,14]
118 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
119 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYGON)
120 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL)
121 conn2dpolymetis=(list(conn)==connectivite)
122 conn_index2dpolymetis=(list(conn_index)==connectivite_index)
123 PolyMetis2D=conn2dpolymetis and conn_index2dpolymetis and (nbcell2dpolymetis==9)
124 os.remove(dir_mesh+"/out_"+filename)
125
126
127 ##                                         ***************
128 ##                                         *** TEST 3D ***
129 ##                                         ***************
130
131
132 filename="Test3D.med"
133 meshname="Mesh_1"
134
135
136 print "TEST 3D Boost"
137 method="BOOST"
138 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
139 eval("os.system("+string_to_execute+")")
140 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
141 nbcell3dboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
142 connectivite=[23,13,5,18,27,22,14,26,17,6,13,23,25,16,22,27,27,22,14,26,24,15,7,20,9,23,18,1,21,27,26,10,25,16,22,27,19,8,15,24,2,17,23,9,12,25,27,21,21,27,26,10,11,24,20,3,12,25,27,21,4,19,24,11]
143 connectivite_index=[1,9,17,25,33,41,49,57,65]
144 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_HEXA8)
145 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
146 conn3dboost=(list(conn)==connectivite)
147 conn_index3dboost=(list(conn_index)==connectivite_index)
148 Boost3D=conn3dboost and conn_index3dboost and (nbcell3dboost==8)
149 os.remove(dir_mesh+"/out_"+filename)
150
151
152 print "TEST 3D Metis"
153 method="METIS"
154 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
155 eval("os.system("+string_to_execute+")")
156 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
157 nbcell3dmetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
158 connectivite=[12,25,27,21,4,19,24,11,27,22,14,26,24,15,7,20,17,6,13,23,25,16,22,27,9,23,18,1,21,27,26,10,23,13,5,18,27,22,14,26,25,16,22,27,19,8,15,24,2,17,23,9,12,25,27,21,21,27,26,10,11,24,20,3]
159 connectivite_index=[1,9,17,25,33,41,49,57,65]
160 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_HEXA8)
161 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
162 conn3dmetis=(list(conn)==connectivite)
163 conn_index3dmetis=(list(conn_index)==connectivite_index)
164 Metis3D=conn3dmetis&conn_index3dmetis&(nbcell3dmetis==8)
165 os.remove(dir_mesh+"/out_"+filename)
166
167
168 ## *** Avec polyedres ***
169
170 ## 23,13,5,18,27,26,14,22,23,27,22,13,13,22,14,5,5,14,26,18,18,26,27,23,
171 ## 21,27,26,10,11,3,20,24,21,11,24,27,27,24,20,26,26,20,3,10,10,3,11,21,
172 ## 12,25,27,21,4,11,24,19,12,4,19,25,25,19,24,27,27,24,11,21,21,11,4,12,
173 ## 9,23,18,1,21,10,26,27,9,21,27,23,23,27,26,18,18,26,10,1,1,10,21,9,
174 ## 2,17,23,9,12,21,27,25,2,12,25,17,17,25,27,23,23,27,21,9,9,21,12,2,
175 ## 25,16,22,27,19,24,15,8,25,19,8,16,16,8,15,22,22,15,24,27,27,24,19,25,
176 ## 17,6,13,23,25,27,22,16,17,25,16,6,6,16,22,13,13,22,27,23,23,27,25,17,
177 ## 27,22,14,26,24,20,7,15,27,24,15,22,22,15,7,14,14,7,20,26,26,20,24,27,
178
179
180 filename="Test3Dpoly.med"
181 meshname="Mesh_1"
182
183
184 print "TEST 3D Boost with polyhedra"
185 method="BOOST"
186 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
187 eval("os.system("+string_to_execute+")")
188 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
189 nbcell3dpolyboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
190 connectivite=[23,13,5,18,-1,27,26,14,22,-1,23,27,22,13,-1,13,22,14,5,-1,5,14,26,18,-1,18,26,27,23,
191               17,6,13,23,-1,25,27,22,16,-1,17,25,16,6,-1,6,16,22,13,-1,13,22,27,23,-1,23,27,25,17,
192               27,22,14,26,-1,24,20,7,15,-1,27,24,15,22,-1,22,15,7,14,-1,14,7,20,26,-1,26,20,24,27,
193               9,23,18,1,-1,21,10,26,27,-1,9,21,27,23,-1,23,27,26,18,-1,18,26,10,1,-1,1,10,21,9,
194               25,16,22,27,-1,19,24,15,8,-1,25,19,8,16,-1,16,8,15,22,-1,22,15,24,27,-1,27,24,19,25,
195               2,17,23,9,-1,12,21,27,25,-1,2,12,25,17,-1,17,25,27,23,-1,23,27,21,9,-1,9,21,12,2,
196               21,27,26,10,-1,11,3,20,24,-1,21,11,24,27,-1,27,24,20,26,-1,26,20,3,10,-1,10,3,11,21,
197               12,25,27,21,-1,4,11,24,19,-1,12,4,19,25,-1,25,19,24,27,-1,27,24,11,21,-1,21,11,4,12]
198 connectivite_index=[1, 30, 59, 88, 117, 146, 175, 204, 233]
199 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYHEDRA)
200 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
201 conn3dpolyboost=(connectivite==list(conn))
202 conn_index3dpolyboost=(connectivite_index==list(conn_index))
203 PolyBoost3D=(conn3dpolyboost and conn_index3dpolyboost and (nbcell3dpolyboost==8))
204 os.remove(dir_mesh+"/out_"+filename)
205
206
207 print "TEST 3D Metis with polyhedra"
208 method="METIS"
209 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
210 eval("os.system("+string_to_execute+")")
211 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
212 nbcell3dpolymetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
213 connectivite=[12,25,27,21,-1,4,11,24,19,-1,12,4,19,25,-1,25,19,24,27,-1,27,24,11,21,-1,21,11,4,12,
214               27,22,14,26,-1,24,20,7,15,-1,27,24,15,22,-1,22,15,7,14,-1,14,7,20,26,-1,26,20,24,27,
215               17,6,13,23,-1,25,27,22,16,-1,17,25,16,6,-1,6,16,22,13,-1,13,22,27,23,-1,23,27,25,17,
216               9,23,18,1,-1,21,10,26,27,-1,9,21,27,23,-1,23,27,26,18,-1,18,26,10,1,-1,1,10,21,9,
217               23,13,5,18,-1,27,26,14,22,-1,23,27,22,13,-1,13,22,14,5,-1,5,14,26,18,-1,18,26,27,23,
218               25,16,22,27,-1,19,24,15,8,-1,25,19,8,16,-1,16,8,15,22,-1,22,15,24,27,-1,27,24,19,25,
219               2,17,23,9,-1,12,21,27,25,-1,2,12,25,17,-1,17,25,27,23,-1,23,27,21,9,-1,9,21,12,2,
220               21,27,26,10,-1,11,3,20,24,-1,21,11,24,27,-1,27,24,20,26,-1,26,20,3,10,-1,10,3,11,21]
221 connectivite_index=[1, 30, 59, 88, 117, 146, 175, 204, 233]
222 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYHEDRA)
223 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
224 conn3dpolymetis=(list(conn)==connectivite)
225 conn_index3dpolymetis=(list(conn_index)==connectivite_index)
226 PolyMetis3D=(conn3dpolymetis and conn_index3dpolymetis and (nbcell3dpolymetis==8))
227 os.remove(dir_mesh+"/out_"+filename)
228
229
230
231
232 print ""
233 if Boost2D:
234     print "Boost 2D ok"
235 else:
236     print "ERROR Boost 2D"
237 if Metis2D:
238     print "Metis 2D ok"
239 else:
240     print "ERROR Metis 2D"
241 if PolyBoost2D:
242     print "Poly Boost 2D ok"
243 else:
244     print "ERROR Poly Boost 2D"
245 if PolyMetis2D:
246     print "Poly Metis 2D ok"
247 else:
248     print "ERROR Poly Metis 2D"
249 if Boost3D:
250     print "Boost 3D ok"
251 else:
252     print "ERROR Boost 3D"
253 if Metis3D:
254     print "Metis 3D ok"
255 else:
256     print "ERROR Metis 3D"
257 if PolyBoost3D:
258     print "Poly Boost 3D ok"
259 else:
260     print "ERROR Poly Boost 3D"
261 if PolyMetis3D:
262     print "Poly Metis 3D ok"
263 else:
264     print "ERROR Poly Metis 3D"
265
266
267 print ""
268 if Boost2D&Metis2D&PolyBoost2D&PolyMetis2D&Boost3D&Metis3D&PolyBoost3D&PolyMetis3D:
269     print "Every mesh correctly renumbered"
270     sys.exit()
271 else:
272     print "Error"
273     sys.exit("Error in the renumbering test")
274
275