From 36796f9c01d530417b2e79157acf1d42a14231a8 Mon Sep 17 00:00:00 2001
From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de>
Date: Mon, 6 Jul 2020 17:13:15 +0200
Subject: [PATCH] [newtonsolver] Use virtual function to update the gridVars
 after an update of the solution

---
 dumux/assembly/fvassembler.hh                  |  3 ---
 dumux/nonlinear/newtonsolver.hh                | 18 ++++++++++--------
 .../porousmediumflow/richards/newtonsolver.hh  | 11 +++--------
 3 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/dumux/assembly/fvassembler.hh b/dumux/assembly/fvassembler.hh
index c60d14fff8..962e83a533 100644
--- a/dumux/assembly/fvassembler.hh
+++ b/dumux/assembly/fvassembler.hh
@@ -154,9 +154,6 @@ public:
     {
         checkAssemblerState_();
 
-        // update the grid variables for the case of active caching
-        gridVariables_->update(curSol);
-
         assemble_([&](const Element& element)
         {
             LocalAssembler localAssembler(*this, element, curSol);
diff --git a/dumux/nonlinear/newtonsolver.hh b/dumux/nonlinear/newtonsolver.hh
index a5e34418f4..4ff3f1b2f2 100644
--- a/dumux/nonlinear/newtonsolver.hh
+++ b/dumux/nonlinear/newtonsolver.hh
@@ -541,17 +541,10 @@ public:
         {
             uCurrentIter = uLastIter;
             uCurrentIter -= deltaU;
+            solutionChanged_(uCurrentIter);
 
             if (enableResidualCriterion_)
                 computeResidualReduction_(uCurrentIter);
-
-            else
-            {
-                // If we get here, the convergence criterion does not require
-                // additional residual evaluations. Thus, the grid variables have
-                // not yet been updated to the new uCurrentIter.
-                this->assembler().updateGridVariables(uCurrentIter);
-            }
         }
     }
 
@@ -782,6 +775,14 @@ public:
 
 protected:
 
+    /*!
+     * \brief Update solution-depended quantities like grid variables after the solution has changed.
+     */
+    virtual void solutionChanged_(const SolutionVector &uCurrentIter)
+    {
+        this->assembler().updateGridVariables(uCurrentIter);
+    }
+
     void computeResidualReduction_(const SolutionVector &uCurrentIter)
     {
         residualNorm_ = this->assembler().residualNorm(uCurrentIter);
@@ -1048,6 +1049,7 @@ private:
             uCurrentIter = deltaU;
             uCurrentIter *= -lambda;
             uCurrentIter += uLastIter;
+            solutionChanged_(uCurrentIter);
 
             computeResidualReduction_(uCurrentIter);
 
diff --git a/dumux/porousmediumflow/richards/newtonsolver.hh b/dumux/porousmediumflow/richards/newtonsolver.hh
index bafc188d17..0e27859933 100644
--- a/dumux/porousmediumflow/richards/newtonsolver.hh
+++ b/dumux/porousmediumflow/richards/newtonsolver.hh
@@ -108,16 +108,11 @@ private:
             }
         }
 
+        // update the grid variables
+        this->solutionChanged_(uCurrentIter);
+
         if (this->enableResidualCriterion())
             this->computeResidualReduction_(uCurrentIter);
-
-        else
-        {
-            // If we get here, the convergence criterion does not require
-            // additional residual evalutions. Thus, the grid variables have
-            // not yet been updated to the new uCurrentIter.
-            this->assembler().updateGridVariables(uCurrentIter);
-        }
     }
 };
 
-- 
GitLab