Loading [MathJax]/extensions/MathMenu.js
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, std::vector< double > &&damping_alpha, bool daming_alpha_switch, const MathLib::VecNormType norm_type)
 
bool hasDeltaXCheck () const override
 
bool hasResidualCheck () const override
 
bool hasNonNegativeDamping () 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.
 
double getDampingFactor (GlobalVector const &minus_delta_x, GlobalVector const &x, double damping_orig) 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 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
 
const std::vector< double > _damping_alpha
 
bool _damping_alpha_switch
 

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,
std::vector< double > && damping_alpha,
bool daming_alpha_switch,
const MathLib::VecNormType norm_type )

Definition at line 21 of file ConvergenceCriterionPerComponentResidual.cpp.

29 _abstols(std::move(absolute_tolerances)),
30 _reltols(std::move(relative_tolerances)),
32 _damping_alpha(std::move(damping_alpha)),
33 _damping_alpha_switch(damping_alpha_switch)
34{
35 if (_abstols.size() != _reltols.size())
36 {
38 "The number of absolute and relative tolerances given must be the "
39 "same.");
40 }
41
42 if (_abstols.empty())
43 {
44 OGS_FATAL("The given tolerances vector is empty.");
45 }
46}
#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 48 of file ConvergenceCriterionPerComponentResidual.cpp.

50{
51 if ((!_dof_table) || (!_mesh))
52 {
53 OGS_FATAL("D.o.f. table or mesh have not been set.");
54 }
55
56 for (unsigned global_component = 0; global_component < _abstols.size();
57 ++global_component)
58 {
59 // TODO short cut if tol <= 0.0
60 auto error_dx = norm(minus_delta_x, global_component, _norm_type,
61 *_dof_table, *_mesh);
62 auto norm_x =
63 norm(x, global_component, _norm_type, *_dof_table, *_mesh);
64
65 INFO(
66 "Convergence criterion, component {:d}: |dx|={:.4e}, |x|={:.4e}, "
67 "|dx|/|x|={:.4e}",
68 global_component, error_dx, norm_x,
69 (norm_x == 0. ? std::numeric_limits<double>::quiet_NaN()
70 : (error_dx / norm_x)));
71 }
72}
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 74 of file ConvergenceCriterionPerComponentResidual.cpp.

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

◆ getDampingFactor()

double NumLib::ConvergenceCriterionPerComponentResidual::getDampingFactor ( GlobalVector const & minus_delta_x,
GlobalVector const & x,
double damping_orig )
overridevirtual

Implements NumLib::ConvergenceCriterion.

Definition at line 117 of file ConvergenceCriterionPerComponentResidual.cpp.

120{
121 if ((!_dof_table) || (!_mesh))
122 {
123 OGS_FATAL("D.o.f. table or mesh have not been set.");
124 }
125
127 double damping_final = 1;
128 for (unsigned global_component = 0;
129 global_component < _damping_alpha.size();
130 ++global_component)
131 {
132 auto const& ms = _dof_table->getMeshSubset(global_component);
133 assert(ms.getMeshID() == _mesh->getID());
134 DBUG("Non-negative damping for component: {:d} alpha: {:g}",
135 global_component, _damping_alpha[global_component]);
136 for (auto const node_id : ms.getNodes() | MeshLib::views::ids)
137 {
138 MeshLib::Location const l{_mesh->getID(),
140 auto index = _dof_table->getGlobalIndex(l, global_component);
141 damping_final = std::min(
142 damping_final,
143 damping_orig / std::max(1.0, (minus_delta_x.get(index) *
144 _damping_alpha[global_component] /
145 x.get(index))));
146 }
147 }
148 DBUG("Final damping value due to non-negative damping: {:g}",
149 damping_final);
150 return damping_final;
151}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121
GlobalIndexType getGlobalIndex(MeshLib::Location const &l, int const variable_id, int const component_id) const
MeshLib::MeshSubset const & getMeshSubset(int const variable_id, int const component_id) const
void setLocalAccessibleVector(PETScVector const &x)
Definition LinAlg.cpp:27
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:225

References _damping_alpha, _dof_table, _mesh, DBUG(), MathLib::EigenVector::get(), NumLib::LocalToGlobalIndexMap::getGlobalIndex(), MeshLib::Mesh::getID(), NumLib::LocalToGlobalIndexMap::getMeshSubset(), MeshLib::views::ids, MeshLib::Node, OGS_FATAL, and MathLib::LinAlg::setLocalAccessibleVector().

◆ 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 39 of file ConvergenceCriterionPerComponentResidual.h.

39{ return true; }

◆ hasNonNegativeDamping()

bool NumLib::ConvergenceCriterionPerComponentResidual::hasNonNegativeDamping ( ) const
inlineoverridevirtual

Implements NumLib::ConvergenceCriterion.

Definition at line 41 of file ConvergenceCriterionPerComponentResidual.h.

42 {
44 }

References _damping_alpha_switch.

◆ 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 40 of file ConvergenceCriterionPerComponentResidual.h.

40{ 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 153 of file ConvergenceCriterionPerComponentResidual.cpp.

155{
156 _dof_table = &dof_table;
157 _mesh = &mesh;
158
160 static_cast<int>(_abstols.size()))
161 {
162 OGS_FATAL(
163 "The number of components in the DOF table and the number of "
164 "tolerances given do not match.");
165 }
166}

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

Member Data Documentation

◆ _abstols

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

◆ _damping_alpha

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

Definition at line 64 of file ConvergenceCriterionPerComponentResidual.h.

Referenced by getDampingFactor().

◆ _damping_alpha_switch

bool NumLib::ConvergenceCriterionPerComponentResidual::_damping_alpha_switch
private

Definition at line 65 of file ConvergenceCriterionPerComponentResidual.h.

Referenced by hasNonNegativeDamping().

◆ _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 63 of file ConvergenceCriterionPerComponentResidual.h.

Referenced by checkResidual().


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