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;
51 VectorType
_vec_r, _vec_s, _vec_p, _vec_q, _vec_t;
66 explicit PCR(
const MatrixType& matrix,
const FilterType& filter,
67 std::shared_ptr<PrecondType> precond =
nullptr) :
96 const MatrixType& matrix,
const FilterType& filter,
97 std::shared_ptr<PrecondType> precond =
nullptr) :
98 BaseClass(
"PCR", section_name, section, precond),
115 _vec_p = this->_system_matrix.create_vector_r();
116 _vec_q = this->_system_matrix.create_vector_r();
117 _vec_r = this->_system_matrix.create_vector_r();
118 _vec_s = this->_system_matrix.create_vector_r();
119 _vec_t = this->_system_matrix.create_vector_r();
124 this->_vec_t.clear();
125 this->_vec_s.clear();
126 this->_vec_r.clear();
127 this->_vec_q.clear();
128 this->_vec_p.clear();
132 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
135 this->_vec_r.copy(vec_def);
150 virtual Status correct(VectorType& vec_sol,
const VectorType& vec_rhs)
override
153 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -DataType(1));
154 this->_system_filter.filter_def(this->_vec_r);
169 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
170 const MatrixType& matrix(this->_system_matrix);
171 const FilterType& filter(this->_system_filter);
172 VectorType& vec_p(this->_vec_p);
173 VectorType& vec_q(this->_vec_q);
174 VectorType& vec_r(this->_vec_r);
175 VectorType& vec_s(this->_vec_s);
178 VectorType& vec_y(this->_vec_t);
179 VectorType& vec_z(this->_vec_t);
193 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
210 matrix.apply(vec_q, vec_p);
211 filter.filter_def(vec_q);
215 DataType gamma = vec_p.dot(vec_q);
231 DataType alpha = gamma / vec_z.dot(vec_q);
235 vec_sol.axpy(vec_p, alpha);
239 vec_r.axpy(vec_q, -alpha);
245 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
251 vec_s.axpy(vec_z, -alpha);
254 matrix.apply(vec_y, vec_s);
255 filter.filter_def(vec_y);
259 DataType gamma2 = gamma;
260 gamma = vec_s.dot(vec_y);
264 DataType beta = gamma / gamma2;
268 vec_p.scale(vec_p, beta);
272 vec_q.scale(vec_q, beta);
299 template<
typename Matrix_,
typename Filter_>
300 inline std::shared_ptr<PCR<Matrix_, Filter_>>
new_pcr(
301 const Matrix_& matrix,
const Filter_& filter,
304 return std::make_shared<PCR<Matrix_, Filter_>>(matrix, filter, precond);
328 template<
typename Matrix_,
typename Filter_>
329 inline std::shared_ptr<PCR<Matrix_, Filter_>>
new_pcr(
331 const Matrix_& matrix,
const Filter_& filter,
334 return std::make_shared<PCR<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
A class organizing a tree of key-value pairs.
Helper class for iteration statistics collection.
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) Conjugate-Residual solver implementation
virtual void done_symbolic() override
Symbolic finalization method.
virtual String name() const override
Returns a descriptive string.
PCR(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
virtual void init_symbolic() override
Symbolic initialization method.
virtual Status _apply_intern(VectorType &vec_sol)
const MatrixType & _system_matrix
the matrix for the solver
PCR(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
const FilterType & _system_filter
the filter for the solver
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< PCR< Matrix_, Filter_ > > new_pcr(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new PCR solver object.