10#include <kernel/solver/iterative.hpp>
24 template<
typename Matrix_,
typename Filter_>
36 typedef typename MatrixType::DataType
DataType;
103 BaseClass(
"Chebyshev", section_name, section),
113 auto fmin_p = section->
query(
"fraction_min_ev");
114 if(fmin_p.second && !fmin_p.first.parse(this->_fraction_min_ev))
115 throw ParseError(section_name +
".fraction_min_ev", fmin_p.first,
"a float");
117 auto fmax_p = section->
query(
"fraction_max_ev");
118 if(fmax_p.second && !fmax_p.first.parse(this->_fraction_max_ev))
119 throw ParseError(section_name +
".fraction_max_ev", fmax_p.first,
"a float");
163 _vec_def = this->_system_matrix.create_vector_r();
164 _vec_cor = this->_system_matrix.create_vector_r();
170 this->_vec_cor.clear();
171 this->_vec_def.clear();
185 const MatrixType& matrix(this->_system_matrix);
189 v.scale(v,
DataType(1) / v.norm2());
191 for (
Index i(0) ; i < max_iters ; ++i)
194 v.scale(z,
DataType(1) / z.norm2());
196 if (
Math::abs((lambda - lambda_old) / lambda) < tolerance)
208 this->_vec_def.copy(vec_def);
214 this->
_status = _apply_intern(vec_cor, vec_def);
222 this->_system_matrix.apply(this->_vec_def, vec_sol, vec_rhs, -
DataType(1));
223 this->_system_filter.filter_def(this->_vec_def);
226 this->
_status = _apply_intern(vec_sol, vec_rhs);
234 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
236 VectorType& vec_def(this->_vec_def);
238 const MatrixType& matrix(this->_system_matrix);
239 const FilterType& filter(this->_system_filter);
248 vec_cor.scale(vec_def, (
DataType(1) / d));
266 vec_cor.scale(vec_cor, beta);
267 vec_cor.axpy(vec_def, alpha);
270 vec_sol.axpy(vec_cor);
273 matrix.apply(vec_def, vec_sol, vec_rhs, -
DataType(1));
274 filter.filter_def(vec_def);
281 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
298 template<
typename Matrix_,
typename Filter_>
300 const Matrix_& matrix,
const Filter_& filter,
301 const typename Matrix_::DataType fraction_min_ev =
typename Matrix_::DataType(0.03),
302 const typename Matrix_::DataType fraction_max_ev =
typename Matrix_::DataType(1.1))
304 return std::make_shared<Chebyshev<Matrix_, Filter_>>(matrix, filter, fraction_min_ev, fraction_max_ev);
325 template<
typename Matrix_,
typename Filter_>
328 const Matrix_& matrix,
const Filter_& filter)
330 return std::make_shared<Chebyshev<Matrix_, Filter_>>(section_name, section, matrix, filter);
Class for parser related errors.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Chebyshev Polynomial implementation.
void set_fraction_min_ev(DataType fraction_min_ev)
Sets the minimum eigenvalue fraction.
virtual void done_symbolic() override
Symbolic finalization method.
Chebyshev(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter)
Constructor using a PropertyMap.
IterativeSolver< VectorType > BaseClass
Our base class.
MatrixType::DataType DataType
The floating point precision.
DataType _fraction_max_ev
maximum eigenvalue fraction
virtual void init_symbolic() override
Symbolic initialization method.
Matrix_ MatrixType
The matrix type.
Filter_ FilterType
The filter type.
DataType _min_ev
the minium eigenvalue of the matrix
DataType _max_ev
the maximum eigenvalue of the matrix
const MatrixType & _system_matrix
the matrix for the solver
DataType _fraction_min_ev
minimum eigenvalue fraction
const FilterType & _system_filter
the filter for the solver
VectorType _vec_cor
correction vector
virtual String name() const override
Returns a descriptive string.
Chebyshev(const MatrixType &matrix, const FilterType &filter, const DataType fraction_min_ev=DataType(0.5), const DataType fraction_max_ev=DataType(0.8))
Constructor.
void set_fraction_max_ev(DataType fraction_max_ev)
Sets the maximum eigenvalue fraction.
virtual ~Chebyshev()
Empty virtual destructor.
MatrixType::VectorTypeL VectorType
The type of vector this solver can be applied to.
VectorType _vec_def
defect vector
virtual void init_numeric() override
Numeric initialization method.
Abstract base-class for iterative solvers.
Index get_num_iter() const
Returns number of performed iterations.
Status _status
current status of the solver
void _set_comm_by_matrix(const Matrix_ &matrix)
Sets the communicator for the solver from a matrix.
virtual Status _set_new_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the new (next) defect vector.
virtual void plot_summary() const
Plot a summary of the last solver run.
virtual Status _set_initial_defect(const VectorType &vec_def, const VectorType &vec_sol)
Internal function: sets the initial defect vector.
virtual void init_symbolic()
Symbolic initialization method.
virtual void init_numeric()
Numeric initialization method.
virtual void done_symbolic()
Symbolic finalization method.
String class implementation.
T_ abs(T_ x)
Returns the absolute value.
Status
Solver status return codes enumeration.
@ progress
continue iteration (internal use only)
std::shared_ptr< Chebyshev< Matrix_, Filter_ > > new_chebyshev(const Matrix_ &matrix, const Filter_ &filter, const typename Matrix_::DataType fraction_min_ev=typename Matrix_::DataType(0.03), const typename Matrix_::DataType fraction_max_ev=typename Matrix_::DataType(1.1))
Creates a new Chebyshev solver object.
std::uint64_t Index
Index data type.