From 463d655aa87b9c51726b4cf1579c20ed6708f927 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Mon, 14 Jan 2013 13:46:28 +0100
Subject: [PATCH] Move code around

Do not re-create overallSolver for every timestep
---
 dune/tectonic/nicefunction.hh |  4 ++++
 src/one-body-sample.cc        | 11 +++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/dune/tectonic/nicefunction.hh b/dune/tectonic/nicefunction.hh
index 979efc78..9561d5b5 100644
--- a/dune/tectonic/nicefunction.hh
+++ b/dune/tectonic/nicefunction.hh
@@ -73,6 +73,8 @@ class RuinaFunction : public NiceFunction {
   }
 
   double virtual second_deriv(double x) const {
+    assert(x >= 0);
+    assert(V0 > 0);
     double const arg = x / V0;
     if (arg <= rho)
       return 0;
@@ -81,6 +83,8 @@ class RuinaFunction : public NiceFunction {
   }
 
   double virtual regularity(double x) const {
+    assert(x >= 0);
+    assert(V0 > 0);
     double const arg = x / V0;
     // TODO: Make this controllable
     if (std::abs(arg - rho) < 1e-14)
diff --git a/src/one-body-sample.cc b/src/one-body-sample.cc
index 9058bf1e..5da3d094 100644
--- a/src/one-body-sample.cc
+++ b/src/one-body-sample.cc
@@ -308,9 +308,13 @@ int main(int argc, char *argv[]) {
     MySolver<dims, MatrixType, VectorType, GridType, MyBlockProblemType>
     mySolver(parset.sub("solver.tnnmg"), refinements, solver_tolerance, *grid,
              ignoreNodes);
-
+    auto multigridStep = mySolver.getSolver();
     Solver::VerbosityMode const verbosity =
         parset.get<bool>("verbose") ? Solver::FULL : Solver::QUIET;
+    LoopSolver<VectorType> overallSolver(
+        multigridStep, parset.get<size_t>("solver.tnnmg.maxiterations"),
+        parset.get<double>("solver.tolerance"), &energyNorm, verbosity,
+        false); // absolute error
 
     std::fstream coordinate_writer("coordinates", std::fstream::out);
     for (size_t i = 0; i < frictionalNodes.size(); ++i)
@@ -374,13 +378,8 @@ int main(int argc, char *argv[]) {
         MyConvexProblemType const myConvexProblem(
             problem_A, *myGlobalNonlinearity, problem_rhs);
         MyBlockProblemType myBlockProblem(parset, myConvexProblem);
-        auto multigridStep = mySolver.getSolver();
         multigridStep->setProblem(_problem_iterate, myBlockProblem);
 
-        LoopSolver<VectorType> overallSolver(
-            multigridStep, parset.get<size_t>("solver.tnnmg.maxiterations"),
-            parset.get<double>("solver.tolerance"), &energyNorm, verbosity,
-            false); // absolute error
         overallSolver.preprocess();
         overallSolver.solve();
       };
-- 
GitLab