OGS
NumLib::ConvergenceCriterionResidual Class Referencefinal

Detailed Description

Convergence criterion applying a single absolute or relative tolerance to the whole residual vector.

A check of the solution increment is not done. If both an absolute and a relative tolerance are specified, at least one of them has to be satisfied.

Definition at line 26 of file ConvergenceCriterionResidual.h.

#include <ConvergenceCriterionResidual.h>

Inheritance diagram for NumLib::ConvergenceCriterionResidual:
[legend]
Collaboration diagram for NumLib::ConvergenceCriterionResidual:
[legend]

Public Member Functions

 ConvergenceCriterionResidual (std::optional< double > &&absolute_tolerance, std::optional< double > &&relative_tolerance, const MathLib::VecNormType norm_type)
 
bool hasDeltaXCheck () const override
 
bool hasResidualCheck () const override
 
void checkDeltaX (const GlobalVector &minus_delta_x, GlobalVector const &x) override
 
void checkResidual (const GlobalVector &residual) override
 Check if the residual satisfies the convergence criterion.
 
- Public Member Functions inherited from NumLib::ConvergenceCriterion
 ConvergenceCriterion (const MathLib::VecNormType norm_type)
 
virtual void preFirstIteration ()
 
virtual void setNoFirstIteration ()
 
virtual void reset ()
 
virtual bool isSatisfied () const
 Tell if the convergence criterion is satisfied.
 
MathLib::VecNormType getVectorNormType () const
 
virtual ~ConvergenceCriterion ()=default
 

Private Attributes

const std::optional< double > _abstol
 
const std::optional< double > _reltol
 
double _residual_norm_0
 

Additional Inherited Members

- Protected Attributes inherited from NumLib::ConvergenceCriterion
bool _satisfied = true
 
bool _is_first_iteration = true
 
const MathLib::VecNormType _norm_type
 

Constructor & Destructor Documentation

◆ ConvergenceCriterionResidual()

NumLib::ConvergenceCriterionResidual::ConvergenceCriterionResidual ( std::optional< double > && absolute_tolerance,
std::optional< double > && relative_tolerance,
const MathLib::VecNormType norm_type )

Definition at line 19 of file ConvergenceCriterionResidual.cpp.

23 : ConvergenceCriterion(norm_type),
24 _abstol(std::move(absolute_tolerance)),
25 _reltol(std::move(relative_tolerance))
26{
27 if ((!_abstol) && (!_reltol))
28 {
30 "At least one of absolute or relative tolerance has to be "
31 "specified.");
32 }
33}
#define OGS_FATAL(...)
Definition Error.h:26
ConvergenceCriterion(const MathLib::VecNormType norm_type)

References _abstol, _reltol, and OGS_FATAL.

Member Function Documentation

◆ checkDeltaX()

void NumLib::ConvergenceCriterionResidual::checkDeltaX ( const GlobalVector & minus_delta_x,
GlobalVector const & x )
overridevirtual

The function will only do diagnostic output and no actual check of the solution increment is made

Implements NumLib::ConvergenceCriterion.

Definition at line 35 of file ConvergenceCriterionResidual.cpp.

37{
38 auto error_dx = MathLib::LinAlg::norm(minus_delta_x, _norm_type);
39 auto norm_x = MathLib::LinAlg::norm(x, _norm_type);
40
41 INFO("Convergence criterion: |dx|={:.4e}, |x|={:.4e}, |dx|/|x|={:.4e}",
42 error_dx, norm_x,
43 (norm_x == 0. ? std::numeric_limits<double>::quiet_NaN()
44 : (error_dx / norm_x)));
45}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
const MathLib::VecNormType _norm_type
double norm(MatrixOrVector const &x, MathLib::VecNormType type)
Definition LinAlg.h:96

References NumLib::ConvergenceCriterion::_norm_type, INFO(), and MathLib::LinAlg::norm().

◆ checkResidual()

void NumLib::ConvergenceCriterionResidual::checkResidual ( const GlobalVector & residual)
overridevirtual

Check if the residual satisfies the convergence criterion.

Implements NumLib::ConvergenceCriterion.

Definition at line 47 of file ConvergenceCriterionResidual.cpp.

48{
49 auto norm_res = MathLib::LinAlg::norm(residual, _norm_type);
50
52 {
53 INFO("Convergence criterion: |r0|={:.4e}", norm_res);
54 _residual_norm_0 = norm_res;
55 }
56 else
57 {
59 (_residual_norm_0 < std::numeric_limits<double>::epsilon())
60 ? norm_res
62 if (_residual_norm_0 < std::numeric_limits<double>::epsilon())
63 {
64 INFO("Convergence criterion: |r|={:.4e} |r0|={:.4e}", norm_res,
66 }
67 else
68 {
69 INFO(
70 "Convergence criterion: |r|={:.4e} |r0|={:.4e} |r|/|r0|={:.4e}",
71 norm_res, _residual_norm_0,
72 (_residual_norm_0 == 0.
73 ? std::numeric_limits<double>::quiet_NaN()
74 : (norm_res / _residual_norm_0)));
75 }
76 }
77
78 bool satisfied_abs = false;
79 bool satisfied_rel = false;
80
81 if (_abstol)
82 {
83 satisfied_abs = norm_res < *_abstol;
84 }
86 {
87 satisfied_rel =
89 }
90
91 _satisfied = _satisfied && (satisfied_abs || satisfied_rel);
92}
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)

References _abstol, NumLib::ConvergenceCriterion::_is_first_iteration, NumLib::ConvergenceCriterion::_norm_type, _reltol, _residual_norm_0, NumLib::ConvergenceCriterion::_satisfied, NumLib::checkRelativeTolerance(), INFO(), and MathLib::LinAlg::norm().

◆ hasDeltaXCheck()

bool NumLib::ConvergenceCriterionResidual::hasDeltaXCheck ( ) const
inlineoverridevirtual

Tells if the change of the solution between iterations is checked.

Remarks
This method allows to save some computations if no such check will be done.

Implements NumLib::ConvergenceCriterion.

Definition at line 33 of file ConvergenceCriterionResidual.h.

33{ return true; }

◆ hasResidualCheck()

bool NumLib::ConvergenceCriterionResidual::hasResidualCheck ( ) const
inlineoverridevirtual

Tells if the residual is checked.

Remarks
This method allows to save some computations if no such check will be done.

Implements NumLib::ConvergenceCriterion.

Definition at line 34 of file ConvergenceCriterionResidual.h.

34{ return true; }

Member Data Documentation

◆ _abstol

const std::optional<double> NumLib::ConvergenceCriterionResidual::_abstol
private

Definition at line 43 of file ConvergenceCriterionResidual.h.

Referenced by ConvergenceCriterionResidual(), and checkResidual().

◆ _reltol

const std::optional<double> NumLib::ConvergenceCriterionResidual::_reltol
private

Definition at line 44 of file ConvergenceCriterionResidual.h.

Referenced by ConvergenceCriterionResidual(), and checkResidual().

◆ _residual_norm_0

double NumLib::ConvergenceCriterionResidual::_residual_norm_0
private

Definition at line 45 of file ConvergenceCriterionResidual.h.

Referenced by checkResidual().


The documentation for this class was generated from the following files: