10#include <kernel/solver/iterative.hpp>
29 template<
typename Matrix_,
typename Filter_>
34 typedef Matrix_ MatrixType;
35 typedef Filter_ FilterType;
36 typedef typename MatrixType::VectorTypeR VectorType;
37 typedef typename MatrixType::DataType DataType;
70 explicit Richardson(
const MatrixType& matrix,
const FilterType& filter,
71 DataType omega = DataType(1), std::shared_ptr<PrecondType> precond =
nullptr) :
101 const MatrixType& matrix,
const FilterType& filter,
102 std::shared_ptr<PrecondType> precond =
nullptr) :
103 BaseClass(
"Richardson", section_name, section, precond),
111 auto omega_p = section->
query(
"omega");
114 set_omega(DataType(std::stod(omega_p.first)));
147 _vec_def = this->_system_matrix.create_vector_r();
148 _vec_cor = this->_system_matrix.create_vector_r();
153 this->_vec_cor.clear();
154 this->_vec_def.clear();
158 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
161 this->_vec_def.copy(vec_def);
167 this->
_status = _apply_intern(vec_cor, vec_def);
172 virtual Status correct(VectorType& vec_sol,
const VectorType& vec_rhs)
override
175 this->_system_matrix.apply(this->_vec_def, vec_sol, vec_rhs, -DataType(1));
176 this->_system_filter.filter_def(this->_vec_def);
179 this->
_status = _apply_intern(vec_sol, vec_rhs);
185 virtual Status _apply_intern(VectorType& vec_sol,
const VectorType& vec_rhs)
187 IterationStats pre_iter(*
this);
188 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
190 VectorType& vec_def(this->_vec_def);
191 VectorType& vec_cor(this->_vec_cor);
192 const MatrixType& matrix(this->_system_matrix);
193 const FilterType& filter(this->_system_filter);
203 IterationStats stat(*
this);
214 vec_sol.axpy(vec_cor, this->_omega);
217 matrix.apply(vec_def, vec_sol, vec_rhs, -DataType(1));
218 filter.filter_def(vec_def);
225 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
248 template<
typename Matrix_,
typename Filter_>
250 const Matrix_& matrix,
const Filter_& filter,
251 typename Matrix_::DataType omega =
typename Matrix_::DataType(1),
254 return std::make_shared<Richardson<Matrix_, Filter_>>(matrix, filter, omega, precond);
278 template<
typename Matrix_,
typename Filter_>
281 const Matrix_& matrix,
const Filter_& filter,
284 return std::make_shared<Richardson<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
#define XASSERT(expr)
Assertion macro definition.
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.
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.
Abstract base-class for preconditioned iterative solvers.
virtual void init_symbolic() override
Symbolic initialization method.
bool _apply_precond(VectorType &vec_cor, const VectorType &vec_def, const Filter_ &filter)
Applies the preconditioner onto a defect vector.
virtual void done_symbolic() override
Symbolic finalization method.
(Preconditioned) Richardson solver implementation
VectorType _vec_cor
correction vector
Richardson(const MatrixType &matrix, const FilterType &filter, DataType omega=DataType(1), std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
virtual ~Richardson()
Empty virtual destructor.
void set_omega(DataType omega)
Sets the damping parameter.
const FilterType & _system_filter
the filter for the solver
virtual String name() const override
Returns a descriptive string.
Richardson(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
DataType _omega
damping parameter
const MatrixType & _system_matrix
the matrix for the solver
virtual void done_symbolic() override
Symbolic finalization method.
VectorType _vec_def
defect vector
virtual void init_symbolic() override
Symbolic initialization method.
Polymorphic solver interface.
String class implementation.
Status
Solver status return codes enumeration.
@ progress
continue iteration (internal use only)
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
std::shared_ptr< Richardson< Matrix_, Filter_ > > new_richardson(const Matrix_ &matrix, const Filter_ &filter, typename Matrix_::DataType omega=typename Matrix_::DataType(1), std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new Richardson solver object.