From 4354cab850a095e993408cf8f356a03a4de7d4e8 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Fri, 7 Jan 2011 10:23:03 +0000
Subject: [PATCH] Fixed some more periodic BC problems in 3D. Should work now
 correctly.

---
 AMDiS/src/parallel/ElementObjectData.cc |   7 +
 AMDiS/src/parallel/ElementObjectData.h  |  96 ++++++++-----
 AMDiS/src/parallel/MeshDistributor.cc   | 180 +++++++++++++++---------
 AMDiS/src/parallel/MeshDistributor.h    |  89 ++++++------
 4 files changed, 225 insertions(+), 147 deletions(-)

diff --git a/AMDiS/src/parallel/ElementObjectData.cc b/AMDiS/src/parallel/ElementObjectData.cc
index 18c072be..3e22eaa1 100644
--- a/AMDiS/src/parallel/ElementObjectData.cc
+++ b/AMDiS/src/parallel/ElementObjectData.cc
@@ -152,6 +152,9 @@ namespace AMDiS {
       serialize(out, it->second);
     }
 
+    SerUtil::serialize(out, periodicVertices);
+    SerUtil::serialize(out, periodicEdges);
+    SerUtil::serialize(out, periodicFaces);
   }
 
 
@@ -257,6 +260,10 @@ namespace AMDiS {
       deserialize(in, data);
       faceInRank[face] = data;
     }
+
+    SerUtil::deserialize(in, periodicVertices);
+    SerUtil::deserialize(in, periodicEdges);
+    SerUtil::deserialize(in, periodicFaces);  
   }
 
 
diff --git a/AMDiS/src/parallel/ElementObjectData.h b/AMDiS/src/parallel/ElementObjectData.h
index 317b9de8..6c900bff 100644
--- a/AMDiS/src/parallel/ElementObjectData.h
+++ b/AMDiS/src/parallel/ElementObjectData.h
@@ -34,6 +34,15 @@
 
 namespace AMDiS {
 
+  using namespace std;
+
+  template<typename T>
+  struct PerBoundMap 
+  {
+    typedef map<pair<T, T>, BoundaryType> type;
+    typedef typename type::iterator iterator;
+  };
+
   struct ElementObjectData {
     ElementObjectData(int a = -1, int b = 0, BoundaryType c = INTERIOR)
       : elIndex(a),
@@ -48,7 +57,7 @@ namespace AMDiS {
     BoundaryType boundaryType;
 
 
-    void serialize(std::ostream &out) const
+    void serialize(ostream &out) const
     {
       SerUtil::serialize(out, elIndex);
       SerUtil::serialize(out, ithObject);
@@ -56,7 +65,7 @@ namespace AMDiS {
     }
 
 
-    void deserialize(std::istream &in)
+    void deserialize(istream &in)
     {
       SerUtil::deserialize(in, elIndex);
       SerUtil::deserialize(in, ithObject);
@@ -90,7 +99,6 @@ namespace AMDiS {
 
     void addVertex(Element *el, int ith, BoundaryType bound = INTERIOR)
     {
-      //    DegreeOfFreedom vertex = el->getObject<DegreeOfFreedom>(ith);
       DegreeOfFreedom vertex = el->getDof(ith, 0);
       int elIndex = el->getIndex();
       ElementObjectData elObj(elIndex, ith, bound);
@@ -102,7 +110,6 @@ namespace AMDiS {
 
     void addEdge(Element *el, int ith, BoundaryType bound = INTERIOR)
     {
-      //      DofEdge edge = el->getObject<DofEdge>(ith);
       DofEdge edge = el->getEdge(ith);
       int elIndex = el->getIndex();
       ElementObjectData elObj(elIndex, ith, bound);
@@ -114,7 +121,6 @@ namespace AMDiS {
 
     void addFace(Element *el, int ith, BoundaryType bound = INTERIOR)
     {
-      //      DofFace face = el->getObject<DofFace>(ith);
       DofFace face = el->getFace(ith);
       int elIndex = el->getIndex();
       ElementObjectData elObj(elIndex, ith, bound);
@@ -136,8 +142,23 @@ namespace AMDiS {
 	addFace(el, i);
     }
 
+    void addPeriodicVertex(pair<DegreeOfFreedom, DegreeOfFreedom> perVertex, 
+			   BoundaryType bType)
+    {
+      periodicVertices[perVertex] = bType;
+    }
+    
+    void addPeriodicEdge(pair<DofEdge, DofEdge> perEdge, BoundaryType bType)
+    {
+      periodicEdges[perEdge] = bType;
+    }
+
+    void addPeriodicFace(pair<DofFace, DofFace> perFace, BoundaryType bType)
+    {
+      periodicFaces[perFace] = bType;
+    }
 
-    void createRankData(std::map<int, int>& macroElementRankMap);
+    void createRankData(map<int, int>& macroElementRankMap);
 
 
     bool iterate(GeoIndex pos)
@@ -200,7 +221,7 @@ namespace AMDiS {
     }
 
 
-    std::map<int, ElementObjectData>& getIterateData()
+    map<int, ElementObjectData>& getIterateData()
     {
       switch (iterGeoPos) {
       case VERTEX:
@@ -274,33 +295,33 @@ namespace AMDiS {
     }
 
 
-    std::vector<ElementObjectData>& getElements(DegreeOfFreedom vertex)
+    vector<ElementObjectData>& getElements(DegreeOfFreedom vertex)
     {
       return vertexElements[vertex];
     }
 
-    std::vector<ElementObjectData>& getElements(DofEdge edge)
+    vector<ElementObjectData>& getElements(DofEdge edge)
     {
       return edgeElements[edge];
     }
 
-    std::vector<ElementObjectData>& getElements(DofFace face)
+    vector<ElementObjectData>& getElements(DofFace face)
     {
       return faceElements[face];
     }
 
 
-    std::map<int, ElementObjectData>& getElementsInRank(DegreeOfFreedom vertex)
+    map<int, ElementObjectData>& getElementsInRank(DegreeOfFreedom vertex)
     {
       return vertexInRank[vertex];
     }
 
-    std::map<int, ElementObjectData>& getElementsInRank(DofEdge edge)
+    map<int, ElementObjectData>& getElementsInRank(DofEdge edge)
     {
       return edgeInRank[edge];
     }
 
-    std::map<int, ElementObjectData>& getElementsInRank(DofFace face)
+    map<int, ElementObjectData>& getElementsInRank(DofFace face)
     {
       return faceInRank[face];
     }
@@ -320,45 +341,50 @@ namespace AMDiS {
       return faceLocalMap[data];
     }
 
-    void serialize(std::ostream &out);
+    void serialize(ostream &out);
 
-    void deserialize(std::istream &in);
+    void deserialize(istream &in);
 
   private:
-    void serialize(std::ostream &out, std::vector<ElementObjectData>& elVec);
+    void serialize(ostream &out, vector<ElementObjectData>& elVec);
 
-    void deserialize(std::istream &in, std::vector<ElementObjectData>& elVec);
+    void deserialize(istream &in, vector<ElementObjectData>& elVec);
 
-    void serialize(std::ostream &out, std::map<int, ElementObjectData>& data);
+    void serialize(ostream &out, map<int, ElementObjectData>& data);
 
-    void deserialize(std::istream &in, std::map<int, ElementObjectData>& data);
+    void deserialize(istream &in, map<int, ElementObjectData>& data);
 
   private:
-    std::map<DegreeOfFreedom, std::vector<ElementObjectData> > vertexElements;
-    std::map<DofEdge, std::vector<ElementObjectData> > edgeElements;
-    std::map<DofFace, std::vector<ElementObjectData> > faceElements;
+    map<DegreeOfFreedom, vector<ElementObjectData> > vertexElements;
+    map<DofEdge, vector<ElementObjectData> > edgeElements;
+    map<DofFace, vector<ElementObjectData> > faceElements;
 
 
-    std::map<ElementObjectData, DegreeOfFreedom> vertexLocalMap;
-    std::map<ElementObjectData, DofEdge> edgeLocalMap;
-    std::map<ElementObjectData, DofFace> faceLocalMap;
+    map<ElementObjectData, DegreeOfFreedom> vertexLocalMap;
+    map<ElementObjectData, DofEdge> edgeLocalMap;
+    map<ElementObjectData, DofFace> faceLocalMap;
 
 
-    std::map<DegreeOfFreedom, int> vertexOwner;
-    std::map<DofEdge, int> edgeOwner;
-    std::map<DofFace, int> faceOwner;
+    map<DegreeOfFreedom, int> vertexOwner;
+    map<DofEdge, int> edgeOwner;
+    map<DofFace, int> faceOwner;
 
 
-    std::map<DegreeOfFreedom, std::map<int, ElementObjectData> > vertexInRank;
-    std::map<DofEdge, std::map<int, ElementObjectData> > edgeInRank;
-    std::map<DofFace, std::map<int, ElementObjectData> > faceInRank;
+    map<DegreeOfFreedom, map<int, ElementObjectData> > vertexInRank;
+    map<DofEdge, map<int, ElementObjectData> > edgeInRank;
+    map<DofFace, map<int, ElementObjectData> > faceInRank;
 
-
-    std::map<DegreeOfFreedom, std::map<int, ElementObjectData> >::iterator vertexIter;
-    std::map<DofEdge, std::map<int, ElementObjectData> >::iterator edgeIter;
-    std::map<DofFace, std::map<int, ElementObjectData> >::iterator faceIter;
+    map<DegreeOfFreedom, map<int, ElementObjectData> >::iterator vertexIter;
+    map<DofEdge, map<int, ElementObjectData> >::iterator edgeIter;
+    map<DofFace, map<int, ElementObjectData> >::iterator faceIter;
 
     GeoIndex iterGeoPos;
+
+  public:
+    // The following three data structures store periodic DOFs, edges and faces.
+    PerBoundMap<DegreeOfFreedom>::type periodicVertices;
+    PerBoundMap<DofEdge>::type periodicEdges;
+    PerBoundMap<DofFace>::type periodicFaces;
   };
 
 }
diff --git a/AMDiS/src/parallel/MeshDistributor.cc b/AMDiS/src/parallel/MeshDistributor.cc
index e21545ae..4e234d5a 100644
--- a/AMDiS/src/parallel/MeshDistributor.cc
+++ b/AMDiS/src/parallel/MeshDistributor.cc
@@ -1323,13 +1323,11 @@ namespace AMDiS {
 	    DofEdge edge2 = neigh->getEdge(elInfo->getOppVertex(i));
 	    BoundaryType boundaryType = elInfo->getBoundary(EDGE, i);
 
-	    periodicEdges[std::make_pair(edge1, edge2)] = boundaryType;
-
+	    elObjects.addPeriodicEdge(std::make_pair(edge1, edge2), boundaryType);
 	    periodicEdgeAssoc[edge1].insert(edge2);
 
-	    periodicVertices[std::make_pair(edge1.first, edge2.first)] = boundaryType;
-	    periodicVertices[std::make_pair(edge1.second, edge2.second)] = boundaryType;
-
+	    elObjects.addPeriodicVertex(std::make_pair(edge1.first, edge2.first), boundaryType);
+	    elObjects.addPeriodicVertex(std::make_pair(edge1.second, edge2.second), boundaryType);
 	    periodicDofAssoc[edge1.first].insert(boundaryType);
 	    periodicDofAssoc[edge1.second].insert(boundaryType);
 
@@ -1348,11 +1346,11 @@ namespace AMDiS {
 	    DofFace face2 = neigh->getFace(elInfo->getOppVertex(i));
 	    BoundaryType boundaryType = elInfo->getBoundary(FACE, i);
 
-	    periodicFaces[std::make_pair(face1, face2)] = elInfo->getBoundary(i);
+	    elObjects.addPeriodicFace(std::make_pair(face1, face2), elInfo->getBoundary(i));
 
-	    periodicVertices[std::make_pair(face1.get<0>(), face2.get<0>())] = boundaryType;
-	    periodicVertices[std::make_pair(face1.get<1>(), face2.get<1>())] = boundaryType;
-	    periodicVertices[std::make_pair(face1.get<2>(), face2.get<2>())] = boundaryType;
+	    elObjects.addPeriodicVertex(std::make_pair(face1.get<0>(), face2.get<0>()), boundaryType);
+	    elObjects.addPeriodicVertex(std::make_pair(face1.get<1>(), face2.get<1>()), boundaryType);
+	    elObjects.addPeriodicVertex(std::make_pair(face1.get<2>(), face2.get<2>()), boundaryType);
 
 	    periodicDofAssoc[face1.get<0>()].insert(boundaryType);
 	    periodicDofAssoc[face1.get<1>()].insert(boundaryType);
@@ -1371,9 +1369,10 @@ namespace AMDiS {
 	    DofEdge neighEdge2 = std::make_pair(face2.get<0>(), face2.get<2>());
 	    DofEdge neighEdge3 = std::make_pair(face2.get<1>(), face2.get<2>());
 
-	    periodicEdges[std::make_pair(elEdge1, neighEdge1)] = boundaryType;
-	    periodicEdges[std::make_pair(elEdge2, neighEdge2)] = boundaryType;
-	    periodicEdges[std::make_pair(elEdge3, neighEdge3)] = boundaryType;
+
+	    elObjects.addPeriodicEdge(std::make_pair(elEdge1, neighEdge1), boundaryType);
+	    elObjects.addPeriodicEdge(std::make_pair(elEdge2, neighEdge2), boundaryType);
+	    elObjects.addPeriodicEdge(std::make_pair(elEdge3, neighEdge3), boundaryType);
 
 	    periodicEdgeAssoc[elEdge1].insert(neighEdge1);
 	    periodicEdgeAssoc[elEdge2].insert(neighEdge2);
@@ -1394,7 +1393,7 @@ namespace AMDiS {
 
     // === Search for interectly connected vertices in periodic boundaries. ===
 
-    if (periodicVertices.size() > 0) {
+    if (elObjects.periodicVertices.size() > 0) {
 
       
       // === Search for an unsed boundary index. ===
@@ -1412,42 +1411,100 @@ namespace AMDiS {
 
       // === Get all vertex DOFs that have multiple periodic associations. ===
 
-      std::map<int, std::vector<DegreeOfFreedom> > multiplePeriodicDof;
+      std::vector<DegreeOfFreedom> multPeriodicDof2, multPeriodicDof3;
       for (std::map<DegreeOfFreedom, std::set<BoundaryType> >::iterator it = periodicDofAssoc.begin();
 	   it != periodicDofAssoc.end(); ++it) {
 	TEST_EXIT_DBG((mesh->getDim() == 2 && it->second.size() <= 2) ||
 		      (mesh->getDim() == 3 && it->second.size() <= 3))
 	  ("Should not happen!\n");
 	
-	multiplePeriodicDof[it->second.size()].push_back(it->first);
+	if (it->second.size() == 2)
+	  multPeriodicDof2.push_back(it->first);
+	if (it->second.size() == 3)
+	  multPeriodicDof3.push_back(it->first);
+      }
+
+
+      if (mesh->getDim() == 2) {
+	TEST_EXIT_DBG(multPeriodicDof2.size() == 0 || 
+		      multPeriodicDof2.size() == 4)
+	  ("Should not happen (%d)!\n", multPeriodicDof2.size());
+	TEST_EXIT_DBG(multPeriodicDof3.size() == 0)("Should not happen!\n");
+      }
+      if (mesh->getDim() == 3) {
+	TEST_EXIT_DBG(multPeriodicDof3.size() == 0 || 
+		      multPeriodicDof3.size() == 8)
+	  ("Should not happen (%d)!\n", multPeriodicDof3.size());
       }
 
 
-      if (mesh->getDim() == 2)
-	TEST_EXIT_DBG(multiplePeriodicDof[2].size() == 0 || 
-		      multiplePeriodicDof[2].size() == 4)
-	  ("Should not happen (%d)!\n", multiplePeriodicDof[2].size());
-      if (mesh->getDim() == 3)
-	TEST_EXIT_DBG(multiplePeriodicDof[3].size() == 0 || 
-		      multiplePeriodicDof[3].size() == 8)
-	  ("Should not happen (%d)!\n", multiplePeriodicDof[3].size());
+      if (multPeriodicDof2.size() > 0) {
+	for (unsigned int i = 0; i < multPeriodicDof2.size(); i++) {
+	  DegreeOfFreedom dof0 = multPeriodicDof2[i];
+	  if (dof0 == -1)
+	    continue;
+
+	  DegreeOfFreedom dof1 = -1;
+	  DegreeOfFreedom dof2 = -1;
+	  BoundaryType type0 = *(periodicDofAssoc[dof0].begin());
+	  BoundaryType type1 = *(++(periodicDofAssoc[dof0].begin()));
+
+	  for (PerBoundMap<DegreeOfFreedom>::iterator it = elObjects.periodicVertices.begin();
+	       it != elObjects.periodicVertices.end(); ++it) {
+	    if (it->first.first == dof0 && it->second == type0)
+	      dof1 = it->first.second;
+	    if (it->first.first == dof0 && it->second == type1)
+	      dof2 = it->first.second;
+
+	    if (dof1 != -1 && dof2 != -1)
+	      break;
+	  }
+
+	  TEST_EXIT_DBG(dof1 != -1 && dof2 != -1)("Should not happen!\n");
+
+	  DegreeOfFreedom dof3 = -1;
+	  for (PerBoundMap<DegreeOfFreedom>::iterator it = elObjects.periodicVertices.begin();
+	       it != elObjects.periodicVertices.end(); ++it) {
+	    if (it->first.first == dof1 && it->second == type1) {
+	      dof3 = it->first.second;
 
+	      TEST_EXIT_DBG(elObjects.periodicVertices[std::make_pair(dof2, dof3)] == type0)
+		("Should not happen!\n");
 
-      for (int k = 2; k <= 3; k++) {
-	int nMultiplePeriodicDofs = multiplePeriodicDof[k].size();
-	for (int i = 0; i < nMultiplePeriodicDofs; i++) {
-	  for (int j = i + 1; j < nMultiplePeriodicDofs; j++) {
+	      break;
+	    }
+	  }
+	  
+	  TEST_EXIT_DBG(dof3 != -1)("Should not happen!\n");
+	  TEST_EXIT_DBG(elObjects.periodicVertices.count(std::make_pair(dof0, dof3)) == 0)
+	    ("Should not happen!\n");
+	  TEST_EXIT_DBG(elObjects.periodicVertices.count(std::make_pair(dof3, dof0)) == 0)
+	    ("Should not happen!\n");
+	  
+	  elObjects.periodicVertices[std::make_pair(dof0, dof3)] = newPeriodicBoundaryType;
+	  elObjects.periodicVertices[std::make_pair(dof3, dof0)] = newPeriodicBoundaryType;
+
+	  for (unsigned int j = i + 1; j < multPeriodicDof2.size(); j++)
+	    if (multPeriodicDof2[j] == dof3)
+	      multPeriodicDof2[j] = -1;
+	}
+      }
+
+      if (multPeriodicDof3.size() > 0) {
+	int nMultPeriodicDofs = multPeriodicDof3.size();
+	for (int i = 0; i < nMultPeriodicDofs; i++) {
+	  for (int j = i + 1; j < nMultPeriodicDofs; j++) {
 	    std::pair<DegreeOfFreedom, DegreeOfFreedom> perDofs0 = 
-	      std::make_pair(multiplePeriodicDof[k][i], multiplePeriodicDof[k][j]);
+	      std::make_pair(multPeriodicDof3[i], multPeriodicDof3[j]);
 	    std::pair<DegreeOfFreedom, DegreeOfFreedom> perDofs1 = 
-	      std::make_pair(multiplePeriodicDof[k][j], multiplePeriodicDof[k][i]);
+	      std::make_pair(multPeriodicDof3[j], multPeriodicDof3[i]);
 	    
-	    if (periodicVertices.count(perDofs0) == 0) {
-	      TEST_EXIT_DBG(periodicVertices.count(perDofs1) == 0)
+	    if (elObjects.periodicVertices.count(perDofs0) == 0) {
+	      TEST_EXIT_DBG(elObjects.periodicVertices.count(perDofs1) == 0)
 		("Should not happen!\n");
 	      
-	      periodicVertices[perDofs0] = newPeriodicBoundaryType;
-	      periodicVertices[perDofs1] = newPeriodicBoundaryType;
+	      elObjects.periodicVertices[perDofs0] = newPeriodicBoundaryType;
+	      elObjects.periodicVertices[perDofs1] = newPeriodicBoundaryType;
 	      newPeriodicBoundaryType--;
 	      mesh->getPeriodicAssociations()[newPeriodicBoundaryType] = 
 		new VertexVector(feSpace->getAdmin(), "");
@@ -1470,8 +1527,8 @@ namespace AMDiS {
 	  std::pair<DofEdge, DofEdge> perEdge1 =
 	    std::make_pair(perEdge0.second, perEdge0.first);
 
-	  periodicEdges[perEdge0] = newPeriodicBoundaryType;
-	  periodicEdges[perEdge1] = newPeriodicBoundaryType;
+	  elObjects.periodicEdges[perEdge0] = newPeriodicBoundaryType;
+	  elObjects.periodicEdges[perEdge1] = newPeriodicBoundaryType;
 	  newPeriodicBoundaryType--;
 	  mesh->getPeriodicAssociations()[newPeriodicBoundaryType] = 
 	    new VertexVector(feSpace->getAdmin(), "");      
@@ -1484,31 +1541,31 @@ namespace AMDiS {
       // === there must be a mapping B -> A with the same boundary type.          ===
 
 #if (DEBUG != 0)
-      for (std::map<std::pair<DegreeOfFreedom, DegreeOfFreedom>, BoundaryType>::iterator it = periodicVertices.begin();
-	   it != periodicVertices.end(); ++it) {
+      for (PerBoundMap<DegreeOfFreedom>::iterator it = elObjects.periodicVertices.begin();
+	   it != elObjects.periodicVertices.end(); ++it) {
 	std::pair<DegreeOfFreedom, DegreeOfFreedom> testVertex = 
 	  std::make_pair(it->first.second, it->first.first);
 	
-	TEST_EXIT_DBG(periodicVertices.count(testVertex) == 1)("Should not happen!\n");
-	TEST_EXIT_DBG(periodicVertices[testVertex] == it->second)("Should not happen!\n");
+	TEST_EXIT_DBG(elObjects.periodicVertices.count(testVertex) == 1)("Should not happen!\n");
+	TEST_EXIT_DBG(elObjects.periodicVertices[testVertex] == it->second)("Should not happen!\n");
       }
 
-      for (std::map<std::pair<DofEdge, DofEdge>, BoundaryType>::iterator it = periodicEdges.begin();
-	   it != periodicEdges.end(); ++it) {
+      for (PerBoundMap<DofEdge>::iterator it = elObjects.periodicEdges.begin();
+	   it != elObjects.periodicEdges.end(); ++it) {
 	std::pair<DofEdge, DofEdge> testEdge = 
 	  std::make_pair(it->first.second, it->first.first);
 	
-	TEST_EXIT_DBG(periodicEdges.count(testEdge) == 1)("Should not happen!\n");
-	TEST_EXIT_DBG(periodicEdges[testEdge] == it->second)("Should not happen!\n");
+	TEST_EXIT_DBG(elObjects.periodicEdges.count(testEdge) == 1)("Should not happen!\n");
+	TEST_EXIT_DBG(elObjects.periodicEdges[testEdge] == it->second)("Should not happen!\n");
       }
 
-      for (std::map<std::pair<DofFace, DofFace>, BoundaryType>::iterator it = periodicFaces.begin();
-	   it != periodicFaces.end(); ++it) {
+      for (PerBoundMap<DofFace>::iterator it = elObjects.periodicFaces.begin();
+	   it != elObjects.periodicFaces.end(); ++it) {
 	std::pair<DofFace, DofFace> testFace = 
 	  std::make_pair(it->first.second, it->first.first);
 	
-	TEST_EXIT_DBG(periodicFaces.count(testFace) == 1)("Should not happen!\n");
-	TEST_EXIT_DBG(periodicFaces[testFace] == it->second)("Should not happen!\n");
+	TEST_EXIT_DBG(elObjects.periodicFaces.count(testFace) == 1)("Should not happen!\n");
+	TEST_EXIT_DBG(elObjects.periodicFaces[testFace] == it->second)("Should not happen!\n");
       }
 #endif
 
@@ -1613,8 +1670,8 @@ namespace AMDiS {
     
     // === Create periodic boundary data structure. ===
 
-    for (std::map<std::pair<DegreeOfFreedom, DegreeOfFreedom>, BoundaryType>::iterator it = periodicVertices.begin();
-	 it != periodicVertices.end(); ++it) {
+    for (PerBoundMap<DegreeOfFreedom>::iterator it = elObjects.periodicVertices.begin();
+	 it != elObjects.periodicVertices.end(); ++it) {
       if (elObjects.isInRank(it->first.first, mpiRank) == false)
 	continue;
 
@@ -1622,10 +1679,10 @@ namespace AMDiS {
       mesh->getDofIndexCoords(it->first.first, feSpace, c0);
       mesh->getDofIndexCoords(it->first.second, feSpace, c1);
 
-      MSG("CREATE BOUNDARY FOR DOF MAP: %d (%.3f %.3f %.3f)<-> %d (%.3f %.3f %.3f)\n", it->first.first, 
-	  c0[0], c0[1], c0[2], it->first.second, c1[0], c1[1], c1[2]);
+//       MSG("CREATE BOUNDARY FOR DOF MAP: %d (%.3f %.3f %.3f)<-> %d (%.3f %.3f %.3f)\n", it->first.first, 
+// 	  c0[0], c0[1], c0[2], it->first.second, c1[0], c1[1], c1[2]);
       ElementObjectData& perDofEl0 = elObjects.getElementsInRank(it->first.first)[mpiRank];
-      MSG("DATA: %d %d %d\n", perDofEl0.elIndex, VERTEX, perDofEl0.ithObject);
+//       MSG("DATA: %d %d %d\n", perDofEl0.elIndex, VERTEX, perDofEl0.ithObject);
 
       for (std::map<int, ElementObjectData>::iterator elIt = elObjects.getElementsInRank(it->first.second).begin();
 	   elIt != elObjects.getElementsInRank(it->first.second).end(); ++elIt) {
@@ -1654,8 +1711,8 @@ namespace AMDiS {
     }
 
 
-    for (std::map<std::pair<DofEdge, DofEdge>, BoundaryType>::iterator it = periodicEdges.begin();
-	 it != periodicEdges.end(); ++it) {
+    for (PerBoundMap<DofEdge>::iterator it = elObjects.periodicEdges.begin();
+	 it != elObjects.periodicEdges.end(); ++it) {
       if (elObjects.isInRank(it->first.first, mpiRank) == false)
 	continue;
 
@@ -1693,8 +1750,8 @@ namespace AMDiS {
     }
 
 
-    for (std::map<std::pair<DofFace, DofFace>, BoundaryType>::iterator it = periodicFaces.begin();
-	 it != periodicFaces.end(); ++it) {
+    for (PerBoundMap<DofFace>::iterator it = elObjects.periodicFaces.begin();
+	 it != elObjects.periodicFaces.end(); ++it) {
       if (elObjects.isInRank(it->first.first, mpiRank) == false)
 	continue;
 
@@ -2191,8 +2248,7 @@ namespace AMDiS {
       WorldVector<double> c;
       mesh->getDofIndexCoords(it->first, feSpace, c);
       int nAssoc = it->second.size();
-      TEST_EXIT_DBG(nAssoc == 1 || nAssoc == 3 || 
-		    (mesh->getDim() == 3 && (nAssoc == 7 || nAssoc == 11)))
+      TEST_EXIT_DBG(nAssoc == 1 || nAssoc == 3 || (mesh->getDim() == 3 && nAssoc == 7))
 	("Should not happen! DOF %d (%e %e %e) has %d periodic associations!\n", 
 	 it->first, c[0], c[1], (mesh->getDim() == 2 ? 0.0 : c[2]), nAssoc);
     }    
@@ -2247,10 +2303,6 @@ namespace AMDiS {
 
     elObjects.serialize(out);
 
-    SerUtil::serialize(out, periodicVertices);
-    SerUtil::serialize(out, periodicEdges);
-    SerUtil::serialize(out, periodicFaces);
-
     myIntBoundary.serialize(out);
     otherIntBoundary.serialize(out);
     periodicBoundary.serialize(out);
@@ -2311,10 +2363,6 @@ namespace AMDiS {
 
     elObjects.deserialize(in);
    
-    SerUtil::deserialize(in, periodicVertices);
-    SerUtil::deserialize(in, periodicEdges);
-    SerUtil::deserialize(in, periodicFaces);
-   
     myIntBoundary.deserialize(in, elIndexMap);
     otherIntBoundary.deserialize(in, elIndexMap);
     periodicBoundary.deserialize(in, elIndexMap);
diff --git a/AMDiS/src/parallel/MeshDistributor.h b/AMDiS/src/parallel/MeshDistributor.h
index 7a05fd16..406dad0d 100644
--- a/AMDiS/src/parallel/MeshDistributor.h
+++ b/AMDiS/src/parallel/MeshDistributor.h
@@ -40,6 +40,8 @@
 #include "AMDiS_fwd.h"
 
 namespace AMDiS {
+
+  using namespace std;
   
   class ParMetisPartitioner;
 
@@ -47,36 +49,36 @@ namespace AMDiS {
   {
   protected:
     /// Defines a mapping type from DOFs to rank numbers.
-    typedef std::map<const DegreeOfFreedom*, int> DofToRank;
+    typedef map<const DegreeOfFreedom*, int> DofToRank;
 
     /// Defines a mapping type from DOFs to a set of rank numbers.
-    typedef std::map<const DegreeOfFreedom*, std::set<int> > DofToPartitions;
+    typedef map<const DegreeOfFreedom*, std::set<int> > DofToPartitions;
 
     /// Defines a mapping type from rank numbers to sets of DOFs.
-    typedef std::map<int, DofContainer> RankToDofContainer;
+    typedef map<int, DofContainer> RankToDofContainer;
 
     /// Defines a mapping type from DOF indices to DOF indices.
-    typedef std::map<DegreeOfFreedom, DegreeOfFreedom> DofMapping;
+    typedef map<DegreeOfFreedom, DegreeOfFreedom> DofMapping;
 
     /// Defines a mapping type from DOFs to boolean values.
-    typedef std::map<const DegreeOfFreedom*, bool> DofToBool;
+    typedef map<const DegreeOfFreedom*, bool> DofToBool;
 
     /// Defines a mapping type from DOF indices to boolean values.
-    typedef std::map<DegreeOfFreedom, bool> DofIndexToBool;
+    typedef map<DegreeOfFreedom, bool> DofIndexToBool;
 
     /// Forward type (it maps rank numbers to the interior boundary objects).
     typedef InteriorBoundary::RankToBoundMap RankToBoundMap;
 
-    typedef std::map<const DegreeOfFreedom*, DegreeOfFreedom> DofIndexMap;
+    typedef map<const DegreeOfFreedom*, DegreeOfFreedom> DofIndexMap;
 
     /// Mapps a boundar type, i.e., a boundary identifier index, to a periodic 
     /// dof mapping.
-    typedef std::map<BoundaryType, DofMapping> PeriodicDofMap;
-    
-    typedef std::vector<MeshStructure> MeshCodeVec;
+    typedef map<BoundaryType, DofMapping> PeriodicDofMap;
+
+    typedef vector<MeshStructure> MeshCodeVec;
 
   public:
-    MeshDistributor(std::string str);
+    MeshDistributor(string str);
 		          
     virtual ~MeshDistributor() {}
 
@@ -106,7 +108,7 @@ namespace AMDiS {
     /// Set for each element on the partitioning level the number of leaf elements.
     void setInitialElementWeights();
 
-    inline virtual std::string getName() 
+    inline virtual string getName() 
     { 
       return name; 
     }
@@ -208,10 +210,10 @@ namespace AMDiS {
     }
 
     // Writes all data of this object to an output stream.
-    void serialize(std::ostream &out);
+    void serialize(ostream &out);
 
     // Reads the object data from an input stream.
-    void deserialize(std::istream &in);
+    void deserialize(istream &in);
 
     /** \brief
      * This function must be used if the values of a DOFVector must be synchronised
@@ -288,7 +290,7 @@ namespace AMDiS {
      * are colored by the partition they are part of. This function can be used for
      * debugging.
      */
-    void writePartitioningMesh(std::string filename);
+    void writePartitioningMesh(string filename);
 
     /// Sets \ref isRankDof to all matrices and rhs vectors in all stationary problems.
     void setRankDofs();
@@ -345,38 +347,38 @@ namespace AMDiS {
 			      bool reverseMode);
 
     /// Writes a vector of dof pointers to an output stream.
-    void serialize(std::ostream &out, DofContainer &data);
+    void serialize(ostream &out, DofContainer &data);
 
     /// Reads a vector of dof pointers from an input stream.
-    void deserialize(std::istream &in, DofContainer &data,
-		     std::map<int, const DegreeOfFreedom*> &dofMap);
+    void deserialize(istream &in, DofContainer &data,
+		     map<int, const DegreeOfFreedom*> &dofMap);
 
     /// Writes a \ref RankToDofContainer to an output stream.
-    void serialize(std::ostream &out, RankToDofContainer &data);
+    void serialize(ostream &out, RankToDofContainer &data);
 
     /// Reads a \ref RankToDofContainer from an input stream.
-    void deserialize(std::istream &in, RankToDofContainer &data,
-		     std::map<int, const DegreeOfFreedom*> &dofMap);
+    void deserialize(istream &in, RankToDofContainer &data,
+		     map<int, const DegreeOfFreedom*> &dofMap);
 
     /// Writes a periodic dof mapping to an output stream.
-    void serialize(std::ostream &out, PeriodicDofMap &data);
+    void serialize(ostream &out, PeriodicDofMap &data);
 
-    void serialize(std::ostream &out, std::map<int, std::set<int> >& data);
+    void serialize(ostream &out, map<int, std::set<int> >& data);
 
     /// Reads a periodic dof mapping from an input stream.
-    void deserialize(std::istream &in, PeriodicDofMap &data);
+    void deserialize(istream &in, PeriodicDofMap &data);
 
-    void deserialize(std::istream &in, std::map<int, std::set<int> >& data);
+    void deserialize(istream &in, map<int, std::set<int> >& data);
 
     /// Writes a mapping from dof pointers to some values to an output stream.
     template<typename T>
-    void serialize(std::ostream &out, std::map<const DegreeOfFreedom*, T> &data)
+    void serialize(ostream &out, map<const DegreeOfFreedom*, T> &data)
     {
       FUNCNAME("ParallelDomainBase::serialize()");
 
       int mapSize = data.size();
       SerUtil::serialize(out, mapSize);
-      for (typename std::map<const DegreeOfFreedom*, T>::iterator it = data.begin();
+      for (typename map<const DegreeOfFreedom*, T>::iterator it = data.begin();
 	   it != data.end(); ++it) {
 	int v1 = (*(it->first));
 	T v2 = it->second;
@@ -387,8 +389,8 @@ namespace AMDiS {
 
     /// Reads a mapping from dof pointer to some values from an input stream.
     template<typename T>
-    void deserialize(std::istream &in, std::map<const DegreeOfFreedom*, T> &data,
-		     std::map<int, const DegreeOfFreedom*> &dofMap)
+    void deserialize(istream &in, map<const DegreeOfFreedom*, T> &data,
+		     map<int, const DegreeOfFreedom*> &dofMap)
     {
       FUNCNAME("ParallelDomainBase::deserialize()");
 
@@ -407,11 +409,11 @@ namespace AMDiS {
     }
 
   public:
-    std::vector<DOFVector<double>* > testVec;
+    vector<DOFVector<double>* > testVec;
 		        
   protected:
     ///
-    std::vector<ProblemVec*> probStat;
+    vector<ProblemVec*> probStat;
 
     /// The rank of the current process.
     int mpiRank;
@@ -427,7 +429,7 @@ namespace AMDiS {
     MPI::Intracomm mpiComm;
 
     /// Name of the problem (as used in the init files)
-    std::string name;
+    string name;
 
     /// Finite element space of the problem.
     FiniteElemSpace *feSpace;
@@ -449,19 +451,19 @@ namespace AMDiS {
     ParMetisPartitioner *partitioner;
 
     /// Weights for the elements, i.e., the number of leaf elements within this element.
-    std::map<int, double> elemWeights;
+    map<int, double> elemWeights;
 
     /** \brief
      * Stores to every macro element index the number of the rank that owns this
      * macro element.
      */
-    std::map<int, int> partitionVec;
+    map<int, int> partitionVec;
 
     /** \brief
      * Stores an old partitioning of elements. To every macro element index the
      * number of the rank it corresponds to is stored.
      */
-    std::map<int, int> oldPartitionVec;    
+    map<int, int> oldPartitionVec;    
    
     /// Number of DOFs in the rank mesh.
     int nRankDofs;
@@ -473,15 +475,10 @@ namespace AMDiS {
     ElementObjects elObjects;
 
     // Maps to each macro element index a pointer to the corresponding element.
-    std::map<int, Element*> macroElIndexMap;
+    map<int, Element*> macroElIndexMap;
     
     // Maps to each macro element index the type of this element.
-    std::map<int, int> macroElIndexTypeMap;
-
-    // The following three data structures store periodic DOFs, edges and faces.
-    std::map<std::pair<DegreeOfFreedom, DegreeOfFreedom>, BoundaryType> periodicVertices;
-    std::map<std::pair<DofEdge, DofEdge>, BoundaryType> periodicEdges;
-    std::map<std::pair<DofFace, DofFace>, BoundaryType> periodicFaces;
+    map<int, int> macroElIndexTypeMap;
 
     /** \brief 
      * Defines the interior boundaries of the domain that result from partitioning
@@ -545,7 +542,7 @@ namespace AMDiS {
      * DOFs are only on one periodic boundary. Only, e.g., in a box with all boundaries
      * being periodic, the for corners are associated by two different boundaries.     
      */
-    std::map<int, std::set<BoundaryType> > periodicDofAssociations;
+    map<int, std::set<BoundaryType> > periodicDofAssociations;
 
     /// Is the index of the first row of the linear system, which is owned by the rank.
     int rstart;
@@ -571,7 +568,7 @@ namespace AMDiS {
     int repartCounter;
 
     /// Directory name where all debug output files should be written to.
-    std::string debugOutputDir;
+    string debugOutputDir;
 
     /** \brief
      * Stores the mesh change index. This is used to recognize changes in the mesh 
@@ -579,11 +576,11 @@ namespace AMDiS {
      */
     long lastMeshChangeIndex;
 
-    std::map<int, std::vector<int> > macroElementNeighbours;
+    map<int, vector<int> > macroElementNeighbours;
 
     /// Store all macro elements of the overall mesh, i.e., before the macro mesh is
     /// redistributed for the first time.
-    std::vector<MacroElement*> allMacroElements;
+    vector<MacroElement*> allMacroElements;
 
     friend class ParallelDebug;
   };
-- 
GitLab