preCICE v3.1.1
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
16namespace precice {
17namespace cplscheme {
18namespace tests {
19class RelativeConvergenceMeasureTest;
20}
21} // namespace cplscheme
22} // namespace precice
23
24// ----------------------------------------------------------- CLASS DEFINITION
25
26namespace precice {
27namespace cplscheme {
28namespace impl {
29
42public:
50 RelativeConvergenceMeasure(double convergenceLimitPercent);
51
53
54 virtual void newMeasurementSeries()
55 {
56 _isConvergence = false;
57 }
58
59 virtual void measure(
60 const Eigen::VectorXd &oldValues,
61 const Eigen::VectorXd &newValues)
62 {
63 /*
64 std::cout<<"\n-------\n";
65 std::cout<<" old val: \n"<<oldValues<<'\n';
66 std::cout<<" new val: \n"<<newValues<<"\n\n";
67 std::cout<<"-------\n\n";
68*/
69
70 _normDiff = utils::IntraComm::l2norm(newValues - oldValues);
73 }
74
75 virtual bool isConvergence() const
76 {
77 return _isConvergence;
78 }
79
83 virtual std::string printState(const std::string &dataName)
84 {
86 os << "relative convergence measure: ";
87 os << "relative two-norm diff of data \"" << dataName << "\" = ";
89 os << ", limit = " << _convergenceLimitPercent;
90 os << ", normalization = " << _norm;
91 os << ", conv = ";
93 os << "true";
94 else
95 os << "false";
96 return os.str();
97 }
98
99 virtual double getNormResidual()
100 {
101 if (math::equals(_norm, 0.))
103 else
104 return _normDiff / _norm;
105 }
106
108 {
109 return "Rel";
110 }
111
112private:
113 logging::Logger _log{"cplscheme::RelativeConvergenceMeasure"};
114
116
117 double _normDiff = 0;
118
119 double _norm = 0;
120
121 bool _isConvergence = false;
122};
123} // namespace impl
124} // namespace cplscheme
125} // 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 double getNormResidual()
Returns the l2-norm of the coupling residuum.
RelativeConvergenceMeasure(double convergenceLimitPercent)
Constructor.
virtual void newMeasurementSeries()
To be called when a new meas. series (iteration process) starts.
virtual bool isConvergence() const
Returns true, if the last measurement indicates convergence.
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 void measure(const Eigen::VectorXd &oldValues, const Eigen::VectorXd &newValues)
Performs convergence measurement.
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)