OGS 6.1.0-1699-ge946d4c5f
ConvergenceCriterion.cpp
Go to the documentation of this file.
1 
10 #include "ConvergenceCriterion.h"
11 #include "BaseLib/ConfigTree.h"
12 #include "BaseLib/Error.h"
13 
18 
19 namespace NumLib
20 {
21 std::unique_ptr<ConvergenceCriterion> createConvergenceCriterion(
22  const BaseLib::ConfigTree& config)
23 {
25  auto const type = config.peekConfigParameter<std::string>("type");
26 
27  if (type == "DeltaX") {
28  return createConvergenceCriterionDeltaX(config);
29  }
30  if (type == "Residual")
31  {
33  }
34  if (type == "PerComponentDeltaX")
35  {
37  }
38  if (type == "PerComponentResidual")
39  {
41  }
42 
43  OGS_FATAL("There is no convergence criterion of type `%s'.", type.c_str());
44 }
45 
46 bool checkRelativeTolerance(const double reltol, const double numerator,
47  const double denominator)
48 {
49  auto const eps = std::numeric_limits<double>::epsilon();
50  return std::abs(numerator) <
51  std::abs(reltol) * (std::abs(denominator) + eps);
52 }
53 
54 } // NumLib
std::unique_ptr< ConvergenceCriterionPerComponentResidual > createConvergenceCriterionPerComponentResidual(const BaseLib::ConfigTree &config)
std::unique_ptr< ConvergenceCriterionResidual > createConvergenceCriterionResidual(const BaseLib::ConfigTree &config)
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)
T peekConfigParameter(std::string const &param) const
std::unique_ptr< ConvergenceCriterionPerComponentDeltaX > createConvergenceCriterionPerComponentDeltaX(const BaseLib::ConfigTree &config)
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
std::unique_ptr< ConvergenceCriterion > createConvergenceCriterion(const BaseLib::ConfigTree &config)
Creates a convergence criterion from the given configuration.
std::unique_ptr< ConvergenceCriterionDeltaX > createConvergenceCriterionDeltaX(const BaseLib::ConfigTree &config)