preCICE v3.1.1
Loading...
Searching...
No Matches
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
16namespace precice {
17namespace cplscheme {
18namespace tests {
19class AbsoluteOrRelativeConvergenceMeasureTest;
20}
21} // namespace cplscheme
22} // namespace precice
23
24// ----------------------------------------------------------- CLASS DEFINITION
25
26namespace precice {
27namespace cplscheme {
28namespace impl {
29
43public:
54 AbsoluteOrRelativeConvergenceMeasure(double absLimit, double relLimit);
55
57
58 virtual void newMeasurementSeries()
59 {
60 _isConvergence = false;
61 }
62
63 virtual void measure(
64 const Eigen::VectorXd &oldValues,
65 const Eigen::VectorXd &newValues)
66 {
67 _normDiff = utils::IntraComm::l2norm(newValues - oldValues);
70 }
71
72 virtual bool isConvergence() const
73 {
74 return _isConvergence;
75 }
76
80 virtual std::string printState(const std::string &dataName)
81 {
83 os << "absolute convergence measure: ";
84 os << "two-norm diff of data \"" << dataName << "\" = ";
86 os << ", limit = " << _convergenceLimit;
87
88 os << ", relative convergence measure: ";
89 os << "relative two-norm diff of data \"" << dataName << "\" = ";
91 os << ", limit = " << _convergenceLimitPercent;
92 os << ", normalization = " << _norm;
93 os << ", conv = ";
95 os << "true";
96 else
97 os << "false";
98 return os.str();
99 }
100
101 virtual double getNormAbsResidual()
102 {
103 return _normDiff;
104 }
105
106 virtual double getNormRelResidual()
107 {
108 if (math::equals(_norm, 0.))
110 else
111 return _normDiff / _norm;
112 }
113
115 {
116 return "AbsOrRel";
117 }
118
119private:
120 logging::Logger _log{"cplscheme::AbsoluteOrRelativeConvergenceMeasure"};
121
123
125
126 double _normDiff = 0;
127
128 double _norm = 0;
129
130 bool _isConvergence = false;
131};
132} // namespace impl
133} // namespace cplscheme
134} // namespace precice
Measures the convergence from an old data set to a new one.
virtual std::string printState(const std::string &dataName)
Adds current convergence information to output stream.
virtual std::string getAbbreviation() const
Returns an abbreviation of the name of the measure for the log file headers.
virtual void measure(const Eigen::VectorXd &oldValues, const Eigen::VectorXd &newValues)
Performs convergence measurement.
virtual bool isConvergence() const
Returns true, if the last measurement indicates convergence.
virtual void newMeasurementSeries()
To be called when a new meas. series (iteration process) starts.
Interface for measures checking the convergence of a series of datasets.
This class provides a lightweight logger.
Definition Logger.hpp:16
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.
Main namespace of the precice library.
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21
T setprecision(T... args)