From 4fdd4d7adadb2ecda624c902b3dd08880a186e63 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 6 Sep 2013 08:34:58 +0000
Subject: [PATCH] adding partition and saveInterpMat option to
 PVIewData::writeMSH

---
 Post/PViewData.h           |  3 ++-
 Post/PViewDataGModel.h     |  3 ++-
 Post/PViewDataGModelIO.cpp | 17 ++++++++++++-----
 Post/PViewDataIO.cpp       |  3 ++-
 Post/PViewDataList.h       |  3 ++-
 Post/PViewDataListIO.cpp   | 13 +++++++++----
 6 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/Post/PViewData.h b/Post/PViewData.h
index 6d6bd13f52..6f98f2df2f 100644
--- a/Post/PViewData.h
+++ b/Post/PViewData.h
@@ -270,7 +270,8 @@ class PViewData {
   virtual bool writePOS(const std::string &fileName, bool binary=false,
                         bool parsed=true, bool append=false);
   virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false,
-                        bool savemesh=true, bool multipleView=false);
+                        bool savemesh=true, bool multipleView=false,
+                        int partitionNum=0, bool saveInterpolationMatrices=true);
   virtual bool writeMED(const std::string &fileName);
   virtual bool toVector(std::vector<std::vector<double> > &vec);
   virtual bool fromVector(const std::vector<std::vector<double> > &vec);
diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h
index b29a023907..bf3d53ad36 100644
--- a/Post/PViewDataGModel.h
+++ b/Post/PViewDataGModel.h
@@ -250,7 +250,8 @@ class PViewDataGModel : public PViewData {
                double time, int partition, int numComp, int numNodes,
                const std::string &interpolationScheme);
   virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false,
-                        bool savemesh=true, bool multipleView=false);
+                        bool savemesh=true, bool multipleView=false,
+                        int partitionNum=0, bool saveInterpolationMatrices=true);
   bool readMED(const std::string &fileName, int fileIndex);
   bool writeMED(const std::string &fileName);
 };
diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp
index 6d79ff9ad3..dbe8f67034 100644
--- a/Post/PViewDataGModelIO.cpp
+++ b/Post/PViewDataGModelIO.cpp
@@ -133,7 +133,8 @@ bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fi
 }
 
 bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool binary,
-                               bool savemesh, bool multipleView)
+                               bool savemesh, bool multipleView, int partitionNum,
+                               bool saveInterpolationMatrices)
 {
   if(_steps.empty()) return true;
 
@@ -181,7 +182,7 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool
     }
   }
 
-  if(haveInterpolationMatrices()){
+  if(saveInterpolationMatrices && haveInterpolationMatrices()){
     fprintf(fp, "$InterpolationScheme\n");
     fprintf(fp, "\"INTERPOLATION_SCHEME\"\n");
     fprintf(fp, "%d\n", (int)_interpolation.size());
@@ -212,7 +213,10 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool
         fprintf(fp, "$NodeData\n");
         fprintf(fp, "1\n\"%s\"\n", getName().c_str());
         fprintf(fp, "1\n%.16g\n", _steps[step]->getTime());
-        fprintf(fp, "3\n%d\n%d\n%d\n", step, numComp, numEnt);
+        if(partitionNum)
+          fprintf(fp, "4\n%d\n%d\n%d\n%d\n", step, numComp, numEnt, partitionNum);
+        else
+          fprintf(fp, "3\n%d\n%d\n%d\n", step, numComp, numEnt);
         for(int i = 0; i < _steps[step]->getNumData(); i++){
           if(_steps[step]->getData(i)){
             MVertex *v = _steps[step]->getModel()->getMeshVertexByTag(i);
@@ -242,13 +246,16 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, double version, bool
           fprintf(fp, "$ElementNodeData\n");
         else
           fprintf(fp, "$ElementData\n");
-        if(haveInterpolationMatrices())
+        if(saveInterpolationMatrices && haveInterpolationMatrices())
           fprintf(fp, "2\n\"%s\"\n\"INTERPOLATION_SCHEME\"\n", getName().c_str());
         else
           fprintf(fp, "1\n\"%s\"\n", getName().c_str());
 
         fprintf(fp, "1\n%.16g\n", _steps[step]->getTime());
-        fprintf(fp, "3\n%d\n%d\n%d\n", step, numComp, numEnt);
+        if(partitionNum)
+          fprintf(fp, "4\n%d\n%d\n%d\n%d\n", step, numComp, numEnt, partitionNum);
+        else
+          fprintf(fp, "3\n%d\n%d\n%d\n", step, numComp, numEnt);
         for(int i = 0; i < _steps[step]->getNumData(); i++){
           if(_steps[step]->getData(i)){
             MElement *e = model->getMeshElementByTag(i);
diff --git a/Post/PViewDataIO.cpp b/Post/PViewDataIO.cpp
index 6b571abff5..9e3eac75e8 100644
--- a/Post/PViewDataIO.cpp
+++ b/Post/PViewDataIO.cpp
@@ -179,7 +179,8 @@ bool PViewData::writePOS(const std::string &fileName, bool binary, bool parsed,
 }
 
 bool PViewData::writeMSH(const std::string &fileName, double version, bool binary,
-                         bool savemesh, bool multipleView)
+                         bool savemesh, bool multipleView, int partitionNum,
+                         bool saveInterpolationMatrices)
 {
   Msg::Error("MSH export not implemented for this view type");
   return false;
diff --git a/Post/PViewDataList.h b/Post/PViewDataList.h
index bea48f95f6..5b2dd2abb1 100644
--- a/Post/PViewDataList.h
+++ b/Post/PViewDataList.h
@@ -127,7 +127,8 @@ class PViewDataList : public PViewData {
   bool writePOS(const std::string &fileName, bool binary=false, bool parsed=true,
                 bool append=false);
   virtual bool writeMSH(const std::string &fileName, double version=2.2, bool binary=false,
-                        bool savemesh=true, bool multipleView=false);
+                        bool savemesh=true, bool multipleView=false,
+                        int partitionNum=0, bool saveInterpolationMatrices=true);
   virtual void importLists(int N[24], std::vector<double> *V[24]);
   virtual void getListPointers(int N[24], std::vector<double> *V[24]);
 };
diff --git a/Post/PViewDataListIO.cpp b/Post/PViewDataListIO.cpp
index 8ba69355a7..6ad08a7f14 100644
--- a/Post/PViewDataListIO.cpp
+++ b/Post/PViewDataListIO.cpp
@@ -527,7 +527,8 @@ static void createElements(std::vector<double> &list, int nbelm, int nbnod,
 }
 
 bool PViewDataList::writeMSH(const std::string &fileName, double version, bool binary,
-                             bool savemesh, bool multipleView)
+                             bool savemesh, bool multipleView,
+                             int partitionNum, bool saveInterpolationMatrices)
 {
   if(_adaptive){
     Msg::Warning("Writing adapted dataset (will only export current time step)");
@@ -588,7 +589,7 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b
   }
   fprintf(fp, "$EndElements\n");
 
-  if(haveInterpolationMatrices()){
+  if(saveInterpolationMatrices && haveInterpolationMatrices()){
     fprintf(fp, "$InterpolationScheme\n");
     fprintf(fp, "\"INTERPOLATION_SCHEME\"\n");
     fprintf(fp, "%d\n", (int)_interpolation.size());
@@ -612,12 +613,16 @@ bool PViewDataList::writeMSH(const std::string &fileName, double version, bool b
 
   for(int ts = 0; ts < NbTimeStep; ts++){
     fprintf(fp, "$ElementNodeData\n");
-    if(haveInterpolationMatrices())
+    if(saveInterpolationMatrices && haveInterpolationMatrices())
       fprintf(fp, "2\n\"%s\"\n\"INTERPOLATION_SCHEME\"\n", getName().c_str());
     else
       fprintf(fp, "1\n\"%s\"\n", getName().c_str());
     fprintf(fp, "1\n%.16g\n", getTime(ts));
-    fprintf(fp, "3\n%d\n%d\n%d\n", ts, numComponents, (int)elements.size());
+    if(partitionNum)
+      fprintf(fp, "4\n%d\n%d\n%d\n%d\n", ts, numComponents, (int)elements.size(),
+              partitionNum);
+    else
+      fprintf(fp, "3\n%d\n%d\n%d\n", ts, numComponents, (int)elements.size());
     num = 0;
     for(int i = 0; i < 24; i++){
       std::vector<double> *list = 0;
-- 
GitLab