From f710c45698adcbe5813edcefbcc32b3f31adbf1a Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Tue, 4 Nov 2014 16:30:55 +0100
Subject: [PATCH] [Cleanup] multigridStep: Only retrieve multigrid step once

---
 src/fixedpointiterator.cc | 12 +++++-------
 src/fixedpointiterator.hh |  2 +-
 src/solverfactory.hh      |  3 ++-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/fixedpointiterator.cc b/src/fixedpointiterator.cc
index b8fa3e55..29557480 100644
--- a/src/fixedpointiterator.cc
+++ b/src/fixedpointiterator.cc
@@ -19,7 +19,7 @@ FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::
     FixedPointIterator(Factory &factory, Dune::ParameterTree const &parset,
                        std::shared_ptr<Nonlinearity> globalFriction,
                        ErrorNorm const &errorNorm)
-    : factory_(factory),
+    : step_(factory.getStep()),
       parset_(parset),
       globalFriction_(globalFriction),
       fixedPointMaxIterations_(parset.get<size_t>("v.fpi.maximumIterations")),
@@ -38,12 +38,10 @@ FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
     std::shared_ptr<VelocityUpdater> velocityUpdater,
     Matrix const &velocityMatrix, Vector const &velocityRHS,
     Vector &velocityIterate) {
-  auto multigridStep = factory_.getStep();
-
   EnergyNorm<Matrix, Vector> energyNorm(velocityMatrix);
-  LoopSolver<Vector> velocityProblemSolver(
-      multigridStep.get(), velocityMaxIterations_, velocityTolerance_,
-      &energyNorm, verbosity_, false); // absolute error
+  LoopSolver<Vector> velocityProblemSolver(step_.get(), velocityMaxIterations_,
+                                           velocityTolerance_, &energyNorm,
+                                           verbosity_, false); // absolute error
 
   size_t fixedPointIteration;
   size_t multigridIterations = 0;
@@ -56,7 +54,7 @@ FixedPointIterator<Factory, StateUpdater, VelocityUpdater, ErrorNorm>::run(
     ConvexProblem convexProblem(1.0, velocityMatrix, *globalFriction_,
                                 velocityRHS, velocityIterate);
     BlockProblem velocityProblem(parset_, convexProblem);
-    multigridStep->setProblem(velocityIterate, velocityProblem);
+    step_->setProblem(velocityIterate, velocityProblem);
     velocityProblemSolver.preprocess();
     velocityProblemSolver.solve();
 
diff --git a/src/fixedpointiterator.hh b/src/fixedpointiterator.hh
index f7c8ccec..56ba7f28 100644
--- a/src/fixedpointiterator.hh
+++ b/src/fixedpointiterator.hh
@@ -38,7 +38,7 @@ class FixedPointIterator {
       Vector &velocityIterate);
 
 private:
-  Factory &factory_;
+  std::shared_ptr<typename Factory::Step> step_;
   Dune::ParameterTree const &parset_;
   std::shared_ptr<Nonlinearity> globalFriction_;
 
diff --git a/src/solverfactory.hh b/src/solverfactory.hh
index 91353289..055401f4 100644
--- a/src/solverfactory.hh
+++ b/src/solverfactory.hh
@@ -26,10 +26,11 @@ class SolverFactory {
 
 private:
   using NonlinearSmoother = GenericNonlinearGS<BlockProblem>;
+
+public:
   using Step =
       TruncatedNonsmoothNewtonMultigrid<BlockProblem, NonlinearSmoother>;
 
-public:
   SolverFactory(Dune::ParameterTree const &parset, size_t refinements,
                 Grid const &grid, Dune::BitSetVector<dim> const &ignoreNodes);
 
-- 
GitLab