OGS
NumLib::ConvergenceCriterionDeltaX Class Referencefinal

Detailed Description

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

A residual check 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 ConvergenceCriterionDeltaX.h.

#include <ConvergenceCriterionDeltaX.h>

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

Public Member Functions

 ConvergenceCriterionDeltaX (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 &) override
 Check if the residual satisfies the convergence criterion. More...
 
void reset () override
 
- Public Member Functions inherited from NumLib::ConvergenceCriterion
 ConvergenceCriterion (const MathLib::VecNormType norm_type)
 
virtual void preFirstIteration ()
 
virtual void setNoFirstIteration ()
 
virtual bool isSatisfied () const
 Tell if the convergence criterion is satisfied. More...
 
MathLib::VecNormType getVectorNormType () const
 
virtual ~ConvergenceCriterion ()=default
 

Private Attributes

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

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

◆ ConvergenceCriterionDeltaX()

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

Definition at line 19 of file ConvergenceCriterionDeltaX.cpp.

23  : ConvergenceCriterion(norm_type),
24  _abstol(std::move(absolute_tolerance)),
25  _reltol(std::move(relative_tolerance))
26 {
27  if ((!_abstol) && (!_reltol))
28  {
29  OGS_FATAL(
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::ConvergenceCriterionDeltaX::checkDeltaX ( const GlobalVector minus_delta_x,
GlobalVector const &  x 
)
overridevirtual

Check if the change of the solution between iterations satisfies the convergence criterion.

Parameters
minus_delta_xthe current solution update
xthe new solution from the current iteration
Remarks
The Newton-Raphson solver computes minus_delta_x. x is needed for relative tolerances.

Implements NumLib::ConvergenceCriterion.

Definition at line 35 of file ConvergenceCriterionDeltaX.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 
46  bool satisfied_abs = false;
47  bool satisfied_rel = false;
48 
49  if (_abstol)
50  {
51  satisfied_abs = error_dx < *_abstol;
52  }
53  if (_reltol)
54  {
55  satisfied_rel = checkRelativeTolerance(*_reltol, error_dx, norm_x);
56  }
57 
58  _satisfied = _satisfied && (satisfied_abs || satisfied_rel);
59 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
const MathLib::VecNormType _norm_type
double norm(MatrixOrVector const &x, MathLib::VecNormType type)
Definition: LinAlg.h:88
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)

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

◆ checkResidual()

void NumLib::ConvergenceCriterionDeltaX::checkResidual ( const GlobalVector residual)
inlineoverridevirtual

Check if the residual satisfies the convergence criterion.

Implements NumLib::ConvergenceCriterion.

Definition at line 38 of file ConvergenceCriterionDeltaX.h.

38 {}

◆ hasDeltaXCheck()

bool NumLib::ConvergenceCriterionDeltaX::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 ConvergenceCriterionDeltaX.h.

33 { return true; }

◆ hasResidualCheck()

bool NumLib::ConvergenceCriterionDeltaX::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 ConvergenceCriterionDeltaX.h.

34 { return false; }

◆ reset()

void NumLib::ConvergenceCriterionDeltaX::reset ( )
inlineoverridevirtual

Indicate that a new iteration now starts.

A concrete implementation of ConvergenceCriterion might want to check both delta x and the residual. I.e., in a new iteration both checks have to be done anew. This method will make the ConvergenceCriterion forget the result of all checks already done, s.t. all necessary checks will have to be repeated in order to satisfy the ConvergenceCriterion.

Reimplemented from NumLib::ConvergenceCriterion.

Definition at line 40 of file ConvergenceCriterionDeltaX.h.

40 { this->_satisfied = true; }

References NumLib::ConvergenceCriterion::_satisfied.

Member Data Documentation

◆ _abstol

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

Definition at line 43 of file ConvergenceCriterionDeltaX.h.

Referenced by ConvergenceCriterionDeltaX(), and checkDeltaX().

◆ _reltol

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

Definition at line 44 of file ConvergenceCriterionDeltaX.h.

Referenced by ConvergenceCriterionDeltaX(), and checkDeltaX().


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