preCICE v3.1.2
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
11namespace precice {
12namespace acceleration {
13namespace impl {
14
24public:
30 int filter = 0,
31 double omega = 0,
32 double theta = 1. / 0.7,
33 double sigma = std::numeric_limits<double>::min());
34
40 Eigen::MatrixXd A,
41 int filter,
42 double omega = 0,
43 double theta = 1. / 0.7,
44 double sigma = std::numeric_limits<double>::min());
45
51 Eigen::MatrixXd Q,
52 Eigen::MatrixXd R,
53 int rows,
54 int cols,
55 int filter,
56 double omega = 0,
57 double theta = 1. / 0.7,
58 double sigma = std::numeric_limits<double>::min());
59
63 virtual ~QRFactorization() {}
64
68 void reset();
69
73 void reset(
74 Eigen::MatrixXd const &Q,
75 Eigen::MatrixXd const &R,
76 int rows,
77 int cols,
78 double omega = 0,
79 double theta = 1. / 0.7,
80 double sigma = std::numeric_limits<double>::min());
81
85 void reset(
86 Eigen::MatrixXd const &A,
87 int globalRows,
88 double omega = 0,
89 double theta = 1. / 0.7,
90 double sigma = std::numeric_limits<double>::min());
91
96 bool insertColumn(int k, const Eigen::VectorXd &v, double singularityLimit = 0);
97
102 void deleteColumn(int k);
103
109 void pushFront(const Eigen::VectorXd &v);
110
116 void pushBack(const Eigen::VectorXd &v);
117
122 void popFront();
123
128 void popBack();
129
135 void applyFilter(double singularityLimit, std::vector<int> &delIndices, Eigen::MatrixXd &V);
136
140 Eigen::MatrixXd &matrixQ();
141
145 Eigen::MatrixXd &matrixR();
146
147 // @brief returns the number of columns in the QR-decomposition
148 int cols() const;
149 // @brief returns the number of rows in the QR-decomposition
150 int rows() const;
151
152 // @brief optional file-stream for logging output
153 void setfstream(std::fstream *stream);
154
155 // @brief set number of global rows
156 void setGlobalRows(int gr);
157
158 // @brief sets the filtering technique to maintain good conditioning of the least squares system
159 void setFilter(int filter);
160
161private:
162 struct givensRot {
163 int i, j;
164 double sigma, gamma;
165 };
166
178 int orthogonalize_stable(Eigen::VectorXd &v, Eigen::VectorXd &r, double &rho, int colNum);
179
192 int orthogonalize(Eigen::VectorXd &v, Eigen::VectorXd &r, double &rho, int colNum);
193
197 void computeReflector(givensRot &grot, double &x, double &y);
198
203 void applyReflector(const givensRot &grot, int k, int l, Eigen::VectorXd &p, Eigen::VectorXd &q);
204
205 logging::Logger _log{"acceleration::QRFactorization"};
206
207 Eigen::MatrixXd _Q;
208 Eigen::MatrixXd _R;
209
210 int _rows;
211 int _cols;
212
214 double _omega;
215 double _theta;
216 double _sigma;
217
218 // @brief optional infostream that writes information to file
221
223};
224
225} // namespace impl
226} // namespace acceleration
227} // namespace precice
Class that provides functionality for a dynamic QR-decomposition, that can be updated in O(mn) flops ...
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 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 ...
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:16
Main namespace of the precice library.
static std::unique_ptr< precice::Participant > impl
Definition preciceC.cpp:21