32 double initialRelaxation,
33 bool forceInitialRelaxation,
34 int maxIterationsUsed,
35 int pastTimeWindowsReused,
37 double singularityLimit,
40 bool alwaysBuildJacobian,
43 int RSLSreusedTimeWindows,
44 double RSSVDtruncationEps,
46 :
BaseQNAcceleration(initialRelaxation, forceInitialRelaxation, maxIterationsUsed, pastTimeWindowsReused,
47 filter, singularityLimit,
std::move(dataIDs), preconditioner, reducedTimeGrid),
58 _svdJ(RSSVDtruncationEps, preconditioner),
104 Eigen::VectorXd wtil = Eigen::VectorXd::Zero(
_matrixW.rows());
110 for (
int i = 0; i < static_cast<int>(
_WtilChunk.size()); i++) {
113 Eigen::VectorXd Zv = Eigen::VectorXd::Zero(colsLSSystemBackThen);
137 if (not columnLimitReached && overdetermined) {
183 auto Q =
_qrV.matrixQ();
184 auto R =
_qrV.matrixR();
199 for (
int i = 0; i < Q.rows(); i++) {
200 Eigen::VectorXd Qrow = Q.row(i);
201 yVec = R.triangularView<Eigen::Upper>().solve<Eigen::OnTheLeft>(Qrow);
228 for (
int i = 0; i < static_cast<int>(
_WtilChunk.size()); i++) {
231 Eigen::MatrixXd ZV = Eigen::MatrixXd::Zero(colsLSSystemBackThen,
_qrV.cols());
267 Eigen::MatrixXd Z(
_qrV.cols(),
_qrV.rows());
277 PRECICE_WARN(
" ATTENTION, in buildJacobian call for buildWtill() - this should not be the case except the coupling did only one iteration");
317 Eigen::MatrixXd Z(
_qrV.cols(),
_qrV.rows());
355 xUpdate = Eigen::VectorXd::Zero(
_residuals.size());
356 xUptmp =
_Wtil * r_til;
365 for (
int i = 0; i < static_cast<int>(
_WtilChunk.size()); i++) {
368 r_til = Eigen::VectorXd::Zero(colsLSSystemBackThen);
385 _Wtil.conservativeResize(0, 0);
402 Eigen::MatrixXd Z(
_qrV.cols(),
_qrV.rows());
440 for (
int i = 0; i < static_cast<int>(
_WtilChunk.size()); i++) {
451 int q =
_svdJ.isSVDinitialized() ? 1 : 0;
454 for (; q < static_cast<int>(
_WtilChunk.size()); q++) {
466 auto &psi =
_svdJ.matrixPsi();
467 auto &sigma =
_svdJ.singularValues();
468 auto &phi =
_svdJ.matrixPhi();
473 Eigen::MatrixXd Z(phi.cols(), phi.rows());
474 for (
int i = 0; i < static_cast<int>(Z.rows()); i++)
475 for (
int j = 0; j < static_cast<int>(Z.cols()); j++)
476 Z(i, j) = phi(j, i) * sigma[i];
479 int waste =
_svdJ.getWaste();
491 PRECICE_DEBUG(
"MVJ-RESTART, mode=SVD. Rank of truncated SVD of Jacobian {}, new modes: {}, truncated modes: {} avg rank: {}", rankAfter, rankAfter - rankBefore, waste,
_avgRank /
_nbRestarts);
495 _infostringstream <<
" - MVJ-RESTART " <<
_nbRestarts <<
", mode= SVD -\n new modes: " << rankAfter - rankBefore <<
"\n rank svd: " << rankAfter <<
"\n avg rank: " <<
_avgRank /
_nbRestarts <<
"\n truncated modes: " << waste <<
"\n"
522 for (
int i = 0; i < static_cast<int>(
_matrixV_RSLS.cols()); i++) {
533 for (
int i = delIndices.
size() - 1; i >= 0; i--) {
549 for (
int i = 0; i < Q.rows(); i++) {
550 Eigen::VectorXd Qrow = Q.row(i);
551 yVec = R.triangularView<Eigen::Upper>().solve<Eigen::OnTheLeft>(Qrow);
589 for (
int i =
static_cast<int>(
_WtilChunk.size()) - 1; i >= 1; i--) {
593 Eigen::MatrixXd ZV = Eigen::MatrixXd::Zero(colsLSSystemBackThen,
_qrV.cols());
597 Eigen::MatrixXd tmp = Eigen::MatrixXd::Zero(
_residuals.rows(),
_qrV.cols());
638 for (
int i = 0; i < toRemove; i++) {
674 Eigen::MatrixXd Z(
_qrV.cols(),
_qrV.rows());
694 restartUpdate.
stop();
743 global_n = cplDataEntries;
755 _invJacobian = Eigen::MatrixXd::Zero(global_n, entries);
772 _Wtil = Eigen::MatrixXd::Zero(cplDataEntries, 0);
800 if (cols > columnIndex) {
#define PRECICE_WARN(...)
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
std::map< int, cplscheme::PtrCouplingData > DataMap
Map from data ID to data values.
static const int QR2FILTER
static const int NOFILTER
virtual void updateDifferenceMatrices(const DataMap &cplData)
Updates the V, W matrices (as well as the matrices for the secondary data)
int getLSSystemCols() const
: computes number of cols in least squares system, i.e, number of cols in _matrixV,...
virtual void applyFilter()
Applies the filter method for the least-squares system, defined in the configuration.
Eigen::VectorXd _primaryResiduals
Current iteration residuals of primary IQN data. Temporary.
std::ostringstream _infostringstream
write some debug/acceleration info to file
bool _resetLS
If true, the LS system has been modified (reset or recomputed) in such a way, that mere updating of m...
bool _hasNodesOnInterface
const int _filter
filter method that is used to maintain good conditioning of the least-squares system Either of two ty...
Eigen::MatrixXd _matrixV
Stores residual deltas.
std::vector< int > _dimOffsets
Stores the local dimensions, i.e., the offsets in _invJacobian for all processors.
const double _singularityLimit
Determines sensitivity when two matrix columns are considered equal.
const int _maxIterationsUsed
Maximum number of old data iterations kept.
Eigen::VectorXd _residuals
Current iteration residuals of IQN data. Temporary.
virtual void removeMatrixColumn(int columnIndex)
Removes one iteration from V,W matrices and adapts _matrixCols.
Eigen::MatrixXd _matrixW
Stores x tilde deltas, where x tilde are values computed by solvers.
int getPrimaryLSSystemRows() const
const int _timeWindowsReused
Maximum number of old time windows (with data values) kept.
int getLSSystemRows() const
BaseQNAcceleration(double initialRelaxation, bool forceInitialRelaxation, int maxIterationsUsed, int timeWindowsReused, int filter, double singularityLimit, std::vector< int > dataIDs, impl::PtrPreconditioner preconditioner, bool reducedTimeGrid)
bool _firstIteration
Indicates the first iteration, where constant relaxation is used.
impl::PtrPreconditioner _preconditioner
Preconditioner for least-squares system if vectorial system is used.
impl::QRFactorization _qrV
Stores the current QR decomposition ov _matrixV, can be updated via deletion/insertion of columns.
bool _forceInitialRelaxation
const bool _imvjRestart
: If true, the imvj method is used with the restart chunk based approach that avoids to explicitly bu...
static const int RS_SLIDE
int _RSLSreusedTimeWindows
: Number of reused time windows at restart if restart-mode = RS-LS
const int _imvjRestartType
: Indicates the type of the imvj restart-mode:
static const int NO_RESTART
void updateDifferenceMatrices(const DataMap &cplData) override
: updates the V, W matrices (as well as the matrices for the secondary data)
void pseudoInverse(Eigen::MatrixXd &pseudoInverse)
: computes the pseudo inverse of V multiplied with V^T, i.e., Z = (V^TV)^-1V^T via QR-dec
~IQNIMVJAcceleration() override
Destructor, empty.
Eigen::MatrixXd _matrixW_RSLS
stores columns from previous _RSLSreusedTimeWindows time windows if RS-LS restart-mode is active
int _nbRestarts
tracks the number of restarts of IMVJ
void computeQNUpdate(Eigen::VectorXd &xUpdate) override
: computes the IQNIMVJ update using QR decomposition of V, furthermore it updates the inverse of the ...
Eigen::MatrixXd _invJacobian
stores the approximation of the inverse Jacobian of the system at current time window.
void removeMatrixColumn(int columnIndex) override
: Removes one iteration from V,W matrices and adapts _matrixCols.
void specializedInitializeVectorsAndPreconditioner(const DataMap &cplData) final override
impl::PtrParMatrixOps _parMatrixOps
encapsulates matrix-matrix and matrix-vector multiplications for serial and parallel execution
int _chunkSize
: Number of time windows between restarts for the imvj method in restart mode
void computeNewtonUpdate(Eigen::VectorXd &update)
: computes the quasi-Newton update vector based on the matrices V and W using a QR decomposition of V...
Eigen::MatrixXd _Wtil
stores the sub result (W-J_prev*V) for the current iteration
void removeMatrixColumnRSLS(int columnINdex)
: Removes one column form the V_RSLS and W_RSLS matrices and adapts _matrixCols_RSLS
void buildWtil()
: re-computes the matrix _Wtil = ( W - J_prev * V) instead of updating it according to V
void specializedIterationsConverged(const DataMap &cplData) override
Marks a iteration sequence as converged.
IQNIMVJAcceleration(double initialRelaxation, bool forceInitialRelaxation, int maxIterationsUsed, int pastTimeWindowsReused, int filter, double singularityLimit, std::vector< int > dataIDs, const impl::PtrPreconditioner &preconditioner, bool alwaysBuildJacobian, int imvjRestartType, int chunkSize, int RSLSreusedTimeWindows, double RSSVDtruncationEps, bool reducedTimeGrid)
Constructor.
bool _alwaysBuildJacobian
If true, the less efficient method to compute the quasi-Newton update is used, that explicitly builds...
void restartIMVJ()
: restarts the imvj method, i.e., drops all stored matrices Wtil and Z and computes a initial guess o...
void buildJacobian()
: computes a explicit representation of the Jacobian, i.e., n x n matrix
void computeNewtonUpdateEfficient(Eigen::VectorXd &update)
: computes the quasi-Newton update vector based on the same numerics as above. However,...
std::vector< Eigen::MatrixXd > _pseudoInverseChunk
stores all pseudo inverses within the current chunk of the imvj restart mode, disabled if _imvjRestar...
Eigen::MatrixXd _oldInvJacobian
stores the approximation of the inverse Jacobian from the previous time window.
Eigen::MatrixXd _matrixV_RSLS
stores columns from previous _RSLSreusedTimeWindows time windows if RS-LS restart-mode is active
std::deque< int > _matrixCols_RSLS
number of cols per time window
std::vector< Eigen::MatrixXd > _WtilChunk
stores all Wtil matrices within the current chunk of the imvj restart mode, disabled if _imvjRestart ...
impl::SVDFactorization _svdJ
holds and maintains a truncated SVD decomposition of the Jacobian matrix
Class that provides functionality for a dynamic QR-decomposition, that can be updated in O(mn) flops ...
void setGlobalRows(int gr)
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 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...
Eigen::MatrixXd & matrixQ()
returns a matrix representation of the orthogonal matrix Q
void stop()
Stops a running event.
static bool isPrimary()
True if this process is running the primary rank.
static bool isParallel()
True if this process is running in parallel.
std::shared_ptr< Preconditioner > PtrPreconditioner
contains implementations of acceleration schemes.
std::shared_ptr< CouplingData > PtrCouplingData
void removeColumnFromMatrix(Eigen::MatrixXd &A, int col)
void appendFront(Eigen::MatrixXd &A, Eigen::VectorXd &v)
void shiftSetFirst(Eigen::MatrixXd &A, const Eigen::VectorXd &v)