preCICE v3.1.1
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
14namespace precice {
15namespace cplscheme {
16namespace impl {
17
30public:
38 explicit ResidualRelativeConvergenceMeasure(double convergenceLimitPercent);
39
41
48
49 virtual void measure(
50 const Eigen::VectorXd &oldValues,
51 const Eigen::VectorXd &newValues)
52 {
53 _normDiff = utils::IntraComm::l2norm(newValues - oldValues);
56 _isFirstIteration = false;
57 }
59 }
60
61 virtual bool isConvergence() const
62 {
63 return _isConvergence;
64 }
65
67 virtual std::string printState(const std::string &dataName)
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 virtual double getNormResidual()
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 impl
110} // namespace cplscheme
111} // namespace precice
Interface for measures checking the convergence of a series of datasets.
Measures the convergence from an old data set to a new one.
virtual void measure(const Eigen::VectorXd &oldValues, const Eigen::VectorXd &newValues)
Performs convergence measurement.
virtual std::string getAbbreviation() const
Returns an abbreviation of the name of the measure for the log file headers.
virtual std::string printState(const std::string &dataName)
Adds current convergence information to output stream.
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.
virtual double getNormResidual()
Returns the l2-norm of the coupling residuum.
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)
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.
Main namespace of the precice library.
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21
T setprecision(T... args)