Back to index

salome-med  6.5.0
testRenumbering.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #  -*- coding: iso-8859-1 -*-
00003 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00004 #
00005 # This library is free software; you can redistribute it and/or
00006 # modify it under the terms of the GNU Lesser General Public
00007 # License as published by the Free Software Foundation; either
00008 # version 2.1 of the License.
00009 #
00010 # This library is distributed in the hope that it will be useful,
00011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 # Lesser General Public License for more details.
00014 #
00015 # You should have received a copy of the GNU Lesser General Public
00016 # License along with this library; if not, write to the Free Software
00017 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 #
00019 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00020 #
00021 
00022 from libMEDMEM_Swig import *
00023 import os
00024 import sys
00025 
00026 ##                                         ***************
00027 ##                                         *** TEST 2D ***
00028 ##                                         ***************
00029 srcdir   = os.getenv("srcdir")
00030 med_root = os.getenv("MED_ROOT_DIR")
00031 if srcdir:
00032     # make check is being performed
00033     dir_renumber="./renumber"
00034     dir_mesh = os.path.join( srcdir, "../../resources")
00035 elif med_root:
00036     # hope renumber has been already installed
00037     dir_renumber=os.path.join( med_root, "bin/salome/renumber")
00038     dir_mesh = os.path.join( med_root, "share/salome/resources/med")
00039 else:
00040     # initial version
00041     dir_renumber="../../../MED_INSTALL/bin/salome/renumber"
00042     dir_mesh="../../resources"
00043 
00044 filename="Test2D.med"
00045 meshname="Mesh_1"
00046 
00047 print "TEST 2D Boost"
00048 method="BOOST"
00049 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00050 eval("os.system("+string_to_execute+")")
00051 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00052 
00053 field_ini=[2,3,12,13,14,15,4,5,6,7,8,9,16,17,0,1,10,11]
00054 s = m.getSupportOnAll(MED_CELL)
00055 f = FIELDDOUBLE(s,2)
00056 id=f.addDriver(MED_DRIVER,dir_mesh+"/out_"+filename,"Test field")
00057 f.read(id);
00058 field=True
00059 for i in range(9):
00060     field=field&(f.getValueIJ(i+1,1)==field_ini[i*2])
00061     field=field&(f.getValueIJ(i+1,2)==field_ini[i*2+1])
00062 f.rmDriver(id)
00063 
00064 nbcell2dboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00065 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]
00066 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
00067 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_QUAD4)
00068 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
00069 conn2dboost=(list(conn)==connectivite) # convert numpy.ndarray to list
00070 conn_index2dboost=(list(conn_index)==connectivite_index)
00071 Boost2D=conn2dboost and conn_index2dboost and (nbcell2dboost==9) and field
00072 os.remove(dir_mesh+"/out_"+filename)
00073 
00074 
00075 print "TEST 2D Metis"
00076 method="METIS"
00077 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00078 eval("os.system("+string_to_execute+")")
00079 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00080 nbcell2dmetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00081 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]
00082 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
00083 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_QUAD4)
00084 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
00085 conn2dmetis=(list(conn)==connectivite)
00086 conn_index2dmetis=(list(conn_index)==connectivite_index)
00087 Metis2D=conn2dmetis and conn_index2dmetis and (nbcell2dmetis==9)
00088 os.remove(dir_mesh+"/out_"+filename)
00089 
00090 ## *** Avec polygone ***
00091 
00092 filename="Test2Dpoly.med"
00093 meshname="Mesh_1"
00094 
00095 
00096 print "TEST 2D Boost with polygons"
00097 method="BOOST"
00098 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00099 eval("os.system("+string_to_execute+")")
00100 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00101 nbcell2dpolyboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00102 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]
00103 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
00104 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYGON)
00105 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL)
00106 conn2dpolyboost=(list(conn)==connectivite)
00107 conn_index2dpolyboost=(list(conn_index)==connectivite_index)
00108 PolyBoost2D=conn2dpolyboost and conn_index2dpolyboost and (nbcell2dpolyboost==9)
00109 os.remove(dir_mesh+"/out_"+filename)
00110 
00111 print "TEST 2D Metis with polygons"
00112 method="METIS"
00113 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00114 eval("os.system("+string_to_execute+")")
00115 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00116 nbcell2dpolymetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00117 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]
00118 connectivite_index=[1,5,9,13,17,21,25,29,33,37]
00119 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYGON)
00120 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL)
00121 conn2dpolymetis=(list(conn)==connectivite)
00122 conn_index2dpolymetis=(list(conn_index)==connectivite_index)
00123 PolyMetis2D=conn2dpolymetis and conn_index2dpolymetis and (nbcell2dpolymetis==9)
00124 os.remove(dir_mesh+"/out_"+filename)
00125 
00126 
00127 ##                                         ***************
00128 ##                                         *** TEST 3D ***
00129 ##                                         ***************
00130 
00131 
00132 filename="Test3D.med"
00133 meshname="Mesh_1"
00134 
00135 
00136 print "TEST 3D Boost"
00137 method="BOOST"
00138 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00139 eval("os.system("+string_to_execute+")")
00140 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00141 nbcell3dboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00142 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]
00143 connectivite_index=[1,9,17,25,33,41,49,57,65]
00144 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_HEXA8)
00145 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
00146 conn3dboost=(list(conn)==connectivite)
00147 conn_index3dboost=(list(conn_index)==connectivite_index)
00148 Boost3D=conn3dboost and conn_index3dboost and (nbcell3dboost==8)
00149 os.remove(dir_mesh+"/out_"+filename)
00150 
00151 
00152 print "TEST 3D Metis"
00153 method="METIS"
00154 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00155 eval("os.system("+string_to_execute+")")
00156 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00157 nbcell3dmetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00158 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]
00159 connectivite_index=[1,9,17,25,33,41,49,57,65]
00160 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_HEXA8)
00161 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
00162 conn3dmetis=(list(conn)==connectivite)
00163 conn_index3dmetis=(list(conn_index)==connectivite_index)
00164 Metis3D=conn3dmetis&conn_index3dmetis&(nbcell3dmetis==8)
00165 os.remove(dir_mesh+"/out_"+filename)
00166 
00167 
00168 ## *** Avec polyedres ***
00169 
00170 ## 23,13,5,18,27,26,14,22,23,27,22,13,13,22,14,5,5,14,26,18,18,26,27,23,
00171 ## 21,27,26,10,11,3,20,24,21,11,24,27,27,24,20,26,26,20,3,10,10,3,11,21,
00172 ## 12,25,27,21,4,11,24,19,12,4,19,25,25,19,24,27,27,24,11,21,21,11,4,12,
00173 ## 9,23,18,1,21,10,26,27,9,21,27,23,23,27,26,18,18,26,10,1,1,10,21,9,
00174 ## 2,17,23,9,12,21,27,25,2,12,25,17,17,25,27,23,23,27,21,9,9,21,12,2,
00175 ## 25,16,22,27,19,24,15,8,25,19,8,16,16,8,15,22,22,15,24,27,27,24,19,25,
00176 ## 17,6,13,23,25,27,22,16,17,25,16,6,6,16,22,13,13,22,27,23,23,27,25,17,
00177 ## 27,22,14,26,24,20,7,15,27,24,15,22,22,15,7,14,14,7,20,26,26,20,24,27,
00178 
00179 
00180 filename="Test3Dpoly.med"
00181 meshname="Mesh_1"
00182 
00183 
00184 print "TEST 3D Boost with polyhedra"
00185 method="BOOST"
00186 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00187 eval("os.system("+string_to_execute+")")
00188 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00189 nbcell3dpolyboost=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00190 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,
00191               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,
00192               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,
00193               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,
00194               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,
00195               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,
00196               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,
00197               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]
00198 connectivite_index=[1, 30, 59, 88, 117, 146, 175, 204, 233]
00199 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYHEDRA)
00200 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
00201 conn3dpolyboost=(connectivite==list(conn))
00202 conn_index3dpolyboost=(connectivite_index==list(conn_index))
00203 PolyBoost3D=(conn3dpolyboost and conn_index3dpolyboost and (nbcell3dpolyboost==8))
00204 os.remove(dir_mesh+"/out_"+filename)
00205 
00206 
00207 print "TEST 3D Metis with polyhedra"
00208 method="METIS"
00209 string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
00210 eval("os.system("+string_to_execute+")")
00211 m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
00212 nbcell3dpolymetis=m.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00213 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,
00214               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,
00215               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,
00216               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,
00217               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,
00218               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,
00219               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,
00220               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]
00221 connectivite_index=[1, 30, 59, 88, 117, 146, 175, 204, 233]
00222 conn=m.getConnectivity(MED_NODAL,MED_CELL,MED_POLYHEDRA)
00223 conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
00224 conn3dpolymetis=(list(conn)==connectivite)
00225 conn_index3dpolymetis=(list(conn_index)==connectivite_index)
00226 PolyMetis3D=(conn3dpolymetis and conn_index3dpolymetis and (nbcell3dpolymetis==8))
00227 os.remove(dir_mesh+"/out_"+filename)
00228 
00229 
00230 
00231 
00232 print ""
00233 if Boost2D:
00234     print "Boost 2D ok"
00235 else:
00236     print "ERROR Boost 2D"
00237 if Metis2D:
00238     print "Metis 2D ok"
00239 else:
00240     print "ERROR Metis 2D"
00241 if PolyBoost2D:
00242     print "Poly Boost 2D ok"
00243 else:
00244     print "ERROR Poly Boost 2D"
00245 if PolyMetis2D:
00246     print "Poly Metis 2D ok"
00247 else:
00248     print "ERROR Poly Metis 2D"
00249 if Boost3D:
00250     print "Boost 3D ok"
00251 else:
00252     print "ERROR Boost 3D"
00253 if Metis3D:
00254     print "Metis 3D ok"
00255 else:
00256     print "ERROR Metis 3D"
00257 if PolyBoost3D:
00258     print "Poly Boost 3D ok"
00259 else:
00260     print "ERROR Poly Boost 3D"
00261 if PolyMetis3D:
00262     print "Poly Metis 3D ok"
00263 else:
00264     print "ERROR Poly Metis 3D"
00265 
00266 
00267 print ""
00268 if Boost2D&Metis2D&PolyBoost2D&PolyMetis2D&Boost3D&Metis3D&PolyBoost3D&PolyMetis3D:
00269     print "Every mesh correctly renumbered"
00270     sys.exit()
00271 else:
00272     print "Error"
00273     sys.exit("Error in the renumbering test")
00274 
00275