From 23739fc5ff7707c8e9ed403c4cdd82bded1f985b Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 3 Aug 2010 20:56:06 +0000
Subject: [PATCH] consolidate maxXXNum into getMaxElementaryNumber + improve
 multi-elementary IO read

---
 Fltk/classificationEditor.cpp |   8 +--
 Geo/GModel.cpp                |  57 +------------------
 Geo/GModel.h                  |   6 +-
 Geo/GModelIO_ACIS.cpp         |   8 +--
 Geo/GModelIO_Mesh.cpp         |  11 ++--
 Geo/discreteEdge.cpp          | 103 ++++++++++++++++++++++------------
 Mesh/meshGFace.cpp            |  10 ++--
 Mesh/meshPartition.cpp        |   4 +-
 8 files changed, 90 insertions(+), 117 deletions(-)

diff --git a/Fltk/classificationEditor.cpp b/Fltk/classificationEditor.cpp
index d62e6d5e25..4a1249c7b3 100644
--- a/Fltk/classificationEditor.cpp
+++ b/Fltk/classificationEditor.cpp
@@ -62,7 +62,7 @@ static GEdge *getNewModelEdge(GFace *gf1, GFace *gf2,
     newEdges.find(std::make_pair<int, int>(i1, i2));
   if(it == newEdges.end()){
     discreteEdge *ge = new discreteEdge
-      (GModel::current(), GModel::current()->maxEdgeNum() + 1, 0, 0);
+      (GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0);
     GModel::current()->add(ge);
     newEdges[std::make_pair<int, int>(i1, i2)] = ge;
     return ge;
@@ -168,7 +168,7 @@ static void select_elements_cb(Fl_Widget *w, void *data)
   // allocate discrete edge to hold the selected mesh segments
   if(!e->selected){
     e->selected = new discreteEdge
-      (GModel::current(), GModel::current()->maxEdgeNum() + 1, 0, 0);
+      (GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0);
     GModel::current()->add(e->selected);
   }
 
@@ -400,7 +400,7 @@ static void classify_cb(Fl_Widget *w, void *data)
   while(it != tris.end()){
     if(!(*it)->isDeleted()){
       discreteFace *gf = new discreteFace
-        (GModel::current(), GModel::current()->maxFaceNum() + 1);
+        (GModel::current(), GModel::current()->getMaxElementaryNumber(2) + 1);
       recurClassify(*it, gf, lines, reverse);
       GModel::current()->add(gf);
     }
@@ -467,7 +467,7 @@ static void classify_cb(Fl_Widget *w, void *data)
         vE = temp;
       }
       GEdge *newGe = new discreteEdge
-        (GModel::current(), GModel::current()->maxEdgeNum() + 1, 0, 0);
+        (GModel::current(), GModel::current()->getMaxElementaryNumber(1) + 1, 0, 0);
       newGe->lines.insert(newGe->lines.end(), myLines.begin(), myLines.end());
       GModel::current()->add(newGe);
     }
diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index f735595192..a6c8872600 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -268,57 +268,6 @@ bool GModel::empty() const
   return vertices.empty() && edges.empty() && faces.empty() && regions.empty();
 }
 
-int GModel::maxVertexNum()
-{
-  viter it = firstVertex();
-  viter itv = lastVertex();
-  int MAXX = 0;
-  while(it != itv){
-    MAXX = std::max(MAXX, (*it)->tag());
-    ++it;
-  }
-  return MAXX;
-
-}
-int GModel::maxEdgeNum()
-{
-  eiter it = firstEdge();
-  eiter ite = lastEdge();
-  int MAXX = 0;
-  while(it != ite){
-    MAXX = std::max(MAXX, (*it)->tag());
-    ++it;
-  }
-  return MAXX;
-
-}
-
-int GModel::maxFaceNum()
-{
-
-  fiter it =  firstFace();
-  fiter ite = lastFace();
-  int MAXX = 0;
-  while(it != ite){
-    MAXX = std::max(MAXX, (*it)->tag());
-    ++it;
-  }
-  return MAXX;
-}
-
-int GModel::maxRegionNum()
-{
-
-  riter it =  firstRegion();
-  riter ite = lastRegion();
-  int MAXX = 0;
-  while(it != ite){
-    MAXX = std::max(MAXX, (*it)->tag());
-    ++it;
-  }
-  return MAXX;
-}
-
 std::vector<GRegion*> GModel::bindingsGetRegions()
 {
   return std::vector<GRegion*> (regions.begin(), regions.end());
@@ -453,7 +402,7 @@ int GModel::getMaxElementaryNumber(int dim)
   getEntities(entities);
   int num = 0;
   for(unsigned int i = 0; i < entities.size(); i++)
-    if(entities[i]->dim() == dim)
+    if(dim < 0 || entities[i]->dim() == dim)
       num = std::max(num, std::abs(entities[i]->tag()));
   return num;
 }
@@ -1232,7 +1181,7 @@ void GModel::createTopologyFromMesh()
 
       int numF;
       if (nbFaces == 1) numF = (*itF)->tag(); 
-      else numF = maxFaceNum()+1;
+      else numF = getMaxElementaryNumber(2) + 1;
       discreteFace *f = new discreteFace(this, numF);
       //printf("*** Created discreteFace %d \n", numF);
       add(f);
@@ -1425,7 +1374,7 @@ void GModel::createTopologyFromFaces(std::vector<discreteFace*> &discFaces)
     for (int ib  = 0; ib < nbBounds; ib++){
       std::vector<MEdge> myLines = boundaries[ib];
 
-      int numE = maxEdgeNum()+1;
+      int numE = getMaxElementaryNumber(1) + 1;
       discreteEdge *e = new discreteEdge(this, numE, 0, 0);
       //printf("*** Created discreteEdge %d \n", numE);
       add(e);
diff --git a/Geo/GModel.h b/Geo/GModel.h
index 2e2ac3269f..9138f7adfa 100644
--- a/Geo/GModel.h
+++ b/Geo/GModel.h
@@ -180,10 +180,6 @@ class GModel
   int getNumFaces() const { return faces.size(); }
   int getNumEdges() const { return edges.size(); }
   int getNumVertices() const { return vertices.size(); }
-  int maxVertexNum();
-  int maxEdgeNum();
-  int maxFaceNum();
-  int maxRegionNum();
 
   // quickly check if the model is empty (i.e., if it contains no
   // entities)
@@ -234,7 +230,7 @@ class GModel
   void getEntities(std::vector<GEntity*> &entities);
 
   // return the highest number associated with an elementary entity of
-  // a given dimension
+  // a given dimension (or the highest overall if dim < 0)
   int getMaxElementaryNumber(int dim);
 
   // check if there are no physical entities in the model
diff --git a/Geo/GModelIO_ACIS.cpp b/Geo/GModelIO_ACIS.cpp
index 0c0d7da397..062e0fa9ad 100644
--- a/Geo/GModelIO_ACIS.cpp
+++ b/Geo/GModelIO_ACIS.cpp
@@ -168,7 +168,7 @@ void ACIS_Internals::addVertices (GModel *gm, ENTITY_LIST &l)
     if (av){
       GVertex *v = getACISVertexByNativePtr(gm, av);
       if (!v)
-	gm->add(new ACISVertex (gm,gm->maxVertexNum() + 1, av));
+	gm->add(new ACISVertex (gm, gm->getMaxElementaryNumber(0) + 1, av));
     }
   }
 }
@@ -184,13 +184,12 @@ void ACIS_Internals::addEdges (GModel *gm, ENTITY_LIST &l)
       if (!v){
 	GVertex *v1 = getACISVertexByNativePtr(gm, av->start());
 	GVertex *v2 = getACISVertexByNativePtr(gm, av->end());      
-	gm->add(new ACISEdge(gm,av,gm->maxEdgeNum() + 1, v1, v2));
+	gm->add(new ACISEdge(gm, av, gm->getMaxElementaryNumber(1) + 1, v1, v2));
       }
     }
   }
 }
 
-
 void ACIS_Internals::addFaces (GModel *gm, ENTITY_LIST &l)
 {
   l.init();
@@ -200,13 +199,12 @@ void ACIS_Internals::addFaces (GModel *gm, ENTITY_LIST &l)
     if (av){
       GFace *v = getACISFaceByNativePtr(gm,av);
       if (!v){
-	gm->add(new ACISFace(gm,av,gm->maxFaceNum()+1));
+	gm->add(new ACISFace(gm, av, gm->getMaxElementaryNumber(2) + 1));
       }
     }
   }
 }
 
-
 void ACIS_Internals::loadSAT(std::string fileName, GModel *gm)
 {
   FILE *f = fopen (fileName.c_str(), "r");
diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp
index 525c16d7b3..7642d0829c 100644
--- a/Geo/GModelIO_Mesh.cpp
+++ b/Geo/GModelIO_Mesh.cpp
@@ -1035,7 +1035,7 @@ int GModel::readSTL(const std::string &name, double tolerance)
     }
     Msg::Info("%d facets in solid %d", points[i].size() / 3, i);
     // create face
-    GFace *face = new discreteFace(this, getNumFaces() + 1);
+    GFace *face = new discreteFace(this, getMaxElementaryNumber(2) + 1);
     faces.push_back(face);
     add(face);
   }
@@ -1228,7 +1228,7 @@ int GModel::readVRML(const std::string &name)
   // need)
   std::vector<MVertex*> vertexVector, allVertexVector;
   std::map<int, std::vector<MElement*> > elements[3];
-  int region = 0;
+  int region = getMaxElementaryNumber(-1);
   char buffer[256], str[256];
   while(!feof(fp)) {
     if(!fgets(buffer, sizeof(buffer), fp)) break;
@@ -1240,6 +1240,7 @@ int GModel::readVRML(const std::string &name)
         if(!readVerticesVRML(fp, vertexVector, allVertexVector)) break;
       }
       else if(!strcmp(str, "coord")){
+        region++;
         vertexVector.clear();
         if(!skipUntil(fp, "point")) break;
         if(!readVerticesVRML(fp, vertexVector, allVertexVector)) break;
@@ -1384,7 +1385,7 @@ int GModel::readUNV(const std::string &name)
           int num, type, elementary, physical, color, numNodes;
           if(sscanf(buffer, "%d %d %d %d %d %d", &num, &type, &elementary, &physical,
                     &color, &numNodes) != 6) break;
-          if(elementary < 0) elementary = 1;
+          if(elementary < 0) elementary = getMaxElementaryNumber(-1) + 1;
           if(physical < 0) physical = 0;
           switch(type){
           case 11: case 21: case 22: case 31:
@@ -2178,7 +2179,7 @@ int GModel::readP3D(const std::string &name)
 
   for(int n = 0; n < numBlocks; n++){
     if(Nk[n] == 1){
-      GFace *gf = new discreteFace(this, getNumFaces() + 1);
+      GFace *gf = new discreteFace(this, getMaxElementaryNumber(2) + 1);
       add(gf);
       gf->transfinite_vertices.resize(Ni[n]);
       for(int i = 0; i < Ni[n]; i++)
@@ -2211,7 +2212,7 @@ int GModel::readP3D(const std::string &name)
                              gf->transfinite_vertices[i    ][j + 1]));
     }
     else{
-      GRegion *gr = new discreteRegion(this, getNumRegions() + 1);
+      GRegion *gr = new discreteRegion(this,  getMaxElementaryNumber(3) + 1);
       add(gr);
       gr->transfinite_vertices.resize(Ni[n]);
       for(int i = 0; i < Ni[n]; i++){
diff --git a/Geo/discreteEdge.cpp b/Geo/discreteEdge.cpp
index 7bedd8791f..a06f135058 100644
--- a/Geo/discreteEdge.cpp
+++ b/Geo/discreteEdge.cpp
@@ -31,7 +31,6 @@ discreteEdge::discreteEdge(GModel *model, int num, GVertex *_v0, GVertex *_v1)
 
 void discreteEdge::createTopo()
 {
-
   if(!createdTopo){ 
     orderMLines();
     setBoundVertices();
@@ -50,7 +49,8 @@ void discreteEdge::orderMLines()
   }
 
   // find a lonly MLine
-  for (std::list<MLine*>::iterator it = segments.begin(); it != segments.end(); ++it){
+  for (std::list<MLine*>::iterator it = segments.begin(); 
+       it != segments.end(); ++it){
     MVertex *vL = (*it)->getVertex(0);
     MVertex *vR = (*it)->getVertex(1);
     std::map<MVertex*,MLine*>::iterator it1 = boundv.find(vL);
@@ -65,7 +65,8 @@ void discreteEdge::orderMLines()
   MLine *firstLine;
   if (boundv.size() == 2){   // non periodic
     firstLine = (boundv.begin())->second;
-    for (std::list<MLine*>::iterator it = segments.begin(); it != segments.end(); ++it){
+    for (std::list<MLine*>::iterator it = segments.begin(); 
+         it != segments.end(); ++it){
       if (*it == firstLine){
         segments.erase(it);
         break;
@@ -77,7 +78,8 @@ void discreteEdge::orderMLines()
     segments.erase(segments.begin());
   }
   else{
-    Msg::Error("EdgeCompound %d is wrong (it has %d end points)",tag(),boundv.size());
+    Msg::Error("EdgeCompound %d is wrong (it has %d end points)", 
+               tag(), boundv.size());
   }
 
   //loop over all segments to order segments and store it in the list _m
@@ -88,7 +90,8 @@ void discreteEdge::orderMLines()
   while (first != last){
     if (segments.empty())break;
     bool found = false;
-    for (std::list<MLine*>::iterator it = segments.begin(); it != segments.end(); ++it){
+    for (std::list<MLine*>::iterator it = segments.begin(); 
+         it != segments.end(); ++it){
       MLine *e = *it;
       if (e->getVertex(0) == last){
         _m.push_back(e);
@@ -129,8 +132,10 @@ void discreteEdge::orderMLines()
   for (unsigned int i = 0; i < lines.size(); ++i){
     MVertex *v1 = lines[i]->getVertex(0);
     MVertex *v2 = lines[i]->getVertex(1);
-    if (std::find(mesh_vertices.begin(), mesh_vertices.end(), v1) ==  mesh_vertices.end()) mesh_vertices.push_back(v1);
-    if (std::find(mesh_vertices.begin(), mesh_vertices.end(), v2) ==  mesh_vertices.end()) mesh_vertices.push_back(v2);
+    if (std::find(mesh_vertices.begin(), mesh_vertices.end(), v1) ==  
+        mesh_vertices.end()) mesh_vertices.push_back(v1);
+    if (std::find(mesh_vertices.begin(), mesh_vertices.end(), v2) ==  
+        mesh_vertices.end()) mesh_vertices.push_back(v2);
     v1->setEntity(this);
     v2->setEntity(this);
   }
@@ -139,15 +144,14 @@ void discreteEdge::orderMLines()
   if (lines.size() < 2) return;
   if (_orientation[0] && lines[0]->getVertex(1) != lines[1]->getVertex(1)
       && lines[0]->getVertex(1) != lines[1]->getVertex(0)){
-    for (unsigned int i = 0; i < lines.size(); i++) _orientation[i] = !_orientation[i];
+    for (unsigned int i = 0; i < lines.size(); i++) 
+      _orientation[i] = !_orientation[i];
   }
-
 }
 
 void discreteEdge::setBoundVertices()
 {
-
-  if (boundv.size()==2){
+  if (boundv.size() == 2){
     std::vector<GVertex*> bound_vertices;
     for (std::map<MVertex*,MLine*>::const_iterator iter = boundv.begin(); 
          iter != boundv.end(); iter++){
@@ -162,7 +166,8 @@ void discreteEdge::setBoundVertices()
         }
       }
       if(!existVertex){
-        GVertex *gvB = new discreteVertex(model(), model()->maxVertexNum()+1);      
+        GVertex *gvB = new discreteVertex
+          (model(), model()->getMaxElementaryNumber(0) + 1);      
         //printf("*** Created discreteVertex %d\n", gvB->tag());
         bound_vertices.push_back(gvB);
         vE->setEntity(gvB);
@@ -170,19 +175,23 @@ void discreteEdge::setBoundVertices()
         gvB->points.push_back(new MPoint(gvB->mesh_vertices.back()));
         model()->add(gvB);
       }
-      std::vector<MVertex*>::iterator itve = std::find(mesh_vertices.begin(), mesh_vertices.end(), vE);
+      std::vector<MVertex*>::iterator itve = 
+        std::find(mesh_vertices.begin(), mesh_vertices.end(), vE);
       if (itve != mesh_vertices.end()) mesh_vertices.erase(itve);
 
       for(GModel::eiter edge = model()->firstEdge(); edge != model()->lastEdge(); edge++){
-        std::vector<MVertex*>::iterator itve = std::find((*edge)->mesh_vertices.begin(), (*edge)->mesh_vertices.end(), vE);
+        std::vector<MVertex*>::iterator itve = 
+          std::find((*edge)->mesh_vertices.begin(), (*edge)->mesh_vertices.end(), vE);
         if (itve != (*edge)->mesh_vertices.end()) (*edge)->mesh_vertices.erase(itve);
       }
       for(GModel::fiter face = model()->firstFace(); face != model()->lastFace(); face++){
-        std::vector<MVertex*>::iterator itve = std::find((*face)->mesh_vertices.begin(), (*face)->mesh_vertices.end(), vE);
+        std::vector<MVertex*>::iterator itve = 
+          std::find((*face)->mesh_vertices.begin(), (*face)->mesh_vertices.end(), vE);
         if (itve != (*face)->mesh_vertices.end()) (*face)->mesh_vertices.erase(itve);
       }
       for(GModel::riter reg = model()->firstRegion(); reg != model()->lastRegion(); reg++){
-        std::vector<MVertex*>::iterator itve = std::find((*reg)->mesh_vertices.begin(), (*reg)->mesh_vertices.end(), vE);
+        std::vector<MVertex*>::iterator itve = 
+          std::find((*reg)->mesh_vertices.begin(), (*reg)->mesh_vertices.end(), vE);
         if (itve != (*reg)->mesh_vertices.end()) (*reg)->mesh_vertices.erase(itve);
       }
 
@@ -196,7 +205,8 @@ void discreteEdge::setBoundVertices()
     std::vector<MLine*>::const_iterator it = lines.begin();
     MVertex* vE = (*it)->getVertex(0);
     bool existVertex  = false;
-    for(GModel::viter point = model()->firstVertex(); point != model()->lastVertex(); point++){
+    for(GModel::viter point = model()->firstVertex(); 
+        point != model()->lastVertex(); point++){
       if ((*point)->mesh_vertices[0]->getNum() == vE->getNum()){
         bound_vertex = (*point);
         existVertex = true;
@@ -205,7 +215,8 @@ void discreteEdge::setBoundVertices()
       }
     }
     if(!existVertex){
-      GVertex *gvB = new discreteVertex(model(), model()->maxVertexNum()+1);
+      GVertex *gvB = new discreteVertex
+        (model(), model()->getMaxElementaryNumber(0) + 1);
       //printf("*** Created discreteVertex %d\n", gvB->tag());
       bound_vertex = gvB;
       vE->setEntity(gvB);
@@ -213,19 +224,26 @@ void discreteEdge::setBoundVertices()
       gvB->points.push_back(new MPoint(gvB->mesh_vertices.back()));
       model()->add(gvB);
     }
-    std::vector<MVertex*>::iterator itve = std::find(mesh_vertices.begin(),mesh_vertices.end(), vE);
-    if (itve != mesh_vertices.end())  mesh_vertices.erase(itve);
+    std::vector<MVertex*>::iterator itve = 
+      std::find(mesh_vertices.begin(),mesh_vertices.end(), vE);
+    if (itve != mesh_vertices.end()) mesh_vertices.erase(itve);
    
-    for(GModel::eiter edge = model()->firstEdge(); edge != model()->lastEdge(); edge++){
-      std::vector<MVertex*>::iterator itve = std::find((*edge)->mesh_vertices.begin(), (*edge)->mesh_vertices.end(), vE);
+    for(GModel::eiter edge = model()->firstEdge(); 
+        edge != model()->lastEdge(); edge++){
+      std::vector<MVertex*>::iterator itve = 
+        std::find((*edge)->mesh_vertices.begin(), (*edge)->mesh_vertices.end(), vE);
       if (itve != (*edge)->mesh_vertices.end()) (*edge)->mesh_vertices.erase(itve);
     }
-    for(GModel::fiter face = model()->firstFace(); face != model()->lastFace(); face++){
-      std::vector<MVertex*>::iterator itve = std::find((*face)->mesh_vertices.begin(), (*face)->mesh_vertices.end(), vE);
+    for(GModel::fiter face = model()->firstFace(); 
+        face != model()->lastFace(); face++){
+      std::vector<MVertex*>::iterator itve = 
+        std::find((*face)->mesh_vertices.begin(), (*face)->mesh_vertices.end(), vE);
       if (itve != (*face)->mesh_vertices.end()) (*face)->mesh_vertices.erase(itve);
     }
-    for(GModel::riter reg = model()->firstRegion(); reg != model()->lastRegion(); reg++){
-      std::vector<MVertex*>::iterator itve = std::find((*reg)->mesh_vertices.begin(), (*reg)->mesh_vertices.end(), vE);
+    for(GModel::riter reg = model()->firstRegion(); 
+        reg != model()->lastRegion(); reg++){
+      std::vector<MVertex*>::iterator itve = 
+        std::find((*reg)->mesh_vertices.begin(), (*reg)->mesh_vertices.end(), vE);
       if (itve != (*reg)->mesh_vertices.end()) (*reg)->mesh_vertices.erase(itve);
     }
 
@@ -242,8 +260,10 @@ void discreteEdge::setBoundVertices()
     +---------------+--------------+----------- ... ----------+
     _pars[0]=0   _pars[1]=1    _pars[2]=2             _pars[N+1]=N+1
 */
-void discreteEdge::parametrize( std::map<GFace*,   std::map<MVertex*, MVertex*, std::less<MVertex*> > > &face2Vert, 
-				std::map<GRegion*, std::map<MVertex*, MVertex*, std::less<MVertex*> > > &region2Vert)
+void discreteEdge::parametrize(std::map<GFace*, std::map<MVertex*, MVertex*,
+                               std::less<MVertex*> > > &face2Vert, 
+                               std::map<GRegion*, std::map<MVertex*, MVertex*,
+                               std::less<MVertex*> > > &region2Vert)
 { 
   for (unsigned int i = 0; i < lines.size() + 1; i++){
     _pars.push_back(i);
@@ -262,7 +282,8 @@ void discreteEdge::parametrize( std::map<GFace*,   std::map<MVertex*, MVertex*,
     if (_orientation[i] == 1 ) vR = lines[i]->getVertex(1);
     else vR = lines[i]->getVertex(0);
     int param = i+1;
-    MVertex *vNEW = new MEdgeVertex(vR->x(),vR->y(),vR->z(), this, param, -1., vR->getNum());
+    MVertex *vNEW = new MEdgeVertex(vR->x(),vR->y(),vR->z(), this, 
+                                    param, -1., vR->getNum());
     old2new.insert(std::make_pair(vR,vNEW));
     newVertices.push_back(vNEW);
     newLines.push_back(new MLine(vL, vNEW));
@@ -283,16 +304,19 @@ void discreteEdge::parametrize( std::map<GFace*,   std::map<MVertex*, MVertex*,
   //  we need to recreate lines, triangles and tets
   //  that contain those new MEdgeVertices
   
-   for(std::list<GFace*>::iterator iFace = l_faces.begin(); iFace != l_faces.end(); ++iFace){
+   for(std::list<GFace*>::iterator iFace = l_faces.begin(); 
+       iFace != l_faces.end(); ++iFace){
 
      //for each face find correspondane face2Vertex
-     std::map<GFace*,  std::map<MVertex*, MVertex*, std::less<MVertex*> > >::iterator itmap = face2Vert.find(*iFace);
+     std::map<GFace*, std::map<MVertex*, MVertex*, 
+       std::less<MVertex*> > >::iterator itmap = face2Vert.find(*iFace);
      if (itmap == face2Vert.end()) {
        face2Vert.insert(std::make_pair(*iFace, old2new));
      }
      else{
        std::map<MVertex*, MVertex*, std::less<MVertex*> > mapVert = itmap->second;
-       for (std::map<MVertex*, MVertex*, std::less<MVertex*> >::iterator it = old2new.begin(); it != old2new.end(); it++)
+       for (std::map<MVertex*, MVertex*, std::less<MVertex*> >::iterator it =
+              old2new.begin(); it != old2new.end(); it++)
          mapVert.insert(*it);
        itmap->second = mapVert;
      }
@@ -300,13 +324,15 @@ void discreteEdge::parametrize( std::map<GFace*,   std::map<MVertex*, MVertex*,
      //do the same for regions
      for ( int j = 0; j < (*iFace)->numRegions(); j++){
        GRegion *r = (*iFace)->getRegion(j);
-       std::map<GRegion*,  std::map<MVertex*, MVertex*, std::less<MVertex*> > >::iterator itmap = region2Vert.find(r);
+       std::map<GRegion*,  std::map<MVertex*, MVertex*, 
+         std::less<MVertex*> > >::iterator itmap = region2Vert.find(r);
        if (itmap == region2Vert.end()) {
 	 region2Vert.insert(std::make_pair(r, old2new));
        }
        else{
 	 std::map<MVertex*, MVertex*, std::less<MVertex*> > mapVert = itmap->second;
-	 for (std::map<MVertex*, MVertex*, std::less<MVertex*> >::iterator it = old2new.begin(); it != old2new.end(); it++)
+	 for (std::map<MVertex*, MVertex*, std::less<MVertex*> >::iterator it = 
+                old2new.begin(); it != old2new.end(); it++)
 	   mapVert.insert(*it);
 	 itmap->second = mapVert;
        }
@@ -318,7 +344,8 @@ void discreteEdge::parametrize( std::map<GFace*,   std::map<MVertex*, MVertex*,
 void discreteEdge::computeNormals () const
 {
   _normals.clear();
-  for (unsigned int i= 0; i < mesh_vertices.size(); i++) _normals[mesh_vertices[i]] = SVector3(0.0,0.0,0.0);
+  for (unsigned int i= 0; i < mesh_vertices.size(); i++) 
+    _normals[mesh_vertices[i]] = SVector3(0.0,0.0,0.0);
   _normals[getBeginVertex()->mesh_vertices[0]] = SVector3(0.0,0.0,0.0);
   _normals[getBeginVertex()->mesh_vertices[0]] = SVector3(0.0,0.0,0.0);
   double J[3][3];
@@ -328,7 +355,8 @@ void discreteEdge::computeNormals () const
     for (unsigned int i = 0; i < (*iFace)->triangles.size(); ++i){
       MTriangle *t = (*iFace)->triangles[i];
       for (int j = 0; j < 3; j++){
-        std::map<MVertex*, SVector3, std::less<MVertex*> >::iterator itn = _normals.find(t->getVertex(j));
+        std::map<MVertex*, SVector3, std::less<MVertex*> >::iterator 
+          itn = _normals.find(t->getVertex(j));
         if (itn != _normals.end()){
           t->getJacobian(0, 0, 0, J);
           SVector3 d1(J[0][0], J[0][1], J[0][2]);
@@ -371,7 +399,8 @@ void discreteEdge::getLocalParameter(const double &t, int &iLine,
     double tmin = _pars[iLine];
     double tmax = _pars[iLine+1];
     if (t >= tmin && t <= tmax){
-      tLoc = _orientation[iLine] ? (t-tmin)/(tmax-tmin) : 1 - (t-tmin)/(tmax-tmin);
+      tLoc = _orientation[iLine] ? (t-tmin)/(tmax-tmin) :
+        1 - (t-tmin)/(tmax-tmin);
       return;
     }
   }
diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp
index e4102b51a6..9534642e83 100644
--- a/Mesh/meshGFace.cpp
+++ b/Mesh/meshGFace.cpp
@@ -1561,9 +1561,9 @@ void partitionAndRemesh(GFaceCompound *gf)
   //gf->partitionFaceCM(); 
 
   int NF = msp->getNumberOfParts();
-  int numv = gf->model()->maxVertexNum() + 1;
-  int nume = gf->model()->maxEdgeNum() + 1;
-  int numf = gf->model()->maxFaceNum() + 1;
+  int numv = gf->model()->getMaxElementaryNumber(0) + 1;
+  int nume = gf->model()->getMaxElementaryNumber(1) + 1;
+  int numf = gf->model()->getMaxElementaryNumber(2) + 1;
   std::vector<discreteFace*> pFaces;
   createPartitionFaces(gf->model(), gf, NF, pFaces); 
   
@@ -1577,7 +1577,7 @@ void partitionAndRemesh(GFaceCompound *gf)
   Msg::Info("--- Parametrize Compounds:");
  
   //Parametrize Compound Lines
-  int NE = gf->model()->maxEdgeNum() - nume + 1;
+  int NE = gf->model()->getMaxElementaryNumber(1) - nume + 1;
   for (int i=0; i < NE; i++){
     std::vector<GEdge*>e_compound;
     GEdge *pe = gf->model()->getEdgeByTag(nume+i);//partition edge
@@ -1640,7 +1640,7 @@ void partitionAndRemesh(GFaceCompound *gf)
   }
 
   //Removing discrete Vertices - Edges - Faces
-  int NV = gf->model()->maxVertexNum() - numv + 1;
+  int NV = gf->model()->getMaxElementaryNumber(0) - numv + 1;
   for (int i=0; i < NV; i++){
     GVertex *pv = gf->model()->getVertexByTag(numv+i);
     gf->model()->remove(pv);
diff --git a/Mesh/meshPartition.cpp b/Mesh/meshPartition.cpp
index 5f84c66b7b..2cec0fb4d0 100644
--- a/Mesh/meshPartition.cpp
+++ b/Mesh/meshPartition.cpp
@@ -1147,7 +1147,7 @@ void  splitBoundaryEdges(GModel *model,  std::set<partitionEdge*, Less_partition
         vE = temp;
       }
       if (nbSplit == 0 && segments.empty()) break; 
-      int numEdge = model->maxEdgeNum() + 1;
+      int numEdge = model->getMaxElementaryNumber(1) + 1;
       discreteEdge *newGe = new discreteEdge(model, numEdge, 0, 0);
       newGe->lines.insert(newGe->lines.end(), myLines.begin(), myLines.end());
       model->add(newGe);
@@ -1378,7 +1378,7 @@ void createPartitionFaces(GModel *model, GFaceCompound *gf, int N,
   // Compound is partitioned in N discrete faces
   //--------------------------------------------
   std::vector<std::set<MVertex*> > allNodes;
-  int numMax = model->maxFaceNum() + 1;
+  int numMax = model->getMaxElementaryNumber(2) + 1;
   for(int i = 0; i < N; i++){
     //printf("*** Created discreteFace %d \n", numMax+i);
     discreteFace *face = new discreteFace(model, numMax+i);
-- 
GitLab