From 311723f6c55c2a5a1f849dd4a0153cf245ad1c5c Mon Sep 17 00:00:00 2001
From: Michel Rasquin <michel.rasquin@cenaero.be>
Date: Fri, 25 Sep 2015 14:52:56 +0000
Subject: [PATCH] Fix element numbering for partitioned meshes in case
 uniqueness of element ids through all partitions is requested

---
 Geo/GModelIO_MSH2.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp
index dd77c6a8e4..efb40fe9f3 100644
--- a/Geo/GModelIO_MSH2.cpp
+++ b/Geo/GModelIO_MSH2.cpp
@@ -1070,7 +1070,8 @@ int GModel::writePartitionedMSH(const std::string &baseName, bool binary,
                                 bool saveAll, bool saveParametric,
                                 double scalingFactor)
 {
-  int index = 0;
+  int numElements;
+  int startNum = 0;
   for(std::set<int>::iterator it = meshPartitions.begin();
       it != meshPartitions.end(); it++){
     int partition = *it;
@@ -1078,11 +1079,11 @@ int GModel::writePartitionedMSH(const std::string &baseName, bool binary,
     std::ostringstream sstream;
     sstream << baseName << "_" << std::setw(6) << std::setfill('0') << partition;
 
-    int startNum = index ? getNumElementsMSH(this, saveAll, partition) : 0;
+    numElements = getNumElementsMSH(this, saveAll, partition);
     Msg::Info("Writing partition %d in file '%s'", partition, sstream.str().c_str());
     _writeMSH2(sstream.str(), 2.2, binary, saveAll, saveParametric,
                scalingFactor, startNum, partition);
-    index++;
+    startNum += numElements; // update for next iteration in the loop
   }
 
 #if 0
-- 
GitLab