OGS
NumLib::ConvergenceCriterionPerComponentResidual Class Reference

Detailed Description

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

A check of the solution increment 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 28 of file ConvergenceCriterionPerComponentResidual.h.

#include <ConvergenceCriterionPerComponentResidual.h>

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

Public Member Functions

 ConvergenceCriterionPerComponentResidual (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 &residual) override
 Check if the residual satisfies the convergence criterion.
 
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 void reset ()
 
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
 
std::vector< double > _residual_norms_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

◆ ConvergenceCriterionPerComponentResidual()

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

Definition at line 20 of file ConvergenceCriterionPerComponentResidual.cpp.

26 _abstols(std::move(absolute_tolerances)),
27 _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::ConvergenceCriterionPerComponentResidual::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 43 of file ConvergenceCriterionPerComponentResidual.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}
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)

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

◆ checkResidual()

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

Check if the residual satisfies the convergence criterion.

Implements NumLib::ConvergenceCriterion.

Definition at line 69 of file ConvergenceCriterionPerComponentResidual.cpp.

71{
72 if ((!_dof_table) || (!_mesh))
73 {
74 OGS_FATAL("D.o.f. table or mesh have not been set.");
75 }
76
77 for (unsigned global_component = 0; global_component < _abstols.size();
78 ++global_component)
79 {
80 // TODO short cut if tol <= 0.0
81 auto norm_res =
82 norm(residual, global_component, _norm_type, *_dof_table, *_mesh);
83
85 {
86 INFO("Convergence criterion, component {:d}: |r0|={:.4e}",
87 global_component, norm_res);
88 _residual_norms_0[global_component] = norm_res;
89 }
90 else
91 {
92 auto const norm_res0 = _residual_norms_0[global_component];
93 INFO(
94 "Convergence criterion, component {:d}: |r|={:.4e}, "
95 "|r0|={:.4e}, |r|/|r0|={:.4e}",
96 global_component, norm_res, norm_res0,
97 (norm_res0 == 0. ? std::numeric_limits<double>::quiet_NaN()
98 : (norm_res / norm_res0)));
99 }
100
101 bool const satisfied_abs = norm_res < _abstols[global_component];
102 // Make sure that in the first iteration the relative residual tolerance
103 // is not satisfied.
104 bool const satisfied_rel =
106 checkRelativeTolerance(_reltols[global_component], norm_res,
107 _residual_norms_0[global_component]);
108 _satisfied = _satisfied && (satisfied_abs || satisfied_rel);
109 }
110}
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)

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

◆ hasDeltaXCheck()

bool NumLib::ConvergenceCriterionPerComponentResidual::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 37 of file ConvergenceCriterionPerComponentResidual.h.

37{ return true; }

◆ hasResidualCheck()

bool NumLib::ConvergenceCriterionPerComponentResidual::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 38 of file ConvergenceCriterionPerComponentResidual.h.

38{ return true; }

◆ setDOFTable()

void NumLib::ConvergenceCriterionPerComponentResidual::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 112 of file ConvergenceCriterionPerComponentResidual.cpp.

114{
115 _dof_table = &dof_table;
116 _mesh = &mesh;
117
119 static_cast<int>(_abstols.size()))
120 {
121 OGS_FATAL(
122 "The number of components in the DOF table and the number of "
123 "tolerances given do not match.");
124 }
125}

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

Member Data Documentation

◆ _abstols

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

◆ _dof_table

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

◆ _mesh

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

◆ _reltols

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

◆ _residual_norms_0

std::vector<double> NumLib::ConvergenceCriterionPerComponentResidual::_residual_norms_0
private

Definition at line 54 of file ConvergenceCriterionPerComponentResidual.h.

Referenced by checkResidual().


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