14 #if !defined(KRATOS_POWER_ITERATION_HIGHEST_EIGENVALUE_SOLVER_H_INCLUDED )
15 #define KRATOS_POWER_ITERATION_HIGHEST_EIGENVALUE_SOLVER_H_INCLUDED
20 #include "boost/range/algorithm/max_element.hpp"
59 class TPreconditionerType = Preconditioner<TSparseSpaceType, TDenseSpaceType>,
60 class TReordererType = Reorderer<TSparseSpaceType, TDenseSpaceType> >
62 :
public IterativeSolver<TSparseSpaceType, TDenseSpaceType, TPreconditionerType, TReordererType>
102 unsigned int MaxIterationNumber,
103 unsigned int RequiredEigenvalueNumber,
104 typename TLinearSolverType::Pointer pLinearSolver
105 ):
BaseType(MaxTolerance, MaxIterationNumber),
106 mRequiredEigenvalueNumber(RequiredEigenvalueNumber),
107 mpLinearSolver(pLinearSolver)
120 typename TLinearSolverType::Pointer pLinearSolver
121 ): mpLinearSolver(pLinearSolver)
125 "solver_type" : "power_iteration_highest_eigenvalue_solver",
126 "max_iteration" : 10000,
128 "required_eigen_number" : 1,
129 "shifting_convergence" : 0.25,
131 "linear_solver_settings" : {}
136 mRequiredEigenvalueNumber = ThisParameters["required_eigen_number"].
GetInt();
137 mEchoLevel = ThisParameters[
"verbosity"].
GetInt();
189 VectorType x = boost::numeric::ublas::zero_vector<double>(size);
190 VectorType y = boost::numeric::ublas::zero_vector<double>(size);
194 if(Eigenvalues.size() < 1) {
195 Eigenvalues.resize(1);
196 Eigenvalues[0] = 0.0;
201 double old_rho = Eigenvalues[0];
202 VectorType y_old = boost::numeric::ublas::zero_vector<double>(size);
211 rho =
static_cast<double>(*boost::max_element(
y));
215 TSparseSpaceType::InplaceMult(
y, 1.0/
rho);
217 const double convergence_rho = std::abs((
rho - old_rho) /
rho);
221 convergence_norm /= norm_y;
224 KRATOS_INFO(
"Power Iterator Highest Eigenvalue Solver: ") <<
"Iteration: " <<
i <<
"\trho: " <<
rho <<
" \tConvergence norm: " << convergence_norm <<
" \tConvergence rho: " <<
225 convergence_rho << std::endl;
227 if(convergence_norm < tolerance || convergence_rho < tolerance)
234 if (mEchoLevel > 0) {
239 Eigenvalues[0] =
rho;
241 if((Eigenvectors.size1() != 1) || (Eigenvectors.size2() < size))
242 Eigenvectors.resize(1, size,
false);
245 Eigenvectors(0,
i) =
y[
i];
263 std::string
Info()
const override
265 std::stringstream buffer;
336 unsigned int mRequiredEigenvalueNumber;
338 unsigned int mEchoLevel;
340 typename TLinearSolverType::Pointer mpLinearSolver;
383 template<
class TSparseSpaceType,
class TDenseSpaceType,
384 class TPreconditionerType,
385 class TReordererType>
388 TPreconditionerType, TReordererType>& rThis)
394 template<
class TSparseSpaceType,
class TDenseSpaceType,
395 class TPreconditionerType,
396 class TReordererType>
399 TPreconditionerType, TReordererType>& rThis)
401 rThis.PrintInfo(OStream);
402 OStream << std::endl;
403 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_highest_eigenvalue_solver.h:63
PowerIterationHighestEigenvalueSolver & operator=(const PowerIterationHighestEigenvalueSolver &Other)
Assignment operator.
Definition: power_iteration_highest_eigenvalue_solver.h:161
std::size_t IndexType
Definition: power_iteration_highest_eigenvalue_solver.h:83
PowerIterationHighestEigenvalueSolver(Parameters ThisParameters, typename TLinearSolverType::Pointer pLinearSolver)
Alternative constructor.
Definition: power_iteration_highest_eigenvalue_solver.h:118
std::size_t SizeType
Definition: power_iteration_highest_eigenvalue_solver.h:81
PowerIterationHighestEigenvalueSolver()
Default constructor.
Definition: power_iteration_highest_eigenvalue_solver.h:90
TDenseSpaceType::MatrixType DenseMatrixType
Definition: power_iteration_highest_eigenvalue_solver.h:77
IterativeSolver< TSparseSpaceType, TDenseSpaceType, TPreconditionerType, TReordererType > BaseType
Definition: power_iteration_highest_eigenvalue_solver.h:71
~PowerIterationHighestEigenvalueSolver() override
Destructor.
Definition: power_iteration_highest_eigenvalue_solver.h:150
PowerIterationHighestEigenvalueSolver(const PowerIterationHighestEigenvalueSolver &Other)
Copy constructor.
Definition: power_iteration_highest_eigenvalue_solver.h:143
std::string Info() const override
Turn back information as a string.
Definition: power_iteration_highest_eigenvalue_solver.h:263
PowerIterationHighestEigenvalueSolver(double MaxTolerance, unsigned int MaxIterationNumber, unsigned int RequiredEigenvalueNumber, typename TLinearSolverType::Pointer pLinearSolver)
Alternative constructor.
Definition: power_iteration_highest_eigenvalue_solver.h:100
KRATOS_CLASS_POINTER_DEFINITION(PowerIterationHighestEigenvalueSolver)
Pointer definition of PowerIterationHighestEigenvalueSolver.
TSparseSpaceType::VectorType VectorType
Definition: power_iteration_highest_eigenvalue_solver.h:75
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: power_iteration_highest_eigenvalue_solver.h:271
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: power_iteration_highest_eigenvalue_solver.h:277
TSparseSpaceType::MatrixType SparseMatrixType
Definition: power_iteration_highest_eigenvalue_solver.h:73
void Solve(SparseMatrixType &K, SparseMatrixType &M, DenseVectorType &Eigenvalues, DenseMatrixType &Eigenvectors) override
The power iteration algorithm.
Definition: power_iteration_highest_eigenvalue_solver.h:178
TDenseSpaceType::VectorType DenseVectorType
Definition: power_iteration_highest_eigenvalue_solver.h:79
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
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