preCICE
Loading...
Searching...
No Matches
QRFactorization.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <fstream>
5#include <limits>
6#include <string>
7#include <vector>
8#include "logging/Logger.hpp"
10
12
22public:
28 int filter = 0,
29 double omega = 0,
30 double theta = 1. / 0.7,
31 double sigma = std::numeric_limits<double>::min());
32
38 Eigen::MatrixXd A,
39 int filter,
40 double omega = 0,
41 double theta = 1. / 0.7,
42 double sigma = std::numeric_limits<double>::min());
43
49 Eigen::MatrixXd Q,
50 Eigen::MatrixXd R,
51 int rows,
52 int cols,
53 int filter,
54 double omega = 0,
55 double theta = 1. / 0.7,
56 double sigma = std::numeric_limits<double>::min());
57
61 virtual ~QRFactorization() = default;
62
68 void resetFilter(double singularityLimit, std::vector<int> &delIndices, Eigen::MatrixXd &V);
69
73 void reset();
74
78 void reset(
79 Eigen::MatrixXd const &Q,
80 Eigen::MatrixXd const &R,
81 int rows,
82 int cols,
83 double omega = 0,
84 double theta = 1. / 0.7,
85 double sigma = std::numeric_limits<double>::min());
86
92 [[nodiscard]] std::vector<int> reset(
93 Eigen::MatrixXd const &A,
94 int globalRows,
95 double omega = 0,
96 double theta = 1. / 0.7,
97 double sigma = std::numeric_limits<double>::min());
98
103 bool insertColumn(int k, const Eigen::VectorXd &v, double singularityLimit = 0);
104
109 void deleteColumn(int k);
110
116 void pushFront(const Eigen::VectorXd &v);
117
123 void pushBack(const Eigen::VectorXd &v);
124
129 void popFront();
130
135 void popBack();
136
142 void applyFilter(double singularityLimit, std::vector<int> &delIndices, Eigen::MatrixXd &V);
143
147 Eigen::MatrixXd &matrixQ();
148
152 Eigen::MatrixXd &matrixR();
153
154 // @brief returns the number of columns in the QR-decomposition
155 int cols() const;
156 // @brief returns the number of rows in the QR-decomposition
157 int rows() const;
158
159 // @brief optional file-stream for logging output
160 void setfstream(std::fstream *stream);
161
162 // @brief set number of global rows
163 void setGlobalRows(int gr);
164
165 // @brief sets the filtering technique to maintain good conditioning of the least squares system
166 void setFilter(int filter);
167
168 // @brief returns the number of times the QR2 filter step was performed
169 size_t getResetFilterCounter() const;
170
171 // @brief marks that the prescaling coefficients aren't constant and the QR3 filter needs to fallback to QR2
172 void requireQR3Fallback();
173
174private:
175 struct givensRot {
176 int i, j;
177 double sigma, gamma;
178 };
179
191 int orthogonalize_stable(Eigen::VectorXd &v, Eigen::VectorXd &r, double &rho, int colNum);
192
205 int orthogonalize(Eigen::VectorXd &v, Eigen::VectorXd &r, double &rho, int colNum);
206
210 void computeReflector(givensRot &grot, double &x, double &y);
211
216 void applyReflector(const givensRot &grot, int k, int l, Eigen::VectorXd &p, Eigen::VectorXd &q);
217
218 logging::Logger _log{"acceleration::QRFactorization"};
219
220 Eigen::MatrixXd _Q;
221 Eigen::MatrixXd _R;
222
223 int _rows;
224 int _cols;
225
227 double _omega;
228 double _theta;
229 double _sigma;
230
231 bool _computeQR2Filter = true; // flag to indicate if the QR2 filter step should be performed
232 size_t _resetFilterCounter = 0; // counter for the number of times the QR2 filter step was performed
233
234 // @brief optional infostream that writes information to file
235 std::fstream *_infostream;
237
239};
240
241} // namespace precice::acceleration::impl
int orthogonalize_stable(Eigen::VectorXd &v, Eigen::VectorXd &r, double &rho, int colNum)
assuming Q(1:n,1:m) has nearly orthonormal columns, this procedure orthogonlizes v(1:n) to the column...
bool insertColumn(int k, const Eigen::VectorXd &v, double singularityLimit=0)
inserts a new column at arbitrary position and updates the QR factorization This function works on th...
int orthogonalize(Eigen::VectorXd &v, Eigen::VectorXd &r, double &rho, int colNum)
assuming Q(1:n,1:m) has nearly orthonormal columns, this procedure orthogonlizes v(1:n) to the column...
Eigen::MatrixXd & matrixR()
returns a matrix representation of the upper triangular matrix R
void applyFilter(double singularityLimit, std::vector< int > &delIndices, Eigen::MatrixXd &V)
filters the least squares system, i.e., the decomposition Q*R = V according to the defined filter tec...
void computeReflector(givensRot &grot, double &x, double &y)
computes parameters for givens matrix G for which (x,y)G = (z,0). replaces (x,y) by (z,...
void resetFilter(double singularityLimit, std::vector< int > &delIndices, Eigen::MatrixXd &V)
Performs a reset of A = QR using the QR2 Filter. This eliminates columns during the reconstruction of...
void pushBack(const Eigen::VectorXd &v)
inserts a new column at position _cols-1, i.e., appends a column at the end and updates the QR factor...
void reset()
resets the QR factorization zo zero Q(0:0, 0:0)R(0:0, 0:0)
void popBack()
deletes the column at position _cols-1, i.e., deletes the last column and updates the QR factorizatio...
void pushFront(const Eigen::VectorXd &v)
inserts a new column at position 0, i.e., shifts right and inserts at first position and updates the ...
virtual ~QRFactorization()=default
Destructor, empty.
QRFactorization(int filter=0, double omega=0, double theta=1./0.7, double sigma=std::numeric_limits< double >::min())
Constructor.
void applyReflector(const givensRot &grot, int k, int l, Eigen::VectorXd &p, Eigen::VectorXd &q)
this procedure replaces the two column matrix [p(k:l-1), q(k:l-1)] by [p(k:l), q(k:l)]*G,...
Eigen::MatrixXd & matrixQ()
returns a matrix representation of the orthogonal matrix Q
void popFront()
deletes the column at position 0, i.e., deletes and shifts columns to the left and updates the QR fac...
void deleteColumn(int k)
updates the factorization A=Q[1:n,1:m]R[1:m,1:n] when the kth column of A is deleted....
This class provides a lightweight logger.
Definition Logger.hpp:17