preCICE v3.1.2
Loading...
Searching...
No Matches
ResidualPreconditioner.cpp
Go to the documentation of this file.
2#include <cstddef>
3#include <vector>
5#include "utils/IntraComm.hpp"
6#include "utils/assertion.hpp"
7
9
11 : Preconditioner(maxNonConstTimeWindows)
12{
13}
14
15void ResidualPreconditioner::_update_(bool timeWindowComplete,
16 const Eigen::VectorXd &oldValues,
17 const Eigen::VectorXd &res)
18{
19 if (not timeWindowComplete) {
21
22 int offset = 0;
23 for (size_t k = 0; k < _subVectorSizes.size(); k++) {
24 Eigen::VectorXd part = Eigen::VectorXd::Zero(_subVectorSizes[k]);
25 for (size_t i = 0; i < _subVectorSizes[k]; i++) {
26 part(i) = res(i + offset);
27 }
28 norms[k] = utils::IntraComm::l2norm(part);
29 offset += _subVectorSizes[k];
30 }
31
32 offset = 0;
33 for (size_t k = 0; k < _subVectorSizes.size(); k++) {
34 if (norms[k] < math::NUMERICAL_ZERO_DIFFERENCE) {
35 PRECICE_WARN("A sub-vector in the residual preconditioner became numerically zero. "
36 "If this occurred in the second iteration and the initial-relaxation factor is equal to 1.0, "
37 "check if the coupling data values of one solver is zero in the first iteration. "
38 "The preconditioner scaling factors were not applied for this iteration.");
39 } else {
40 for (size_t i = 0; i < _subVectorSizes[k]; i++) {
41 PRECICE_ASSERT(norms[k] > 0.0);
42 _weights[i + offset] = 1.0 / norms[k];
43 _invWeights[i + offset] = norms[k];
44 }
45 }
46 offset += _subVectorSizes[k];
47 }
48
49 _requireNewQR = true;
50 }
51}
52
53} // namespace precice::acceleration::impl
#define PRECICE_WARN(...)
Definition LogMacros.hpp:11
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Interface for preconditioner variants that can be applied to quasi-Newton acceleration schemes.
std::vector< size_t > _subVectorSizes
Sizes of each sub-vector, i.e. each coupling data.
std::vector< double > _invWeights
Inverse weights (for efficiency reasons)
std::vector< double > _weights
Weights used to scale the matrix V and the residual.
bool _requireNewQR
True if a QR decomposition from scratch is necessary.
virtual void _update_(bool timeWindowComplete, const Eigen::VectorXd &oldValues, const Eigen::VectorXd &res)
Update the scaling after every FSI iteration.
static double l2norm(const Eigen::VectorXd &vec)
The l2 norm of a vector is calculated on distributed data.
Definition IntraComm.cpp:67
constexpr double NUMERICAL_ZERO_DIFFERENCE
T size(T... args)