9#include <kernel/solver/iterative.hpp>
37 typedef Matrix_ MatrixType;
38 typedef Filter_ FilterType;
39 typedef typename MatrixType::VectorTypeR VectorType;
40 typedef typename MatrixType::DataType DataType;
66 explicit PSD(
const MatrixType& matrix,
const FilterType& filter,
67 std::shared_ptr<PrecondType> precond =
nullptr) :
95 const MatrixType& matrix,
const FilterType& filter,
96 std::shared_ptr<PrecondType> precond =
nullptr) :
97 BaseClass(
"PSD", section_name, section, precond),
114 _vec_r = this->_system_matrix.create_vector_r();
115 _vec_q = this->_system_matrix.create_vector_r();
116 _vec_z = this->_system_matrix.create_vector_r();
121 this->_vec_z.clear();
122 this->_vec_q.clear();
123 this->_vec_r.clear();
127 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
130 this->_vec_r.copy(vec_def);
136 this->
_status = _apply_intern(vec_cor);
145 virtual Status correct(VectorType& vec_sol,
const VectorType& vec_rhs)
override
148 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -DataType(1));
149 this->_system_filter.filter_def(this->_vec_r);
152 this->
_status = _apply_intern(vec_sol);
162 virtual Status _apply_intern(VectorType& vec_sol)
164 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
166 const MatrixType& matrix(this->_system_matrix);
167 const FilterType& filter(this->_system_filter);
168 VectorType& vec_r(this->_vec_r);
169 VectorType& vec_q(this->_vec_q);
170 VectorType& vec_z(this->_vec_z);
177 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
184 IterationStats stat(*
this);
195 matrix.apply(vec_q, vec_z);
196 filter.filter_def(vec_q);
199 DataType alpha = vec_z.dot(vec_r) / vec_z.dot(vec_q);
203 vec_sol.axpy(vec_z, alpha);
207 vec_r.axpy(vec_q, -alpha);
214 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
240 template<
typename Matrix_,
typename Filter_>
241 inline std::shared_ptr<PSD<Matrix_, Filter_>>
new_psd(
242 const Matrix_& matrix,
const Filter_& filter,
245 return std::make_shared<PSD<Matrix_, Filter_>>(matrix, filter, precond);
269 template<
typename Matrix_,
typename Filter_>
270 inline std::shared_ptr<PSD<Matrix_, Filter_>>
new_psd(
272 const Matrix_& matrix,
const Filter_& filter,
275 return std::make_shared<PSD<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
A class organizing a tree of key-value pairs.
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.
(Preconditioned) Steepest-Descent solver implementation
const FilterType & _system_filter
the filter for the solver
virtual void init_symbolic() override
Symbolic initialization method.
virtual String name() const override
Returns a descriptive string.
PSD(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
const MatrixType & _system_matrix
the matrix for the solver
virtual void done_symbolic() override
Symbolic finalization method.
PSD(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
VectorType _vec_r
temporary vectors
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.
Polymorphic solver interface.
String class implementation.
Status
Solver status return codes enumeration.
@ progress
continue iteration (internal use only)
@ undefined
undefined status
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)
std::shared_ptr< PSD< Matrix_, Filter_ > > new_psd(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new PSD solver object.