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

Definition at line 23 of file ConvergenceCriterionPerComponentDeltaX.cpp.

30 _abstols(std::move(absolute_tolerances)),
31 _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::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 48 of file ConvergenceCriterionPerComponentDeltaX.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 bool const satisfied_abs = error_dx < _abstols[global_component];
73 bool const satisfied_rel = checkRelativeTolerance(
74 _reltols[global_component], error_dx, norm_x);
75
76 _satisfied = _satisfied && (satisfied_abs || satisfied_rel);
77 }
78}
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 46 of file ConvergenceCriterionPerComponentDeltaX.h.

46{}

◆ getDampingFactor()

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

Implements NumLib::ConvergenceCriterion.

Definition at line 80 of file ConvergenceCriterionPerComponentDeltaX.cpp.

83{
84 if ((!_dof_table) || (!_mesh))
85 {
86 OGS_FATAL("D.o.f. table or mesh have not been set.");
87 }
88
90 double damping_final = 1;
91 for (unsigned global_component = 0;
92 global_component < _damping_alpha.size();
93 ++global_component)
94 {
95 auto const& ms = _dof_table->getMeshSubset(global_component);
96 assert(ms.getMeshID() == _mesh->getID());
97 DBUG("Non-negative damping for component: {:d} alpha: {:g}",
98 global_component, _damping_alpha[global_component]);
99 for (auto const node_id : ms.getNodes() | MeshLib::views::ids)
100 {
101 MeshLib::Location const l{_mesh->getID(),
103 auto index = _dof_table->getGlobalIndex(l, global_component);
104 damping_final = std::min(
105 damping_final,
106 damping_orig / std::max(1.0, (minus_delta_x.get(index) *
107 _damping_alpha[global_component] /
108 x.get(index))));
109 }
110 }
111 DBUG("Final damping value due to non-negative damping: {:g}",
112 damping_final);
113 return damping_final;
114}
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
double get(IndexType rowId) const
get entry
Definition EigenVector.h:58
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::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 37 of file ConvergenceCriterionPerComponentDeltaX.h.

37{ return true; }

◆ hasNonNegativeDamping()

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

Implements NumLib::ConvergenceCriterion.

Definition at line 39 of file ConvergenceCriterionPerComponentDeltaX.h.

40 {
42 }

References _damping_alpha_switch.

◆ 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 38 of file ConvergenceCriterionPerComponentDeltaX.h.

38{ 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 51 of file ConvergenceCriterionPerComponentDeltaX.h.

51{ 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 116 of file ConvergenceCriterionPerComponentDeltaX.cpp.

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

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

Member Data Documentation

◆ _abstols

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

◆ _damping_alpha

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

Definition at line 59 of file ConvergenceCriterionPerComponentDeltaX.h.

Referenced by getDampingFactor().

◆ _damping_alpha_switch

bool NumLib::ConvergenceCriterionPerComponentDeltaX::_damping_alpha_switch
private

Definition at line 60 of file ConvergenceCriterionPerComponentDeltaX.h.

Referenced by hasNonNegativeDamping().

◆ _dof_table

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

◆ _mesh

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

◆ _reltols

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

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