From 36796f9c01d530417b2e79157acf1d42a14231a8 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 6 Jul 2020 17:13:15 +0200 Subject: [PATCH 1/2] [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 From 8613440513d091ed6d3c05e8c3a34b38e69d2be7 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Tue, 7 Jul 2020 09:20:31 +0200 Subject: [PATCH 2/2] [ricahrds] Clean up Newton solver * use std::clamp * clean up docu * clean up includes --- dumux/porousmediumflow/richards/newtonsolver.hh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/dumux/porousmediumflow/richards/newtonsolver.hh b/dumux/porousmediumflow/richards/newtonsolver.hh index 0e27859933..421f3783d8 100644 --- a/dumux/porousmediumflow/richards/newtonsolver.hh +++ b/dumux/porousmediumflow/richards/newtonsolver.hh @@ -25,7 +25,7 @@ #ifndef DUMUX_RICHARDS_NEWTON_SOLVER_HH #define DUMUX_RICHARDS_NEWTON_SOLVER_HH -#include +#include #include #include @@ -37,8 +37,6 @@ namespace Dumux { * This solver 'knows' what a 'physically meaningful' solution is * and can thus do update smarter than the plain Newton solver. * - * \todo make this typetag independent by extracting anything model specific from assembler - * or from possible ModelTraits. */ template class RichardsNewtonSolver : public NewtonSolver @@ -96,14 +94,13 @@ private: const Scalar pcOld = pn - pw; const Scalar SwOld = max(0.0, MaterialLaw::sw(materialLawParams, pcOld)); - // convert into minimum and maximum wetting phase - // pressures + // convert into minimum and maximum wetting phase pressures const Scalar pwMin = pn - MaterialLaw::pc(materialLawParams, SwOld - 0.2); const Scalar pwMax = pn - MaterialLaw::pc(materialLawParams, SwOld + 0.2); // clamp the result - using std::min; using std::max; - uCurrentIter[dofIdxGlobal][pressureIdx] = max(pwMin, min(uCurrentIter[dofIdxGlobal][pressureIdx], pwMax)); + using std::clamp; + uCurrentIter[dofIdxGlobal][pressureIdx] = clamp(uCurrentIter[dofIdxGlobal][pressureIdx], pwMin, pwMax); } } } -- GitLab