From 9df9d4af7b7aa3d8720c912c2086eb4289b080f2 Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Wed, 3 Dec 2008 14:26:24 +0000
Subject: [PATCH] * Added debug information output to AdaptInstationary

---
 AMDiS/src/AdaptInfo.h          | 146 ++++++++++++++++++---------------
 AMDiS/src/AdaptInstationary.cc |  42 ++++++----
 AMDiS/src/AdaptInstationary.h  |   8 +-
 3 files changed, 113 insertions(+), 83 deletions(-)

diff --git a/AMDiS/src/AdaptInfo.h b/AMDiS/src/AdaptInfo.h
index 018a392c..b7bcb416 100644
--- a/AMDiS/src/AdaptInfo.h
+++ b/AMDiS/src/AdaptInfo.h
@@ -84,7 +84,7 @@ namespace AMDiS {
 	spaceTolerance = totalTol * relSpaceErr;
 	timeTolerance = totalTol * relTimeErr * timeTheta1;
 	timeErrLow = totalTol * relTimeErr * timeTheta2;
-      };
+      }
 
       /** \brief
        * Sum of all error estimates
@@ -192,7 +192,7 @@ namespace AMDiS {
 	  scalContents[i] = new ScalContent(name + std::string(number)); 
 	}
       }
-    };
+    }
 
     /** \brief
      * Destructor.
@@ -201,7 +201,7 @@ namespace AMDiS {
       for (int i = 0;  i < scalContents.getSize(); i++) {
 	delete scalContents[i];
       }
-    };
+    }
 
     inline void reset() 
     {
@@ -215,7 +215,7 @@ namespace AMDiS {
       solverResidual = 0.0;
 
       GET_PARAMETER(0, name + "->timestep", "%f", &timestep);
-    };
+    }
 
     /** \brief
      * Returns whether space tolerance is reached.
@@ -228,7 +228,7 @@ namespace AMDiS {
 	}
       }
       return true;
-    };
+    }
 
     /** \brief
      * Returns whether space tolerance of component i is reached.
@@ -239,7 +239,7 @@ namespace AMDiS {
       } else {
 	return true;
       }
-    };
+    }
 
     /** \brief
      * Returns whether time tolerance is reached.
@@ -252,7 +252,7 @@ namespace AMDiS {
 	}
       }
       return true;
-    };
+    }
 
     /** \brief
      * Returns whether time tolerance of component i is reached.
@@ -263,7 +263,7 @@ namespace AMDiS {
       } else {
 	return true;
       }
-    };
+    }
 
     /** \brief
      * Returns whether time error is under its lower bound.
@@ -276,210 +276,220 @@ namespace AMDiS {
 	}
       }
       return true;
-    };
+    }
+
+    /** \brief
+     * Print debug information about time error and its bound.
+     */
+    void printTimeErrorLowInfo() {
+      for (int i = 0; i < scalContents.getSize(); i++) {
+	std::cout << "    Time error estimate = " << scalContents[i]->est_t_sum 
+		  << "    Time error bound = " << scalContents[i]->timeErrLow << "\n";
+      }
+    }
 
     /** \brief
      * Returns \ref spaceIteration.
      */
     inline int getSpaceIteration() { 
       return spaceIteration; 
-    };
+    }
 
     /** \brief
      * Sets \ref spaceIteration.
      */
     inline void setSpaceIteration(int it) { 
       spaceIteration = it; 
-    };
+    }
   
     /** \brief
      * Returns \ref maxSpaceIteration.
      */
     inline int getMaxSpaceIteration() { 
       return maxSpaceIteration;
-    };
+    }
 
     /** \brief
      * Sets \ref maxSpaceIteration.
      */
     inline void setMaxSpaceIteration(int it) { 
       maxSpaceIteration = it; 
-    };
+    }
   
     /** \brief
      * Increments \ref spaceIteration by 1;
      */
     inline void incSpaceIteration() { 
       spaceIteration++; 
-    };
+    }
 
     /** \brief
      * Sets \ref timestepIteration.
      */
     inline void setTimestepIteration(int it) { 
       timestepIteration = it; 
-    };
+    }
   
     /** \brief
      * Returns \ref timestepIteration.
      */
     inline int getTimestepIteration() { 
       return timestepIteration; 
-    };
+    }
 
     /** \brief
      * Increments \ref timestepIteration by 1;
      */
     inline void incTimestepIteration() { 
       timestepIteration++; 
-    };
+    }
 
     /** \brief
      * Returns \ref maxTimestepIteration.
      */
     inline int getMaxTimestepIteration() { 
       return maxTimestepIteration; 
-    };
+    }
 
     /** \brief
      * Sets \ref maxTimestepIteration.
      */
     inline void setMaxTimestepIteration(int it) { 
       maxTimestepIteration = it; 
-    };
+    }
   
     /** \brief
      * Sets \ref timeIteration.
      */
     inline void setTimeIteration(int it) { 
       timeIteration = it; 
-    };
+    }
   
     /** \brief
      * Returns \ref timeIteration.
      */
     inline int getTimeIteration() { 
       return timeIteration; 
-    };
+    }
 
     /** \brief
      * Increments \ref timesIteration by 1;
      */
     inline void incTimeIteration() { 
       timeIteration++; 
-    };
+    }
 
     /** \brief
      * Returns \ref maxTimeIteration.
      */
     inline int getMaxTimeIteration() { 
       return maxTimeIteration; 
-    };
+    }
 
     /** \brief
      * Sets \ref maxTimeIteration.
      */
     inline void setMaxTimeIteration(int it) { 
       maxTimeIteration = it; 
-    };
+    }
   
     /** \brief
      * Returns \ref timestepNumber.
      */
     inline int getTimestepNumber() { 
       return timestepNumber; 
-    };
+    }
 
     /** \brief
      * Increments \ref timestepNumber by 1;
      */
     inline void incTimestepNumber() { 
       timestepNumber++; 
-    };
+    }
 
     /** \brief
      * Sets \ref est_sum.
      */
     inline void setEstSum(double e, int index) {
       scalContents[index]->est_sum = e;
-    };
+    }
 
     /** \brief
      * Sets \ref est_max.
      */
     inline void setEstMax(double e, int index) {
       scalContents[index]->est_max = e;
-    };
+    }
 
     /** \brief
      * Sets \ref est_max.
      */
     inline void setTimeEstMax(double e, int index) {
       scalContents[index]->est_t_max = e;
-    };
+    }
 
     /** \brief
      * Sets \ref est_t_sum.
      */
     inline void setTimeEstSum(double e, int index) {
       scalContents[index]->est_t_sum = e;
-    };
+    }
 
     /** \brief
      * Returns \ref est_sum.
      */
     inline double getEstSum(int index) { 
       return scalContents[index]->est_sum; 
-    };
+    }
 
     /** \brief
      * Returns \ref est_t_sum.
      */
     inline double getEstTSum(int index) { 
       return scalContents[index]->est_t_sum; 
-    };
+    }
 
     /** \brief
      * Returns \ref est_max.
      */
     inline double getEstMax(int index) { 
       return scalContents[index]->est_max; 
-    };
+    }
 
     /** \brief
      * Returns \ref est_max.
      */
     inline double getTimeEstMax(int index) { 
       return scalContents[index]->est_t_max; 
-    };
+    }
 
     /** \brief
      * Returns \ref est_t_sum.
      */
     inline double getTimeEstSum(int index) { 
       return scalContents[index]->est_t_sum; 
-    };
+    }
 
     /** \brief
      * Returns \ref spaceTolerance.
      */
     inline double getSpaceTolerance(int index) { 
       return scalContents[index]->spaceTolerance; 
-    };  
+    }  
 
     /** \brief
      * Sets \ref spaceTolerance.
      */
     inline void setSpaceTolerance(int index, double tol) { 
       scalContents[index]->spaceTolerance = tol; 
-    };  
+    }  
 
     /** \brief
      * Returns \ref timeTolerance.
      */
     inline double getTimeTolerance(int index) { 
       return scalContents[index]->timeTolerance; 
-    };  
+    }  
 
     /** \brief
      * Sets \ref time
@@ -492,21 +502,21 @@ namespace AMDiS {
 	time = startTime;
 
       return time;
-    };
+    }
 
     /** \brief
      * Gets \ref time
      */
     inline double getTime() { 
       return time; 
-    };  
+    }  
 
     /** \brief
      * Gets \ref &time
      */
     inline double *getTimePtr() { 
       return &time; 
-    };  
+    }  
 
     /** \brief
      * Sets \ref timestep
@@ -524,162 +534,162 @@ namespace AMDiS {
       }
       
       return timestep;
-    };
+    }
 
     /** \brief
      * Gets \ref timestep
      */
     inline double getTimestep() { 
       return timestep; 
-    };
+    }
 
     /** \brief
      * Sets \ref minTimestep
      */
     inline void setMinTimestep(double t) { 
       minTimestep = t; 
-    };
+    }
 
     /** \brief
      * Gets \ref minTimestep
      */
     inline double getMinTimestep() { 
       return minTimestep; 
-    };  
+    }  
 
     /** \brief
      * Sets \ref maxTimestep
      */
     inline void setMaxTimestep(double t) { 
       maxTimestep = t; 
-    };
+    }
 
     /** \brief
      * Gets \ref maxTimestep
      */
     inline double getMaxTimestep() { 
       return maxTimestep; 
-    };  
+    }  
 
     /** \brief
      * Gets \ref &timestep
      */
     inline double *getTimestepPtr() { 
       return &timestep; 
-    };  
+    }  
 
     /** \brief
      * Sets \ref startTime = time
      */
     inline void setStartTime(double time) { 
       startTime = time; 
-    };
+    }
 
     /** \brief
      * Sets \ref endTime = time
      */
     inline void setEndTime(double time) { 
       endTime = time; 
-    };
+    }
 
     /** \brief
      * Returns \ref startTime
      */
     inline double getStartTime() { 
       return startTime; 
-    };
+    }
 
     /** \brief
      * Returns \ref endTime
      */
     inline double getEndTime() { 
       return endTime; 
-    };
+    }
 
     /** \brief
      * Returns \ref timeErrLow.
      */
     inline double getTimeErrLow(int index) { 
       return scalContents[index]->timeErrLow; 
-    };  
+    }  
 
     /** \brief
      * Returns whether coarsening is allowed or not.
      */
     inline bool isCoarseningAllowed(int index) {
       return (scalContents[index]->coarsenAllowed == 1);
-    };
+    }
 
     /** \brief
      * Returns whether coarsening is allowed or not.
      */
     inline bool isRefinementAllowed(int index) {
       return (scalContents[index]->refinementAllowed == 1);
-    };
+    }
 
     /** \brief
      * 
      */
     inline void allowRefinement(bool allow, int index) {
       scalContents[index]->refinementAllowed = allow;
-    };
+    }
 
     /** \brief
      * 
      */
     inline void allowCoarsening(bool allow, int index) {
       scalContents[index]->coarsenAllowed = allow;
-    };
+    }
 
     /** \brief
      * Returns \ref refineBisections
      */
     inline const int getRefineBisections(int index) const {
       return scalContents[index]->refineBisections;
-    };
+    }
 
     /** \brief
      * Returns \ref coarseBisections
      */
     inline const int getCoarseBisections(int index) const {
       return scalContents[index]->coarseBisections;
-    };
+    }
 
     inline int getSize() { 
       return scalContents.getSize(); 
-    };
+    }
 
     inline void setSolverIterations(int it) {
       solverIterations = it;
-    };
+    }
   
     inline int getSolverIterations() {
       return solverIterations;
-    };
+    }
   
     inline void setMaxSolverIterations(int it) {
       maxSolverIterations = it;
-    };
+    }
   
     inline int getMaxSolverIterations() {
       return maxSolverIterations;
-    };
+    }
   
     inline void setSolverTolerance(double tol) {
       solverTolerance = tol;
-    };
+    }
   
     inline double getSolverTolerance() {
       return solverTolerance;
-    };
+    }
   
     inline void setSolverResidual(double res) {
       solverResidual = res;
-    };
+    }
   
     inline double getSolverResidual() {
       return solverResidual;
-    };
+    }
 
     /** \brief
      * Returns true, if the adaptive procedure was deserialized from a file.
diff --git a/AMDiS/src/AdaptInstationary.cc b/AMDiS/src/AdaptInstationary.cc
index d185d75e..7a810425 100644
--- a/AMDiS/src/AdaptInstationary.cc
+++ b/AMDiS/src/AdaptInstationary.cc
@@ -15,7 +15,8 @@ namespace AMDiS {
 				       AdaptInfo *initialInfo,
 				       time_t initialTimestamp)
     : AdaptBase(name, problemStat, info, problemInstat, initialInfo),
-      breakWhenStable(0)
+      breakWhenStable(0),
+      dbgMode(false)
   {
     FUNCNAME("AdaptInstationary::AdaptInstationary()");
 
@@ -162,27 +163,40 @@ namespace AMDiS {
 
     if (!fixedTimestep_ && adaptInfo_->timeErrorLow()) {
       adaptInfo_->setTimestep(adaptInfo_->getTimestep() *time_delta_2);
+      if (dbgMode) {
+	// print information about timestep increase
+      }
+    } else {
+      if (dbgMode) {
+	std::cout << "=== ADAPT INFO DEBUG MODE ===\n";
+	std::cout << " Do not increase timestep: \n";
+	if (fixedTimestep_) {
+	  std::cout << "   fixedTimestep = true\n";	
+	}
+	if (!adaptInfo_->timeErrorLow()) {
+	  adaptInfo_->printTimeErrorLowInfo();
+	}
+      }
     }
   }
 
   void AdaptInstationary::oneTimestep()
   {
-    FUNCNAME("AdaptInstationary::oneTimestep");
+    FUNCNAME("AdaptInstationary::oneTimestep()");
 
     adaptInfo_->setTimestepIteration(0);
 
-    switch(strategy)
-      {
-      case 0:
-	explicitTimeStrategy();
-	break;
-      case 1:
-	implicitTimeStrategy();
-	break;
-      default:
-	MSG("unknown strategy = %d; use explicit strategy\n", strategy);
-	explicitTimeStrategy();
-      }
+    switch (strategy) {
+    case 0:
+      explicitTimeStrategy();
+      break;
+    case 1:
+      implicitTimeStrategy();
+      break;
+    default:
+      MSG("unknown strategy = %d; use explicit strategy\n", strategy);
+      explicitTimeStrategy();
+    }
 
     adaptInfo_->incTimestepNumber();
   }
diff --git a/AMDiS/src/AdaptInstationary.h b/AMDiS/src/AdaptInstationary.h
index 47f319b1..1cbf8cf7 100644
--- a/AMDiS/src/AdaptInstationary.h
+++ b/AMDiS/src/AdaptInstationary.h
@@ -71,7 +71,7 @@ namespace AMDiS {
      */
     inline void setStrategy(int aStrategy) { 
       strategy = aStrategy; 
-    };
+    }
 
     /** \brief
      * Returns \ref strategy
@@ -187,6 +187,12 @@ namespace AMDiS {
      * Stores the runtime (in seconds) of some last timestep iterations.
      */
     std::queue<int> lastIterationsDuration_;
+
+    /** \brief
+     * In debug mode, the adapt loop will print information about timestep
+     * decreasing and increasing.
+     */
+    bool dbgMode;
   };
 
 }
-- 
GitLab