preCICE v3.2.0
Loading...
Searching...
No Matches
RelativeConvergenceMeasure.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 RelativeConvergenceMeasureTest;
19}
20
21// ----------------------------------------------------------- CLASS DEFINITION
22
24
37public:
45 RelativeConvergenceMeasure(double convergenceLimitPercent);
46
47 ~RelativeConvergenceMeasure() override = default;
48
49 void newMeasurementSeries() override
50 {
51 _isConvergence = false;
52 }
53
54 void measure(
55 const Eigen::VectorXd &oldValues,
56 const Eigen::VectorXd &newValues) override
57 {
58 PRECICE_ASSERT(oldValues.size() == newValues.size());
59 /*
60 std::cout<<"\n-------\n";
61 std::cout<<" old val: \n"<<oldValues<<'\n';
62 std::cout<<" new val: \n"<<newValues<<"\n\n";
63 std::cout<<"-------\n\n";
64*/
65
66 _normDiff = utils::IntraComm::l2norm(newValues - oldValues);
69 }
70
71 bool isConvergence() const override
72 {
73 return _isConvergence;
74 }
75
79 std::string printState(const std::string &dataName) override
80 {
82 os << "relative convergence measure: ";
83 os << "relative two-norm diff of data \"" << dataName << "\" = ";
85 os << ", limit = " << _convergenceLimitPercent;
86 os << ", normalization = " << _norm;
87 os << ", conv = ";
89 os << "true";
90 else
91 os << "false";
92 return os.str();
93 }
94
95 double getNormResidual() override
96 {
97 if (math::equals(_norm, 0.))
99 else
100 return _normDiff / _norm;
101 }
102
104 {
105 return "Rel";
106 }
107
108private:
109 logging::Logger _log{"cplscheme::RelativeConvergenceMeasure"};
110
112
113 double _normDiff = 0;
114
115 double _norm = 0;
116
117 bool _isConvergence = false;
118};
119} // namespace precice::cplscheme::impl
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
Interface for measures checking the convergence of a series of datasets.
RelativeConvergenceMeasure(double convergenceLimitPercent)
Constructor.
bool isConvergence() const override
Returns true, if the last measurement indicates convergence.
double getNormResidual() override
Returns the l2-norm of the coupling residuum.
void newMeasurementSeries() override
To be called when a new meas. series (iteration process) starts.
void measure(const Eigen::VectorXd &oldValues, const Eigen::VectorXd &newValues) override
Performs convergence measurement.
std::string printState(const std::string &dataName) override
Adds current convergence information to output stream.
std::string getAbbreviation() const override
Returns an abbreviation of the name of the measure for the log file headers.
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)
T str(T... args)