From f1a78af6f141482076058ca8859069d1e8988aae Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Sat, 16 Jul 2016 18:44:13 +0200
Subject: [PATCH] Avoid division by zero convergence rate

---
 dune/solvers/solvers/loopsolver.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/dune/solvers/solvers/loopsolver.cc b/dune/solvers/solvers/loopsolver.cc
index 1d73be7e..c90363c4 100644
--- a/dune/solvers/solvers/loopsolver.cc
+++ b/dune/solvers/solvers/loopsolver.cc
@@ -110,7 +110,8 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
         // Please don't replace this call to 'diff' by computing the norm of the difference.
         // In some nonlinear DD applications the 'diff' method may be nonlinear.
         real_type normOfCorrection = this->errorNorm_->diff(oldSolution,iterationStep_->getSol());
-        real_type convRate = normOfCorrection / normOfOldCorrection;
+        real_type convRate = (normOfOldCorrection > 0)
+            ? normOfCorrection / normOfOldCorrection : 0.0;
         error = normOfCorrection;
         normOfOldCorrection = normOfCorrection;
 
@@ -118,7 +119,7 @@ void ::LoopSolver<VectorType, BitVectorType>::solve()
         if (referenceSolution_)
         {
             normOfError = this->errorNorm_->diff(iterationStep_->getSol(), *referenceSolution_);
-            convRate = normOfError / normOfOldError;
+            convRate = (normOfOldError > 0) ? normOfError / normOfOldError : 0.0;
             error = normOfError;
             normOfOldError = normOfError;
         }
-- 
GitLab