From 411d0fae4b3f5c9c8e1a84224ba8bd34a8f32143 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Tue, 3 Sep 2013 16:30:51 +0000
Subject: [PATCH] Allow to specify a minimal number of trust-region iterations

[[Imported from SVN: r9450]]
---
 dune/gfe/targetspacertrsolver.cc | 6 +++++-
 dune/gfe/targetspacertrsolver.hh | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/dune/gfe/targetspacertrsolver.cc b/dune/gfe/targetspacertrsolver.cc
index 2612f63f..c1c4d5aa 100644
--- a/dune/gfe/targetspacertrsolver.cc
+++ b/dune/gfe/targetspacertrsolver.cc
@@ -24,6 +24,7 @@ setup(const AverageDistanceAssembler<TargetSpace>* assembler,
     innerIterations_          = innerIterations;
     innerTolerance_           = innerTolerance;
     this->verbosity_          = NumProc::QUIET;
+    minNumberOfIterations_    = 4;
 
     // ////////////////////////////////
     //   Create a projected gauss-seidel solver
@@ -48,6 +49,8 @@ setup(const AverageDistanceAssembler<TargetSpace>* assembler,
 template <class TargetSpace>
 void TargetSpaceRiemannianTRSolver<TargetSpace>::solve()
 {
+    assert(minNumberOfIterations_ > 0);
+
     MaxNormTrustRegion<blocksize,field_type> trustRegion(1,   // we have only one block
                                               initialTrustRegionRadius_);
 
@@ -93,7 +96,7 @@ void TargetSpaceRiemannianTRSolver<TargetSpace>::solve()
         if (this->verbosity_ == NumProc::FULL)
             std::cout << "Infinity norm of the correction: " << corr.infinity_norm() << std::endl;
 
-        if (corr.infinity_norm() < this->tolerance_) {
+        if (corr.infinity_norm() < this->tolerance_ and i>=minNumberOfIterations_-1) {
             if (this->verbosity_ == NumProc::FULL)
                 std::cout << "CORRECTION IS SMALL ENOUGH" << std::endl;
 
@@ -136,6 +139,7 @@ void TargetSpaceRiemannianTRSolver<TargetSpace>::solve()
         }
 
         if (energy >= oldEnergy &&
+            i>minNumberOfIterations_-1 &&
             (std::abs(oldEnergy-energy)/energy < 1e-9 || modelDecrease/energy < 1e-9)) {
             if (this->verbosity_ == NumProc::FULL)
                 std::cout << "Suspecting rounding problems" << std::endl;
diff --git a/dune/gfe/targetspacertrsolver.hh b/dune/gfe/targetspacertrsolver.hh
index 2213cb15..8c34f20e 100644
--- a/dune/gfe/targetspacertrsolver.hh
+++ b/dune/gfe/targetspacertrsolver.hh
@@ -81,6 +81,15 @@ protected:
     /** \brief Norm for the quadratic inner problems */
     std::auto_ptr<EnergyNorm<MatrixType, CorrectionType> > energyNorm_;
 
+    /** \brief Specify a minimal number of iterations the trust-region solver has to do
+     *
+     * This is needed when working with automatic differentiation.    While a very low
+     * number of iterations may be enough to precisely compute the value of a
+     * geodesic finite element function, a higher number may be needed to make an AD
+     * system compute a derivative with sufficient precision.
+     */
+    size_t minNumberOfIterations_;
+
 };
 
 #include "targetspacertrsolver.cc"
-- 
GitLab