preCICE v3.2.0
Loading...
Searching...
No Matches
ResidualRelativeConvergenceMeasure.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <iomanip>
5#include <limits>
6#include <ostream>
7#include <string>
8#include "../CouplingData.hpp"
10#include "logging/Logger.hpp"
11#include "math/differences.hpp"
12#include "utils/IntraComm.hpp"
13#include "utils/assertion.hpp"
14
16
29public:
37 explicit ResidualRelativeConvergenceMeasure(double convergenceLimitPercent);
38
40
47
48 void measure(
49 const Eigen::VectorXd &oldValues,
50 const Eigen::VectorXd &newValues) override
51 {
52 PRECICE_ASSERT(oldValues.size() == newValues.size());
53 _normDiff = utils::IntraComm::l2norm(newValues - oldValues);
56 _isFirstIteration = false;
57 }
59 }
60
61 bool isConvergence() const override
62 {
63 return _isConvergence;
64 }
65
67 std::string printState(const std::string &dataName) override
68 {
70 os << "residual relative convergence measure: ";
71 os << "relative two-norm diff of data \"" << dataName << "\" = ";
73 os << ", limit = " << _convergenceLimitPercent;
74 os << ", normalization = " << _normFirstResidual;
75 os << ", conv = ";
77 os << "true";
78 else
79 os << "false";
80 return os.str();
81 }
82
83 double getNormResidual() override
84 {
87 else
89 }
90
92 {
93 return "Drop";
94 }
95
96private:
97 logging::Logger _log{"cplscheme::ResidualRelativeConvergenceMeasure"};
98
100
101 bool _isFirstIteration = true;
102
104
105 double _normDiff = 0;
106
107 bool _isConvergence = false;
108};
109} // namespace precice::cplscheme::impl
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
Interface for measures checking the convergence of a series of datasets.
std::string getAbbreviation() const override
Returns an abbreviation of the name of the measure for the log file headers.
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.
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.
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)
T max(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)