From 29ad7918072ff3a65bab772e6044f752dd4efabc Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Fri, 13 Aug 2010 07:34:53 +0000
Subject: [PATCH] Solved small problem considering periodic boundary conditions
 in parallel computations.

---
 AMDiS/libtool                          |  64 +++++------
 AMDiS/src/parallel/ElementObjectData.h |  34 ++++++
 AMDiS/src/parallel/MeshDistributor.cc  | 144 +++++++++++++++----------
 3 files changed, 156 insertions(+), 86 deletions(-)

diff --git a/AMDiS/libtool b/AMDiS/libtool
index 4a4a59e3..62951082 100755
--- a/AMDiS/libtool
+++ b/AMDiS/libtool
@@ -30,10 +30,10 @@
 # the same distribution terms that you use for the rest of that program.
 
 # A sed program that does not truncate output.
-SED="/bin/sed"
+SED="/usr/bin/sed"
 
 # Sed that helps us avoid accidentally triggering echo(1) options like -n.
-Xsed="/bin/sed -e 1s/^X//"
+Xsed="/usr/bin/sed -e 1s/^X//"
 
 # The HP-UX ksh and POSIX shell print the target directory to stdout
 # if CDPATH is set.
@@ -44,7 +44,7 @@ available_tags=" CXX F77"
 
 # ### BEGIN LIBTOOL CONFIG
 
-# Libtool was configured on host NWRW15:
+# Libtool was configured on host deimos104:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -66,12 +66,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=i686-redhat-linux-gnu
+host=x86_64-unknown-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=i686-redhat-linux-gnu
+build=x86_64-unknown-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -82,13 +82,13 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="gcc"
+LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="gcc"
+CC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
@@ -97,7 +97,7 @@ with_gcc=yes
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/bin/ld"
+LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -171,7 +171,7 @@ dlopen_self=unknown
 dlopen_self_static=unknown
 
 # Compiler flag to prevent dynamic linking.
-link_static_flag="-static"
+link_static_flag=""
 
 # Compiler flag to turn off builtin functions.
 no_builtin_flag=" -fno-builtin"
@@ -325,10 +325,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=" /u/witkowski/local/lib/i386-redhat-linux/4.1.2/ /u/witkowski/local/lib/ /u/witkowski/local/intel/mkl/10.0.1.014/lib/32/i386-redhat-linux/4.1.2/ /u/witkowski/local/intel/mkl/10.0.1.014/lib/32/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../ /lib/i386-redhat-linux/4.1.2/ /lib/ /usr/lib/i386-redhat-linux/4.1.2/ /usr/lib/"
+sys_lib_search_path_spec=" /fastfs/wir/local/lib/x86_64-suse-linux/4.1.2/ /fastfs/wir/local/lib/../lib64/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/ /usr/lib/gcc/x86_64-suse-linux/4.1.2/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/x86_64-suse-linux/4.1.2/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/../lib64/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../x86_64-suse-linux/4.1.2/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/ /lib/x86_64-suse-linux/4.1.2/ /lib/../lib64/ /usr/lib/x86_64-suse-linux/4.1.2/ /usr/lib/../lib64/ /fastfs/wir/local/lib/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../ /lib/ /usr/lib/"
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/mysql /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib /usr/lib/qt4/lib /usr/lib/xulrunner-1.9.2 "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
@@ -7263,7 +7263,7 @@ disable_libs=static
 # End:
 # ### BEGIN LIBTOOL TAG CONFIG: CXX
 
-# Libtool was configured on host NWRW15:
+# Libtool was configured on host deimos104:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7285,12 +7285,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=i686-redhat-linux-gnu
+host=x86_64-unknown-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=i686-redhat-linux-gnu
+build=x86_64-unknown-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -7301,13 +7301,13 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="gcc"
+LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
 
 # A language-specific compiler.
-CC="g++"
+CC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicxx"
 
 # Is the compiler the GNU C compiler?
 with_gcc=yes
@@ -7316,7 +7316,7 @@ with_gcc=yes
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/bin/ld"
+LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -7390,7 +7390,7 @@ dlopen_self=unknown
 dlopen_self_static=unknown
 
 # Compiler flag to prevent dynamic linking.
-link_static_flag="-static"
+link_static_flag=""
 
 # Compiler flag to turn off builtin functions.
 no_builtin_flag=" -fno-builtin"
@@ -7445,11 +7445,11 @@ striplib="strip --strip-unneeded"
 
 # Dependencies to place before the objects being linked to create a
 # shared library.
-predep_objects="/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbeginS.o"
+predep_objects="/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtbeginS.o"
 
 # Dependencies to place after the objects being linked to create a
 # shared library.
-postdep_objects="/usr/lib/gcc/i386-redhat-linux/4.1.2/crtendS.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o"
+postdep_objects="/usr/lib64/gcc/x86_64-suse-linux/4.1.2/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/crtn.o"
 
 # Dependencies to place before the objects being linked to create a
 # shared library.
@@ -7457,11 +7457,11 @@ predeps=""
 
 # Dependencies to place after the objects being linked to create a
 # shared library.
-postdeps="-lstdc++ -lm -lgcc_s -lc -lgcc_s"
+postdeps="-lmpi_cxx -lmpi -lopen-rte -lopen-pal -libverbs -lrt -lnuma -ldl -lnsl -lutil -ldl -lstdc++ -lm -lgcc_s -lpthread -lc -lgcc_s"
 
 # The library search path used internally by the compiler when linking
 # a shared library.
-compiler_lib_search_path="-L/u/witkowski/local/lib -L/u/witkowski/local/intel/mkl/10.0.1.014/lib/32 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.."
+compiler_lib_search_path="-L/usr/lib64 -L/licsoft/libraries/openmpi/1.2.6/64bit/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2 -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/fastfs/wir/local/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../.."
 
 # Method to check whether dependent libraries are shared objects.
 deplibs_check_method="pass_all"
@@ -7541,10 +7541,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=" /u/witkowski/local/lib/i386-redhat-linux/4.1.2/ /u/witkowski/local/lib/ /u/witkowski/local/intel/mkl/10.0.1.014/lib/32/i386-redhat-linux/4.1.2/ /u/witkowski/local/intel/mkl/10.0.1.014/lib/32/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../i386-redhat-linux/4.1.2/ /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../ /lib/i386-redhat-linux/4.1.2/ /lib/ /usr/lib/i386-redhat-linux/4.1.2/ /usr/lib/"
+sys_lib_search_path_spec=" /fastfs/wir/local/lib/x86_64-suse-linux/4.1.2/ /fastfs/wir/local/lib/../lib64/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/ /usr/lib/gcc/x86_64-suse-linux/4.1.2/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/x86_64-suse-linux/4.1.2/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/../lib64/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../x86_64-suse-linux/4.1.2/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../lib64/ /lib/x86_64-suse-linux/4.1.2/ /lib/../lib64/ /usr/lib/x86_64-suse-linux/4.1.2/ /usr/lib/../lib64/ /fastfs/wir/local/lib/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/lib/ /usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../ /lib/ /usr/lib/"
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/mysql /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib /usr/lib/qt4/lib /usr/lib/xulrunner-1.9.2 "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
@@ -7568,7 +7568,7 @@ include_expsyms=""
 
 # ### BEGIN LIBTOOL TAG CONFIG: F77
 
-# Libtool was configured on host NWRW15:
+# Libtool was configured on host deimos104:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7590,12 +7590,12 @@ fast_install=yes
 
 # The host system.
 host_alias=
-host=i686-redhat-linux-gnu
+host=x86_64-unknown-linux-gnu
 host_os=linux-gnu
 
 # The build system.
 build_alias=
-build=i686-redhat-linux-gnu
+build=x86_64-unknown-linux-gnu
 build_os=linux-gnu
 
 # An echo program that does not interpret backslashes.
@@ -7606,7 +7606,7 @@ AR="ar"
 AR_FLAGS="cru"
 
 # A C compiler.
-LTCC="gcc"
+LTCC="/licsoft/libraries/openmpi/1.2.6/64bit/bin/mpicc"
 
 # LTCC compiler flags.
 LTCFLAGS="-g -O2"
@@ -7615,13 +7615,13 @@ LTCFLAGS="-g -O2"
 CC="g77"
 
 # Is the compiler the GNU C compiler?
-with_gcc=yes
+with_gcc=
 
 # An ERE matcher.
 EGREP="grep -E"
 
 # The linker used to build libraries.
-LD="/usr/bin/ld"
+LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
 
 # Whether we need hard or soft links.
 LN_S="ln -s"
@@ -7849,10 +7849,10 @@ variables_saved_for_relink="PATH LD_LIBRARY_PATH LD_RUN_PATH GCC_EXEC_PREFIX COM
 link_all_deplibs=unknown
 
 # Compile-time system search path for libraries
-sys_lib_search_path_spec=" /u/witkowski/local/lib/i386-redhat-linux/3.4.6/ /u/witkowski/local/lib/ /u/witkowski/local/intel/mkl/10.0.1.014/lib/32/i386-redhat-linux/3.4.6/ /u/witkowski/local/intel/mkl/10.0.1.014/lib/32/ /usr/lib/gcc/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../i386-redhat-linux/lib/i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../i386-redhat-linux/lib/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../i386-redhat-linux/3.4.6/ /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../ /lib/i386-redhat-linux/3.4.6/ /lib/ /usr/lib/i386-redhat-linux/3.4.6/ /usr/lib/"
+sys_lib_search_path_spec=" /fastfs/wir/local/lib/x86_64-suse-linux/3.3.5/ /fastfs/wir/local/lib/ /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/ /usr/lib/gcc/x86_64-suse-linux/3.3.5/ /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../../x86_64-suse-linux/lib/x86_64-suse-linux/3.3.5/ /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../../x86_64-suse-linux/lib/ /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../x86_64-suse-linux/3.3.5/ /usr/lib64/gcc-lib/x86_64-suse-linux/3.3.5/../../../ /lib/x86_64-suse-linux/3.3.5/ /lib/ /usr/lib/x86_64-suse-linux/3.3.5/ /usr/lib/"
 
 # Run-time system search path for libraries
-sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/lib/mysql /usr/lib/octave-2.9.9 /usr/lib/qt-3.3/lib /usr/lib/qt4/lib /usr/lib/xulrunner-1.9.2 "
+sys_lib_dlsearch_path_spec="/lib /usr/lib /usr/X11R6/lib64/Xaw3d /usr/X11R6/lib64 /usr/X11R6/lib/Xaw3d /usr/X11R6/lib /usr/x86_64-suse-linux/lib /usr/local/lib64 /usr/local/lib /opt/kde3/lib64 /opt/kde3/lib /opt/gnome/lib64 /opt/gnome/lib /lib64 /lib /usr/lib64 /usr/lib /opt/cluster/intel/cce/9.1.042/lib /opt/cluster/intel/fce/9.1.036/lib /opt/cluster/Pathscale3.0/lib/2.9.99 /opt/cluster/Pathscale3.0/lib/2.9.99/32 /work/licsoft/compilers/pgi/linux86-64/6.2/lib /work/licsoft/compilers/pgi/linux86-64/6.2/libso "
 
 # Fix the shell variable $srcfile for the compiler.
 fix_srcfile_path=""
diff --git a/AMDiS/src/parallel/ElementObjectData.h b/AMDiS/src/parallel/ElementObjectData.h
index 27a7108d..5607ea20 100644
--- a/AMDiS/src/parallel/ElementObjectData.h
+++ b/AMDiS/src/parallel/ElementObjectData.h
@@ -179,6 +179,7 @@ namespace AMDiS {
       }
     }
 
+
     int getOwner(DegreeOfFreedom vertex)
     {
       return vertexOwner[vertex];
@@ -194,6 +195,23 @@ namespace AMDiS {
       return faceOwner[face];
     }
 
+
+    int isInRank(DegreeOfFreedom vertex, int rank)
+    {
+      return (vertexInRank[vertex].count(rank));
+    }
+
+    int isInRank(DofEdge edge, int rank)
+    {
+      return (edgeInRank[edge].count(rank));
+    }
+
+    int isInRank(DofFace face, int rank)
+    {
+      return (faceInRank[face].count(rank));
+    }
+
+
     std::vector<ElementObjectData>& getElements(DegreeOfFreedom vertex)
     {
       return vertexElements[vertex];
@@ -209,6 +227,22 @@ namespace AMDiS {
       return faceElements[face];
     }
 
+
+    std::map<int, ElementObjectData>& getElementsInRank(DegreeOfFreedom vertex)
+    {
+      return vertexInRank[vertex];
+    }
+
+    std::map<int, ElementObjectData>& getElementsInRank(DofEdge edge)
+    {
+      return edgeInRank[edge];
+    }
+
+    std::map<int, ElementObjectData>& getElementsInRank(DofFace face)
+    {
+      return faceInRank[face];
+    }
+
   private:
     std::map<int, int> elementInRank;
 
diff --git a/AMDiS/src/parallel/MeshDistributor.cc b/AMDiS/src/parallel/MeshDistributor.cc
index a63ac2fe..2f356178 100644
--- a/AMDiS/src/parallel/MeshDistributor.cc
+++ b/AMDiS/src/parallel/MeshDistributor.cc
@@ -948,7 +948,7 @@ namespace AMDiS {
 	   rankIt != periodicBoundary.boundary.end(); ++rankIt) {
 
 	TEST_EXIT_DBG(rankIt->first != mpiRank)
-	  ("It is no possible to have an interior boundary within a rank partition!\n");
+	  ("It is not allowed to have an interior boundary within a rank partition!\n");
 
 	if (rankIt->first < mpiRank)
 	  sendBounds.boundary[rankIt->first] = rankIt->second;
@@ -1001,6 +1001,7 @@ namespace AMDiS {
 
     std::map<std::pair<DofEdge, DofEdge>, BoundaryType> periodicEdges;
     std::map<std::pair<DofFace, DofFace>, BoundaryType> periodicFaces;
+    std::map<std::pair<DegreeOfFreedom, DegreeOfFreedom>, BoundaryType> periodicDofs;
 
     // === PHASE 1 ===
 
@@ -1028,9 +1029,30 @@ namespace AMDiS {
 	for (int i = 0; i < el->getGeo(EDGE); i++) {
 	  if (mesh->isPeriodicAssociation(elInfo->getBoundary(i))) {
 	    DofEdge edge1 = el->getEdge(i);
-	    DofEdge edge2 = elInfo->getNeighbour(i)->getEdge(elInfo->getOppVertex(i));
-	    
-	    periodicEdges[std::make_pair(edge1, edge2)] = elInfo->getBoundary(i);
+	    DofEdge edge2 = elInfo->getNeighbour(i)->getEdge(elInfo->getOppVertex(i));	    
+	    BoundaryType boundaryType = elInfo->getBoundary(i);
+
+	    periodicEdges[std::make_pair(edge1, edge2)] = boundaryType;
+
+
+	    for (int j = 0; j < 2; j++) {
+	      int ithDofRankObj = el->getVertexOfEdge(i, j);
+	      DegreeOfFreedom dof = el->getDOF(ithDofRankObj, 0);
+
+	      DegreeOfFreedom neighDof = -1;	  
+	      int ithDofNeighObj = -1;	  
+	      for (int k = 0; k < 3; k++) {
+		if (elInfo->getNeighbour(i)->getDOF(k, 0) == 
+		    mesh->getPeriodicAssociations(boundaryType)[dof]) {
+		  neighDof = elInfo->getNeighbour(i)->getDOF(k, 0);
+		  ithDofNeighObj = k;
+		  break;
+		}
+	      }
+	      TEST_EXIT_DBG(neighDof > -1)("Should not happen!\n");
+      		
+	      periodicDofs[std::make_pair(dof, neighDof)] = boundaryType;
+	    }
 	  }
 	}
 	break;
@@ -1130,67 +1152,82 @@ namespace AMDiS {
     
     // === PHASE 4 ===
 
-    for (std::map<std::pair<DofEdge, DofEdge>, BoundaryType>::iterator it = periodicEdges.begin();
-	 it != periodicEdges.end(); ++it) {
-      int perEdgeOwner0 = elObjects.getOwner(it->first.first);
-      int perEdgeOwner1 = elObjects.getOwner(it->first.second);
+    for (std::map<std::pair<DegreeOfFreedom, DegreeOfFreedom>, BoundaryType>::iterator it = periodicDofs.begin();
+	 it != periodicDofs.end(); ++it) {
+      if (elObjects.isInRank(it->first.first, mpiRank) == false)
+	continue;
+
+      for (std::map<int, ElementObjectData>::iterator elIt = elObjects.getElementsInRank(it->first.second).begin();
+	   elIt != elObjects.getElementsInRank(it->first.second).end(); ++elIt) {
+
+	int otherElementRank = elIt->first;
+	ElementObjectData& perDofEl0 = elObjects.getElementsInRank(it->first.first)[mpiRank];
+	ElementObjectData& perDofEl1 = elIt->second;
 
-      if (perEdgeOwner0 == mpiRank) {
-	TEST_EXIT_DBG(perEdgeOwner0 != perEdgeOwner1)("Should not happen!\n");
-	TEST_EXIT_DBG(elObjects.getElements(it->first.first).size() == 1)
-	  ("Should not happen!\n");
-	TEST_EXIT_DBG(elObjects.getElements(it->first.second).size() == 1)
-	  ("Should not happen!\n");
-
-	int otherElementRank = perEdgeOwner1;
-	ElementObjectData& perEdgeEl0 = elObjects.getElements(it->first.first)[0];
-	ElementObjectData& perEdgeEl1 = elObjects.getElements(it->first.second)[0];
-
-	AtomicBoundary bound;	    	    
-	bound.rankObj.el = elIndexMap[perEdgeEl0.elIndex];
-	bound.rankObj.elIndex = perEdgeEl0.elIndex;
-	bound.rankObj.elType = elIndexTypeMap[perEdgeEl0.elIndex];
-	bound.rankObj.subObj = EDGE;
-	bound.rankObj.ithObj = perEdgeEl0.ithObject;
-
-	bound.neighObj.el = elIndexMap[perEdgeEl1.elIndex];
-	bound.neighObj.elIndex = perEdgeEl1.elIndex;
+	AtomicBoundary bound;
+	bound.rankObj.el = elIndexMap[perDofEl0.elIndex];
+	bound.rankObj.elIndex = perDofEl0.elIndex;
+	bound.rankObj.elType = elIndexTypeMap[perDofEl0.elIndex];
+	bound.rankObj.subObj = VERTEX;
+	bound.rankObj.ithObj = perDofEl0.ithObject;
+
+	bound.neighObj.el = elIndexMap[perDofEl1.elIndex];
+	bound.neighObj.elIndex = perDofEl1.elIndex;
 	bound.neighObj.elType = -1;
-	bound.neighObj.subObj = EDGE;
-	bound.neighObj.ithObj = perEdgeEl1.ithObject;
+	bound.neighObj.subObj = VERTEX;
+	bound.neighObj.ithObj = perDofEl1.ithObject;
 
 	bound.type = it->second;
-	
+
 	AtomicBoundary& b = periodicBoundary.getNewAtomic(otherElementRank);
 	b = bound;
+      }
+    }
 
-	if (mpiRank > otherElementRank)
-	  b.rankObj.setReverseMode(b.neighObj, feSpace);
-	else
-	  b.neighObj.setReverseMode(b.rankObj, feSpace);
 
-	for (int i = 0; i < 2; i++) {
-	  int ithDofRankObj = bound.rankObj.el->getVertexOfEdge(perEdgeEl0.ithObject, i);
-	  DegreeOfFreedom dof = bound.rankObj.el->getDOF(ithDofRankObj, 0);
-	  
-	  int ithDofNeighObj = -1;	  
-	  for (int j = 0; j < 3; j++)
-	    if (bound.neighObj.el->getDOF(j, 0) ==
-		mesh->getPeriodicAssociations(bound.type)[dof])
-	      ithDofNeighObj = j;
-	  TEST_EXIT_DBG(ithDofNeighObj > -1)("Should not happen!\n");
 
-	  bound.rankObj.subObj = VERTEX;
-	  bound.rankObj.ithObj = ithDofRankObj;
+    for (std::map<std::pair<DofEdge, DofEdge>, BoundaryType>::iterator it = periodicEdges.begin();
+	 it != periodicEdges.end(); ++it) {
+      int perEdgeOwner0 = elObjects.getOwner(it->first.first);
+      int perEdgeOwner1 = elObjects.getOwner(it->first.second);
 
-	  bound.neighObj.subObj = VERTEX;
-	  bound.neighObj.ithObj = ithDofNeighObj;
+      if (perEdgeOwner0 != mpiRank)
+	continue;
 
-	  AtomicBoundary& b = periodicBoundary.getNewAtomic(otherElementRank);
-	  b = bound;	  
-	}
-      }
+      TEST_EXIT_DBG(perEdgeOwner0 != perEdgeOwner1)("Should not happen!\n");
+      TEST_EXIT_DBG(elObjects.getElements(it->first.first).size() == 1)
+	("Should not happen!\n");
+      TEST_EXIT_DBG(elObjects.getElements(it->first.second).size() == 1)
+	("Should not happen!\n");
+      
+      int otherElementRank = perEdgeOwner1;
+      ElementObjectData& perEdgeEl0 = elObjects.getElements(it->first.first)[0];
+      ElementObjectData& perEdgeEl1 = elObjects.getElements(it->first.second)[0];
+      
+      AtomicBoundary bound;	    	    
+      bound.rankObj.el = elIndexMap[perEdgeEl0.elIndex];
+      bound.rankObj.elIndex = perEdgeEl0.elIndex;
+      bound.rankObj.elType = elIndexTypeMap[perEdgeEl0.elIndex];
+      bound.rankObj.subObj = EDGE;
+      bound.rankObj.ithObj = perEdgeEl0.ithObject;
+      
+      bound.neighObj.el = elIndexMap[perEdgeEl1.elIndex];
+      bound.neighObj.elIndex = perEdgeEl1.elIndex;
+      bound.neighObj.elType = -1;
+      bound.neighObj.subObj = EDGE;
+      bound.neighObj.ithObj = perEdgeEl1.ithObject;
+      
+      bound.type = it->second;
+      
+      AtomicBoundary& b = periodicBoundary.getNewAtomic(otherElementRank);
+      b = bound;
+      
+      if (mpiRank > otherElementRank)
+	b.rankObj.setReverseMode(b.neighObj, feSpace);
+      else
+	b.neighObj.setReverseMode(b.rankObj, feSpace);     
     }
+
   }
 
 
@@ -1855,7 +1892,6 @@ namespace AMDiS {
  	 it->first, nAssoc);
     }
 #endif
-
   }
 
 
-- 
GitLab