diff --git a/dune/solvers/solvers/criterion.hh b/dune/solvers/solvers/criterion.hh index 076198b022646babe2898d6f7532f2d8e30428bc..cd5ed60d1919c4700d6770a8e7664ea7cca3cc78 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