OGS 6.2.2-87-g988ee9c30.dirty.20200123122242
ConvergenceCriterion.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <memory>
14 #include "MathLib/LinAlg/LinAlg.h" // For MathLib::VecNormType
15 #include "NumLib/NumericsConfig.h"
16 
17 namespace BaseLib {
18 class ConfigTree;
19 } // BaseLib
20 
21 namespace NumLib
22 {
30 {
31 public:
32  explicit ConvergenceCriterion(const MathLib::VecNormType norm_type)
33  : _norm_type(norm_type)
34  {
35  }
36 
42  virtual bool hasDeltaXCheck() const = 0;
43 
49  virtual bool hasResidualCheck() const = 0;
50 
60  virtual void checkDeltaX(GlobalVector const& minus_delta_x,
61  GlobalVector const& x) = 0;
62 
64  virtual void checkResidual(GlobalVector const& residual) = 0;
65 
68  virtual void preFirstIteration() { _is_first_iteration = true; }
69 
72  virtual void setNoFirstIteration() { _is_first_iteration = false; }
73 
81  virtual void reset() { _satisfied = true; _is_first_iteration = false; };
82 
84  virtual bool isSatisfied() const { return _satisfied; };
85 
86  MathLib::VecNormType getVectorNormType() const { return _norm_type; }
87 
88  virtual ~ConvergenceCriterion() = default;
89 
90 protected:
91  bool _satisfied = true;
92  bool _is_first_iteration = true;
94 };
95 
97 std::unique_ptr<ConvergenceCriterion> createConvergenceCriterion(
98  BaseLib::ConfigTree const& config);
99 
103 bool checkRelativeTolerance(double const reltol,
104  double const numerator,
105  double const denominator);
106 
107 } // namespace NumLib
ConvergenceCriterion(const MathLib::VecNormType norm_type)
MathLib::VecNormType getVectorNormType() const
VecNormType
Norm type. Not declared as class type in order to use the members as integers.
Definition: LinAlgEnums.h:21
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)
Functionality to build different search length algorithm objects from given config.
virtual bool isSatisfied() const
Tell if the convergence criterion is satisfied.
const MathLib::VecNormType _norm_type
std::unique_ptr< ConvergenceCriterion > createConvergenceCriterion(const BaseLib::ConfigTree &config)
Creates a convergence criterion from the given configuration.