13 #if !defined(KRATOS_DEFLATED_CG_SOLVER_H_INCLUDED )
14 #define KRATOS_DEFLATED_CG_SOLVER_H_INCLUDED
59 template<
class TSparseSpaceType,
class TDenseSpaceType,
60 class TPreconditionerType = Preconditioner<TSparseSpaceType, TDenseSpaceType>,
61 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
93 DeflatedCGSolver(
double NewMaxTolerance,
bool assume_constant_structure,
int max_reduced_size) :
95 , mmax_reduced_size(max_reduced_size)
96 , massume_constant_structure(assume_constant_structure)
100 DeflatedCGSolver(
double NewMaxTolerance,
unsigned int NewMaxIterationsNumber,
bool assume_constant_structure,
int max_reduced_size) :
101 BaseType(NewMaxTolerance, NewMaxIterationsNumber)
102 , mmax_reduced_size(max_reduced_size)
103 , massume_constant_structure(assume_constant_structure)
108 typename TPreconditionerType::Pointer pNewPreconditioner,
bool assume_constant_structure,
int max_reduced_size) :
109 BaseType(NewMaxTolerance, NewMaxIterationsNumber, pNewPreconditioner)
110 , mmax_reduced_size(max_reduced_size)
111 , massume_constant_structure(assume_constant_structure)
116 typename TPreconditionerType::Pointer pNewPreconditioner = Kratos::make_shared<TPreconditionerType>()
125 "solver_type": "DeflatedCGSolver",
126 "tolerance" : 1.0e-6,
127 "max_iteration" : 200,
128 "assume_constant_structure" : false,
129 "max_reduced_size" : 1024,
136 this->
SetTolerance( settings[
"tolerance"].GetDouble() );
138 massume_constant_structure = settings[
"assume_constant_structure"].
GetBool();
139 mmax_reduced_size = settings[
"max_reduced_size"].
GetInt();
191 bool is_solved = IterativeSolve(rA, rX, rB);
209 std::cout <<
"************ DeflatedCGSolver::Solve(SparseMatrixType&, DenseMatrixType&, DenseMatrixType&) not defined! ************" << std::endl;
230 std::string
Info()
const override
232 std::stringstream buffer;
304 int mmax_reduced_size;
305 bool massume_constant_structure;
326 if (massume_constant_structure ==
false || mw.size() == 0)
334 std::size_t reduced_size = mAdeflated.size1();
338 LUSkylineFactorization<TSparseSpaceType, TDenseSpaceType> Factorization;
341 Factorization.copyFromCSRMatrix(mAdeflated);
342 Factorization.factorize();
359 Factorization.backForwardSolve(reduced_size,
th, dh);
382 Factorization.backForwardSolve(reduced_size,
th, dh);
399 if (fabs(roh0) < 1.0e-30)
return false;
410 if (fabs(
pq) <= 1.0e-30)
420 beta = (roh1 / roh0);
431 Factorization.backForwardSolve(reduced_size,
th, dh);
490 template<
class TSparseSpaceType,
class TDenseSpaceType,
491 class TPreconditionerType,
492 class TReordererType>
495 TPreconditionerType, TReordererType>& rThis)
502 template<
class TSparseSpaceType,
class TDenseSpaceType,
503 class TPreconditionerType,
504 class TReordererType>
507 TPreconditionerType, TReordererType>& rThis)
509 rThis.PrintInfo(OStream);
510 OStream << std::endl;
511 rThis.PrintData(OStream);
Short class definition.
Definition: deflated_cg_solver.h:63
~DeflatedCGSolver() override
Destructor.
Definition: deflated_cg_solver.h:153
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: deflated_cg_solver.h:239
DeflatedCGSolver(const DeflatedCGSolver &Other)
Copy constructor.
Definition: deflated_cg_solver.h:146
TSparseSpaceType::VectorType SparseVectorType
Definition: deflated_cg_solver.h:77
DeflatedCGSolver(Parameters settings, typename TPreconditionerType::Pointer pNewPreconditioner=Kratos::make_shared< TPreconditionerType >())
Definition: deflated_cg_solver.h:115
DeflatedCGSolver & operator=(const DeflatedCGSolver &Other)
Assignment operator.
Definition: deflated_cg_solver.h:164
DeflatedCGSolver(double NewMaxTolerance, unsigned int NewMaxIterationsNumber, bool assume_constant_structure, int max_reduced_size)
Definition: deflated_cg_solver.h:100
TDenseSpaceType::MatrixType DenseMatrixType
Definition: deflated_cg_solver.h:79
std::string Info() const override
Turn back information as a string.
Definition: deflated_cg_solver.h:230
DeflatedCGSolver(double NewMaxTolerance, unsigned int NewMaxIterationsNumber, typename TPreconditionerType::Pointer pNewPreconditioner, bool assume_constant_structure, int max_reduced_size)
Definition: deflated_cg_solver.h:107
DeflatedCGSolver(double NewMaxTolerance, bool assume_constant_structure, int max_reduced_size)
Definition: deflated_cg_solver.h:93
IterativeSolver< TSparseSpaceType, TDenseSpaceType, TPreconditionerType, TReordererType > BaseType
Definition: deflated_cg_solver.h:71
KRATOS_CLASS_POINTER_DEFINITION(DeflatedCGSolver)
Pointer definition of DeflatedCGSolver.
TSparseSpaceType::MatrixType SparseMatrixType
Definition: deflated_cg_solver.h:75
DeflatedCGSolver()
Default constructor.
Definition: deflated_cg_solver.h:89
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: deflated_cg_solver.h:246
TDenseSpaceType::VectorType DenseVectorType
Definition: deflated_cg_solver.h:81
bool Solve(SparseMatrixType &rA, SparseVectorType &rX, SparseVectorType &rB) override
Definition: deflated_cg_solver.h:182
bool Solve(SparseMatrixType &rA, DenseMatrixType &rX, DenseMatrixType &rB) override
Definition: deflated_cg_solver.h:206
static void FillDeflatedMatrix(const SparseMatrixType &rA, std::vector< int > &w, SparseMatrixType &Ah)
Definition: deflation_utils.h:362
static void ApplyW(const std::vector< int > &w, const SparseVectorType &x, SparseVectorType &y)
Definition: deflation_utils.h:324
static void ApplyWtranspose(const std::vector< int > &w, const SparseVectorType &x, SparseVectorType &y)
Definition: deflation_utils.h:338
static void ConstructW(const std::size_t max_reduced_size, SparseMatrixType &rA, std::vector< int > &w, SparseMatrixType &deflatedA)
Definition: deflation_utils.h:181
Base class for all the iterative solvers in Kratos.
Definition: iterative_solver.h:68
void SetTolerance(double NewTolerance) override
Definition: iterative_solver.h:305
IndexType mIterationsNumber
Definition: iterative_solver.h:403
virtual bool IterationNeeded()
Definition: iterative_solver.h:331
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: iterative_solver.h:360
double mResidualNorm
Definition: iterative_solver.h:399
void PreconditionedMult(SparseMatrixType &rA, VectorType &rX, VectorType &rY)
Definition: iterative_solver.h:416
double mBNorm
Definition: iterative_solver.h:405
virtual void SetMaxIterationsNumber(unsigned int NewMaxIterationsNumber)
Definition: iterative_solver.h:285
IterativeSolver & operator=(const IterativeSolver &Other)
Assignment operator.
Definition: iterative_solver.h:176
virtual TPreconditionerType::Pointer GetPreconditioner(void)
Definition: iterative_solver.h:260
virtual bool IsConverged()
Definition: iterative_solver.h:336
virtual bool IsNotConsistent(SparseMatrixType &rA, VectorType &rX, VectorType &rB)
This method checks if the dimensions of the system of equations are not consistent.
Definition: linear_solver.h:346
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
void ScaleAndAdd(TSpaceType &dummy, const double A, const typename TSpaceType::VectorType &rX, const double B, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:91
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
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
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
alpha
Definition: generate_convection_diffusion_explicit_element.py:113
q
Definition: generate_convection_diffusion_explicit_element.py:109
th
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:32
int t
Definition: ode_solve.py:392
int d
Definition: ode_solve.py:397
p
Definition: sensitivityMatrix.py:52
subroutine pq(T, p, q)
Definition: TensorModule.f:339