85 Q = Matrix::Zero(A.rows(), A.cols());
86 R = Matrix::Zero(A.cols(), A.cols());
97 for (
int colIndex = 0; colIndex < A.cols(); colIndex++) {
103 Vector col = A.col(colIndex);
106 if (globalRows == colIndex) {
107 PRECICE_WARN(
"The matrix that is about to be factorized is quadratic, i.e., the new column cannot be orthogonalized; discard.");
114 Vector r = Vector::Zero(R.rows());
115 Vector s = Vector::Zero(R.rows());
116 Vector u = Vector::Zero(A.rows());
117 double rho_orth = 0.;
122 bool termination =
false;
123 bool orthogonalized =
true;
125 while (!termination) {
128 u = Vector::Zero(A.rows());
129 for (
int j = 0; j < colsQ; j++) {
138 u += Q.col(j) * r_ij;
154 PRECICE_DEBUG(
"The norm of v_orthogonal is almost zero, i.e., failed to orthogonalize column v; discard.");
155 orthogonalized =
false;
171 if (rho_orth * theta <= rho0 + omega * norm_coefficients) {
174 PRECICE_WARN(
"Matrix Q is not sufficiently orthogonal. Failed to orthogonalize new column after 4 iterations. New column will be discarded.");
175 orthogonalized =
false;
189 orthogonalized =
false;
193 double rho = orthogonalized ? rho_orth : 1.0;
213 if (not orthogonalized) {
220 Q.col(colsQ) = Vector::Zero(A.rows());
226 R.row(rowsR) = Vector::Zero(A.cols());
230 Q.conservativeResize(A.rows(), colsQ);
231 R.conservativeResize(rowsR, colsR);
#define PRECICE_WARN(...)
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
int _cols
Number of columns, i.e., rank of the truncated svd.
PtrParMatrixOps _parMatrixOps
: object for parallel matrix operations, i.e., parallel mat-mat/ mat-vec multiplications
void setApplyFilterQR(bool b, double eps=1e-3)
: enables or disables an additional QR-2 filter for the QR-decomposition
double _truncationEps
Truncation parameter for the updated SVD decomposition.
bool _initialSVD
true, if at least one update has been made, i.e., the number of rows is known and a initial rank is g...
void initialize(PtrParMatrixOps parMatOps, int globalRowsA, int globalRowsB)
: initializes the updated SVD factorization, i.e., sets the object for parallel matrix-matrix operati...
double getThreshold()
: returns the truncation threshold for the SVD
bool _preconditionerApplied
true if the preconditioner has been applied appropriate to the updated SVD decomposition
void setThreshold(double eps)
: sets the threshold for the truncation of the SVD factorization
Matrix _psi
: SVD factorization of the matrix J = _psi * _sigma * _phi^T
void setPrecondApplied(bool b)
: applies the preconditioner to the factorized and truncated representation of the Jacobian matrix
Matrix & matrixPhi()
: returns a matrix representation of the orthogonal matrix Phi, A = Psi * Sigma * Phi^T
Vector & singularValues()
: returns a matrix representation of the orthogonal matrix Sigma, A = Psi * Sigma * Phi^T
void reset()
: resets the SVD factorization
Rank rank()
: returns the rank of the truncated SVD factorization
int _globalRowsB
Number of global rows of second multiplicator, i.e., sum of _rows for all procs.
double _epsQR2
Threshold for the QR2 filter for the QR decomposition.
int _globalRowsA
Number of global rows of first multiplicator, i.e., sum of _rows for all procs.
Matrix & matrixPsi()
: returns a matrix representation of the orthogonal matrix Psi, A = Psi * Sigma * Phi^bs
bool _initialized
true, if ParallelMatrixOperations object is set, i.e., initialized
int cols()
: returns the number of columns in the QR-decomposition
SVDFactorization(double eps, PtrPreconditioner preconditioner)
Constructor.
void computeQRdecomposition(Matrix const &A, int globalRows, Matrix &Q, Matrix &R)
: computes the QR decomposition of a matrix A of type A = PSI^T*A \in R^(rank x n)
PtrPreconditioner _preconditioner
: preconditioner for least-squares system if vectorial system is used.
int getWaste()
: returns the total number of truncated modes since last call to this method
static double l2norm(const Eigen::VectorXd &vec)
The l2 norm of a vector is calculated on distributed data.
static double dot(const Eigen::VectorXd &vec1, const Eigen::VectorXd &vec2)
std::shared_ptr< Preconditioner > PtrPreconditioner
std::shared_ptr< ParallelMatrixOperations > PtrParMatrixOps