preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AbsoluteOrRelativeConvergenceMeasure.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <iomanip>
5#include <limits>
6#include <math.h>
7#include <ostream>
8#include <string>
9#include "../CouplingData.hpp"
11#include "logging/Logger.hpp"
12#include "math/differences.hpp"
13#include "math/math.hpp"
14#include "utils/IntraComm.hpp"
15#include "utils/assertion.hpp"
16
18class AbsoluteOrRelativeConvergenceMeasureTest;
19}
20
21// ----------------------------------------------------------- CLASS DEFINITION
22
24
38public:
49 AbsoluteOrRelativeConvergenceMeasure(double absLimit, double relLimit);
50
52
53 void newMeasurementSeries() override
54 {
55 _isConvergence = false;
56 }
57
58 void measure(
59 const Eigen::VectorXd &oldValues,
60 const Eigen::VectorXd &newValues) override
61 {
62 PRECICE_ASSERT(oldValues.size() == newValues.size());
63 _normDiff = utils::IntraComm::l2norm(newValues - oldValues);
66 }
67
68 bool isConvergence() const override
69 {
70 return _isConvergence;
71 }
72
76 std::string printState(const std::string &dataName) override
77 {
79 os << "absolute convergence measure: ";
80 os << "two-norm diff of data \"" << dataName << "\" = ";
82 os << ", limit = " << _convergenceLimit;
83
84 os << ", relative convergence measure: ";
85 os << "relative two-norm diff of data \"" << dataName << "\" = ";
87 os << ", limit = " << _convergenceLimitPercent;
88 os << ", normalization = " << _norm;
89 os << ", conv = ";
91 os << "true";
92 else
93 os << "false";
94 return os.str();
95 }
96
97 virtual double getNormAbsResidual()
98 {
99 return _normDiff;
100 }
101
102 virtual double getNormRelResidual()
103 {
104 if (math::equals(_norm, 0.))
106 else
107 return _normDiff / _norm;
108 }
109
111 {
112 return "AbsOrRel";
113 }
114
115private:
116 logging::Logger _log{"cplscheme::AbsoluteOrRelativeConvergenceMeasure"};
117
119
121
122 double _normDiff = 0;
123
124 double _norm = 0;
125
126 bool _isConvergence = false;
127};
128} // namespace precice::cplscheme::impl
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
Measures the convergence from an old data set to a new one.
void measure(const Eigen::VectorXd &oldValues, const Eigen::VectorXd &newValues) override
Performs convergence measurement.
std::string getAbbreviation() const override
Returns an abbreviation of the name of the measure for the log file headers.
void newMeasurementSeries() override
To be called when a new meas. series (iteration process) starts.
bool isConvergence() const override
Returns true, if the last measurement indicates convergence.
std::string printState(const std::string &dataName) override
Adds current convergence information to output stream.
Interface for measures checking the convergence of a series of datasets.
This class provides a lightweight logger.
Definition Logger.hpp:17
static double l2norm(const Eigen::VectorXd &vec)
The l2 norm of a vector is calculated on distributed data.
Definition IntraComm.cpp:67
T scientific(T... args)
T infinity(T... args)
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
T setprecision(T... args)