From 7eb521290d25c58fd3ae201f821af22ea5a9e633 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Thu, 23 Oct 2014 16:13:39 +0200
Subject: [PATCH] [Output]  Write out multigrid iterations

---
 src/coupledtimestepper.cc |  4 ++--
 src/coupledtimestepper.hh |  3 ++-
 src/fixedpointiterator.cc | 14 ++++++++++++--
 src/fixedpointiterator.hh | 17 +++++++++++++----
 4 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/src/coupledtimestepper.cc b/src/coupledtimestepper.cc
index 1dd286ff..6df09828 100644
--- a/src/coupledtimestepper.cc
+++ b/src/coupledtimestepper.cc
@@ -3,7 +3,6 @@
 #endif
 
 #include "coupledtimestepper.hh"
-#include "fixedpointiterator.hh"
 
 template <class Factory, class StateUpdater, class VelocityUpdater,
           class ErrorNorm>
@@ -26,7 +25,8 @@ CoupledTimeStepper<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::
 
 template <class Factory, class StateUpdater, class VelocityUpdater,
           class ErrorNorm>
-int CoupledTimeStepper<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::step(
+FixedPointIterationCounter
+CoupledTimeStepper<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::step(
     double relativeTime, double relativeTau) {
   stateUpdater_->nextTimeStep();
   velocityUpdater_->nextTimeStep();
diff --git a/src/coupledtimestepper.hh b/src/coupledtimestepper.hh
index f8122e62..a0398299 100644
--- a/src/coupledtimestepper.hh
+++ b/src/coupledtimestepper.hh
@@ -5,6 +5,7 @@
 #include <memory>
 
 #include <dune/common/parametertree.hh>
+#include "fixedpointiterator.hh"
 
 template <class Factory, class StateUpdater, class VelocityUpdater,
           class ErrorNorm>
@@ -23,7 +24,7 @@ class CoupledTimeStepper {
                      ErrorNorm const &errorNorm,
                      std::function<void(double, Vector &)> externalForces);
 
-  int step(double relativeTime, double relativeTau);
+  FixedPointIterationCounter step(double relativeTime, double relativeTau);
 
 private:
   double finalTime_;
diff --git a/src/fixedpointiterator.cc b/src/fixedpointiterator.cc
index 23569d9f..8a73ba48 100644
--- a/src/fixedpointiterator.cc
+++ b/src/fixedpointiterator.cc
@@ -32,7 +32,8 @@ FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::
 
 template <class Factory, class StateUpdater, class VelocityUpdater,
           class ErrorNorm>
-int FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
+FixedPointIterationCounter
+FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
     std::shared_ptr<StateUpdater> stateUpdater,
     std::shared_ptr<VelocityUpdater> velocityUpdater,
     Matrix const &velocityMatrix, Vector const &velocityRHS,
@@ -45,6 +46,7 @@ int FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
       verbosity_, false); // absolute error
 
   size_t fixedPointIteration;
+  size_t multigridIterations = 0;
   ScalarVector alpha;
   stateUpdater->extractAlpha(alpha);
   for (fixedPointIteration = 0; fixedPointIteration < fixedPointMaxIterations_;
@@ -58,6 +60,8 @@ int FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
     velocityProblemSolver.preprocess();
     velocityProblemSolver.solve();
 
+    multigridIterations += velocityProblemSolver.getResult().iterations;
+
     Vector v_m;
     velocityUpdater->extractOldVelocity(v_m);
     v_m *= 1.0 - lambda_;
@@ -79,7 +83,13 @@ int FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
 
   velocityUpdater->postProcess(velocityIterate);
 
-  return fixedPointIteration;
+  return { fixedPointIteration, multigridIterations };
+}
+
+std::ostream &operator<<(std::ostream &stream,
+                         FixedPointIterationCounter const &fpic) {
+  return stream << "(" << fpic.iterations << "," << fpic.multigridIterations
+                << ")";
 }
 
 #include "fixedpointiterator_tmpl.cc"
diff --git a/src/fixedpointiterator.hh b/src/fixedpointiterator.hh
index 34a7d42f..f7c8ccec 100644
--- a/src/fixedpointiterator.hh
+++ b/src/fixedpointiterator.hh
@@ -8,6 +8,14 @@
 #include <dune/solvers/norms/norm.hh>
 #include <dune/solvers/solvers/solver.hh>
 
+struct FixedPointIterationCounter {
+  size_t iterations;
+  size_t multigridIterations;
+};
+
+std::ostream &operator<<(std::ostream &stream,
+                         FixedPointIterationCounter const &fpic);
+
 template <class Factory, class StateUpdater, class VelocityUpdater,
           class ErrorNorm>
 class FixedPointIterator {
@@ -23,10 +31,11 @@ class FixedPointIterator {
                      std::shared_ptr<Nonlinearity> globalFriction,
                      ErrorNorm const &errorNorm_);
 
-  int run(std::shared_ptr<StateUpdater> stateUpdater,
-          std::shared_ptr<VelocityUpdater> velocityUpdater,
-          Matrix const &velocityMatrix, Vector const &velocityRHS,
-          Vector &velocityIterate);
+  FixedPointIterationCounter run(
+      std::shared_ptr<StateUpdater> stateUpdater,
+      std::shared_ptr<VelocityUpdater> velocityUpdater,
+      Matrix const &velocityMatrix, Vector const &velocityRHS,
+      Vector &velocityIterate);
 
 private:
   Factory &factory_;
-- 
GitLab