From cbc573e3350543875fd85a526d6d052c5200c76d Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Mon, 12 Jul 2010 12:36:10 +0000
Subject: [PATCH] Fixed refinement bug in 3D.

---
 AMDiS/libtool                         |  6 ++--
 AMDiS/other/include/Makefile_AMDiS.mk | 14 ++++++--
 AMDiS/src/Element.h                   |  2 +-
 AMDiS/src/Mesh.cc                     |  2 ++
 AMDiS/src/RefinementManager3d.cc      | 48 ++++++++++++++-------------
 AMDiS/src/Traverse.cc                 | 21 ++++++------
 AMDiS/src/parallel/MeshDistributor.cc |  2 +-
 7 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/AMDiS/libtool b/AMDiS/libtool
index 1a37a1c4..02151259 100755
--- a/AMDiS/libtool
+++ b/AMDiS/libtool
@@ -44,7 +44,7 @@ available_tags=" CXX F77"
 
 # ### BEGIN LIBTOOL CONFIG
 
-# Libtool was configured on host deimos102:
+# Libtool was configured on host deimos103:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -6760,7 +6760,7 @@ build_old_libs=`case $build_libtool_libs in yes) $echo no;; *) $echo yes;; esac`
 # End:
 # ### BEGIN LIBTOOL TAG CONFIG: CXX
 
-# Libtool was configured on host deimos102:
+# Libtool was configured on host deimos103:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
@@ -7065,7 +7065,7 @@ include_expsyms=""
 
 # ### BEGIN LIBTOOL TAG CONFIG: F77
 
-# Libtool was configured on host deimos102:
+# Libtool was configured on host deimos103:
 
 # Shell to use when invoking shell scripts.
 SHELL="/bin/sh"
diff --git a/AMDiS/other/include/Makefile_AMDiS.mk b/AMDiS/other/include/Makefile_AMDiS.mk
index 72b7e796..9950a2df 100644
--- a/AMDiS/other/include/Makefile_AMDiS.mk
+++ b/AMDiS/other/include/Makefile_AMDiS.mk
@@ -68,6 +68,10 @@ endif
 # ============================================================================
 
 ifeq ($(strip $(USE_PARALLEL_AMDIS)), 1)
+	include ${PETSC_DIR}/conf/variables
+	CFLAGS = ${PETSC_CC_INCLUDES}
+	FFLAGS = ${PETSC_FC_INCLUDES}
+
 	ifeq ($(strip $(USE_SERVER)), mars)
 		ifeq ($(strip $(USE_COMPILER)), gcc)
 			COMPILE = g++
@@ -78,8 +82,9 @@ ifeq ($(strip $(USE_PARALLEL_AMDIS)), 1)
 		COMPILE = $(MPI_DIR)/bin/mpiCC
 	endif
 
-	LIBS += $(PARMETIS_LIB) -lmpi
 	CPPFLAGS += -DHAVE_PARALLEL_DOMAIN_AMDIS
+	INCLUDES += $(PETSC_INCLUDE)
+	LIBS += $(PARMETIS_LIB) -lmpi $(PETSC_LIB)
 else
 	ifeq ($(strip $(USE_COMPILER)), gcc)
 		COMPILE = g++
@@ -116,7 +121,12 @@ endif
 # ============================================================================
 
 LIBTOOL = $(AMDIS_DIR)/libtool
-LINK = $(LIBTOOL) --mode=link $(COMPILE)
+
+ifeq ($(strip $(USE_PARALLEL_AMDIS)), 1)
+	LINK = $(LIBTOOL) --tag=mpiCC --mode=link $(COMPILE)
+else
+	LINK = $(LIBTOOL) --mode=link $(COMPILE)
+endif
 
 # ============================================================================
 # ===== rules ================================================================
diff --git a/AMDiS/src/Element.h b/AMDiS/src/Element.h
index f1500f02..2822cb6c 100644
--- a/AMDiS/src/Element.h
+++ b/AMDiS/src/Element.h
@@ -106,7 +106,7 @@ namespace AMDiS {
     /// Returns \ref child[i], i=0,1
     inline Element* getChild(int i) const 
     {
-      TEST_EXIT_DBG(i == 0 || i == 1)("i must be 0 or 1\n");
+      TEST_EXIT_DBG(i == 0 || i == 1)("There is only child 0 or 1! (i = %d)\n", i);
       return child[i];
     }
 
diff --git a/AMDiS/src/Mesh.cc b/AMDiS/src/Mesh.cc
index 0d4433a1..0dcdbaa0 100644
--- a/AMDiS/src/Mesh.cc
+++ b/AMDiS/src/Mesh.cc
@@ -1149,6 +1149,7 @@ namespace AMDiS {
     initialized = true;
   }
 
+
   bool Mesh::associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2) 
   {
     std::map<BoundaryType, VertexVector*>::iterator it;
@@ -1159,6 +1160,7 @@ namespace AMDiS {
     return false;
   }
 
+
   bool Mesh::indirectlyAssociated(DegreeOfFreedom dof1, DegreeOfFreedom dof2) 
   {
     std::vector<DegreeOfFreedom> associatedToDOF1;
diff --git a/AMDiS/src/RefinementManager3d.cc b/AMDiS/src/RefinementManager3d.cc
index 06083e2b..40069bd6 100644
--- a/AMDiS/src/RefinementManager3d.cc
+++ b/AMDiS/src/RefinementManager3d.cc
@@ -141,6 +141,7 @@ namespace AMDiS {
 						  int index)
   {
     FUNCNAME("RefinementManager3d::fillPatchConnectivity");
+
     Element *el = ref_list->getElement(index), *neigh;
     int el_type = ref_list->getType(index);
     int n_type = 0;
@@ -221,7 +222,7 @@ namespace AMDiS {
 	    node1 = mesh->getNode(FACE) + j_neigh;
 
 	    TEST_EXIT_DBG(neigh->getChild(j)->getDOF(node1))
-	      ("no dof on neighbour %d at node %d\n",
+	      ("No DOF on neighbour %d at node %d!\n",
 	       neigh->getChild(j)->getIndex(), node1);
 
 	    (const_cast<Element*>(el->getChild(i)))->
@@ -394,7 +395,7 @@ namespace AMDiS {
       dynamic_cast<Tetrahedron*>(const_cast<Element*>((*el_info)->getElement()));
     
     if ((*el_info)->getNeighbour(3 - dir) == NULL)
-      return 1;
+      return 1;    
   
     int opp_v = (*el_info)->getOppVertex(3-dir);
     ElInfo *neigh_info = stack->traverseNeighbour3d((*el_info), 3 - dir);
@@ -528,24 +529,26 @@ namespace AMDiS {
 	  break;
       }
     }
-    
+   
     if (neigh == el) {
       (*el_info) = neigh_info;
       return 0;
     }
-    
+
+   
     /****************************************************************************/
     /*  the domain's boundary is reached; loop back to the starting el          */
     /****************************************************************************/
     
-    i = *n_neigh-1;
+    i = *n_neigh - 1;
     opp_v = refineList->getOppVertex(i, 0);
     do {
-      TEST_EXIT_DBG(neigh_info->getNeighbour(opp_v)  &&  i > 0)
-	("while looping back domains boundary was reached or i == 0\n");
+      TEST_EXIT_DBG(neigh_info->getNeighbour(opp_v) && i > 0)
+	("While looping back domains boundary was reached or i == 0\n");
       opp_v = refineList->getOppVertex(i--, 0);
       neigh_info = stack->traverseNeighbour3d(neigh_info, opp_v);
     } while (neigh_info->getElement() != el);
+
     (*el_info) = neigh_info;
     
     return 1;
@@ -555,6 +558,7 @@ namespace AMDiS {
   ElInfo* RefinementManager3d::refineFunction(ElInfo* el_info)
   {
     FUNCNAME("RefinementManager3d::refineFunction()");
+
     int bound = false;
     DegreeOfFreedom *edge[2];
 
@@ -618,7 +622,7 @@ namespace AMDiS {
     std::map<int, VertexVector*>::iterator it;
     std::map<int, VertexVector*>::iterator end = mesh->getPeriodicAssociations().end();
 
-    while(edge[0] != NULL) {
+    while (edge[0] != NULL) {
       periodicList = ref_list->periodicSplit(edge, 
 					     next_edge,
 					     &n_neigh,
@@ -635,13 +639,12 @@ namespace AMDiS {
 	for (it = mesh->getPeriodicAssociations().begin(); it != end; ++it) {
 	  if (it->second) {
 	    if (((*(it->second))[edge[0][0]] == last_edge[0][0] &&
-		(*(it->second))[edge[1][0]] == last_edge[1][0]) || 
-	       ((*(it->second))[edge[0][0]] == last_edge[1][0] &&
-		(*(it->second))[edge[1][0]] == last_edge[0][0]))
-	      {
-		(*(it->second))[lastNewDOF] = newDOF;
-		(*(it->second))[newDOF] = lastNewDOF;
-	      } 
+		 (*(it->second))[edge[1][0]] == last_edge[1][0]) || 
+		((*(it->second))[edge[0][0]] == last_edge[1][0] &&
+		 (*(it->second))[edge[1][0]] == last_edge[0][0])) {
+	      (*(it->second))[lastNewDOF] = newDOF;
+	      (*(it->second))[newDOF] = lastNewDOF;
+	    } 
 	  }
 	}
       }
@@ -658,13 +661,12 @@ namespace AMDiS {
       for (it = mesh->getPeriodicAssociations().begin(); it != end; ++it) {
 	if (it->second) {
 	  if (((*(it->second))[first_edge[0][0]] == last_edge[0][0] &&
-	      (*(it->second))[first_edge[1][0]] == last_edge[1][0]) || 
-	     ((*(it->second))[first_edge[0][0]] == last_edge[1][0] &&
-	      (*(it->second))[first_edge[1][0]] == last_edge[0][0]))
-	    {
-	      (*(it->second))[lastNewDOF] = firstNewDOF;
-	      (*(it->second))[firstNewDOF] = lastNewDOF;
-	    }
+	       (*(it->second))[first_edge[1][0]] == last_edge[1][0]) || 
+	      ((*(it->second))[first_edge[0][0]] == last_edge[1][0] &&
+	       (*(it->second))[first_edge[1][0]] == last_edge[0][0])) {	    
+	    (*(it->second))[lastNewDOF] = firstNewDOF;
+	    (*(it->second))[firstNewDOF] = lastNewDOF;
+	  }
 	}
       }
     }
@@ -679,7 +681,7 @@ namespace AMDiS {
 
     delete ref_list;
 
-    return(el_info);
+    return el_info;
   }
 
 }
diff --git a/AMDiS/src/Traverse.cc b/AMDiS/src/Traverse.cc
index 99552c98..e6bda8db 100644
--- a/AMDiS/src/Traverse.cc
+++ b/AMDiS/src/Traverse.cc
@@ -487,11 +487,10 @@ namespace AMDiS {
 	int i = 1 - neighbour;
 
 	elinfo_stack[stack_used + 1]->fillElInfo(i, elinfo_stack[stack_used]);
-	if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE))
-	  info_stack[stack_used] = (i == 0 ? 2 : 1);
-	else
+ 	if (traverse_fill_flag.isSet(Mesh::CALL_REVERSE_MODE))
+ 	  info_stack[stack_used] = (i == 0 ? 2 : 1);
+ 	else
 	  info_stack[stack_used] = i + 1;
-
 	stack_used++;
 	info_stack[stack_used] = 0;
 	neighbour = 3;
@@ -501,13 +500,6 @@ namespace AMDiS {
     /* save information about current element and its position in the tree */
     save_traverse_mel = traverse_mel;
     save_stack_used = stack_used;
-    for (int i = stack_used; i <= save_stack_used; i++) {
-      save_info_stack[i] = info_stack[i];
-      *(save_elinfo_stack[i]) = *(elinfo_stack[i]);
-    }
-    ElInfo *old_elinfo = save_elinfo_stack[save_stack_used];
-    int opp_vertex = old_elinfo->getOppVertex(neighbour);
-
 
     // === First phase (see 2D). ===
 
@@ -533,6 +525,13 @@ namespace AMDiS {
       TEST_EXIT_DBG(nb >= 0)("invalid coarse_nb %d\n",nb);
     }
 
+    for (int i = stack_used; i <= save_stack_used; i++) {
+      save_info_stack[i] = info_stack[i];
+      *(save_elinfo_stack[i]) = *(elinfo_stack[i]);
+    }
+    ElInfo *old_elinfo = save_elinfo_stack[save_stack_used];
+    int opp_vertex = old_elinfo->getOppVertex(neighbour);
+
 
     if (nb >= 0) {                           
       // Go to macro element neighbour.
diff --git a/AMDiS/src/parallel/MeshDistributor.cc b/AMDiS/src/parallel/MeshDistributor.cc
index 2a22efb2..a12a6d16 100644
--- a/AMDiS/src/parallel/MeshDistributor.cc
+++ b/AMDiS/src/parallel/MeshDistributor.cc
@@ -152,7 +152,7 @@ namespace AMDiS {
 
     // === Create periodic dof mapping, if there are periodic boundaries. ===
 
-    createPeriodicMap();
+    createPeriodicMap();    
 
 
     // === Global refinements. ===
-- 
GitLab