15 #if !defined(KRATOS_POWER_ITERATION_EIGENVALUE_SOLVER_H_INCLUDED )
16 #define KRATOS_POWER_ITERATION_EIGENVALUE_SOLVER_H_INCLUDED
60 class TPreconditionerType = Preconditioner<TSparseSpaceType, TDenseSpaceType>,
61 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
63 :
public IterativeSolver<TSparseSpaceType, TDenseSpaceType, TPreconditionerType, TReordererType>
103 unsigned int MaxIterationNumber,
104 unsigned int RequiredEigenvalueNumber,
105 typename TLinearSolverType::Pointer pLinearSolver
106 ):
BaseType(MaxTolerance, MaxIterationNumber),
107 mRequiredEigenvalueNumber(RequiredEigenvalueNumber),
108 mpLinearSolver(pLinearSolver)
121 typename TLinearSolverType::Pointer pLinearSolver
122 ): mpLinearSolver(pLinearSolver)
126 "solver_type" : "power_iteration_eigenvalue_solver",
127 "max_iteration" : 10000,
129 "required_eigen_number" : 1,
130 "shifting_convergence" : 0.25,
132 "linear_solver_settings" : {}
137 mRequiredEigenvalueNumber = ThisParameters["required_eigen_number"].
GetInt();
138 mEchoLevel = ThisParameters[
"verbosity"].
GetInt();
191 VectorType x = boost::numeric::ublas::zero_vector<double>(size);
192 VectorType y = boost::numeric::ublas::zero_vector<double>(size);
196 if(Eigenvalues.size() < 1)
197 Eigenvalues.resize(1, 0.0);
202 double old_rho = Eigenvalues[0];
203 VectorType y_old = boost::numeric::ublas::zero_vector<double>(size);
207 mpLinearSolver->Solve(
K,
x,
y);
215 KRATOS_ERROR_IF(beta <= 0.0) <<
"M is not Positive-definite. beta = " << beta << std::endl;
218 beta = std::sqrt(beta);
219 TSparseSpaceType::InplaceMult(
y, 1.0/beta);
223 const double convergence_rho = std::abs((
rho - old_rho) /
rho);
227 KRATOS_INFO(
"Power Iterator Eigenvalue Solver: ") <<
"Iteration: " <<
i <<
" \t beta: " << beta <<
"\trho: " <<
rho <<
" \tConvergence norm: " << convergence_norm <<
" \tConvergence rho: " << convergence_rho << std::endl;
229 if(convergence_norm < tolerance || convergence_rho < tolerance)
236 if (mEchoLevel > 0) {
241 Eigenvalues[0] =
rho;
243 if((Eigenvectors.size1() < 1) || (Eigenvectors.size2() < size))
244 Eigenvectors.resize(1,size);
247 Eigenvectors(0,
i) =
y[
i];
265 std::string
Info()
const override
267 std::stringstream buffer;
338 unsigned int mRequiredEigenvalueNumber;
340 unsigned int mEchoLevel;
342 typename TLinearSolverType::Pointer mpLinearSolver;
385 template<
class TSparseSpaceType,
class TDenseSpaceType,
386 class TPreconditionerType,
387 class TReordererType>
390 TPreconditionerType, TReordererType>& rThis)
396 template<
class TSparseSpaceType,
class TDenseSpaceType,
397 class TPreconditionerType,
398 class TReordererType>
401 TPreconditionerType, TReordererType>& rThis)
403 rThis.PrintInfo(OStream);
404 OStream << std::endl;
405 rThis.PrintData(OStream);
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
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
This class uses the inverted power iteration method to obtain the lowest eigenvalue of a system.
Definition: power_iteration_eigenvalue_solver.h:64
std::size_t IndexType
Definition: power_iteration_eigenvalue_solver.h:84
TDenseSpaceType::MatrixType DenseMatrixType
Definition: power_iteration_eigenvalue_solver.h:78
PowerIterationEigenvalueSolver(double MaxTolerance, unsigned int MaxIterationNumber, unsigned int RequiredEigenvalueNumber, typename TLinearSolverType::Pointer pLinearSolver)
Alternative constructor.
Definition: power_iteration_eigenvalue_solver.h:101
PowerIterationEigenvalueSolver(Parameters ThisParameters, typename TLinearSolverType::Pointer pLinearSolver)
Alternative constructor.
Definition: power_iteration_eigenvalue_solver.h:119
void Solve(SparseMatrixType &K, SparseMatrixType &M, DenseVectorType &Eigenvalues, DenseMatrixType &Eigenvectors) override
The power iteration algorithm.
Definition: power_iteration_eigenvalue_solver.h:179
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: power_iteration_eigenvalue_solver.h:273
std::string Info() const override
Turn back information as a string.
Definition: power_iteration_eigenvalue_solver.h:265
TSparseSpaceType::VectorType VectorType
Definition: power_iteration_eigenvalue_solver.h:76
std::size_t SizeType
Definition: power_iteration_eigenvalue_solver.h:82
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: power_iteration_eigenvalue_solver.h:279
~PowerIterationEigenvalueSolver() override
Destructor.
Definition: power_iteration_eigenvalue_solver.h:151
PowerIterationEigenvalueSolver(const PowerIterationEigenvalueSolver &Other)
Copy constructor.
Definition: power_iteration_eigenvalue_solver.h:144
TSparseSpaceType::MatrixType SparseMatrixType
Definition: power_iteration_eigenvalue_solver.h:74
IterativeSolver< TSparseSpaceType, TDenseSpaceType, TPreconditionerType, TReordererType > BaseType
Definition: power_iteration_eigenvalue_solver.h:72
PowerIterationEigenvalueSolver()
Default constructor.
Definition: power_iteration_eigenvalue_solver.h:91
TDenseSpaceType::VectorType DenseVectorType
Definition: power_iteration_eigenvalue_solver.h:80
KRATOS_CLASS_POINTER_DEFINITION(PowerIterationEigenvalueSolver)
Pointer definition of PowerIterationEigenvalueSolver.
PowerIterationEigenvalueSolver & operator=(const PowerIterationEigenvalueSolver &Other)
Assignment operator.
Definition: power_iteration_eigenvalue_solver.h:162
static void RandomInitialize(const SparseMatrixType &K, VectorType &R, const bool Inverse=false)
This method initializes a vector using a normal distribution. The mean and the variance is taken from...
Definition: random_initializer_utility.h:118
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO(label)
Definition: logger.h:250
LinearSolver< TSpaceType< TDataType >, TLocalSpaceType< TOtherDataType > > TLinearSolverType
Definition: add_linear_solvers_to_python.cpp:50
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
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
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
rho
Definition: generate_droplet_dynamics.py:86
x
Definition: sensitivityMatrix.py:49
K
Definition: sensitivityMatrix.py:73
integer i
Definition: TensorModule.f:17