71 template<
class TSparseSpace,
class TDenseSpace>
109 , mpDenseQR(pDenseQR)
110 , mpDenseSVD(pDenseSVD)
113 mUserNumberOfModes = ConvAcceleratorParameters[
"jacobian_modes"].
GetInt();
114 mAutomaticJacobianModes = ConvAcceleratorParameters[
"automatic_jacobian_modes"].
GetBool();
115 mLimitModesToIterations = ConvAcceleratorParameters[
"limit_modes_to_iterations"].
GetBool();
116 mMinRandSVDExtraModes = ConvAcceleratorParameters[
"min_rand_svd_extra_modes"].
GetInt();
120 KRATOS_WARNING_IF(
"MVQNRandomizedSVDConvergenceAccelerator", mAutomaticJacobianModes && mUserNumberOfModes != 0)
121 <<
"Custom and automatic number of modes have been selected. Automatic will be used." << std::endl;
158 if (mpJacQU !=
nullptr && mpJacSigmaV !=
nullptr) {
159 mpOldJacQU = mpJacQU;
160 mpOldJacSigmaV = mpJacSigmaV;
162 if (n_obs > mOldMaxRank) {
173 mpJacSigmaV =
nullptr;
183 Parameters mvqn_randomized_svd_default_parameters(R
"({
184 "solver_type" : "MVQN_randomized_SVD",
185 "automatic_jacobian_modes" : true,
186 "jacobian_modes" : 0,
188 "cut_off_tol" : 1e-8,
189 "interface_block_newton" : false,
190 "limit_modes_to_iterations" : true,
191 "min_rand_svd_extra_modes" : 1
194 return mvqn_randomized_svd_default_parameters;
237 const bool AutomaticJacobianModes,
238 const unsigned int JacobianModes,
239 const double CutOffTolerance,
240 const bool LimitModesToIterations,
241 const unsigned int MinRandSVDExtraModes)
243 , mUserNumberOfModes(JacobianModes)
244 , mMinRandSVDExtraModes(MinRandSVDExtraModes)
245 , mAutomaticJacobianModes(AutomaticJacobianModes)
246 , mLimitModesToIterations(LimitModesToIterations)
247 , mpDenseQR(pDenseQR)
248 , mpDenseSVD(pDenseSVD)
250 KRATOS_WARNING_IF(
"MVQNRandomizedSVDConvergenceAccelerator", mAutomaticJacobianModes && mUserNumberOfModes != 0)
251 <<
"Custom and automatic number of modes have been selected. Automatic will be used." << std::endl;
280 if (p_V !=
nullptr && p_W !=
nullptr) {
282 const auto& r_V = *p_V;
283 const auto& r_W = *p_W;
287 CalculateAuxiliaryMatrixM(aux_M);
297 if (mpOldJacQU !=
nullptr && mpOldJacSigmaV !=
nullptr) {
298 const auto& r_A = *mpOldJacQU;
299 const auto& r_B = *mpOldJacSigmaV;
308 if (mpOldJacQU !=
nullptr && mpOldJacSigmaV !=
nullptr) {
309 const auto& r_A = *mpOldJacQU;
310 const auto& r_B = *mpOldJacSigmaV;
317 KRATOS_ERROR <<
"There is neither observation nor old Jacobian decomposition. Correction cannot be computed." << std::endl;
329 if (p_V !=
nullptr && p_W !=
nullptr) {
332 CalculateAuxiliaryMatrixM(aux_M);
335 if (!mRandomValuesAreInitialized || mpOmega ==
nullptr) {
336 InitializeRandomValuesMatrix();
342 MultiplyRight(aux_M, *mpOmega,
y);
344 mpDenseQR->Compute(
y);
348 mpDenseQR->MatrixQ(
Q);
351 MultiplyTransposeLeft(aux_M,
Q,
phi);
357 "compute_thin_u" : true,
358 "compute_thin_v" : true
360 mpDenseSVD->Compute(phi, s_svd, u_svd, v_svd, svd_settings);
364 SizeType n_modes_final = n_modes - mNumberOfExtraModes;
365 auto p_aux_Q_U = Kratos::make_shared<MatrixType>(
ZeroMatrix(
n_dofs, n_modes_final));
366 auto p_aux_sigma_V = Kratos::make_shared<MatrixType>(n_modes_final,
n_dofs);
367 auto& r_aux_Q_U = *p_aux_Q_U;
368 auto& r_aux_sigma_V = *p_aux_sigma_V;
372 r_aux_Q_U(I,
j) +=
Q(I,
k) * u_svd(
k,
j);
374 r_aux_sigma_V(
j,I) = s_svd(
j) * v_svd(I,
j);
378 std::swap(mpJacQU, p_aux_Q_U);
379 std::swap(mpJacSigmaV, p_aux_sigma_V);
382 if (mLimitModesToIterations) {
388 mpJacSigmaV =
nullptr;
413 return mpOldJacSigmaV;
431 bool mAutomaticJacobianModes =
true;
432 bool mLimitModesToIterations =
true;
433 bool mRandomValuesAreInitialized =
false;
455 void InitializeRandomValuesMatrix()
463 const SizeType full_rank_modes = mOldMaxRank + n_obs;
465 if (mAutomaticJacobianModes) {
470 n_modes = full_rank_modes;
476 n_modes = mLimitModesToIterations ?
std::min(full_rank_modes, mUserNumberOfModes) : mUserNumberOfModes;
480 const SizeType aux_extra_modes = std::ceil(0.1 * n_modes);
481 mNumberOfExtraModes = mMinRandSVDExtraModes > aux_extra_modes ? mMinRandSVDExtraModes : aux_extra_modes;
482 mCurrentNumberOfModes = n_modes + mNumberOfExtraModes;
486 auto p_aux_omega = Kratos::make_shared<MatrixType>(
n_dofs, mCurrentNumberOfModes);
487 std::swap(p_aux_omega, mpOmega);
491 std::uniform_real_distribution<> distribution(0.0, 1.0);
494 auto& r_omega_matrix = *mpOmega;
496 for (
SizeType j = 0;
j < mCurrentNumberOfModes; ++
j) {
504 mRandomValuesAreInitialized = !mLimitModesToIterations;
509 const Matrix& rRightMatrix,
515 rSolution.resize(
n_dofs, mCurrentNumberOfModes);
526 if (mpOldJacQU ==
nullptr && mpOldJacSigmaV ==
nullptr) {
530 IndexPartition<SizeType>(
n_dofs).for_each([&rSolution,&V_M_omega,
this](
SizeType I){
531 for (
SizeType j = 0;
j < mCurrentNumberOfModes; ++
j) {
532 rSolution(I,
j) += V_M_omega(I,
j);
543 IndexPartition<SizeType>(
n_dofs).for_each([&rSolution,&A_B_omega,&V_M_omega,&A_B_V_M_omega,
this](
SizeType I){
544 for (
SizeType j = 0;
j < mCurrentNumberOfModes; ++
j) {
545 rSolution(I,
j) += A_B_omega(I,
j) + V_M_omega(I,
j) - A_B_V_M_omega(I,
j);
549 IndexPartition<SizeType>(
n_dofs).for_each([&rSolution,&A_B_omega,&A_B_V_M_omega,
this](
SizeType I){
550 for (
SizeType j = 0;
j < mCurrentNumberOfModes; ++
j) {
551 rSolution(I,
j) += A_B_omega(I,
j) - A_B_V_M_omega(I,
j);
558 void MultiplyTransposeLeft(
560 const Matrix& rLeftMatrix,
566 rSolution.resize(mCurrentNumberOfModes,
n_dofs);
574 const auto Qtrans =
trans(rLeftMatrix);
578 if (mpOldJacQU ==
nullptr && mpOldJacSigmaV ==
nullptr) {
583 IndexPartition<SizeType>(
n_dofs).for_each([&rSolution,&Qtrans_V_M,
this](
SizeType J){
584 for (
SizeType i = 0;
i < mCurrentNumberOfModes; ++
i) {
585 rSolution(
i,
J) += Qtrans_V_M(
i,
J);
597 IndexPartition<SizeType>(
n_dofs).for_each([&rSolution,&Qtrans_A_B,&Qtrans_V_M,&Qtrans_A_B_V_M,
this](
SizeType J){
598 for (
SizeType i = 0;
i < mCurrentNumberOfModes; ++
i) {
599 rSolution(
i,
J) += Qtrans_A_B(
i,
J) + Qtrans_V_M(
i,
J) - Qtrans_A_B_V_M(
i,
J);
603 IndexPartition<SizeType>(
n_dofs).for_each([&rSolution,&Qtrans_A_B,&Qtrans_A_B_V_M,
this](
SizeType J){
604 for (
SizeType i = 0;
i < mCurrentNumberOfModes; ++
i) {
605 rSolution(
i,
J) += Qtrans_A_B(
i,
J) - Qtrans_A_B_V_M(
i,
J);
612 void CalculateAuxiliaryMatrixM(
MatrixType& rAuxM)
618 mpDenseQR->Compute(aux_V);
627 mpDenseQR->MatrixQ(
Q);
628 mpDenseQR->MatrixR(
R);
629 mpDenseQR->MatrixP(P);
634 MatrixType R_transP(n_data_cols, n_data_cols);
639 CalculateMoorePenroseInverse(R_transP, R_transP_inv);
646 if (
m != n_data_cols ||
n !=
n_dofs) {
647 TDenseSpace::Resize(rAuxM, n_data_cols,
n_dofs);
654 void CalculateMoorePenroseInverse(
660 KRATOS_ERROR_IF_NOT(aux_size_1 == aux_size_2) <<
"Input matrix is not squared." << std::endl;
665 Parameters svd_settings(R
"({
666 "compute_thin_u" : true,
667 "compute_thin_v" : true
669 mpDenseSVD->Compute(const_cast<MatrixType&
>(rInputMatrix), s_svd, u_svd, v_svd, svd_settings);
670 const std::size_t n_sing_val = s_svd.size();
673 for (std::size_t
i = 0;
i < n_sing_val; ++
i) {
674 s_inv(
i,
i) = 1.0 / s_svd(
i);
678 rMoorePenroseInverse =
ZeroMatrix(aux_size_2, aux_size_1);
681 for (std::size_t
i = 0;
i < aux_size_2; ++
i) {
682 for (std::size_t
j = 0;
j < aux_size_1; ++
j) {
683 double& r_value = rMoorePenroseInverse(
i,
j);
684 for (std::size_t
k = 0;
k < n_sing_val; ++
k) {
685 const double v_ik = v_svd(
i,
k);
686 for (std::size_t
m = 0;
m < n_sing_val; ++
m) {
687 const double ut_mj = u_svd(
j,
m);
688 const double s_inv_km = s_inv(
k,
m);
689 r_value += v_ik * s_inv_km * ut_mj;
Base class for convergence accelerators This class is intended to be the base of any convergence acce...
Definition: convergence_accelerator.h:43
Definition: dense_qr_decomposition.h:44
Definition: dense_svd_decomposition.h:45
Interface Block Newton MVQN with randomized Jacobian convergence accelerator Interface Block Newton e...
Definition: ibqn_mvqn_randomized_svd_convergence_accelerator.h:60
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
MVQN acceleration scheme MultiVectorQuasiNewton convergence accelerator from Bogaers et al....
Definition: mvqn_convergence_accelerator.hpp:58
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
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
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
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
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
MVQN-RZ acceleration scheme RandomiZed Multi-Vector Quasi-Newton (MVQN-RZ) method convergence acceler...
Definition: mvqn_randomized_svd_convergence_accelerator.h:73
BaseType::DenseMatrixPointerType MatrixPointerType
Definition: mvqn_randomized_svd_convergence_accelerator.h:89
std::size_t SizeType
Definition: mvqn_randomized_svd_convergence_accelerator.h:80
BaseType::DenseVectorPointerType VectorPointerType
Definition: mvqn_randomized_svd_convergence_accelerator.h:86
BaseType::DenseMatrixType MatrixType
Definition: mvqn_randomized_svd_convergence_accelerator.h:88
void FinalizeSolutionStep() override
Save the current step Jacobian This method saves the current step Jacobian as previous step Jacobian ...
Definition: mvqn_randomized_svd_convergence_accelerator.h:145
void CalculateCorrectionWithJacobian(VectorType &rCorrection) override
Calculates the current iteration correction with the Jacobian This method calculates the current iter...
Definition: mvqn_randomized_svd_convergence_accelerator.h:273
MatrixPointerType pGetJacobianDecompositionMatrixQU() override
Definition: mvqn_randomized_svd_convergence_accelerator.h:396
KRATOS_CLASS_POINTER_DEFINITION(MVQNRandomizedSVDConvergenceAccelerator)
BaseType::DenseVectorType VectorType
Definition: mvqn_randomized_svd_convergence_accelerator.h:85
DenseQRDecomposition< TDenseSpace >::Pointer DenseQRPointerType
Definition: mvqn_randomized_svd_convergence_accelerator.h:91
void CalculateInverseJacobianRandomizedSVD()
Definition: mvqn_randomized_svd_convergence_accelerator.h:322
void UpdateInverseJacobianApproximation(const VectorType &rResidualVector, const VectorType &rIterationGuess) override
Update the inverse Jacobian approximation This method first appends the current iteration values to t...
Definition: mvqn_randomized_svd_convergence_accelerator.h:258
BaseType::Pointer BaseTypePointer
Definition: mvqn_randomized_svd_convergence_accelerator.h:83
Parameters GetDefaultParameters() const override
Definition: mvqn_randomized_svd_convergence_accelerator.h:181
MatrixPointerType pGetOldJacobianDecompositionMatrixQU() override
Definition: mvqn_randomized_svd_convergence_accelerator.h:406
MVQNRandomizedSVDConvergenceAccelerator(const MVQNRandomizedSVDConvergenceAccelerator &rOther)=default
MVQNRandomizedSVDConvergenceAccelerator(DenseQRPointerType pDenseQR, DenseSVDPointerType pDenseSVD, Parameters ConvAcceleratorParameters)
Construct a new MVQNRandomizedSVDConvergenceAccelerator object MultiVector Quasi-Newton convergence a...
Definition: mvqn_randomized_svd_convergence_accelerator.h:104
MVQNFullJacobianConvergenceAccelerator< TSparseSpace, TDenseSpace > BaseType
Definition: mvqn_randomized_svd_convergence_accelerator.h:82
MatrixPointerType pGetOldJacobianDecompositionMatrixSigmaV() override
Definition: mvqn_randomized_svd_convergence_accelerator.h:411
MVQNRandomizedSVDConvergenceAccelerator(DenseQRPointerType pDenseQR, DenseSVDPointerType pDenseSVD, const bool AutomaticJacobianModes, const unsigned int JacobianModes, const double CutOffTolerance, const bool LimitModesToIterations, const unsigned int MinRandSVDExtraModes)
Construct a new MVQNRandomizedSVDConvergenceAccelerator object Multivector Quasi-Newton convergence a...
Definition: mvqn_randomized_svd_convergence_accelerator.h:234
MatrixPointerType pGetJacobianDecompositionMatrixSigmaV() override
Definition: mvqn_randomized_svd_convergence_accelerator.h:401
virtual ~MVQNRandomizedSVDConvergenceAccelerator()
Definition: mvqn_randomized_svd_convergence_accelerator.h:134
DenseSingularValueDecomposition< TDenseSpace >::Pointer DenseSVDPointerType
Definition: mvqn_randomized_svd_convergence_accelerator.h:92
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
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
#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
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
TDenseSpace::MatrixPointerType DenseMatrixPointerType
Definition: convergence_accelerator.h:59
TDenseSpace::MatrixType DenseMatrixType
Definition: convergence_accelerator.h:57
TSparseSpace::MatrixPointerType MatrixPointerType
Definition: convergence_accelerator.h:54
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
TDenseSpace::VectorPointerType DenseVectorPointerType
Definition: convergence_accelerator.h:60
TSparseSpace::MatrixType MatrixType
Definition: convergence_accelerator.h:51
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
static double min(double a, double b)
Definition: GeometryFunctions.h:71
TSpaceType::IndexType Size1(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:117
TSpaceType::IndexType Size2(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:123
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
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
n_dofs
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:151
phi
Definition: isotropic_damage_automatic_differentiation.py:168
R
Definition: isotropic_damage_automatic_differentiation.py:172
tuple Q
Definition: isotropic_damage_automatic_differentiation.py:235
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
J
Definition: sensitivityMatrix.py:58
generator
Definition: generate_quadrilateral.py:19
integer i
Definition: TensorModule.f:17