OGS  v6.4.0
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 27 of file ConvergenceCriterionPerComponentResidual.h.

#include <ConvergenceCriterionPerComponentResidual.h>

Inheritance diagram for NumLib::ConvergenceCriterionPerComponentResidual:
Collaboration diagram for NumLib::ConvergenceCriterionPerComponentResidual:

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. More...
 
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. More...
 
- 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. More...
 
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  {
32  OGS_FATAL(
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:25
ConvergenceCriterionPerComponent(const MathLib::VecNormType norm_type)

References _abstols, _reltols, and OGS_FATAL.

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 44 of file ConvergenceCriterionPerComponentResidual.cpp.

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

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

36 { 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 37 of file ConvergenceCriterionPerComponentResidual.h.

37 { 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 116 of file ConvergenceCriterionPerComponentResidual.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::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 53 of file ConvergenceCriterionPerComponentResidual.h.

Referenced by checkResidual().


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