preCICE v3.1.2
|
Class that provides functionality for a dynamic QR-decomposition, that can be updated in O(mn) flops if a column is inserted or deleted. The new column is orthogonalized to the existing columns in Q using a modified GramSchmidt algorithm. The zero-elements are generated using suitable givens-roatations. The Interface provides fnctions such as insertColumn, deleteColumn at arbitrary position an push or pull column at front or back, resp. More...
#include <QRFactorization.hpp>
Classes | |
struct | givensRot |
Public Member Functions | |
QRFactorization (int filter=0, double omega=0, double theta=1./0.7, double sigma=std::numeric_limits< double >::min()) | |
Constructor. | |
QRFactorization (Eigen::MatrixXd A, int filter, double omega=0, double theta=1./0.7, double sigma=std::numeric_limits< double >::min()) | |
Constructor. | |
QRFactorization (Eigen::MatrixXd Q, Eigen::MatrixXd R, int rows, int cols, int filter, double omega=0, double theta=1./0.7, double sigma=std::numeric_limits< double >::min()) | |
Constructor. | |
virtual | ~QRFactorization () |
Destructor, empty. | |
void | reset () |
resets the QR factorization zo zero Q(0:0, 0:0)R(0:0, 0:0) | |
void | reset (Eigen::MatrixXd const &Q, Eigen::MatrixXd const &R, int rows, int cols, double omega=0, double theta=1./0.7, double sigma=std::numeric_limits< double >::min()) |
resets the QR factorization to the given factorization Q, R | |
void | reset (Eigen::MatrixXd const &A, int globalRows, double omega=0, double theta=1./0.7, double sigma=std::numeric_limits< double >::min()) |
resets the QR factorization to be the factorization of A = QR | |
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 the memory of v, thus changes the Vector v. | |
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. Returns the deleted column v(1:n) | |
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 QR factorization. This function works on the memory of v, thus changes the Vector v. | |
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 factorization This function works on the memory of v, thus changes the Vector v. | |
void | popFront () |
deletes the column at position 0, i.e., deletes and shifts columns to the left and updates the QR factorization | |
void | popBack () |
deletes the column at position _cols-1, i.e., deletes the last column and updates the QR factorization | |
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 technique. This is done to ensure good conditioning | |
Eigen::MatrixXd & | matrixQ () |
returns a matrix representation of the orthogonal matrix Q | |
Eigen::MatrixXd & | matrixR () |
returns a matrix representation of the upper triangular matrix R | |
int | cols () const |
int | rows () const |
void | setfstream (std::fstream *stream) |
void | setGlobalRows (int gr) |
void | setFilter (int filter) |
Private Member Functions | |
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 columns of Q, and normalizes the result. r(1:n) is the array of Fourier coefficients, and rho is the distance from v to range of Q, r and its corrections are computed in double precision. This method tries to re-orthogonalize the matrix Q for a maximum of 4 iterations if ||v_orth|| / ||v|| <= 1/theta is toot small, i.e. the gram schmidt process is iterated. If ||v_orth|| / ||v|| <= std::numeric_limit, a unit vector that is orthogonal to Q is inserted and rho is set to 0. i.e., R has a zero on the diagonal in the respective column. | |
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 columns of Q, and normalizes the result. r(1:n) is the array of Fourier coefficients, and rho is the distance from v to range of Q, r and its corrections are computed in double precision. This method tries to re-orthogonalize the matrix Q for a maximum of 4 iterations if ||v_orth|| / ||v|| <= 1/theta is toot small, i.e. the gram schmidt process is iterated. | |
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,0) | |
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, where G is the Givens matrix grot, determined by sigma and gamma. | |
Private Attributes | |
logging::Logger | _log {"acceleration::QRFactorization"} |
Eigen::MatrixXd | _Q |
Eigen::MatrixXd | _R |
int | _rows |
int | _cols |
int | _filter |
double | _omega |
double | _theta |
double | _sigma |
std::fstream * | _infostream |
bool | _fstream_set |
int | _globalRows |
Class that provides functionality for a dynamic QR-decomposition, that can be updated in O(mn) flops if a column is inserted or deleted. The new column is orthogonalized to the existing columns in Q using a modified GramSchmidt algorithm. The zero-elements are generated using suitable givens-roatations. The Interface provides fnctions such as insertColumn, deleteColumn at arbitrary position an push or pull column at front or back, resp.
Definition at line 23 of file QRFactorization.hpp.
precice::acceleration::impl::QRFactorization::QRFactorization | ( | int | filter = 0, |
double | omega = 0, | ||
double | theta = 1. / 0.7, | ||
double | sigma = std::numeric_limits<double>::min() ) |
Constructor.
theta | - singularity limit for reothogonalization ||v_orth|| / ||v|| <= 1/theta |
Constructor
Definition at line 86 of file QRFactorization.cpp.
precice::acceleration::impl::QRFactorization::QRFactorization | ( | Eigen::MatrixXd | A, |
int | filter, | ||
double | omega = 0, | ||
double | theta = 1. / 0.7, | ||
double | sigma = std::numeric_limits<double>::min() ) |
Constructor.
theta | - singularity limit for reothogonalization ||v_orth|| / ||v|| <= 1/theta |
Constructor
Definition at line 53 of file QRFactorization.cpp.
precice::acceleration::impl::QRFactorization::QRFactorization | ( | Eigen::MatrixXd | Q, |
Eigen::MatrixXd | R, | ||
int | rows, | ||
int | cols, | ||
int | filter, | ||
double | omega = 0, | ||
double | theta = 1. / 0.7, | ||
double | sigma = std::numeric_limits<double>::min() ) |
Constructor.
theta | - singularity limit for reothogonalization ||v_orth|| / ||v|| <= 1/theta |
Definition at line 22 of file QRFactorization.cpp.
|
inlinevirtual |
Destructor, empty.
Definition at line 63 of file QRFactorization.hpp.
void precice::acceleration::impl::QRFactorization::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 technique. This is done to ensure good conditioning
[out] | delIndices | - a vector of indices of deleted columns from the LS-system |
Definition at line 105 of file QRFactorization.cpp.
|
private |
this procedure replaces the two column matrix [p(k:l-1), q(k:l-1)] by [p(k:l), q(k:l)]*G, where G is the Givens matrix grot, determined by sigma and gamma.
Definition at line 641 of file QRFactorization.cpp.
int precice::acceleration::impl::QRFactorization::cols | ( | ) | const |
Definition at line 673 of file QRFactorization.cpp.
|
private |
computes parameters for givens matrix G for which (x,y)G = (z,0). replaces (x,y) by (z,0)
Definition at line 616 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::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. Returns the deleted column v(1:n)
updates the factorization A=Q[1:n,1:m]R[1:m,1:n] when the kth column of A is deleted. Returns the deleted column v(1:n)
Definition at line 165 of file QRFactorization.cpp.
bool precice::acceleration::impl::QRFactorization::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 the memory of v, thus changes the Vector v.
Definition at line 207 of file QRFactorization.cpp.
Eigen::MatrixXd & precice::acceleration::impl::QRFactorization::matrixQ | ( | ) |
returns a matrix representation of the orthogonal matrix Q
Definition at line 663 of file QRFactorization.cpp.
Eigen::MatrixXd & precice::acceleration::impl::QRFactorization::matrixR | ( | ) |
returns a matrix representation of the upper triangular matrix R
Definition at line 668 of file QRFactorization.cpp.
|
private |
assuming Q(1:n,1:m) has nearly orthonormal columns, this procedure orthogonlizes v(1:n) to the columns of Q, and normalizes the result. r(1:n) is the array of Fourier coefficients, and rho is the distance from v to range of Q, r and its corrections are computed in double precision. This method tries to re-orthogonalize the matrix Q for a maximum of 4 iterations if ||v_orth|| / ||v|| <= 1/theta is toot small, i.e. the gram schmidt process is iterated.
assuming Q(1:n,1:m) has nearly orthonormal columns, this procedure orthogonlizes v(1:n) to the columns of Q, and normalizes the result. r(1:n) is the array of Fourier coefficients, and rho is the distance from v to range of Q, r and its corrections are computed in double precision.
Difference to the method orthogonalize_stable(): if ||v_orth||/||v|| approx 0, no unit vector is inserted.
re-orthogonalize if: ||v_orth|| / ||v|| <= 1/theta
Definition at line 313 of file QRFactorization.cpp.
|
private |
assuming Q(1:n,1:m) has nearly orthonormal columns, this procedure orthogonlizes v(1:n) to the columns of Q, and normalizes the result. r(1:n) is the array of Fourier coefficients, and rho is the distance from v to range of Q, r and its corrections are computed in double precision. This method tries to re-orthogonalize the matrix Q for a maximum of 4 iterations if ||v_orth|| / ||v|| <= 1/theta is toot small, i.e. the gram schmidt process is iterated. If ||v_orth|| / ||v|| <= std::numeric_limit, a unit vector that is orthogonal to Q is inserted and rho is set to 0. i.e., R has a zero on the diagonal in the respective column.
assuming Q(1:n,1:m) has nearly orthonormal columns, this procedure orthogonlizes v(1:n) to the columns of Q, and normalizes the result. r(1:n) is the array of Fourier coefficients, and rho is the distance from v to range of Q, r and its corrections are computed in double precision.
test if reorthogonalization is necessary - rho0 = |v_init|, t = |r_(i,cols-1)|, rho1 = |v_orth| rho1 is small, if the new information incorporated in v is small, i.e., the part of v orthogonal to _Q is small. if rho1 is very small it is possible, that we are adding (more or less) only round-off errors to the decomposition. Later normalization will scale this new information so that it is equally weighted as the columns in Q. To keep a good orthogonality, some effort is done if comparatively little new information is added.
re-orthogonalize if: ||v_orth|| / ||v|| <= 1/theta
Definition at line 428 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::popBack | ( | ) |
deletes the column at position _cols-1, i.e., deletes the last column and updates the QR factorization
Definition at line 764 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::popFront | ( | ) |
deletes the column at position 0, i.e., deletes and shifts columns to the left and updates the QR factorization
Definition at line 759 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::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 factorization This function works on the memory of v, thus changes the Vector v.
Definition at line 754 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::pushFront | ( | const Eigen::VectorXd & | v | ) |
inserts a new column at position 0, i.e., shifts right and inserts at first position and updates the QR factorization. This function works on the memory of v, thus changes the Vector v.
Definition at line 749 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::reset | ( | ) |
resets the QR factorization zo zero Q(0:0, 0:0)R(0:0, 0:0)
Definition at line 683 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::reset | ( | Eigen::MatrixXd const & | A, |
int | globalRows, | ||
double | omega = 0, | ||
double | theta = 1. / 0.7, | ||
double | sigma = std::numeric_limits<double>::min() ) |
resets the QR factorization to be the factorization of A = QR
Definition at line 715 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::reset | ( | Eigen::MatrixXd const & | Q, |
Eigen::MatrixXd const & | R, | ||
int | rows, | ||
int | cols, | ||
double | omega = 0, | ||
double | theta = 1. / 0.7, | ||
double | sigma = std::numeric_limits<double>::min() ) |
resets the QR factorization to the given factorization Q, R
Definition at line 692 of file QRFactorization.cpp.
int precice::acceleration::impl::QRFactorization::rows | ( | ) | const |
Definition at line 678 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::setFilter | ( | int | filter | ) |
Definition at line 775 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::setfstream | ( | std::fstream * | stream | ) |
Definition at line 769 of file QRFactorization.cpp.
void precice::acceleration::impl::QRFactorization::setGlobalRows | ( | int | gr | ) |
Definition at line 658 of file QRFactorization.cpp.
|
private |
Definition at line 211 of file QRFactorization.hpp.
|
private |
Definition at line 213 of file QRFactorization.hpp.
|
private |
Definition at line 220 of file QRFactorization.hpp.
|
private |
Definition at line 222 of file QRFactorization.hpp.
|
private |
Definition at line 219 of file QRFactorization.hpp.
|
private |
Definition at line 205 of file QRFactorization.hpp.
|
private |
Definition at line 214 of file QRFactorization.hpp.
|
private |
Definition at line 207 of file QRFactorization.hpp.
|
private |
Definition at line 208 of file QRFactorization.hpp.
|
private |
Definition at line 210 of file QRFactorization.hpp.
|
private |
Definition at line 216 of file QRFactorization.hpp.
|
private |
Definition at line 215 of file QRFactorization.hpp.