From c55e90fa7fdfdaaba930a460d7374e57c5233211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@dune-project.org> Date: Mon, 10 Nov 2014 13:51:11 +0100 Subject: [PATCH] Add convenience method for absulute norm criterion --- dune/solvers/solvers/criterion.hh | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/dune/solvers/solvers/criterion.hh b/dune/solvers/solvers/criterion.hh index 076198b0..cd5ed60d 100644 --- a/dune/solvers/solvers/criterion.hh +++ b/dune/solvers/solvers/criterion.hh @@ -207,6 +207,54 @@ namespace Dune { " iter"); } + /** + * \brief Create a Criterion for checking the correction norm + * + * \param iterationStep The IterationStep to be monitored + * \param norm Norm to be evaluated for the correction + * \param tolerance Tolerance necessary to satisfy the criterion + * \param correctionNorms A container to store the computed correction norms + */ + template<class IterationStepType, class NormType, class CorrectionNormContainer> + Criterion correctionNormCriterion( + const IterationStepType& iterationStep, + const NormType& norm, + double tolerance, + CorrectionNormContainer& correctionNorms) + { + auto lastIterate = std::make_shared<typename IterationStepType::Vector>(*iterationStep.getIterate()); + return Criterion( + [&, lastIterate, tolerance] () mutable { + double normOfCorrection = norm.diff(*lastIterate, *iterationStep.getIterate()); + correctionNorms.push_back(normOfCorrection); + *lastIterate = *iterationStep.getIterate(); + return std::make_tuple(normOfCorrection < tolerance, Dune::formatString(" % 14.7e", normOfCorrection)); + }, + " abs correction"); + } + + /** + * \brief Create a Criterion for checking the correction norm + * + * \param iterationStep The IterationStep to be monitored + * \param norm Norm to be evaluated for the correction + * \param tolerance Tolerance necessary to satisfy the criterion + */ + template<class IterationStepType, class NormType> + Criterion correctionNormCriterion( + const IterationStepType& iterationStep, + const NormType& norm, + double tolerance) + { + auto lastIterate = std::make_shared<typename IterationStepType::Vector>(*iterationStep.getIterate()); + return Criterion( + [&, lastIterate, tolerance] () mutable { + double normOfCorrection = norm.diff(*lastIterate, *iterationStep.getIterate()); + *lastIterate = *iterationStep.getIterate(); + return std::make_tuple(normOfCorrection < tolerance, Dune::formatString(" % 14.7e", normOfCorrection)); + }, + " abs correction"); + } } // end namespace Solvers -- GitLab