15 #if !defined(KRATOS_RAYLEIGH_QUOTIENT_ITERATION_EIGENVALUE_SOLVER_H_INCLUDED )
16 #define KRATOS_RAYLEIGH_QUOTIENT_ITERATION_EIGENVALUE_SOLVER_H_INCLUDED
62 class TPreconditionerType = Preconditioner<TSparseSpaceType, TDenseSpaceType>,
63 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
112 double NewMaxTolerance,
113 unsigned int NewMaxIterationsNumber,
114 unsigned int NewRequiredEigenvalueNumber,
115 typename TLinearSolverType::Pointer pLinearSolver,
116 double ShiftingConvergence = 0.25
117 ):
BaseType(NewMaxTolerance, NewMaxIterationsNumber),
118 mRequiredEigenvalueNumber(NewRequiredEigenvalueNumber),
119 mpLinearSolver(pLinearSolver),
120 mShiftingConvergence(ShiftingConvergence)
132 typename TLinearSolverType::Pointer pLinearSolver
133 ): mpLinearSolver(pLinearSolver)
137 "solver_type" : "rayleigh_quotient_iteration_eigenvalue_solver",
138 "max_iteration" : 500,
140 "required_eigen_number" : 1,
141 "shifting_convergence" : 0.25,
143 "linear_solver_settings" : {}
148 mRequiredEigenvalueNumber = ThisParameters["required_eigen_number"].
GetInt();
149 mShiftingConvergence = ThisParameters[
"shifting_convergence"].
GetDouble();
150 mEchoLevel = ThisParameters[
"verbosity"].
GetInt();
159 mRequiredEigenvalueNumber(Other.mRequiredEigenvalueNumber), mpLinearSolver(Other.mpLinearSolver),
160 mShiftingConvergence(Other.mShiftingConvergence)
197 if (rR.size() != size_m)
204 KRATOS_ERROR_IF(
norm_2(rR) == 0.0) <<
"Invalid M matrix. The norm2 of its diagonal is Zero" << std::endl;
251 VectorType x = boost::numeric::ublas::zero_vector<double>(size);
252 VectorType y = boost::numeric::ublas::zero_vector<double>(size);
256 if(Eigenvalues.size() < 1) {
257 Eigenvalues.resize(1,0.0);
260 const double epsilon = 1.0e-9;
264 double shift_value = 0.0;
267 KRATOS_INFO_IF(
"RayleighQuotientIterationEigenvalueSolver", mEchoLevel > 1) <<
"Iteration beta \t ro \t\t convergence norm \t min \t\t max" << std::endl;
279 double min_shift_value = 0.0;
280 double max_shift_value = 0.0;
282 SizeType smaller_eigenvalue_numbers = 0;
297 const double delta_ro = (ro / beta);
299 ro = delta_ro + shift_value;
301 KRATOS_ERROR_IF(ro == 0.0) <<
"Perpendicular eigenvector to M" << std::endl;
303 double convergence_norm = std::abs((ro - old_ro) / ro);
305 if(convergence_norm < mShiftingConvergence) {
307 if(smaller_eigenvalue_numbers == 0) {
308 max_shift_value = ro;
311 if((ro > max_shift_value)||(ro < min_shift_value)) {
312 shift_value = (max_shift_value + min_shift_value) / 2.0;
317 SparseMatrixMultiplicationUtility::MatrixAdd<SparseMatrixType, SparseMatrixType>(shifted_k, M, - shift_value);
327 if(new_smaller_eigenvalue_numbers == 0) {
328 min_shift_value = shift_value;
330 max_shift_value = shift_value;
331 smaller_eigenvalue_numbers = new_smaller_eigenvalue_numbers;
334 unsigned int iteration_number = 0;
335 unsigned int max_shift_number = 4;
337 while((smaller_eigenvalue_numbers > 1) && (max_shift_value-min_shift_value > epsilon) && (iteration_number++ < max_shift_number)) {
338 shift_value = (max_shift_value + min_shift_value) / 2.0;
340 SparseMatrixMultiplicationUtility::MatrixAdd<SparseMatrixType, SparseMatrixType>(shifted_k, M, - shift_value);
350 if(new_smaller_eigenvalue_numbers == 0) {
351 min_shift_value = shift_value;
352 KRATOS_INFO_IF(
"RayleighQuotientIterationEigenvalueSolver", mEchoLevel > 1) <<
" Finding " << smaller_eigenvalue_numbers <<
" eigenvalues in [" << min_shift_value <<
"," << max_shift_value <<
"]" << std::endl;
354 max_shift_value = shift_value;
355 smaller_eigenvalue_numbers = new_smaller_eigenvalue_numbers;
356 KRATOS_INFO_IF(
"RayleighQuotientIterationEigenvalueSolver", mEchoLevel > 1) <<
" Finding " << smaller_eigenvalue_numbers <<
" eigenvalues in [" << min_shift_value <<
"," << max_shift_value <<
"]" << std::endl;
363 beta = -std::sqrt(-beta);
365 beta = std::sqrt(beta);
368 TSparseSpaceType::InplaceMult(
y, 1.0/beta);
370 KRATOS_INFO_IF(
"RayleighQuotientIterationEigenvalueSolver", mEchoLevel > 1) <<
i <<
" \t " << beta <<
" \t " << ro <<
" \t " << convergence_norm <<
" \t\t " << min_shift_value <<
" \t " << max_shift_value << std::endl;
372 if(convergence_norm < tolerance) {
379 KRATOS_INFO_IF(
"RayleighQuotientIterationEigenvalueSolver", mEchoLevel > 0) <<
"ro:\n" << ro << std::endl << std::endl <<
"y:\n" <<
y << std::endl;
383 if((Eigenvectors.size1() < 1) || (Eigenvectors.size2() < size)) {
384 Eigenvectors.resize(1,size);
388 Eigenvectors(0,
i) =
x[
i] / beta;
407 std::string
Info()
const override
409 std::stringstream buffer;
479 unsigned int mRequiredEigenvalueNumber;
481 unsigned int mEchoLevel;
483 typename TLinearSolverType::Pointer mpLinearSolver;
485 double mShiftingConvergence;
487 std::vector<DenseVectorType> mQVector;
488 std::vector<DenseVectorType> mPVector;
489 std::vector<DenseVectorType> mRVector;
531 template<
class TSparseSpaceType,
class TDenseSpaceType,
532 class TPreconditionerType,
533 class TReordererType>
536 TPreconditionerType, TReordererType>& rThis)
542 template<
class TSparseSpaceType,
class TDenseSpaceType,
543 class TPreconditionerType,
544 class TReordererType>
547 TPreconditionerType, TReordererType>& rThis)
549 rThis.PrintInfo(OStream);
550 OStream << std::endl;
551 rThis.PrintData(OStream);
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
Base class for all the iterative solvers in Kratos.
Definition: iterative_solver.h:68
void SetTolerance(double NewTolerance) override
This method allows to set the tolerance in the linear solver.
Definition: iterative_solver.h:305
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: iterative_solver.h:360
virtual void SetMaxIterationsNumber(unsigned int NewMaxIterationsNumber)
Definition: iterative_solver.h:285
IterativeSolver & operator=(const IterativeSolver &Other)
Assignment operator.
Definition: iterative_solver.h:176
virtual IndexType GetMaxIterationsNumber()
Definition: iterative_solver.h:290
double GetTolerance() override
This method allows to get the tolerance in the linear solver.
Definition: iterative_solver.h:310
virtual TPreconditionerType::Pointer GetPreconditioner(void)
Definition: iterative_solver.h:260
Definition: skyline_lu_factorization_solver.h:30
void copyFromCSRMatrix(SparseMatrixType &A)
Definition: skyline_lu_factorization_solver.h:68
void factorize()
Definition: skyline_lu_factorization_solver.h:404
double * entriesD
Definition: skyline_lu_factorization_solver.h:46
void backForwardSolve(int vector_size, const VectorType &b, VectorType &x)
Definition: skyline_lu_factorization_solver.h:496
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
This is a eigen solver based on the Rayleigh quotient iteration algorithm.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:65
std::size_t SizeType
The size type definiton.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:89
std::size_t IndexType
The index type definition.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:92
void Solve(SparseMatrixType &K, SparseMatrixType &M, DenseVectorType &Eigenvalues, DenseMatrixType &Eigenvectors) override
The Rayleigh quotient iteration method.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:240
RayleighQuotientIterationEigenvalueSolver(double NewMaxTolerance, unsigned int NewMaxIterationsNumber, unsigned int NewRequiredEigenvalueNumber, typename TLinearSolverType::Pointer pLinearSolver, double ShiftingConvergence=0.25)
The "manual" settings constructor.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:111
RayleighQuotientIterationEigenvalueSolver(Parameters ThisParameters, typename TLinearSolverType::Pointer pLinearSolver)
The parameters constructor.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:130
virtual ~RayleighQuotientIterationEigenvalueSolver()
Destructor.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:166
static void InitializeSystem(VectorType &rR, const SparseMatrixType &rM)
This method initializes the system.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:189
RayleighQuotientIterationEigenvalueSolver()
Default constructor.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:99
RayleighQuotientIterationEigenvalueSolver & operator=(const RayleighQuotientIterationEigenvalueSolver &Other)
Assignment operator.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:173
SizeType SturmSequenceCheck(SparseMatrixType &ShiftedK)
This method performs a Sturm Sequence Check.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:213
KRATOS_CLASS_POINTER_DEFINITION(RayleighQuotientIterationEigenvalueSolver)
Pointer definition of RayleighQuotientIterationEigenvalueSolver.
TDenseSpaceType::VectorType DenseVectorType
The "dense" vector definition.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:86
std::string Info() const override
Turn back information as a string.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:407
RayleighQuotientIterationEigenvalueSolver(const RayleighQuotientIterationEigenvalueSolver &Other)
Copy constructor.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:156
TDenseSpaceType::MatrixType DenseMatrixType
The dense matrix definition.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:83
TSparseSpaceType::VectorType VectorType
The vector definition ("sparse")
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:80
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:421
IterativeSolver< TSparseSpaceType, TDenseSpaceType, TPreconditionerType, TReordererType > BaseType
The base class definition.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:74
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:415
TSparseSpaceType::MatrixType SparseMatrixType
The sparse matrix defintion.
Definition: rayleigh_quotient_iteration_eigenvalue_solver.h:77
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
LinearSolver< TSpaceType< TDataType >, TLocalSpaceType< TOtherDataType > > TLinearSolverType
Definition: add_linear_solvers_to_python.cpp:50
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
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
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
int counter
Definition: script_THERMAL_CORRECT.py:218
x
Definition: sensitivityMatrix.py:49
K
Definition: sensitivityMatrix.py:73
integer i
Definition: TensorModule.f:17