11 #if !defined(KRATOS_MVQN_RECURSIVE_CONVERGENCE_ACCELERATOR)
12 #define KRATOS_MVQN_RECURSIVE_CONVERGENCE_ACCELERATOR
48 template<
class TSpace>
55 typedef typename std::unique_ptr< JacobianEmulator<TSpace> >
Pointer;
77 mpOldJacobianEmulator = std::unique_ptr<JacobianEmulator<TSpace>>(std::move(OldJacobianEmulatorPointer));
86 mpOldJacobianEmulator = std::unique_ptr<JacobianEmulator<TSpace> >(std::move(OldJacobianEmulatorPointer));
89 if(EmulatorBufferSize > 1) {
92 for(
unsigned int i = 1;
i < (EmulatorBufferSize);
i++) {
93 if(
i == EmulatorBufferSize-1) {
94 (
p->mpOldJacobianEmulator).reset();
96 p = (
p->mpOldJacobianEmulator).get();
100 (mpOldJacobianEmulator->mpOldJacobianEmulator).reset();
115 mpOldJacobianEmulator = rOther.mpOldJacobianEmulator;
143 if (data_cols == 0) {
144 if (mpOldJacobianEmulator !=
nullptr) {
145 mpOldJacobianEmulator->ApplyJacobian(pWorkVector, pProjectedVector);
153 MatrixPointerType pV = Kratos::make_shared<MatrixType>(residual_size, data_cols);
154 MatrixPointerType pVtrans = Kratos::make_shared<MatrixType>(data_cols,residual_size);
155 for (std::size_t
i = 0;
i < data_cols; ++
i){
156 const auto i_row = mJacobianObsMatrixV[
i];
157 for (std::size_t
j = 0;
j < residual_size; ++
j){
158 (*pV)(
j,
i) = i_row(
j);
159 (*pVtrans)(
i,
j) = i_row(
j);
164 MatrixPointerType pVtransV = Kratos::make_shared<MatrixType>(data_cols, data_cols);
165 for (std::size_t i_row = 0; i_row < data_cols; ++i_row){
166 for (std::size_t i_col = 0; i_col < data_cols; ++i_col){
167 (*pVtransV)(i_row, i_col) =
TSpace::Dot(mJacobianObsMatrixV[i_row],mJacobianObsMatrixV[i_col]);
177 qr_decomposition.
Compute(*pVtransV);
179 qr_decomposition.
Solve(*pVtransWorkVect, *pLambda);
187 if (mpOldJacobianEmulator ==
nullptr) {
188 TSpace::Copy(*pY, *pProjectedVector);
192 mpOldJacobianEmulator->ApplyJacobian(pYminus, pProjectedVector);
197 TSpace::SetToZero(*pW);
198 for (
unsigned int j = 0;
j < data_cols; ++
j) {
222 const double AbsCutOff = 1
e-8)
225 mJacobianObsMatrixV.push_back(rNewColV);
226 mJacobianObsMatrixW.push_back(rNewColW);
232 MatrixPointerType ptransV_V = Kratos::make_shared<MatrixType>(data_cols, data_cols);
233 for (std::size_t i_row = 0; i_row < data_cols; ++i_row){
234 for (std::size_t i_col = 0; i_col < data_cols; ++i_col){
235 (*ptransV_V)(i_row, i_col) =
TSpace::Dot(mJacobianObsMatrixV[i_row],mJacobianObsMatrixV[i_col]);
246 const std::string svd_type =
"Jacobi";
247 const double svd_rel_tol = 1.0e-6;
252 std::vector<double> eig_vector(data_cols);
253 for (std::size_t i_col = 0; i_col < data_cols; ++i_col){
254 const double i_col_eig = std::sqrt(w_svd(i_col,i_col));
255 eig_vector[i_col] = i_col_eig;
259 double max_eig_V = 0.0;
261 for (std::size_t i_col = 0; i_col < data_cols; ++i_col){
262 if (max_eig_V < eig_vector[i_col]) {
263 max_eig_V = eig_vector[i_col];
264 }
else if (min_eig_V > eig_vector[i_col]) {
265 min_eig_V = eig_vector[i_col];
272 if (min_eig_V < AbsCutOff * max_eig_V){
274 <<
"Dropping info for eigenvalue " << min_eig_V <<
" (tolerance " << AbsCutOff * max_eig_V <<
" )" << std::endl;
275 mJacobianObsMatrixV.pop_back();
276 mJacobianObsMatrixW.pop_back();
297 const double AbsCutOffEps = 1
e-8)
300 const bool info_added = this->
AppendDataColumns(rNewColV, rNewColW, AbsCutOffEps);
306 mJacobianObsMatrixV[
i] = mJacobianObsMatrixV[
i+1];
307 mJacobianObsMatrixW[
i] = mJacobianObsMatrixW[
i+1];
310 mJacobianObsMatrixV.pop_back();
311 mJacobianObsMatrixW.pop_back();
326 return mJacobianObsMatrixV.size();
369 std::vector<VectorType> mJacobianObsMatrixV;
370 std::vector<VectorType> mJacobianObsMatrixW;
407 template<
class TSparseSpace,
class TDenseSpace>
435 Parameters mvqn_recursive_default_parameters(R
"(
437 "solver_type" : "MVQN_recursive",
440 "abs_cut_off_tol" : 1e-8,
441 "interface_block_newton" : false
447 mOmega_0 = rConvAcceleratorParameters["w_0"].
GetDouble();
448 mAbsCutOff = rConvAcceleratorParameters[
"abs_cut_off_tol"].
GetDouble();
449 mJacobianBufferSize = rConvAcceleratorParameters[
"buffer_size"].
GetInt();
450 mConvergenceAcceleratorStep = 0;
451 mConvergenceAcceleratorIteration = 0;
452 mConvergenceAcceleratorFirstCorrectionPerformed =
false;
456 double OmegaInitial = 0.825,
457 unsigned int JacobianBufferSize = 10,
458 double AbsCutOff = 1
e-8)
460 mOmega_0 = OmegaInitial;
461 mAbsCutOff = AbsCutOff;
462 mJacobianBufferSize = JacobianBufferSize;
463 mConvergenceAcceleratorStep = 0;
464 mConvergenceAcceleratorIteration = 0;
465 mConvergenceAcceleratorFirstCorrectionPerformed =
false;
494 mpCurrentJacobianEmulatorPointer = Kratos::make_unique<JacobianEmulator<TDenseSpace>>();
508 mConvergenceAcceleratorStep += 1;
509 mConvergenceAcceleratorIteration = 0;
511 if (mConvergenceAcceleratorStep <= mJacobianBufferSize) {
513 mpCurrentJacobianEmulatorPointer = Kratos::make_unique<JacobianEmulator<TDenseSpace>>(std::move(mpCurrentJacobianEmulatorPointer));
516 mpCurrentJacobianEmulatorPointer = Kratos::make_unique<JacobianEmulator<TDenseSpace>>(std::move(mpCurrentJacobianEmulatorPointer), mJacobianBufferSize);
538 std::swap(mpResidualVector_1, pAuxResidualVector);
539 std::swap(mpIterationValue_1, pAuxIterationGuess);
541 if (mConvergenceAcceleratorIteration == 0) {
542 if (mConvergenceAcceleratorFirstCorrectionPerformed ==
false) {
546 mConvergenceAcceleratorFirstCorrectionPerformed =
true;
551 mpCurrentJacobianEmulatorPointer->ApplyJacobian(mpResidualVector_1, pInitialCorrection);
564 bool info_added =
false;
565 const std::size_t n_data_cols = mpCurrentJacobianEmulatorPointer->GetNumberOfDataCols();
566 if (n_data_cols < problem_size) {
567 info_added = (mpCurrentJacobianEmulatorPointer)->AppendDataColumns(*pNewColV, *pNewColW, mAbsCutOff);
569 info_added = (mpCurrentJacobianEmulatorPointer)->DropAndAppendDataColumns(*pNewColV, *pNewColW, mAbsCutOff);
571 KRATOS_WARNING_IF(
"MVQNRecursiveJacobianConvergenceAccelerator", !info_added) <<
"Information not added to the observation matrices." << std::endl;
575 mpCurrentJacobianEmulatorPointer->ApplyJacobian(mpResidualVector_1, pIterationCorrection);
592 mpIterationValue_0 = mpIterationValue_1;
593 mpResidualVector_0 = mpResidualVector_1;
595 mConvergenceAcceleratorIteration += 1;
628 unsigned int mJacobianBufferSize;
629 unsigned int mConvergenceAcceleratorStep;
630 unsigned int mConvergenceAcceleratorIteration;
631 bool mConvergenceAcceleratorFirstCorrectionPerformed;
Base class for convergence accelerators This class is intended to be the base of any convergence acce...
Definition: convergence_accelerator.h:43
Definition: dense_householder_qr_decomposition.h:45
void Compute(MatrixType &rInputMatrix) override
Compute the QR Computes the QR Decomposition (QR) of the given imput matrix Note that the input matri...
Definition: dense_householder_qr_decomposition.h:92
void Solve(MatrixType &rB, MatrixType &rX) const override
Solves the problem Ax=b Being A the input matrix, this method solves the problem Ax = b.
Definition: dense_householder_qr_decomposition.h:148
Jacobian emulator.
Definition: mvqn_recursive_convergence_accelerator.hpp:50
JacobianEmulator(const JacobianEmulator &rOther)
Definition: mvqn_recursive_convergence_accelerator.hpp:113
bool AppendDataColumns(const VectorType &rNewColV, const VectorType &rNewColW, const double AbsCutOff=1e-8)
Definition: mvqn_recursive_convergence_accelerator.hpp:219
TSpace::VectorType VectorType
Definition: mvqn_recursive_convergence_accelerator.hpp:57
JacobianEmulator()
Definition: mvqn_recursive_convergence_accelerator.hpp:108
void ApplyJacobian(const VectorPointerType pWorkVector, VectorPointerType pProjectedVector)
Definition: mvqn_recursive_convergence_accelerator.hpp:136
std::unique_ptr< JacobianEmulator< TSpace > > Pointer
Definition: mvqn_recursive_convergence_accelerator.hpp:55
TSpace::VectorPointerType VectorPointerType
Definition: mvqn_recursive_convergence_accelerator.hpp:58
TSpace::MatrixType MatrixType
Definition: mvqn_recursive_convergence_accelerator.hpp:60
std::size_t GetNumberOfDataCols() const
Get the Number Of Data Cols object This function returns the number of data columns stored....
Definition: mvqn_recursive_convergence_accelerator.hpp:324
virtual ~JacobianEmulator()
Definition: mvqn_recursive_convergence_accelerator.hpp:121
JacobianEmulator(Pointer &&OldJacobianEmulatorPointer)
Definition: mvqn_recursive_convergence_accelerator.hpp:75
TSpace::MatrixPointerType MatrixPointerType
Definition: mvqn_recursive_convergence_accelerator.hpp:61
JacobianEmulator(Pointer &&OldJacobianEmulatorPointer, const unsigned int EmulatorBufferSize)
Definition: mvqn_recursive_convergence_accelerator.hpp:84
std::size_t GetResidualSize() const
Get the Residual Size object This function returns the interface residual size. Since the residual si...
Definition: mvqn_recursive_convergence_accelerator.hpp:337
bool DropAndAppendDataColumns(const VectorType &rNewColV, const VectorType &rNewColW, const double AbsCutOffEps=1e-8)
Definition: mvqn_recursive_convergence_accelerator.hpp:294
Recursive MVQN acceleration scheme Recursive MultiVectorQuasiNewton convergence accelerator....
Definition: mvqn_recursive_convergence_accelerator.hpp:408
MVQNRecursiveJacobianConvergenceAccelerator(const MVQNRecursiveJacobianConvergenceAccelerator &rOther)=delete
MVQNRecursiveJacobianConvergenceAccelerator(Parameters rConvAcceleratorParameters)
Definition: mvqn_recursive_convergence_accelerator.hpp:433
BaseType::MatrixPointerType MatrixPointerType
Definition: mvqn_recursive_convergence_accelerator.hpp:423
void FinalizeNonLinearIteration() override
Do the MVQN variables update Updates the MVQN iteration variables for the next non-linear iteration.
Definition: mvqn_recursive_convergence_accelerator.hpp:587
virtual ~MVQNRecursiveJacobianConvergenceAccelerator()
Definition: mvqn_recursive_convergence_accelerator.hpp:476
JacobianEmulator< TDenseSpace >::Pointer JacobianEmulatorPointerType
Definition: mvqn_recursive_convergence_accelerator.hpp:417
MVQNRecursiveJacobianConvergenceAccelerator(double OmegaInitial=0.825, unsigned int JacobianBufferSize=10, double AbsCutOff=1e-8)
Definition: mvqn_recursive_convergence_accelerator.hpp:455
void InitializeSolutionStep() override
This method initializes the internal counters and constructs the previous step Jacobian emulator....
Definition: mvqn_recursive_convergence_accelerator.hpp:504
KRATOS_CLASS_POINTER_DEFINITION(MVQNRecursiveJacobianConvergenceAccelerator)
BaseType::MatrixType MatrixType
Definition: mvqn_recursive_convergence_accelerator.hpp:422
BaseType::VectorType VectorType
Definition: mvqn_recursive_convergence_accelerator.hpp:419
void UpdateSolution(const VectorType &rResidualVector, VectorType &rIterationGuess) override
Performs the solution update The correction is computed using an inverse Jacobian approximation obtai...
Definition: mvqn_recursive_convergence_accelerator.hpp:528
ConvergenceAccelerator< TSparseSpace, TDenseSpace > BaseType
Definition: mvqn_recursive_convergence_accelerator.hpp:414
BaseType::Pointer BaseTypePointer
Definition: mvqn_recursive_convergence_accelerator.hpp:415
BaseType::VectorPointerType VectorPointerType
Definition: mvqn_recursive_convergence_accelerator.hpp:420
void Initialize() override
Initialize the Jacobian emulator This method constructs the very first Jacobian emulator of the simul...
Definition: mvqn_recursive_convergence_accelerator.hpp:490
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
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
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
TSparseSpace::VectorType VectorType
Definition: convergence_accelerator.h:50
TSparseSpace::VectorPointerType VectorPointerType
Definition: convergence_accelerator.h:53
TSparseSpace::MatrixPointerType MatrixPointerType
Definition: convergence_accelerator.h:54
TSparseSpace::MatrixType MatrixType
Definition: convergence_accelerator.h:51
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
#define KRATOS_WARNING(label)
Definition: logger.h:265
static double max(double a, double b)
Definition: GeometryFunctions.h:79
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
double Dot(SparseSpaceType &dummy, SparseSpaceType::VectorType &rX, SparseSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:85
void UnaliasedAdd(TSpaceType &dummy, typename TSpaceType::VectorType &x, const double A, const typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:170
void Assign(const Expression &rExpression, const IndexType EntityIndex, const IndexType EntityDataBeginIndex, TDataType &rValue, std::index_sequence< TIndex... >)
Definition: variable_expression_data_io.cpp:41
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
int j
Definition: quadrature.py:648
p
Definition: sensitivityMatrix.py:52
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31