72 for (
int k = 0; k < m; k++) {
73 Eigen::VectorXd v = A.col(k);
110 bool linearDependence =
true;
113 while (linearDependence) {
114 linearDependence =
false;
117 for (
size_t i = 0; i < delFlag.
size(); i++) {
129 linearDependence =
true;
149 for (
int k = 0; k < V.cols(); k++) {
150 Eigen::VectorXd v = V.col(k);
175 for (
int l = k; l <
_cols - 1; l++) {
178 Eigen::VectorXd Rr1 =
_R.row(l);
179 Eigen::VectorXd Rr2 =
_R.row(l + 1);
183 Eigen::VectorXd Qc1 =
_Q.col(l);
184 Eigen::VectorXd Qc2 =
_Q.col(l + 1);
190 for (
int j = k; j <
_cols - 1; j++) {
191 for (
int i = 0; i <= j; i++) {
192 _R(i, j) =
_R(i, j + 1);
211 Eigen::VectorXd v(vec);
225 Eigen::VectorXd u(
_cols);
226 double rho_orth = 0., rho0 = 0.;
237 PRECICE_DEBUG(
"The ratio ||v_orth|| / ||v|| is extremely small and either the orthogonalization process of column v failed or the system is quadratic.");
249 if (
applyFilter && (rho0 * singularityLimit > rho_orth)) {
250 PRECICE_DEBUG(
"discarding column as it is filtered out by the QR2-filter: rho0*eps > rho_orth: {} > {}", rho0 * singularityLimit, rho_orth);
260 for (
int j =
_cols - 2; j >= k; j--) {
261 for (
int i = 0; i <= j; i++) {
262 _R(i, j + 1) =
_R(i, j);
266 for (
int j = k + 1; j <
_cols; j++) {
281 for (
int l =
_cols - 2; l >= k; l--) {
284 Eigen::VectorXd Rr1 =
_R.row(l);
285 Eigen::VectorXd Rr2 =
_R.row(l + 1);
289 Eigen::VectorXd Qc1 =
_Q.col(l);
290 Eigen::VectorXd Qc2 =
_Q.col(l + 1);
295 for (
int i = 0; i <= k; i++) {
326 bool termination =
false;
327 double rho0 = 0., rho1 = 0.;
328 Eigen::VectorXd u = Eigen::VectorXd::Zero(
_rows);
329 Eigen::VectorXd s = Eigen::VectorXd::Zero(colNum);
330 r = Eigen::VectorXd::Zero(
_cols);
335 while (!termination) {
338 u = Eigen::VectorXd::Zero(
_rows);
339 for (
int j = 0; j < colNum; j++) {
342 Eigen::VectorXd Qc =
_Q.col(j);
349 u +=
_Q.col(j) * r_ij;
352 for (
int j = 0; j < colNum; j++) {
356 for (
int i = 0; i <
_rows; i++) {
370 PRECICE_WARN(
"The least-squares system matrix is quadratic, i.e., the new column cannot be orthogonalized (and thus inserted) to the LS-system.\nOld columns need to be removed.");
371 v = Eigen::VectorXd::Zero(
_rows);
378 PRECICE_DEBUG(
"The norm of v_orthogonal is almost zero, i.e., failed to orthogonalize column v; discard.");
396 if (rho1 *
_theta <= rho0 +
_omega * norm_coefficients) {
399 PRECICE_WARN(
"Matrix Q is not sufficiently orthogonal. Failed to orthogonalize new column after 4 iterations. New column will be discarded. The least-squares system is very bad conditioned and the quasi-Newton will most probably fail to converge.");
412 rho = null ? 0 : rho1;
441 bool restart =
false;
443 bool termination =
false;
444 double rho0 = 0., rho1 = 0.;
446 Eigen::VectorXd u = Eigen::VectorXd::Zero(
_rows);
447 Eigen::VectorXd s = Eigen::VectorXd::Zero(colNum);
448 r = Eigen::VectorXd::Zero(
_cols);
453 while (!termination) {
455 u = Eigen::VectorXd::Zero(
_rows);
456 for (
int j = 0; j < colNum; j++) {
461 Eigen::VectorXd Qc =
_Q.col(j);
469 for (
int i = 0; i <
_rows; i++) {
470 u(i) = u(i) +
_Q(i, j) * t;
475 for (
int j = 0; j < colNum; j++) {
480 for (
int i = 0; i <
_rows; i++) {
494 PRECICE_WARN(
"The least-squares system matrix is quadratic, i.e., the new column cannot be orthogonalized (and thus inserted) to the LS-system.\nOld columns need to be removed.");
495 v = Eigen::VectorXd::Zero(
_rows);
516 <<
"\ntoo many iterations in orthogonalize, termination failed\n";
517 PRECICE_WARN(
"Matrix Q is not sufficiently orthogonal. Failed to orthogonalize new column after 4 iterations. New column will be discarded. The least-squares system is very bad conditioned and the quasi-Newton will most probably fail to converge.");
523 if (!restart && rho1 <= rho *
_sigma) {
524 PRECICE_WARN(
"The new column is in the range of Q, thus not possible to orthogonalize. Try to insert a unit vector that is orthogonal to the columns space of Q.");
527 (*_infostream) <<
"[QR-dec] - reorthogonalization\n";
538 u = Eigen::VectorXd::Zero(
_rows);
539 for (
int j = 0; j < colNum; j++) {
540 for (
int i = 0; i <
_rows; i++) {
541 u(i) = u(i) +
_Q(i, j) *
_Q(i, j);
548 for (
int i = 0; i <
_rows; i++) {
557 double local_uk = 0.;
558 double global_uk = 0.;
571 if (local_uk < global_uk) {
572 rank = secondaryRank;
573 global_uk = local_uk;
578 (*_infostream) <<
" global u(k):" << global_uk <<
", global k: " << global_k <<
", rank: " << rank <<
'\n';
587 v = Eigen::VectorXd::Zero(
_rows);
608 rho = null ? 0 : rho1;
629 t *= (u < 0) ? -1 : 1;
649 for (
int j = k; j < l; j++) {
654 q(j) = (t + u) * nu - v;
693 Eigen::MatrixXd
const &Q,
694 Eigen::MatrixXd
const &R,
716 Eigen::MatrixXd
const &A,
734 for (; col < m; k++, col++) {
735 Eigen::VectorXd v = A.col(col);
739 PRECICE_DEBUG(
"column {} has not been inserted in the QR-factorization, failed to orthogonalize.", col);
#define PRECICE_WARN(...)
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
static const int QR1FILTER_ABS
static const int QR2FILTER
static const int QR1FILTER
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...
void setGlobalRows(int gr)
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 setfstream(std::fstream *stream)
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 ...
std::fstream * _infostream
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,...
void setFilter(int filter)
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....
static double l2norm(const Eigen::VectorXd &vec)
The l2 norm of a vector is calculated on distributed data.
static Rank getRank()
Current rank.
static double dot(const Eigen::VectorXd &vec1, const Eigen::VectorXd &vec2)
static bool isPrimary()
True if this process is running the primary rank.
static auto allSecondaryRanks()
Returns an iterable range over salve ranks [1, _size)
static bool isParallel()
True if this process is running in parallel.
static bool isSecondary()
True if this process is running a secondary rank.
static com::PtrCommunication & getCommunication()
Intra-participant communication.