]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
creation of a renumbering tool that :
authorvbd <vbd>
Tue, 15 Sep 2009 09:59:17 +0000 (09:59 +0000)
committervbd <vbd>
Tue, 15 Sep 2009 09:59:17 +0000 (09:59 +0000)
- takes as input a MED file (with only one cell type)
- as output creates another file with the same topology, but with renumbered cells so that the mesh is more suitable for numerical computation.

The renumbering can be computed with reverse cuthill mckee algorithm (boost) or with nested dissection (metis)

src/RENUMBER/Makefile.am [new file with mode: 0644]
src/RENUMBER/RENUMBER_BOOSTRenumbering.cxx [new file with mode: 0644]
src/RENUMBER/RENUMBER_BOOSTRenumbering.hxx [new file with mode: 0644]
src/RENUMBER/RENUMBER_METISRenumbering.cxx [new file with mode: 0644]
src/RENUMBER/RENUMBER_METISRenumbering.hxx [new file with mode: 0644]
src/RENUMBER/RENUMBER_Renumbering.cxx [new file with mode: 0644]
src/RENUMBER/RENUMBER_Renumbering.hxx [new file with mode: 0644]
src/RENUMBER/RenumberingFactory.cxx [new file with mode: 0644]
src/RENUMBER/RenumberingFactory.hxx [new file with mode: 0644]
src/RENUMBER/renumbering.cxx [new file with mode: 0644]
src/RENUMBER/testRenumbering.py [new file with mode: 0755]

diff --git a/src/RENUMBER/Makefile.am b/src/RENUMBER/Makefile.am
new file mode 100644 (file)
index 0000000..80d1f77
--- /dev/null
@@ -0,0 +1,92 @@
+#  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+#  MED MEDMEM : MED files in memory
+#
+include $(top_srcdir)/adm_local/unix/make_common_starter.am
+
+# this directory must be recompiled before Test folder
+
+if CPPUNIT_IS_OK
+# SUBDIRS=. Test
+endif
+
+lib_LTLIBRARIES= librenumber.la
+
+salomeinclude_HEADERS= \
+RENUMBER_Renumbering.hxx \
+RenumberingFactory.hxx
+
+if MED_ENABLE_METIS
+    salomeinclude_HEADERS+= RENUMBER_METISRenumbering.hxx
+endif
+if BOOST_IS_OK
+    salomeinclude_HEADERS+= RENUMBER_BOOSTRenumbering.hxx
+endif
+
+dist_librenumber_la_SOURCES= \
+RENUMBER_Renumbering.cxx \
+RenumberingFactory.cxx
+
+if MED_ENABLE_METIS
+    dist_librenumber_la_SOURCES+= RENUMBER_METISRenumbering.cxx
+endif
+if BOOST_IS_OK
+    dist_librenumber_la_SOURCES+= RENUMBER_BOOSTRenumbering.cxx 
+endif
+
+librenumber_la_CPPFLAGS= $(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
+       $(BOOST_CPPFLAGS) \
+       -I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core
+
+librenumber_la_LDFLAGS= 
+#libmedsplitter_la_LDFLAGS= $(MED2_LIBS) $(HDF5_LIBS) $(STDLIB) \
+#      ../MEDMEM/libmedmem.la ../MEDWrapper/V2_1/Core/libmed_V2_1.la
+
+if MED_ENABLE_METIS
+  librenumber_la_CPPFLAGS+= $(METIS_CPPFLAGS)
+  librenumber_la_LDFLAGS+= $(METIS_LIBS)
+endif 
+if BOOST_IS_OK
+  librenumber_la_CPPFLAGS+= $(BOOST_CPPFLAGS) -DENABLE_BOOST
+  librenumber_la_LDFLAGS+= $(BOOST_LIBS)
+endif
+if MED_ENABLE_KERNEL
+  librenumber_la_CPPFLAGS+= ${KERNEL_CXXFLAGS}
+  librenumber_la_LDFLAGS+= ${KERNEL_LDFLAGS} -lSALOMELocalTrace 
+endif
+
+librenumber_la_LDFLAGS+= $(MED2_LIBS) $(HDF5_LIBS) $(STDLIB) \
+       ../MEDMEM/libmedmem.la ../MEDWrapper/V2_1/Core/libmed_V2_1.la  ../INTERP_KERNEL/libinterpkernel.la
+
+# Executables targets
+bin_PROGRAMS= renumber
+
+dist_renumber_SOURCES= renumbering.cxx
+
+renumber_CPPFLAGS= $(librenumber_la_CPPFLAGS)
+renumber_LDADD= $(librenumber_la_LDFLAGS) -lm $(BOOST_LIBS) librenumber.la
+if MED_ENABLE_KERNEL
+  renumber_LDADD+= -lSALOMEBasics
+endif
+
+OBSOLETE_FILES = 
+#      MEDSPLITTER_SequentialTopology.cxx \
+#      test_HighLevelAPI.cxx
+
+EXTRA_DIST += $(OBSOLETE_FILES)
diff --git a/src/RENUMBER/RENUMBER_BOOSTRenumbering.cxx b/src/RENUMBER/RENUMBER_BOOSTRenumbering.cxx
new file mode 100644 (file)
index 0000000..f54a7a1
--- /dev/null
@@ -0,0 +1,35 @@
+
+#include <boost/config.hpp>
+#include <boost/graph/adjacency_list.hpp>
+#include <boost/graph/cuthill_mckee_ordering.hpp>
+#include <boost/graph/properties.hpp>
+#include <boost/graph/bandwidth.hpp>
+
+#include "RENUMBER_BOOSTRenumbering.hxx"
+
+void BOOSTRenumbering::renumber(const int* graph,const int* index_graph,int nb_cell,std::vector<int>& iperm,std::vector<int>& perm)
+{
+  iperm.resize(nb_cell,0);
+  perm.resize(nb_cell,0);
+
+  typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, 
+     boost::property<boost::vertex_color_t, boost::default_color_type,
+       boost::property<boost::vertex_degree_t,int> > > Graph;
+  typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
+  typedef boost::graph_traits<Graph>::vertices_size_type size_type;
+  Graph G(nb_cell);
+  for (int i=0;i<nb_cell;++i)
+    for (int j=index_graph[i]-1;j<index_graph[i+1]-1;++j)
+      add_edge(i,graph[j]-1,G);
+  boost::property_map<Graph, boost::vertex_index_t>::type
+    index_map = boost::get(boost::vertex_index, G);
+  boost::cuthill_mckee_ordering(G, iperm.rbegin(), boost::get(boost::vertex_color, G),
+                           boost::make_degree_map(G));
+  for (size_type c = 0; c != iperm.size(); ++c)
+    perm[index_map[iperm[c]]] = c;
+  for(int i=0;i<nb_cell;++i)
+    {
+      perm[i]+=1;
+      iperm[i]+=1;
+    }
+}
diff --git a/src/RENUMBER/RENUMBER_BOOSTRenumbering.hxx b/src/RENUMBER/RENUMBER_BOOSTRenumbering.hxx
new file mode 100644 (file)
index 0000000..b73f028
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef BOOSTRENUMBERING_HXX_
+#define BOOSTRENUMBERING_HXX_
+
+#include "RENUMBER_Renumbering.hxx"
+
+class BOOSTRenumbering:public Renumbering
+{
+public:
+  virtual void renumber(const int* graph,const int* index_graph,int nb_cell,std::vector<int>& iperm,std::vector<int>& perm);
+};
+
+#endif /*BOOSTRENUMBERING_HXX_*/
diff --git a/src/RENUMBER/RENUMBER_METISRenumbering.cxx b/src/RENUMBER/RENUMBER_METISRenumbering.cxx
new file mode 100644 (file)
index 0000000..5c8daab
--- /dev/null
@@ -0,0 +1,15 @@
+extern "C"
+{
+#include "metis.h"
+}
+
+#include "RENUMBER_METISRenumbering.hxx"
+
+void METISRenumbering::renumber(const int* graph,const int* index_graph,int nb_cell,std::vector<int>& iperm,std::vector<int>& perm)
+{
+  iperm.resize(nb_cell,0);
+  perm.resize(nb_cell,0);
+  int num_flag=1;
+  int options=0;
+  METIS_NodeND(&nb_cell,(int*)index_graph,(int*)graph,&num_flag,&options,&iperm[0],&perm[0]);
+}
diff --git a/src/RENUMBER/RENUMBER_METISRenumbering.hxx b/src/RENUMBER/RENUMBER_METISRenumbering.hxx
new file mode 100644 (file)
index 0000000..560a5c5
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef METISRENUMBERING_HXX_
+#define METISRENUMBERING_HXX_
+
+#include "RENUMBER_Renumbering.hxx"
+
+class METISRenumbering:public Renumbering
+{
+public:
+  virtual void renumber(const int* graph,const int* index_graph,int nb_cell,std::vector<int>& iperm,std::vector<int>& perm);
+};
+
+#endif /*METISRENUMBERING_HXX_*/
diff --git a/src/RENUMBER/RENUMBER_Renumbering.cxx b/src/RENUMBER/RENUMBER_Renumbering.cxx
new file mode 100644 (file)
index 0000000..8d1c8b6
--- /dev/null
@@ -0,0 +1 @@
diff --git a/src/RENUMBER/RENUMBER_Renumbering.hxx b/src/RENUMBER/RENUMBER_Renumbering.hxx
new file mode 100644 (file)
index 0000000..c623d34
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef RENUMBERING_HXX_
+#define RENUMBERING_HXX_
+#include <vector>
+
+class Renumbering
+{
+public:
+  virtual void renumber(const int* graphe,const int* index_graphe,int nb_cell,std::vector<int>& iperm,std::vector<int>& perm)=0;
+}; 
+
+#endif /*RENUMBERING_HXX_*/
diff --git a/src/RENUMBER/RenumberingFactory.cxx b/src/RENUMBER/RenumberingFactory.cxx
new file mode 100644 (file)
index 0000000..4dc9f95
--- /dev/null
@@ -0,0 +1,64 @@
+#include "RenumberingFactory.hxx"
+#include "RENUMBER_Renumbering.hxx"
+#ifdef ENABLE_METIS
+#include "RENUMBER_METISRenumbering.hxx"
+#endif
+#ifdef ENABLE_BOOST
+#include "RENUMBER_BOOSTRenumbering.hxx"
+#endif
+
+#include <iostream>
+
+using namespace std;
+
+namespace MED_RENUMBER
+{
+  Renumbering* RenumberingFactory(const string &s)
+  {
+#ifdef ENABLE_METIS
+#ifdef ENABLE_BOOST
+    if (s=="METIS")
+      {
+        return new METISRenumbering;
+      }
+    else if(s=="BOOST")
+      {
+        return new BOOSTRenumbering;
+      }
+    else 
+      {
+        std::cerr << "The method has to be METIS or BOOST" << std::endl;
+        return 0;
+      }
+#endif
+#ifndef ENABLE_BOOST
+    if (s=="METIS")
+      {
+        return new METISRenumbering;
+      }
+    else
+      {
+        std::cerr << "The method has to be METIS!" << std::endl;
+        return 0;
+      }
+#endif
+#endif
+#ifndef ENABLE_METIS
+#ifdef ENABLE_BOOST
+    if (s=="BOOST")
+      {
+        return new BOOSTRenumbering;
+      }
+    else
+      {
+        std::cerr << "The method has to be BOOST!" << std::endl;
+        return 0;
+      }
+#endif
+#ifndef ENABLE_BOOST
+    std::cerr << "Error, no method compiled" << std::endl;
+    return 0;
+#endif
+#endif
+  }
+}
diff --git a/src/RENUMBER/RenumberingFactory.hxx b/src/RENUMBER/RenumberingFactory.hxx
new file mode 100644 (file)
index 0000000..fe0f13f
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef RENUMBERINGFACTORY_HXX_
+#define RENUMBERINGFACTORY_HXX_
+
+#include <string>
+#include "RENUMBER_Renumbering.hxx"
+
+namespace MED_RENUMBER
+{
+  Renumbering* RenumberingFactory(const std::string& s);
+}
+
+#endif /*RENUMBERINGFACTORY_HXX_*/
diff --git a/src/RENUMBER/renumbering.cxx b/src/RENUMBER/renumbering.cxx
new file mode 100644 (file)
index 0000000..44eac9a
--- /dev/null
@@ -0,0 +1,347 @@
+#include <string>
+#include <stdlib.h>
+#include <iostream>
+#include <fstream>
+
+#include "MEDMEM_Family.hxx"
+#include "MEDMEM_Mesh.hxx"
+#include "MEDMEM_Meshing.hxx"
+#include "MEDMEM_MedMeshDriver.hxx"
+#include "MEDMEM_Connectivity.hxx"
+#include "MEDMEM_Field.hxx"
+#include "MEDMEM_DriversDef.hxx"
+#include "MEDMEM_Med.hxx"
+#include "MEDMEM_MedMeshDriver22.hxx"
+
+#include "RenumberingFactory.hxx"
+
+#include <time.h>
+using namespace MEDMEM;
+using namespace std;
+using namespace MED_EN;
+using namespace MED_RENUMBER;
+
+void computeNeighbour(const MESH* mesh,const medGeometryElement& Type, vector<list<int> >& neighbour, int& ntot,int& nb_cell)
+{
+  CONNECTIVITY* conn = (CONNECTIVITY*)mesh->getConnectivityptr();
+  conn->calculateFullDescendingConnectivity(MED_CELL);
+  const int* rev_conn=mesh->getReverseConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL);
+  const int* rev_conn_index=mesh->getReverseConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL);
+  int nb_face= mesh->getNumberOfElementsWithPoly(MED_FACE,MED_ALL_ELEMENTS);
+  int nb_edge = mesh->getNumberOfElementsWithPoly(MED_EDGE,MED_ALL_ELEMENTS);
+  nb_cell= mesh->getNumberOfElementsWithPoly(MED_CELL,Type);
+
+  int nb_constituent;
+  if(mesh->getMeshDimension()==2)
+    nb_constituent = nb_edge;
+  else if (mesh->getMeshDimension()==3)
+    nb_constituent = nb_face;
+  else
+    throw MEDEXCEPTION("Wrong dimension");
+
+  neighbour.resize(nb_cell,(list<int>)0);
+  ntot=0;
+  for(int i=0;i<nb_constituent;++i)
+    {
+      for(int j=rev_conn_index[i]-1;j<rev_conn_index[i+1]-1;++j)
+        {
+          for(int k=j+1;k<rev_conn_index[i+1]-1;++k)
+            {
+              if(rev_conn[j]!=0 && rev_conn[k]!=0)
+                {
+                  ntot+=2;
+                  neighbour[rev_conn[j]-1].push_back(rev_conn[k]);
+                  neighbour[rev_conn[k]-1].push_back(rev_conn[j]);
+                }
+            }
+        }
+    }
+}
+
+void changeConnectivity(MESH& mesh, const medGeometryElement& Type, const int& nb_cell, const vector<int>& iperm)
+{
+  if(Type==MED_POLYHEDRA)
+    {
+      int *conn_face_index_init=(int*)mesh.getPolyhedronFacesIndex();
+      int *conn_index_init=(int*)mesh.getPolyhedronIndex(MED_FULL_INTERLACE);
+      int *conn_init=(int*)mesh.getPolyhedronConnectivity(MED_FULL_INTERLACE);
+
+      int *conn_index_renum=new int[nb_cell+1];
+      int *conn_face_index_renum=new int[conn_index_init[nb_cell]];
+      int *conn_renum=new int[conn_face_index_init[conn_index_init[nb_cell]-1]-1];
+
+      int i_cell,i_face,i_conn;
+      int iter_face=0;
+      int iter_conn=0;
+      int i2;
+      conn_index_renum[0]=1;
+      conn_face_index_renum[0]=1;
+      for(i_cell=0;i_cell<nb_cell;++i_cell)
+        {
+          i2=iperm[i_cell]-1;
+          for(i_face=conn_index_init[i2]-1;i_face<conn_index_init[i2+1]-1;++i_face)
+            {
+              for(i_conn=conn_face_index_init[i_face]-1;i_conn<conn_face_index_init[i_face+1]-1;++i_conn)
+                {
+                  conn_renum[iter_conn]=conn_init[i_conn];
+                  ++iter_conn;
+                }
+              conn_face_index_renum[iter_face+1]=iter_conn+1;
+              ++iter_face;
+            }
+          conn_index_renum[i_cell+1]=iter_face+1;
+        }
+      memcpy(conn_face_index_init,conn_face_index_renum,sizeof(int)*conn_index_init[nb_cell]);
+      memcpy(conn_index_init,conn_index_renum,sizeof(int)*(nb_cell+1));
+      memcpy(conn_init,conn_renum, sizeof(int)*(conn_face_index_init[conn_index_init[nb_cell]-1]-1));
+
+      delete[] conn_index_renum;
+      delete[] conn_face_index_renum;
+      delete[] conn_renum;
+    }
+  else if (Type==MED_POLYGON)
+    {
+      int *conn_init=(int*)mesh.getPolygonsConnectivity(MED_FULL_INTERLACE,MED_CELL);
+      int *conn_index_init=(int*)mesh.getPolygonsConnectivityIndex(MED_FULL_INTERLACE,MED_CELL);
+      int *conn_index_renum=new int[nb_cell+1];
+      int *conn_renum=new int[conn_index_init[nb_cell]-1];
+
+      int iter=0;
+      int i2;
+      conn_index_renum[0]=1;
+      for(int i=0;i<nb_cell;++i)
+        {
+          i2=iperm[i]-1;
+          for(int k=conn_index_init[i2];k<conn_index_init[i2+1];++k)
+            {
+              conn_renum[iter]=conn_init[k-1];
+              ++iter;
+            }
+          conn_index_renum[i+1]=iter+1;
+        }
+      memcpy(conn_index_init,conn_index_renum,sizeof(int)*(nb_cell+1));
+      memcpy(conn_init,conn_renum, sizeof(int)*(conn_index_init[nb_cell]-1));
+
+      delete[] conn_renum;
+      delete[] conn_index_renum;
+    }
+  else
+    {
+      const int *conn_init=mesh.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,Type);
+      const int *conn_index_init=mesh.getConnectivityIndex(MED_NODAL,MED_CELL);
+      int *conn_renum=new int[conn_index_init[nb_cell]-1];
+      int *conn_index_renum=new int[nb_cell+1];
+
+      int iter=0;
+      int i2;
+      conn_index_renum[0]=1;
+      for(int i=0;i<nb_cell;++i)
+        {
+          i2=iperm[i]-1;
+          for(int k=conn_index_init[i2];k<conn_index_init[i2+1];++k)
+            {
+              conn_renum[iter]=conn_init[k-1];
+              ++iter;
+            }
+          conn_index_renum[i+1]=iter+1;
+        }
+
+      CONNECTIVITY* myConnectivity=(CONNECTIVITY*)mesh.getConnectivityptr();
+      myConnectivity->setNodal(conn_renum,MED_CELL,Type);
+      delete[] conn_renum;
+      delete[] conn_index_renum;
+    }
+}
+
+void changeFamily(MESH* mesh, const medGeometryElement& Type, const vector<int>& perm)
+{
+  int nb_families=mesh->getNumberOfFamilies(MED_CELL);
+  for (int i=0;i<nb_families;++i)
+    {
+      const FAMILY* family=mesh->getFamily(MED_CELL,i+1);
+      if (!family->isOnAllElements())
+        {
+          int nb_elem=family->getNumberOfElements(Type);
+          int *number=(int *)family->getNumber(Type);
+          for(int j=0;j<nb_elem;++j)
+            number[j]=perm[number[j]-1];
+        }
+    }
+}
+
+int main (int argc, char** argv)
+{
+  double t_begin,t_read_st,t_read_mesh,t_compute_graph,t_connectiv,t_family,t_field;
+  t_begin=clock();
+  if (argc <5)
+    {
+      cerr << "Usage : " << argv[0] 
+           << " filename_in meshname method[BOOST/METIS] filename_out" << endl << endl;
+      return -1;
+    }
+  string filename_in = argv[1];
+  string meshname = argv[2];
+  string type_renum = argv[3];
+  string filename_out = argv[4];
+
+  if(type_renum!="METIS" && type_renum!="BOOST")
+    {
+      cout << "The method has to be METIS or BOOST!" << endl;
+      exit(-1);
+    }
+
+  string s="rm "+filename_out;
+  system(s.c_str());
+
+  // Reading file structure
+  const MED med_struct (MED_DRIVER,filename_in);
+  int nb_mesh, nb_fields;
+  deque<string> mesh_names,f_names;
+  nb_mesh=med_struct.getNumberOfMeshes();
+  nb_fields=med_struct.getNumberOfFields();
+  mesh_names=med_struct.getMeshNames();
+  f_names=med_struct.getFieldNames();
+  if(nb_mesh!=1)
+    {
+      cout << "There are many meshes in the file" << endl;
+      return -1;
+    }
+  if(mesh_names[0].c_str()!=meshname)
+    {
+      cout << "Mesh name does not match" << endl;
+      return -1;
+    }
+  vector<string> field_names;
+  vector<int> iternumber;
+  vector<int> ordernumber;
+  vector<int> types;
+  for (int ifield = 0; ifield < nb_fields; ifield++)
+    {
+      deque<DT_IT_> dtit=med_struct.getFieldIteration(f_names[ifield]);
+      for (deque<DT_IT_>::const_iterator iter =dtit.begin(); iter!=dtit.end(); iter++)
+        {
+          field_names.push_back(f_names[ifield]);
+          iternumber.push_back(iter->dt);
+          ordernumber.push_back(iter->it);
+
+          FIELD_* field = med_struct.getField(f_names[ifield],iter->dt,iter->it);
+          if (dynamic_cast<FIELD<double>*>(field))
+            types.push_back(1);
+          else
+            types.push_back(0);
+
+        }
+    }
+  t_read_st=clock();
+
+  // Reading mesh
+  MESH myMesh;
+  myMesh.setName(meshname);
+  MED_MESH_RDONLY_DRIVER22 *drv22=new MED_MESH_RDONLY_DRIVER22(filename_in,&myMesh);
+  drv22->desactivateFacesComputation();
+  int newDrv=myMesh.addDriver(*drv22);
+  delete drv22;
+  myMesh.read(newDrv);
+  int nb_type=myMesh.getNumberOfTypesWithPoly(MED_CELL);
+  if (nb_type!=1)
+    {
+      cout << "Mesh must have only one type of cell" << endl;
+      return -1;
+    }
+  medGeometryElement *Types = myMesh.getTypesWithPoly(MED_CELL);
+  medGeometryElement Type=Types[0];
+  delete[] Types;
+
+  t_read_mesh=clock();
+  MESH* workMesh=new MESH(myMesh);
+  cout << "Building the graph    ";
+  cout.flush();
+  int ntot,nb_cell;
+  vector<list<int> > neighbour;
+  computeNeighbour(workMesh,Type,neighbour,ntot,nb_cell);
+  int* graph=new int[ntot];
+  int* graph_index=new int[nb_cell+1];
+  graph_index[0]=1;
+  int count=0;
+  for(int i=0;i<nb_cell;++i)
+    {
+      for (list<int>::const_iterator it=neighbour[i].begin();it!=neighbour[i].end();++it)
+        {
+          graph[count]=*it;
+          ++count;
+        }
+      graph_index[i+1]=count+1;
+    }
+
+
+  // Compute permutation
+  vector<int> iperm,perm;
+  Renumbering* renumb= RenumberingFactory(type_renum);
+  renumb->renumber(graph,graph_index,nb_cell,iperm,perm);
+  delete renumb;
+  delete workMesh;
+  t_compute_graph=clock();
+  cout << " : " << (t_compute_graph-t_read_mesh)/(double) CLOCKS_PER_SEC << "s" << endl;
+  cout.flush();
+
+  // Connectivity
+  cout << "Computing connectivity";
+  cout.flush();
+  MESH meshRenum(myMesh);
+  changeConnectivity(meshRenum,Type,nb_cell,iperm);
+  t_connectiv=clock();
+  cout << " : " << (t_connectiv-t_compute_graph)/(double) CLOCKS_PER_SEC << "s" << endl;
+  cout.flush();
+
+  // Familles
+  cout << "Computing families    ";
+  cout.flush();
+  changeFamily(&meshRenum,Type,perm);
+  int drv3=meshRenum.addDriver(MED_DRIVER,filename_out,meshRenum.getName());
+  meshRenum.write(drv3);
+  t_family=clock();
+  cout << " : " << (t_family-t_connectiv)/(double) CLOCKS_PER_SEC << "s" << endl;
+  cout.flush();
+
+  // Fields
+  cout << "Computing fields      ";
+  cout.flush();
+  bool exist_type;
+  for(int ifield=0;ifield<nb_fields;++ifield)
+    {
+      exist_type=false;
+      FIELD<double> myField(MED_DRIVER,filename_in,field_names[ifield],iternumber[ifield],ordernumber[ifield]);
+      FIELD<double> newField(myField);
+      const SUPPORT* mySupport=newField.getSupport();
+      const medGeometryElement *typesOfSupport = mySupport->getTypes();
+      for(int t=0;t<mySupport->getNumberOfTypes();++t)
+        {
+          if(typesOfSupport[t]==Type)
+            {
+              exist_type=true;
+              break;
+            }
+        }
+      if(exist_type)
+        {
+          for(int i=0;i<mySupport->getNumberOfElements(Type);++i)
+            {
+              for(int j=0;j<newField.getNumberOfComponents();++j)
+                {
+                  newField.setValueIJ(i+1,j+1,myField.getValueIJ(iperm[i],j+1));
+                }
+            }
+        }
+      int drv=newField.addDriver(MED_DRIVER,filename_out,field_names[ifield]);
+      newField.write(drv);
+      delete (SUPPORT *) newField.getSupport();
+    }
+  t_field=clock();
+  cout << " : " << (t_field-t_family)/(double) CLOCKS_PER_SEC << "s" << endl;
+  cout.flush();
+
+  delete[] graph_index;
+  delete[] graph;
+
+  return 0;
+}
diff --git a/src/RENUMBER/testRenumbering.py b/src/RENUMBER/testRenumbering.py
new file mode 100755 (executable)
index 0000000..2ffba9d
--- /dev/null
@@ -0,0 +1,287 @@
+#!/usr/bin/env python
+
+from libMEDMEM_Swig import *
+import os
+import sys
+
+##                                         ***************
+##                                         *** TEST 2D ***
+##                                         ***************
+dir_renumber="~/Renumbering/MED_INSTALL/bin/salome/renumber"
+dir_mesh="."
+filename="Test2D.med"
+meshname="Mesh_1"
+
+print "TEST 2D Boost"
+method="BOOST"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+
+field_ini=[2,3,12,13,14,15,4,5,6,7,8,9,16,17,0,1,10,11]
+s = SUPPORT(m,"Support on all",MED_CELL)
+f = FIELDDOUBLE(s,2)
+id=f.addDriver(MED_DRIVER,dir_mesh+"/out_"+filename,"Test field")
+f.read(id);
+field=True
+for i in range(9):
+    field=field&(f.getValueIJ(i+1,1)==field_ini[i*2])
+    field=field&(f.getValueIJ(i+1,2)==field_ini[i*2+1])
+f.rmDriver(id)
+
+nbcell2dboost=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+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]
+connectivite_index=[1,5,9,13,17,21,25,29,33,37]
+conn=m.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_QUAD4)
+conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
+conn2dboost=(len(conn)==len(connectivite))
+if conn2dboost:
+    for i in range(0,len(connectivite)):
+        conn2dboost=conn2dboost&(conn[i]==connectivite[i])
+conn_index2dboost=(len(conn_index)==len(connectivite_index))
+if conn_index2dboost:
+    for i in range(0,len(connectivite_index)):
+        conn_index2dboost=conn_index2dboost&(conn_index[i]==connectivite_index[i])
+Boost2D=conn2dboost&conn_index2dboost&(nbcell2dboost==9)&field
+os.remove(dir_mesh+"/out_"+filename)
+
+
+print "TEST 2D Metis"
+method="METIS"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell2dmetis=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+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]
+connectivite_index=[1,5,9,13,17,21,25,29,33,37]
+conn=m.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_QUAD4)
+conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
+conn2dmetis=(len(conn)==len(connectivite))
+if conn2dmetis:
+    for i in range(0,len(connectivite)):
+        conn2dmetis=conn2dmetis&(conn[i]==connectivite[i])
+conn_index2dmetis=(len(conn_index)==len(connectivite_index))
+if conn_index2dmetis:
+    for i in range(0,len(connectivite_index)):
+        conn_index2dmetis=conn_index2dmetis&(conn_index[i]==connectivite_index[i])
+Metis2D=conn2dmetis&conn_index2dmetis&(nbcell2dmetis==9)
+os.remove(dir_mesh+"/out_"+filename)
+
+## *** Avec polygone ***
+
+filename="Test2Dpoly.med"
+meshname="Mesh_1"
+
+
+print "TEST 2D Boost with polygons"
+method="BOOST"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell2dpolyboost=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+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]
+connectivite_index=[1,5,9,13,17,21,25,29,33,37]
+conn=m.getPolygonsConnectivity(MED_FULL_INTERLACE,MED_CELL)
+conn_index=m.getPolygonsConnectivityIndex(MED_FULL_INTERLACE,MED_CELL);
+conn2dpolyboost=(len(conn)==len(connectivite))
+if conn2dpolyboost:
+    for i in range(0,len(connectivite)):
+        conn2dpolyboost=conn2dpolyboost&(conn[i]==connectivite[i])
+conn_index2dpolyboost=(len(conn_index)==len(connectivite_index))
+if conn_index2dpolyboost:
+    for i in range(0,len(connectivite_index)):
+        conn_index2dpolyboost=conn_index2dpolyboost&(conn_index[i]==connectivite_index[i])
+PolyBoost2D=conn2dpolyboost&conn_index2dpolyboost&(nbcell2dpolyboost==9)
+os.remove(dir_mesh+"/out_"+filename)
+
+print "TEST 2D Metis with polygons"
+method="METIS"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell2dpolymetis=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+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]
+connectivite_index=[1,5,9,13,17,21,25,29,33,37]
+conn=m.getPolygonsConnectivity(MED_FULL_INTERLACE,MED_CELL)
+conn_index=m.getPolygonsConnectivityIndex(MED_FULL_INTERLACE,MED_CELL);
+conn2dpolymetis=(len(conn)==len(connectivite))
+if conn2dpolymetis:
+    for i in range(0,len(connectivite)):
+        conn2dpolymetis=conn2dpolymetis&(conn[i]==connectivite[i])
+conn_index2dpolymetis=(len(conn_index)==len(connectivite_index))
+if conn_index2dpolymetis:
+    for i in range(0,len(connectivite_index)):
+        conn_index2dpolymetis=conn_index2dpolymetis&(conn_index[i]==connectivite_index[i])
+PolyMetis2D=conn2dpolymetis&conn_index2dpolymetis&(nbcell2dpolymetis==9)
+os.remove(dir_mesh+"/out_"+filename)
+
+
+##                                         ***************
+##                                         *** TEST 3D ***
+##                                         ***************
+
+
+filename="Test3D.med"
+meshname="Mesh_1"
+
+
+print "TEST 3D Boost"
+method="BOOST"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell3dboost=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+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]
+connectivite_index=[1,9,17,25,33,41,49,57,65]
+conn=m.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_HEXA8)
+conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
+conn3dboost=(len(conn)==len(connectivite))
+if conn3dboost:
+    for i in range(0,len(connectivite)):
+        conn3dboost=conn3dboost&(conn[i]==connectivite[i])
+conn_index3dboost=(len(conn_index)==len(connectivite_index))
+if conn_index3dboost:
+    for i in range(0,len(connectivite_index)):
+        conn_index3dboost=conn_index3dboost&(conn_index[i]==connectivite_index[i])
+Boost3D=conn3dboost&conn_index3dboost&(nbcell3dboost==8)
+os.remove(dir_mesh+"/out_"+filename)
+
+
+print "TEST 3D Metis"
+method="METIS"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell3dmetis=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+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]
+connectivite_index=[1,9,17,25,33,41,49,57,65]
+conn=m.getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_HEXA8)
+conn_index=m.getConnectivityIndex(MED_NODAL,MED_CELL);
+conn3dmetis=(len(conn)==len(connectivite))
+if conn3dmetis:
+    for i in range(0,len(connectivite)):
+        conn3dmetis=conn3dmetis&(conn[i]==connectivite[i])
+conn_index3dmetis=(len(conn_index)==len(connectivite_index))
+if conn_index3dmetis:
+    for i in range(0,len(connectivite_index)):
+        conn_index3dmetis=conn_index3dmetis&(conn_index[i]==connectivite_index[i])
+Metis3D=conn3dmetis&conn_index3dmetis&(nbcell3dmetis==8)
+os.remove(dir_mesh+"/out_"+filename)
+
+
+## *** Avec polyedres ***
+
+## 23,13,5,18,27,26,14,22,23,27,22,13,13,22,14,5,5,14,26,18,18,26,27,23,
+## 21,27,26,10,11,3,20,24,21,11,24,27,27,24,20,26,26,20,3,10,10,3,11,21,
+## 12,25,27,21,4,11,24,19,12,4,19,25,25,19,24,27,27,24,11,21,21,11,4,12,
+## 9,23,18,1,21,10,26,27,9,21,27,23,23,27,26,18,18,26,10,1,1,10,21,9,
+## 2,17,23,9,12,21,27,25,2,12,25,17,17,25,27,23,23,27,21,9,9,21,12,2,
+## 25,16,22,27,19,24,15,8,25,19,8,16,16,8,15,22,22,15,24,27,27,24,19,25,
+## 17,6,13,23,25,27,22,16,17,25,16,6,6,16,22,13,13,22,27,23,23,27,25,17,
+## 27,22,14,26,24,20,7,15,27,24,15,22,22,15,7,14,14,7,20,26,26,20,24,27,
+
+
+filename="Test3Dpoly.med"
+meshname="Mesh_1"
+
+
+print "TEST 3D Boost with polyhedra"
+method="BOOST"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell3dpolyboost=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+connectivite=[23,13,5,18,27,26,14,22,23,27,22,13,13,22,14,5,5,14,26,18,18,26,27,23,17,6,13,23,25,27,22,16,17,25,16,6,6,16,22,13,13,22,27,23,23,27,25,17,27,22,14,26,24,20,7,15,27,24,15,22,22,15,7,14,14,7,20,26,26,20,24,27,9,23,18,1,21,10,26,27,9,21,27,23,23,27,26,18,18,26,10,1,1,10,21,9,25,16,22,27,19,24,15,8,25,19,8,16,16,8,15,22,22,15,24,27,27,24,19,25,2,17,23,9,12,21,27,25,2,12,25,17,17,25,27,23,23,27,21,9,9,21,12,2,21,27,26,10,11,3,20,24,21,11,24,27,27,24,20,26,26,20,3,10,10,3,11,21,12,25,27,21,4,11,24,19,12,4,19,25,25,19,24,27,27,24,11,21,21,11,4,12]
+connectivite_face_index=[1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,129,133,137,141,145,149,153,157,161,165,169,173,177,181,185,189,193]
+connectivite_index=[1,7,13,19,25,31,37,43,49]
+conn=m.getPolyhedronConnectivity(MED_FULL_INTERLACE)
+conn_index=m.getPolyhedronIndex(MED_FULL_INTERLACE)
+conn_face_index=m.getPolyhedronFacesIndex()
+conn3dpolyboost=(len(conn)==len(connectivite))
+if conn3dpolyboost:
+    for i in range(0,len(connectivite)):
+        conn3dpolyboost=conn3dpolyboost&(conn[i]==connectivite[i])
+conn_index3dpolyboost=(len(conn_index)==len(connectivite_index))
+if conn3dpolyboost:
+    for i in range(0,len(connectivite_index)):
+        conn_index3dpolyboost=conn_index3dpolyboost&(conn_index[i]==connectivite_index[i])
+conn_face_index3dpolyboost=(len(conn_face_index)==len(connectivite_face_index))
+if conn_face_index3dpolyboost:
+    for i in range(0,len(connectivite_face_index)):
+        conn_face_index3dpolyboost=conn_face_index3dpolyboost&(conn_face_index[i]==connectivite_face_index[i])
+PolyBoost3D=conn3dpolyboost&conn_index3dpolyboost&conn_face_index3dpolyboost&(nbcell3dpolyboost==8)
+os.remove(dir_mesh+"/out_"+filename)
+
+
+print "TEST 3D Metis with polyhedra"
+method="METIS"
+string_to_execute="'"+dir_renumber+" "+dir_mesh+"/"+filename+" "+meshname+" "+method+" "+dir_mesh+"/out_"+filename+"'"
+eval("os.system("+string_to_execute+")")
+m = MESH(MED_DRIVER,dir_mesh+"/out_"+filename,meshname)
+nbcell3dpolymetis=m.getNumberOfElementsWithPoly(MED_CELL,MED_ALL_ELEMENTS)
+connectivite=[12,25,27,21,4,11,24,19,12,4,19,25,25,19,24,27,27,24,11,21,21,11,4,12,27,22,14,26,24,20,7,15,27,24,15,22,22,15,7,14,14,7,20,26,26,20,24,27,17,6,13,23,25,27,22,16,17,25,16,6,6,16,22,13,13,22,27,23,23,27,25,17,9,23,18,1,21,10,26,27,9,21,27,23,23,27,26,18,18,26,10,1,1,10,21,9,23,13,5,18,27,26,14,22,23,27,22,13,13,22,14,5,5,14,26,18,18,26,27,23,25,16,22,27,19,24,15,8,25,19,8,16,16,8,15,22,22,15,24,27,27,24,19,25,2,17,23,9,12,21,27,25,2,12,25,17,17,25,27,23,23,27,21,9,9,21,12,2,21,27,26,10,11,3,20,24,21,11,24,27,27,24,20,26,26,20,3,10,10,3,11,21]
+connectivite_face_index=[1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77,81,85,89,93,97,101,105,109,113,117,121,125,129,133,137,141,145,149,153,157,161,165,169,173,177,181,185,189,193]
+connectivite_index=[1,7,13,19,25,31,37,43,49]
+conn=m.getPolyhedronConnectivity(MED_FULL_INTERLACE)
+conn_index=m.getPolyhedronIndex(MED_FULL_INTERLACE)
+conn_face_index=m.getPolyhedronFacesIndex()
+conn3dpolymetis=(len(conn)==len(connectivite))
+conn_index3dpolymetis=(len(conn_index)==len(connectivite_index))
+conn_face_index3dpolymetis=(len(conn_face_index)==len(connectivite_face_index))
+if conn3dpolymetis:
+    for i in range(0,len(connectivite)):
+        conn3dpolymetis=conn3dpolymetis&(conn[i]==connectivite[i])
+if conn_index3dpolymetis:
+    for i in range(0,len(connectivite_index)):
+        conn_index3dpolymetis=conn_index3dpolymetis&(conn_index[i]==connectivite_index[i])
+if conn_face_index3dpolymetis:
+    for i in range(0,len(connectivite_face_index)):
+        conn_face_index3dpolymetis=conn_face_index3dpolymetis&(conn_face_index[i]==connectivite_face_index[i])
+PolyMetis3D=conn3dpolymetis&conn_index3dpolymetis&conn_face_index3dpolymetis&(nbcell3dpolymetis==8)
+os.remove(dir_mesh+"/out_"+filename)
+
+
+
+
+print ""
+if Boost2D:
+    print "Boost 2D ok"
+else:
+    print "ERROR Boost 2D"
+if Metis2D:
+    print "Metis 2D ok"
+else:
+    print "ERROR Metis 2D"
+if PolyBoost2D:
+    print "Poly Boost 2D ok"
+else:
+    print "ERROR Poly Boost 2D"
+if PolyMetis2D:
+    print "Poly Metis 2D ok"
+else:
+    print "ERROR Poly Metis 2D"
+if Boost3D:
+    print "Boost 3D ok"
+else:
+    print "ERROR Boost 3D"
+if Metis3D:
+    print "Metis 3D ok"
+else:
+    print "ERROR Metis 3D"
+if PolyBoost3D:
+    print "Poly Boost 3D ok"
+else:
+    print "ERROR Poly Boost 3D"
+if PolyMetis3D:
+    print "Poly Metis 3D ok"
+else:
+    print "ERROR Poly Metis 3D"
+
+
+print ""
+if Boost2D&Metis2D&PolyBoost2D&PolyMetis2D&Boost3D&Metis3D&PolyBoost3D&PolyMetis3D:
+    print "Every mesh correctly renumbered"
+    sys.exit()
+else:
+    print "Error"
+    sys.exit("Error in the renumbering test")