From fecf9c26cfef2616c6024e471668b1d85a65ffa9 Mon Sep 17 00:00:00 2001
From: Matti Pellika <matti.pellikka@tut.fi>
Date: Fri, 1 Jan 2010 12:37:57 +0000
Subject: [PATCH] Save mesh elements of homology generators in GModel and MSH
 file as new physical entities.

---
 Geo/ChainComplex.cpp       | 22 ++++++++++++++++++----
 Geo/GModel.h               |  7 +++++--
 Geo/Homology.h             |  2 +-
 Post/PViewDataGModelIO.cpp |  2 +-
 4 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/Geo/ChainComplex.cpp b/Geo/ChainComplex.cpp
index 1d86167fb6..1e32afa678 100644
--- a/Geo/ChainComplex.cpp
+++ b/Geo/ChainComplex.cpp
@@ -885,10 +885,24 @@ void Chain::createPView(){
     data.insert(std::make_pair(e->getNum(), coeffs));
   }
   
-  std::map<int, std::vector<MElement*> > map;
-  map.insert(std::make_pair(0, elements));
-  _model->storeElementsInEntities(map);
-
+  int max[4];
+  for(int i = 0; i < 4; i++) max[i] = _model->getMaxElementaryNumber(i);
+  int entityNum = *std::max_element(max,max+4) + 1;
+  for(int i = 0; i < 4; i++) max[i] = _model->getMaxPhysicalNumber(i);
+  int physicalNum = *std::max_element(max,max+4) + 1;
+  
+  std::map<int, std::vector<MElement*> > entityMap;
+  //int entityNum = _model->getMaxElementaryNumber(getDim())+1;
+  entityMap[entityNum] = elements;
+  std::map<int, std::map<int, std::string> > physicalMap;
+  std::map<int, std::string> physicalInfo;
+  //int physicalNum = _model->getMaxPhysicalNumber(getDim())+1; 
+  physicalInfo[physicalNum]=getName();
+  physicalMap[entityNum] = physicalInfo;
+  
+  _model->storeChain(getDim(), entityMap, physicalMap);
+  _model->setPhysicalName(getName(), getDim(), physicalNum);
+  
   if(!data.empty()) PView *chain = new PView(getName(), "ElementData", getGModel(), data, 0, 1);
   
   return;
diff --git a/Geo/GModel.h b/Geo/GModel.h
index 1ab1991003..2346ff5c4c 100644
--- a/Geo/GModel.h
+++ b/Geo/GModel.h
@@ -443,8 +443,11 @@ class GModel
 
   static void registerBindings(binding *b);
 
-  void storeElementsInEntities(std::map<int, std::vector<MElement*> > &map){
-    _storeElementsInEntities(map);
+  // Store mesh elements of a chain in a new elementary and physical entity
+  void storeChain(int dim, std::map<int, std::vector<MElement*> > &entityMap, 
+                 std::map<int, std::map<int, std::string> > &physicalMap){
+    _storeElementsInEntities(entityMap);
+    _storePhysicalTagsInEntities(dim, physicalMap);
   }
 };
 
diff --git a/Geo/Homology.h b/Geo/Homology.h
index 3dd6e2b7e6..57786ec3b2 100644
--- a/Geo/Homology.h
+++ b/Geo/Homology.h
@@ -108,7 +108,7 @@ class Homology
    
    // write the generators to a file
    bool writeGeneratorsMSH(std::string fileName, bool binary=false){
-     if(!_model->writeMSH(fileName, 2.0, binary, true, false, 1.0, false)) return false;
+     if(!_model->writeMSH(fileName, 2.0, binary, false, false, 1.0, false)) return false;
      for(int i = 0; i < 4; i++){
        for(int j = 0; j < _generators[i].size(); j++){
          Chain* chain = _generators[i].at(j);
diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp
index 0cad126200..48304312c7 100644
--- a/Post/PViewDataGModelIO.cpp
+++ b/Post/PViewDataGModelIO.cpp
@@ -117,7 +117,7 @@ bool PViewDataGModel::writeMSH(std::string fileName, bool binary)
 
   GModel *model = _steps[0]->getModel();
 
-  if(!model->writeMSH(fileName, 2.0, binary, true, false, 1.0, false)) return false;
+  if(!model->writeMSH(fileName, 2.0, binary, false, false, 1.0, false)) return false;
 
   // append data
   FILE *fp = fopen(fileName.c_str(), binary ? "ab" : "a");
-- 
GitLab