OGS
NumLib::ConvergenceCriterionPerComponentDeltaX Class Reference

Detailed Description

Convergence criterion applying absolute or relative tolerances individually to each component of the whole solution increment vector.

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

Definition at line 26 of file ConvergenceCriterionPerComponentDeltaX.h.

#include <ConvergenceCriterionPerComponentDeltaX.h>

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

Public Member Functions

 ConvergenceCriterionPerComponentDeltaX (std::vector< double > &&absolute_tolerances, std::vector< double > &&relative_tolerances, 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.
 
void reset () override
 
void setDOFTable (const LocalToGlobalIndexMap &dof_table, MeshLib::Mesh const &mesh) override
 Sets the d.o.f. table used to extract data for a specific component.
 
- Public Member Functions inherited from NumLib::ConvergenceCriterionPerComponent
 ConvergenceCriterionPerComponent (const MathLib::VecNormType norm_type)
 
- 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.
 
MathLib::VecNormType getVectorNormType () const
 
virtual ~ConvergenceCriterion ()=default
 

Private Attributes

const std::vector< double > _abstols
 
const std::vector< double > _reltols
 
LocalToGlobalIndexMap const * _dof_table = nullptr
 
MeshLib::Mesh const * _mesh = nullptr
 

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

◆ ConvergenceCriterionPerComponentDeltaX()

NumLib::ConvergenceCriterionPerComponentDeltaX::ConvergenceCriterionPerComponentDeltaX ( std::vector< double > && absolute_tolerances,
std::vector< double > && relative_tolerances,
const MathLib::VecNormType norm_type )

Definition at line 22 of file ConvergenceCriterionPerComponentDeltaX.cpp.

27 _abstols(std::move(absolute_tolerances)),
28 _reltols(std::move(relative_tolerances))
29{
30 if (_abstols.size() != _reltols.size())
31 {
33 "The number of absolute and relative tolerances given must be the "
34 "same.");
35 }
36
37 if (_abstols.empty())
38 {
39 OGS_FATAL("The given tolerances vector is empty.");
40 }
41}
#define OGS_FATAL(...)
Definition Error.h:26
ConvergenceCriterionPerComponent(const MathLib::VecNormType norm_type)

References _abstols, and _reltols.

Member Function Documentation

◆ checkDeltaX()

void NumLib::ConvergenceCriterionPerComponentDeltaX::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 43 of file ConvergenceCriterionPerComponentDeltaX.cpp.

45{
46 if ((!_dof_table) || (!_mesh))
47 {
48 OGS_FATAL("D.o.f. table or mesh have not been set.");
49 }
50
51 for (unsigned global_component = 0; global_component < _abstols.size();
52 ++global_component)
53 {
54 // TODO short cut if tol <= 0.0
55 auto error_dx = norm(minus_delta_x, global_component, _norm_type,
56 *_dof_table, *_mesh);
57 auto norm_x =
58 norm(x, global_component, _norm_type, *_dof_table, *_mesh);
59
60 INFO(
61 "Convergence criterion, component {:d}: |dx|={:.4e}, |x|={:.4e}, "
62 "|dx|/|x|={:.4e}",
63 global_component, error_dx, norm_x,
64 (norm_x == 0. ? std::numeric_limits<double>::quiet_NaN()
65 : (error_dx / norm_x)));
66
67 bool const satisfied_abs = error_dx < _abstols[global_component];
68 bool const satisfied_rel = checkRelativeTolerance(
69 _reltols[global_component], error_dx, norm_x);
70
71 _satisfied = _satisfied && (satisfied_abs || satisfied_rel);
72 }
73}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
const MathLib::VecNormType _norm_type
double norm(GlobalVector const &x, unsigned const global_component, MathLib::VecNormType norm_type, LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh)
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)

References _abstols, _dof_table, _mesh, NumLib::ConvergenceCriterion::_norm_type, _reltols, NumLib::ConvergenceCriterion::_satisfied, NumLib::checkRelativeTolerance(), INFO(), NumLib::norm(), and OGS_FATAL.

◆ checkResidual()

void NumLib::ConvergenceCriterionPerComponentDeltaX::checkResidual ( const GlobalVector & residual)
inlineoverridevirtual

Check if the residual satisfies the convergence criterion.

Implements NumLib::ConvergenceCriterion.

Definition at line 40 of file ConvergenceCriterionPerComponentDeltaX.h.

40{}

◆ hasDeltaXCheck()

bool NumLib::ConvergenceCriterionPerComponentDeltaX::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 35 of file ConvergenceCriterionPerComponentDeltaX.h.

35{ return true; }

◆ hasResidualCheck()

bool NumLib::ConvergenceCriterionPerComponentDeltaX::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 36 of file ConvergenceCriterionPerComponentDeltaX.h.

36{ return false; }

◆ reset()

void NumLib::ConvergenceCriterionPerComponentDeltaX::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 42 of file ConvergenceCriterionPerComponentDeltaX.h.

42{ this->_satisfied = true; }

References NumLib::ConvergenceCriterion::_satisfied.

◆ setDOFTable()

void NumLib::ConvergenceCriterionPerComponentDeltaX::setDOFTable ( const LocalToGlobalIndexMap & dof_table,
MeshLib::Mesh const & mesh )
overridevirtual

Sets the d.o.f. table used to extract data for a specific component.

Implements NumLib::ConvergenceCriterionPerComponent.

Definition at line 75 of file ConvergenceCriterionPerComponentDeltaX.cpp.

77{
78 _dof_table = &dof_table;
79 _mesh = &mesh;
80
82 static_cast<int>(_abstols.size()))
83 {
85 "The number of components in the DOF table and the number of "
86 "tolerances given do not match.");
87 }
88}

References _abstols, _dof_table, _mesh, NumLib::LocalToGlobalIndexMap::getNumberOfGlobalComponents(), and OGS_FATAL.

Member Data Documentation

◆ _abstols

const std::vector<double> NumLib::ConvergenceCriterionPerComponentDeltaX::_abstols
private

◆ _dof_table

LocalToGlobalIndexMap const* NumLib::ConvergenceCriterionPerComponentDeltaX::_dof_table = nullptr
private

Definition at line 50 of file ConvergenceCriterionPerComponentDeltaX.h.

Referenced by checkDeltaX(), and setDOFTable().

◆ _mesh

MeshLib::Mesh const* NumLib::ConvergenceCriterionPerComponentDeltaX::_mesh = nullptr
private

Definition at line 51 of file ConvergenceCriterionPerComponentDeltaX.h.

Referenced by checkDeltaX(), and setDOFTable().

◆ _reltols

const std::vector<double> NumLib::ConvergenceCriterionPerComponentDeltaX::_reltols
private

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