From d710ef89198d7f4bf798d136780a302e362d4aec Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Wed, 16 Mar 2011 09:37:35 +0000
Subject: [PATCH] Merge

---
 AMDiS/src/parallel/MeshDistributor.cc  | 62 +++++++++++++++++++++++++-
 AMDiS/src/parallel/MeshManipulation.cc |  4 +-
 AMDiS/src/parallel/ParallelDebug.cc    |  2 +-
 AMDiS/src/parallel/PetscSolver.cc      |  5 ++-
 4 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/AMDiS/src/parallel/MeshDistributor.cc b/AMDiS/src/parallel/MeshDistributor.cc
index b8b0783c..bc942d23 100644
--- a/AMDiS/src/parallel/MeshDistributor.cc
+++ b/AMDiS/src/parallel/MeshDistributor.cc
@@ -687,7 +687,6 @@ namespace AMDiS {
 
     double first = MPI::Wtime();
 
-
     // === If mesh has not been changed on all ranks, return. ===
 
     int recvAllValues = 0;
@@ -803,6 +802,38 @@ namespace AMDiS {
 
       MSG("Imbalancing factor: %.1f\%\n", imbalance);
     }
+
+
+    {
+      TraverseStack stack;
+      ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL | Mesh::FILL_COORDS);
+      while (elInfo) {
+	if (elInfo->getElement()->getIndex() == 195) {
+	  MSG("FOUND MACRO 195: %d %f %f %f\n", 
+	      elInfo->getElement()->getDof(2, 0),
+	      elInfo->getCoord(2)[0],
+	      elInfo->getCoord(2)[1],
+	      elInfo->getCoord(2)[2]);
+	}
+	elInfo = stack.traverseNext(elInfo);
+      }
+    }
+
+
+    {
+      if (mpiRank == 0) {
+	WorldVector<double> c;
+	mesh->getDofIndexCoords(9, feSpace, c);
+	MSG("9-COORDS %f %f %f\n", c[0], c[1], c[2]);
+      } 
+
+      if (mpiRank == 2) {
+	WorldVector<double> c;
+	mesh->getDofIndexCoords(9, feSpace, c);
+	MSG("9-COORDS %f %f %f\n", c[0], c[1], c[2]);
+      } 
+
+    }
   }
 
   
@@ -1209,6 +1240,11 @@ namespace AMDiS {
     updateInteriorBoundaryInfo();
     updateLocalGlobalNumbering();
 
+    // === Update periodic mapping, if there are periodic boundaries. ===
+
+    createPeriodicMap();
+
+
 #if (DEBUG != 0)
     MSG("AMDiS runs in debug mode, so make some test ...\n");
 
@@ -1217,6 +1253,7 @@ namespace AMDiS {
     ParallelDebug::testAllElements(*this);
     ParallelDebug::testDoubleDofs(mesh);
     ParallelDebug::testInteriorBoundary(*this);
+    ParallelDebug::testPeriodicBoundary(*this);
     ParallelDebug::printBoundaryInfo(*this);
 
     MSG("Debug mode tests finished!\n");
@@ -1809,6 +1846,8 @@ namespace AMDiS {
     for (RankToBoundMap::iterator it = periodicBoundary.boundary.begin();
 	 it != periodicBoundary.boundary.end(); ++it) {
 
+      MSG("PER BOUND WITH RANK %d!\n", it->first);
+
       if (it->first == mpiRank) {
 	TEST_EXIT_DBG(it->second.size() % 2 == 0)("Should not happen!\n");
 
@@ -1835,6 +1874,8 @@ namespace AMDiS {
 	    DegreeOfFreedom globalDof1 = mapLocalGlobalDofs[*(dofs1[j])];
 
 	    if (periodicDofAssociations[globalDof0].count(type) == 0) {
+	      MSG("SET A: %d   %d <-> %d\n", type, globalDof0, globalDof1);
+
 	      periodicDof[type][globalDof0] = globalDof1;
 	      periodicDofAssociations[globalDof0].insert(type);
 	    }
@@ -1847,10 +1888,20 @@ namespace AMDiS {
 	for (vector<AtomicBoundary>::iterator boundIt = it->second.begin();
 	     boundIt != it->second.end(); ++boundIt) {
 
+	  MSG("BOUND %d %d %d - %d %d %d\n",
+	      boundIt->rankObj.elIndex, boundIt->rankObj.subObj, boundIt->rankObj.ithObj,
+	      boundIt->neighObj.elIndex, boundIt->neighObj.subObj, boundIt->neighObj.ithObj);
+
+
+
 	  int nDofs = dofs.size();
 	  boundIt->rankObj.el->getVertexDofs(feSpace, boundIt->rankObj, dofs);
 	  boundIt->rankObj.el->getNonVertexDofs(feSpace, boundIt->rankObj, dofs);
 
+	  for (int i = nDofs; i < dofs.size(); i++) {
+	    MSG("   dof %d\n", *(dofs[i]));
+	  }
+
 	  for (unsigned int i = 0; i < (dofs.size() - nDofs); i++)
 	    rankToDofType[it->first].push_back(boundIt->type);
 	}
@@ -1866,9 +1917,10 @@ namespace AMDiS {
     }
 
     stdMpi.updateSendDataSize();
-
     stdMpi.startCommunication();
 
+    MSG("---------");
+
     // === The rank has received the dofs from the rank on the other side of ===
     // === the boundary. Now it can use them to create the mapping between   ===
     // === the periodic dofs in this rank and the corresponding periodic     ===
@@ -1877,6 +1929,7 @@ namespace AMDiS {
 
     for (RankToBoundMap::iterator it = periodicBoundary.boundary.begin();
 	 it != periodicBoundary.boundary.end(); ++it) {
+      MSG("PER BOUND WITH RANK %d!\n", it->first);
       DofContainer& dofs = rankPeriodicDofs[it->first];
       vector<int>& types = rankToDofType[it->first];
 
@@ -1891,6 +1944,8 @@ namespace AMDiS {
 	// Check if this global dof with the corresponding boundary type was
 	// not added before by another periodic boundary from other rank.
 	if (periodicDofAssociations[globalDofIndex].count(type) == 0) {
+	  MSG("SET B at POS %d: %d   %d/%d <-> %d\n", i, type, *(dofs[i]), globalDofIndex, mapGlobalDofIndex);
+
 	  periodicDof[type][globalDofIndex] = mapGlobalDofIndex;
 	  periodicDofAssociations[globalDofIndex].insert(type);
 	}
@@ -1950,6 +2005,9 @@ namespace AMDiS {
 			periodicDof[perIt->first][dofIt->second] == dofIt->first)
 	    ("Should not happen!\n");
 
+	  MSG("SET C: %d   %d <-> %d\n", 
+	      perIt->first, dofIt->second, dofIt->first);
+
 	  periodicDof[perIt->first][dofIt->second] = dofIt->first;
 	}
       }
diff --git a/AMDiS/src/parallel/MeshManipulation.cc b/AMDiS/src/parallel/MeshManipulation.cc
index bd27f89a..e17f0011 100644
--- a/AMDiS/src/parallel/MeshManipulation.cc
+++ b/AMDiS/src/parallel/MeshManipulation.cc
@@ -141,7 +141,7 @@ namespace AMDiS {
 	    el1->getNonVertexDofs(feSpace, b1, dofs1);
 
 #if (DEBUG != 0)
-	    //	    debug::testDofsByCoords(feSpace, dofs0, dofs1);
+	    debug::testDofsByCoords(feSpace, dofs0, dofs1);
 #endif
 
  	    for (unsigned int i = 0; i < dofs0.size(); i++)
@@ -183,7 +183,7 @@ namespace AMDiS {
 	    el1->getNonVertexDofs(feSpace, b1, dofs1);
 
 #if (DEBUG != 0)
-	    //	    debug::testDofsByCoords(feSpace, dofs0, dofs1);
+	    debug::testDofsByCoords(feSpace, dofs0, dofs1);
 #endif
 
  	    for (unsigned int i = 0; i < dofs0.size(); i++)
diff --git a/AMDiS/src/parallel/ParallelDebug.cc b/AMDiS/src/parallel/ParallelDebug.cc
index a4bc7ea0..dd31b2f1 100644
--- a/AMDiS/src/parallel/ParallelDebug.cc
+++ b/AMDiS/src/parallel/ParallelDebug.cc
@@ -595,7 +595,7 @@ namespace AMDiS {
     TraverseStack stack;
     ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
     while (elInfo) {
-      for (int i = 0; i < 3; i++) {
+      for (int i = 0; i < mesh->getGeo(VERTEX); i++) {
 	WorldVector<double> &c = elInfo->getCoord(i);
 	if (cMap.count(c) == 0) {
 	  cMap[c] = elInfo->getElement()->getDof(i, 0);
diff --git a/AMDiS/src/parallel/PetscSolver.cc b/AMDiS/src/parallel/PetscSolver.cc
index 5353ac6f..02185b26 100644
--- a/AMDiS/src/parallel/PetscSolver.cc
+++ b/AMDiS/src/parallel/PetscSolver.cc
@@ -77,7 +77,7 @@ namespace AMDiS {
 
 
     // === Traverse all rows of the dof matrix and insert row wise the values ===
-    // === to the petsc matrix.                                               ===
+    // === to the PETSc matrix.                                               ===
 
     for (cursor_type cursor = begin<row>(mat->getBaseMatrix()), 
 	   cend = end<row>(mat->getBaseMatrix()); cursor != cend; ++cursor) {
@@ -91,6 +91,7 @@ namespace AMDiS {
 	// === Row DOF index is not periodic. ===
 
 	// Calculate PETSc row index.
+
 	int rowIndex = globalRowDof * dispMult + dispAddRow;
 
 	cols.clear();
@@ -285,7 +286,7 @@ namespace AMDiS {
       // Calculate global row index of the dof.
       DegreeOfFreedom globalRowDof = 
 	meshDistributor->mapLocalToGlobal(dofIt.getDOFIndex());
-      // Calculate petsc index of the row dof.
+      // Calculate PETSc index of the row dof.
       int index = globalRowDof * dispMult + dispAdd;
 
       if (meshDistributor->isPeriodicDof(globalRowDof)) {
-- 
GitLab