From 613caf74534d35729dc1189782ab78ef0ab73b00 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Tue, 30 Nov 2010 11:02:46 +0000
Subject: [PATCH] Transfer of DOFVectors in mesh repartitioning.

---
 AMDiS/src/MeshStructure.cc            | 61 +++++++++++++++++++++++++++
 AMDiS/src/MeshStructure.h             | 11 +++++
 AMDiS/src/io/ArhReader.cc             |  2 +-
 AMDiS/src/io/ArhWriter.cc             |  2 +-
 AMDiS/src/parallel/MeshDistributor.cc | 11 +++--
 AMDiS/src/parallel/MeshDistributor.h  |  3 ++
 AMDiS/src/parallel/StdMpi.cc          | 35 +++++++++++++++
 AMDiS/src/parallel/StdMpi.h           |  6 +++
 8 files changed, 125 insertions(+), 6 deletions(-)

diff --git a/AMDiS/src/MeshStructure.cc b/AMDiS/src/MeshStructure.cc
index 71d98b35..9f2e35a9 100644
--- a/AMDiS/src/MeshStructure.cc
+++ b/AMDiS/src/MeshStructure.cc
@@ -6,6 +6,7 @@
 #include "ElInfo.h"
 #include "RefinementManager.h"
 #include "Debug.h"
+#include "DOFVector.h"
 
 namespace AMDiS {
 
@@ -356,4 +357,64 @@ namespace AMDiS {
   {
     return (other.getCode() == code);
   }
+
+
+  void MeshStructure::getMeshStructureValues(Mesh *mesh,
+					     int macroElIndex,
+					     const DOFVector<double>* vec,
+					     std::vector<double>& values)
+  {
+    FUNCNAME("MeshStructure::getMeshStructureValues()");
+
+    values.clear();
+
+    TraverseStack stack;
+    ElInfo *elInfo = stack.traverseFirstOneMacro(mesh, macroElIndex, -1, 
+						 Mesh::CALL_EVERY_EL_PREORDER);
+    while (elInfo) {
+      if (elInfo->getLevel() == 0) {
+	for (int i = 0; i < mesh->getGeo(VERTEX); i++)
+	  values.push_back((*vec)[elInfo->getElement()->getDof(i, 0)]);
+      } else {
+	if (!elInfo->getElement()->isLeaf())
+	  values.push_back((*vec)[elInfo->getElement()->getChild(0)->getDof(mesh->getDim(), 0)]);
+      }
+
+      elInfo = stack.traverseNext(elInfo);
+    }
+  }
+
+
+  void MeshStructure::setMeshStructureValues(Mesh *mesh,
+					     int macroElIndex,
+					     DOFVector<double>* vec,
+					     const std::vector<double>& values)
+  {
+    FUNCNAME("MeshStructure::setMeshStructureValues()");
+
+    TEST_EXIT_DBG(values.size() >= mesh->getGeo(VERTEX))("Should not happen!\n");
+
+    unsigned int counter = 0;
+
+    TraverseStack stack;
+    ElInfo *elInfo = stack.traverseFirstOneMacro(mesh, macroElIndex, -1, 
+						 Mesh::CALL_EVERY_EL_PREORDER);
+    while (elInfo) {
+      if (elInfo->getLevel() == 0) {
+	for (int i = 0; i < mesh->getGeo(VERTEX); i++)
+	  (*vec)[elInfo->getElement()->getDof(i, 0)] = values[counter++];
+      } else {
+	if (!elInfo->getElement()->isLeaf()) {
+	  TEST_EXIT_DBG(counter < values.size())("Should not happen!\n");
+
+	  (*vec)[elInfo->getElement()->getChild(0)->getDof(mesh->getDim(), 0)] =
+	    values[counter++];
+	}
+      }
+
+      elInfo = stack.traverseNext(elInfo);
+    }
+      
+  }
+
 }
diff --git a/AMDiS/src/MeshStructure.h b/AMDiS/src/MeshStructure.h
index b07842ae..73a14116 100644
--- a/AMDiS/src/MeshStructure.h
+++ b/AMDiS/src/MeshStructure.h
@@ -150,6 +150,17 @@ namespace AMDiS {
     /// Returns true, if the given mesh structure code is equal to this one.
     bool compare(MeshStructure &other);
 
+    void getMeshStructureValues(Mesh *mesh,
+				int macroElIndex,
+				const DOFVector<double>* vec,
+				std::vector<double>& values);
+
+
+    void setMeshStructureValues(Mesh *mesh,
+				int macroElIndex,
+				DOFVector<double>* vec,
+				const std::vector<double>& values);
+
   protected:
     /// Insert a new element to the structure code. Is used by the init function.
     void insertElement(bool isLeaf);
diff --git a/AMDiS/src/io/ArhReader.cc b/AMDiS/src/io/ArhReader.cc
index f05fe9fb..48e84bdb 100644
--- a/AMDiS/src/io/ArhReader.cc
+++ b/AMDiS/src/io/ArhReader.cc
@@ -107,7 +107,7 @@ namespace AMDiS {
     while (elInfo) {
       if (!macroElement) {
 	Element *mEl = elInfo->getMacroElement()->getElement();
-	for (int i = 0; i <= mesh->getDim(); i++)
+	for (int i = 0; i < mesh->getGeo(VERTEX); i++)
 	  (*vec)[mEl->getDof(i, 0)] = values[valuePos++];	
 	macroElement = true;
       }
diff --git a/AMDiS/src/io/ArhWriter.cc b/AMDiS/src/io/ArhWriter.cc
index c8eacac4..0fe46f7b 100644
--- a/AMDiS/src/io/ArhWriter.cc
+++ b/AMDiS/src/io/ArhWriter.cc
@@ -73,7 +73,7 @@ namespace AMDiS {
 	for (unsigned int i = 0; i < vecs.size(); i++) {
 	  values[i].clear();
 
-	  for (int j = 0; j <= mesh->getDim(); j++)
+	  for (int j = 0; j < mesh->getGeo(VERTEX); j++)
 	    values[i].push_back((*vecs[i])[elInfo->getElement()->getDof(j, 0)]);
 	}
       }
diff --git a/AMDiS/src/parallel/MeshDistributor.cc b/AMDiS/src/parallel/MeshDistributor.cc
index de96eb81..a7d22204 100644
--- a/AMDiS/src/parallel/MeshDistributor.cc
+++ b/AMDiS/src/parallel/MeshDistributor.cc
@@ -995,7 +995,7 @@ namespace AMDiS {
       elIndexMap[(*it)->getIndex()] = *it;
 
     
-    // === Craete set of all new macro elements this rank will receive from ===
+    // === Create set of all new macro elements this rank will receive from ===
     // === other ranks.                                                     ===
 
     std::set<MacroElement*> newMacroEl;
@@ -1033,6 +1033,8 @@ namespace AMDiS {
     // === Send and receive mesh structure codes. ===
 
     std::map<int, MeshCodeVec> sendCodes;
+    std::map<int, std::vector<std::vector<double> > > sendValues;
+
     for (std::map<int, std::vector<int> >::iterator it = partitioner->getSendElements().begin();
 	 it != partitioner->getSendElements().end(); ++it) {
       for (std::vector<int>::iterator elIt = it->second.begin();
@@ -1040,6 +1042,10 @@ namespace AMDiS {
 	MeshStructure elCode;
 	elCode.init(mesh, *elIt);
 	sendCodes[it->first].push_back(elCode);
+
+	std::vector<double> valVec;
+	elCode.getMeshStructureValues(mesh, *elIt, testVec, valVec);
+	sendValues[it->first].push_back(valVec);
       }
     }
 
@@ -1136,9 +1142,6 @@ namespace AMDiS {
 
     MSG("Debug mode tests finished!\n");
 #endif
-
-
-    MSG("DONE\n");
   }
 
 
diff --git a/AMDiS/src/parallel/MeshDistributor.h b/AMDiS/src/parallel/MeshDistributor.h
index 2cd48236..45724f9d 100644
--- a/AMDiS/src/parallel/MeshDistributor.h
+++ b/AMDiS/src/parallel/MeshDistributor.h
@@ -402,6 +402,9 @@ namespace AMDiS {
 	data[dofMap[v1]] = v2;
       }
     }
+
+  public:
+    DOFVector<double>* testVec;
 		        
   protected:
     ///
diff --git a/AMDiS/src/parallel/StdMpi.cc b/AMDiS/src/parallel/StdMpi.cc
index b3c27d11..91602ca1 100644
--- a/AMDiS/src/parallel/StdMpi.cc
+++ b/AMDiS/src/parallel/StdMpi.cc
@@ -61,6 +61,16 @@ namespace AMDiS {
     return data.size();
   }
 
+  int intSizeOf(std::vector<std::vector<double> > &data)
+  {
+    int size = 1;
+
+    for (unsigned int i = 0; i < data.size(); i++)
+      size += data[i].size() + 1;
+    
+    return size;
+  }
+
   void makeBuf(int &data, int *buf)
   {
     buf[0] = data;
@@ -269,4 +279,29 @@ namespace AMDiS {
     }
   }
 
+  void makeBuf(std::vector<std::vector<double> > &data, double *buf)
+  {
+    buf[0] = data.size();
+    int counter = 1;
+
+    for (unsigned int i = 0; i < data.size(); i++) {
+      buf[counter++] = data[i].size();
+      for (unsigned int j = 0; j < data[i].size(); j++)
+	buf[counter++] = data[i][j];
+    }
+  }
+
+  void makeFromBuf(std::vector<std::vector<double> > &data, double *buf, int bufSize)
+  {
+    data.resize(buf[0]);
+    int counter = 1;
+
+    for (unsigned int i = 0; i < data.size(); i++) {
+      data[i].resize(buf[counter++]);
+      
+      for (unsigned int j = 0; j < data[i].size(); j++)
+	data[i][j] = buf[counter++];
+    }
+  }
+
 }
diff --git a/AMDiS/src/parallel/StdMpi.h b/AMDiS/src/parallel/StdMpi.h
index c24b530d..4855d7ae 100644
--- a/AMDiS/src/parallel/StdMpi.h
+++ b/AMDiS/src/parallel/StdMpi.h
@@ -52,6 +52,8 @@ namespace AMDiS {
 
   int intSizeOf(std::vector<const DegreeOfFreedom*> &data);
 
+  int intSizeOf(std::vector<std::vector<double> > &data);
+
   void makeBuf(int &data, int *buf);
 
   void makeFromBuf(int &data, int *buf, int bufSize);
@@ -92,6 +94,10 @@ namespace AMDiS {
 
   void makeFromBuf(std::vector<BoundaryObject> &data, int *buf, int bufSize);
 
+  void makeBuf(std::vector<std::vector<double> > &data, double *buf);
+
+  void makeFromBuf(std::vector<std::vector<double> > &data, double *buf, int bufSize);
+
 
 
   template<typename SendT, typename RecvT=SendT>
-- 
GitLab