13 #if !defined(KRATOS_MVQN_CONVERGENCE_ACCELERATOR)
14 #define KRATOS_MVQN_CONVERGENCE_ACCELERATOR
56 template<
class TSparseSpace,
class TDenseSpace>
93 mOmega_0 = rConvAcceleratorParameters[
"w_0"].
GetDouble();
94 mAbsCutOff = rConvAcceleratorParameters[
"abs_cut_off_tol"].
GetDouble();
95 mUsedInBlockNewtonEquations = rConvAcceleratorParameters[
"interface_block_newton"].
GetBool();
105 , mAbsCutOff(AbsCutOff)
106 , mUsedInBlockNewtonEquations(true)
138 mConvergenceAcceleratorIteration = 0;
176 mpIterationValue_0 = mpIterationValue_1;
177 mpResidualVector_0 = mpResidualVector_1;
178 mConvergenceAcceleratorIteration += 1;
200 mpObsMatrixV =
nullptr;
201 mpObsMatrixW =
nullptr;
209 "solver_type" : "MVQN",
211 "abs_cut_off_tol" : 1e-8,
212 "interface_block_newton" : false
215 return mvqn_default_parameters;
266 if (mConvergenceAcceleratorFirstCorrectionPerformed ==
false) {
269 mConvergenceAcceleratorFirstCorrectionPerformed =
true;
294 if (mProblemSize == 0 ) {
301 std::swap(mpResidualVector_1, pAuxResidualVector);
302 std::swap(mpIterationValue_1, pAuxIterationGuess);
304 if (mConvergenceAcceleratorIteration != 0) {
321 if (mConvergenceAcceleratorIteration == 1) {
323 InitializeDataColumns();
327 if (n_old_cols < mProblemSize) {
330 DropAndAppendDataColumns();
344 const auto& r_V = *mpObsMatrixV;
353 std::string svd_type =
"Jacobi";
354 const double svd_rel_tol = 1.0e-6;
360 double max_eig_V = 0.0;
362 for (std::size_t i_col = 0; i_col < data_cols; ++i_col){
363 const double i_eigval = std::sqrt(w_svd(i_col,i_col));
364 if (max_eig_V < i_eigval) {
365 max_eig_V = i_eigval;
366 }
else if (min_eig_V > i_eigval) {
367 min_eig_V = i_eigval;
372 if (min_eig_V < mAbsCutOff * max_eig_V) {
374 <<
"Dropping new observation columns information. Residual observation matrix min. eigval.: " << min_eig_V <<
" (tolerance " << mAbsCutOff * max_eig_V <<
")" << std::endl;
376 this->DropLastDataColumn();
380 transV_V.resize(data_cols, data_cols,
false);
392 auto& r_aux_inv = *p_aux_inv;
393 for (std::size_t
i = 0;
i < data_cols; ++
i) {
394 for (std::size_t
j = 0;
j < data_cols; ++
j) {
395 const double aux = v_svd(
j,
i) / w_svd(
j,
j);
396 for (std::size_t
k = 0;
k < data_cols; ++
k) {
397 r_aux_inv(
i,
k) += aux * u_svd(
k,
j);
401 std::swap(mpVtransVPseudoInv, p_aux_inv);
411 if (!mJacobiansAreInitialized) {
414 InitializeJacobianMatrices();
415 mJacobiansAreInitialized =
true;
440 if (mpObsMatrixV !=
nullptr && mpObsMatrixW !=
nullptr) {
442 const auto& r_V = *mpObsMatrixV;
443 const auto& r_W = *mpObsMatrixW;
451 std::swap(mpJac_k1, p_aux_jac_k1);
474 return mConvergenceAcceleratorIteration;
484 return mConvergenceAcceleratorFirstCorrectionPerformed;
495 return mUsedInBlockNewtonEquations;
505 return mpResidualVector_1;
555 mAbsCutOff = CutOffTolerance;
560 KRATOS_ERROR <<
"Jacobian decomposition not available for this convergence accelerator." << std::endl;
565 KRATOS_ERROR <<
"Jacobian decomposition not available for this convergence accelerator." << std::endl;
570 KRATOS_ERROR <<
"Jacobian decomposition not available for this convergence accelerator." << std::endl;
575 KRATOS_ERROR <<
"Jacobian decomposition not available for this convergence accelerator." << std::endl;
588 double mOmega_0 = 0.825;
590 double mAbsCutOff = 1.0e-8;
591 bool mUsedInBlockNewtonEquations =
false;
592 unsigned int mProblemSize = 0;
593 unsigned int mConvergenceAcceleratorIteration = 0;
594 bool mJacobiansAreInitialized =
false;
595 bool mConvergenceAcceleratorFirstCorrectionPerformed =
false;
613 void InitializeJacobianMatrices()
615 if (mUsedInBlockNewtonEquations) {
617 MatrixPointerType p_new_jac_n = Kratos::make_shared<MatrixType>(mProblemSize,mProblemSize);
618 (*p_new_jac_n) =
ZeroMatrix(mProblemSize,mProblemSize);
619 std::swap(p_new_jac_n,mpJac_n);
623 MatrixPointerType p_new_jac_k1 = Kratos::make_shared<MatrixType>(mProblemSize,mProblemSize);
624 (*p_new_jac_k1) =
ZeroMatrix(mProblemSize,mProblemSize);
625 std::swap(p_new_jac_k1, mpJac_k1);
628 MatrixPointerType p_new_jac_n = Kratos::make_shared<MatrixType>(mProblemSize,mProblemSize);
629 (*p_new_jac_n) = -1.0 *
IdentityMatrix(mProblemSize,mProblemSize);
630 std::swap(p_new_jac_n,mpJac_n);
634 void InitializeDataColumns()
639 std::swap(mpObsMatrixV, p_aux_V);
640 std::swap(mpObsMatrixW, p_aux_W);
643 IndexPartition<unsigned int>(mProblemSize).for_each([&](
unsigned int I){
644 (*mpObsMatrixV)(I,0) = (*mpResidualVector_1)(I) - (*mpResidualVector_0)(I);
645 (*mpObsMatrixW)(I,0) = (*mpIterationValue_1)(I) - (*mpIterationValue_0)(I);
653 void AppendDataColumns()
656 const std::size_t n_old_cols = mpObsMatrixV->size2();
657 MatrixPointerType p_new_V = Kratos::make_shared<MatrixType>(mProblemSize, n_old_cols + 1);
658 MatrixPointerType p_new_W = Kratos::make_shared<MatrixType>(mProblemSize, n_old_cols + 1);
661 IndexPartition<unsigned int>(mProblemSize).for_each([&](
unsigned int I){
662 for (
unsigned int j = 0;
j < n_old_cols;
j++){
663 (*p_new_V)(I,
j) = (*mpObsMatrixV)(I,
j);
664 (*p_new_W)(I,
j) = (*mpObsMatrixW)(I,
j);
669 IndexPartition<unsigned int>(mProblemSize).for_each([&](
unsigned int I){
670 (*p_new_V)(I, n_old_cols) = (*mpResidualVector_1)(I) - (*mpResidualVector_0)(I);
671 (*p_new_W)(I, n_old_cols) = (*mpIterationValue_1)(I) - (*mpIterationValue_0)(I);
674 std::swap(mpObsMatrixV,p_new_V);
675 std::swap(mpObsMatrixW,p_new_W);
682 void DropAndAppendDataColumns()
685 MatrixPointerType p_new_V = Kratos::make_shared<MatrixType>(mProblemSize, mProblemSize);
686 MatrixPointerType p_new_W = Kratos::make_shared<MatrixType>(mProblemSize, mProblemSize);
689 IndexPartition<unsigned int>(mProblemSize).for_each([&](
unsigned int I){
690 for (
unsigned int j = 0;
j < (mProblemSize-1);
j++){
691 (*p_new_V)(I,
j) = (*mpObsMatrixV)(I,
j+1);
692 (*p_new_W)(I,
j) = (*mpObsMatrixW)(I,
j+1);
697 IndexPartition<unsigned int>(mProblemSize).for_each([&](
unsigned int I){
698 (*p_new_V)(I, mProblemSize-1) = (*mpResidualVector_1)(I) - (*mpResidualVector_0)(I);
699 (*p_new_W)(I, mProblemSize-1) = (*mpIterationValue_1)(I) - (*mpIterationValue_0)(I);
702 std::swap(mpObsMatrixV,p_new_V);
703 std::swap(mpObsMatrixW,p_new_W);
710 void DropLastDataColumn()
713 const auto n_cols = mpObsMatrixV->size2() - 1;
714 MatrixPointerType p_aux_V = Kratos::make_shared<MatrixType>(mProblemSize, n_cols);
715 MatrixPointerType p_aux_W = Kratos::make_shared<MatrixType>(mProblemSize, n_cols);
718 IndexPartition<std::size_t>(mProblemSize).for_each([&](
unsigned int IRow){
719 for (std::size_t i_col = 0; i_col < n_cols; ++i_col){
720 (*p_aux_V)(IRow, i_col) = (*mpObsMatrixV)(IRow, i_col);
721 (*p_aux_W)(IRow, i_col) = (*mpObsMatrixW)(IRow, i_col);
726 std::swap(mpObsMatrixV,p_aux_V);
727 std::swap(mpObsMatrixW,p_aux_W);
Base class for convergence accelerators This class is intended to be the base of any convergence acce...
Definition: convergence_accelerator.h:43
Interface Block Newton convergence accelerator Interface Block Newton equations convergence accelerat...
Definition: ibqn_mvqn_convergence_accelerator.h:61
Interface Block Newton MVQN with randomized Jacobian convergence accelerator Interface Block Newton e...
Definition: ibqn_mvqn_randomized_svd_convergence_accelerator.h:60
MVQN acceleration scheme MultiVectorQuasiNewton convergence accelerator from Bogaers et al....
Definition: mvqn_convergence_accelerator.hpp:58
virtual MatrixPointerType pGetJacobianDecompositionMatrixSigmaV()
Definition: mvqn_convergence_accelerator.hpp:563
MVQNFullJacobianConvergenceAccelerator(const double AbsCutOff)
Construct a new MVQNFullJacobianConvergenceAccelerator object This constructor intended to be used wi...
Definition: mvqn_convergence_accelerator.hpp:103
void UpdateIterationGuess(VectorType &rIterationGuess)
Calculate the current iteration correction This method calculates the current iteration correction an...
Definition: mvqn_convergence_accelerator.hpp:264
void CalculateInverseJacobianApproximation()
Calculates the inverse Jacobian approximation This method calculates the MVQN inverse Jacobian approx...
Definition: mvqn_convergence_accelerator.hpp:409
BaseType::DenseVectorType VectorType
Definition: mvqn_convergence_accelerator.hpp:68
MVQNFullJacobianConvergenceAccelerator(const MVQNFullJacobianConvergenceAccelerator &rOther)
virtual MatrixPointerType pGetOldJacobianDecompositionMatrixQU()
Definition: mvqn_convergence_accelerator.hpp:568
void InitializeSolutionStep() override
Initialize the internal iteration counter This method initializes the convergence acceleratior iterat...
Definition: mvqn_convergence_accelerator.hpp:134
KRATOS_CLASS_POINTER_DEFINITION(MVQNFullJacobianConvergenceAccelerator)
void SetInitialRelaxationOmega(const double Omega)
Set the Initial Relaxation Omega This method sets the relaxation parameter to be used in the very fir...
Definition: mvqn_convergence_accelerator.hpp:543
std::size_t GetNumberOfObservations() const
Definition: mvqn_convergence_accelerator.hpp:477
void FinalizeSolutionStep() override
Save the current step Jacobian This method saves the current step Jacobian as previous step Jacobian ...
Definition: mvqn_convergence_accelerator.hpp:187
virtual void UpdateInverseJacobianApproximation(const VectorType &rResidualVector, const VectorType &rIterationGuess)
Update the inverse Jacobian approximation This method first appends the current iteration values to t...
Definition: mvqn_convergence_accelerator.hpp:248
void StoreDataColumns()
Store the current iterations data columns This method initializes the observation matrices for the cu...
Definition: mvqn_convergence_accelerator.hpp:319
BaseType::Pointer BaseTypePointer
Definition: mvqn_convergence_accelerator.hpp:66
BaseType::DenseMatrixType MatrixType
Definition: mvqn_convergence_accelerator.hpp:71
bool IsFirstCorrectionPerformed() const
Definition: mvqn_convergence_accelerator.hpp:482
std::size_t GetProblemSize() const override
Get the Problem Size object This method returns the problem size, which equals the number of interfac...
Definition: mvqn_convergence_accelerator.hpp:467
void UpdateSolution(const VectorType &rResidualVector, VectorType &rIterationGuess) override
Performs the solution update This method computes the solution update using a Jacobian approximation....
Definition: mvqn_convergence_accelerator.hpp:150
virtual void UpdateCurrentJacobianMatrix()
Updates the inverse Jacobian approximation This method updates the inverse Jacobian approximation wit...
Definition: mvqn_convergence_accelerator.hpp:437
MVQNFullJacobianConvergenceAccelerator()=default
Construct a new MVQNFullJacobianConvergenceAccelerator object Default constructor of MVQNFullJacobian...
BaseType::DenseMatrixPointerType MatrixPointerType
Definition: mvqn_convergence_accelerator.hpp:72
void CheckCurrentIterationInformationSingularity()
Check the new data singularity This method checks that the new observation data is not linearly depen...
Definition: mvqn_convergence_accelerator.hpp:341
ConvergenceAccelerator< TSparseSpace, TDenseSpace > BaseType
Definition: mvqn_convergence_accelerator.hpp:65
virtual MatrixPointerType pGetJacobianDecompositionMatrixQU()
Definition: mvqn_convergence_accelerator.hpp:558
VectorPointerType pGetCurrentIterationResidualVector()
Get the residual vector This method returns a pointer to the current iteration residual vector.
Definition: mvqn_convergence_accelerator.hpp:503
MatrixPointerType pGetSolutionObservationMatrix()
Get the observation matrix W This method returns a pointer to the solution observation matrix.
Definition: mvqn_convergence_accelerator.hpp:533
void AppendCurrentIterationInformation(const VectorType &rResidualVector, const VectorType &rIterationGuess)
Append the current iteration information to the observation matrices This method appends the current ...
Definition: mvqn_convergence_accelerator.hpp:289
MVQNFullJacobianConvergenceAccelerator(Parameters rConvAcceleratorParameters)
Construct a new MVQNFullJacobianConvergenceAccelerator object MultiVector Quasi-Newton convergence ac...
Definition: mvqn_convergence_accelerator.hpp:90
std::size_t GetConvergenceAcceleratorIteration() const
Definition: mvqn_convergence_accelerator.hpp:472
MatrixPointerType pGetResidualObservationMatrix()
Get the observation matrix V This method returns a pointer to the residual observation matrix.
Definition: mvqn_convergence_accelerator.hpp:523
MatrixPointerType pGetInverseJacobianApproximation() override
Get the inverse Jacobian approximation This method returns a pointer to the current inverse Jacobian ...
Definition: mvqn_convergence_accelerator.hpp:513
bool IsUsedInBlockNewtonEquations() const
Returns the a bool indicating if IBQN are used This method returns a bool flag indicating if the curr...
Definition: mvqn_convergence_accelerator.hpp:493
void SetCutOffTolerance(const double CutOffTolerance)
Set the Cut Off Tolerance This method sets the cut off relative tolerance value to be used in the inf...
Definition: mvqn_convergence_accelerator.hpp:553
virtual void CalculateCorrectionWithJacobian(VectorType &rCorrection)
Calculates the current iteration correction with the Jacobian This method calculates the current iter...
Definition: mvqn_convergence_accelerator.hpp:428
BaseType::DenseVectorPointerType VectorPointerType
Definition: mvqn_convergence_accelerator.hpp:69
void FinalizeNonLinearIteration() override
Do the MVQN variables update Updates the MVQN iteration variables for the next non-linear iteration.
Definition: mvqn_convergence_accelerator.hpp:169
virtual Parameters GetDefaultParameters() const
Definition: mvqn_convergence_accelerator.hpp:206
virtual ~MVQNFullJacobianConvergenceAccelerator()
Definition: mvqn_convergence_accelerator.hpp:120
virtual MatrixPointerType pGetOldJacobianDecompositionMatrixSigmaV()
Definition: mvqn_convergence_accelerator.hpp:573
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
static std::size_t SingularValueDecomposition(const MatrixType &InputMatrix, MatrixType &UMatrix, MatrixType &SMatrix, MatrixType &VMatrix, Parameters ThisParameters)
This function gives the SVD of a given mxn matrix (m>=n), returns U,S; where A=U*S*V.
Definition: svd_utils.h:103
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
TDenseSpace::VectorType DenseVectorType
Definition: convergence_accelerator.h:56
TSparseSpace::VectorType VectorType
Definition: convergence_accelerator.h:50
#define KRATOS_ERROR
Definition: exception.h:161
TDenseSpace::MatrixPointerType DenseMatrixPointerType
Definition: convergence_accelerator.h:59
TDenseSpace::MatrixType DenseMatrixType
Definition: convergence_accelerator.h:57
TSparseSpace::VectorPointerType VectorPointerType
Definition: convergence_accelerator.h:53
TSparseSpace::MatrixPointerType MatrixPointerType
Definition: convergence_accelerator.h:54
TDenseSpace::VectorPointerType DenseVectorPointerType
Definition: convergence_accelerator.h:60
TSparseSpace::MatrixType MatrixType
Definition: convergence_accelerator.h:51
#define KRATOS_WARNING(label)
Definition: logger.h:265
static double max(double a, double b)
Definition: GeometryFunctions.h:79
TSpaceType::IndexType Size2(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:123
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
void UnaliasedAdd(TSpaceType &dummy, typename TSpaceType::VectorType &x, const double A, const typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:170
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
AMatrix::IdentityMatrix< double > IdentityMatrix
Definition: amatrix_interface.h:564
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
n_dofs
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:151
int max_iter
Definition: hinsberg_optimization.py:139
float aux2
Definition: isotropic_damage_automatic_differentiation.py:240
float aux1
Definition: isotropic_damage_automatic_differentiation.py:239
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17