9#include <kernel/solver/iterative.hpp>
39 typedef Matrix_ MatrixType;
40 typedef Filter_ FilterType;
41 typedef typename MatrixType::VectorTypeR VectorType;
42 typedef typename MatrixType::DataType DataType;
53 VectorType
_vec_r, _vec_z, _vec_s, _vec_p, _vec_S, _vec_Z;
68 explicit GroppPCG(
const MatrixType& matrix,
const FilterType& filter,
69 std::shared_ptr<PrecondType> precond =
nullptr) :
98 const MatrixType& matrix,
const FilterType& filter,
99 std::shared_ptr<PrecondType> precond =
nullptr) :
100 BaseClass(
"GroppPCG", section_name, section, precond),
117 _vec_r = this->_system_matrix.create_vector_r();
118 _vec_z = this->_system_matrix.create_vector_r();
119 _vec_s = this->_system_matrix.create_vector_r();
120 _vec_p = this->_system_matrix.create_vector_r();
121 _vec_S = this->_system_matrix.create_vector_r();
122 _vec_Z = this->_system_matrix.create_vector_r();
127 this->_vec_r.clear();
128 this->_vec_z.clear();
129 this->_vec_s.clear();
130 this->_vec_p.clear();
131 this->_vec_S.clear();
132 this->_vec_Z.clear();
136 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
139 this->_vec_r.copy(vec_def);
154 virtual Status correct(VectorType& vec_sol,
const VectorType& vec_rhs)
override
157 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -DataType(1));
158 this->_system_filter.filter_def(this->_vec_r);
174 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
176 const MatrixType& matrix(this->_system_matrix);
177 const FilterType& filter(this->_system_filter);
178 VectorType& vec_r(this->_vec_r);
179 VectorType& vec_z(this->_vec_z);
180 VectorType& vec_s(this->_vec_s);
181 VectorType& vec_p(this->_vec_p);
182 VectorType& vec_S(this->_vec_S);
183 VectorType& vec_Z(this->_vec_Z);
185 DataType gamma, gamma_new, beta, alpha, t;
187 gamma_new = DataType(0);
196 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
209 gamma = vec_z.dot(vec_r);
211 matrix.apply(vec_s, vec_p);
212 filter.filter_def(vec_s);
221 auto dot_t = vec_s.dot_async(vec_p);
232 vec_r.axpy(vec_s, -alpha);
233 auto norm_def_cur = vec_r.norm2_async();
235 vec_sol.axpy(vec_p, alpha);
237 vec_z.axpy(vec_S, -alpha);
239 auto dot_gamma_new = vec_r.dot_async(vec_z);
240 matrix.apply(vec_Z, vec_z);
241 filter.filter_def(vec_Z);
243 gamma_new = dot_gamma_new.wait();
244 beta = gamma_new / gamma;
247 vec_p.scale(vec_p, beta);
249 vec_s.scale(vec_s, beta);
256 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
282 template<
typename Matrix_,
typename Filter_>
284 const Matrix_& matrix,
const Filter_& filter,
287 return std::make_shared<GroppPCG<Matrix_, Filter_>>(matrix, filter, precond);
311 template<
typename Matrix_,
typename Filter_>
314 const Matrix_& matrix,
const Filter_& filter,
317 return std::make_shared<GroppPCG<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
A class organizing a tree of key-value pairs.
(Preconditioned) pipelined Conjugate-Gradient solver implementation from Bill Gropp
const FilterType & _system_filter
the filter for the solver
virtual void done_symbolic() override
Symbolic finalization method.
GroppPCG(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
GroppPCG(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
virtual void init_symbolic() override
Symbolic initialization method.
virtual Status _apply_intern(VectorType &vec_sol, const VectorType &vec_rhs)
virtual String name() const override
Returns a descriptive string.
const MatrixType & _system_matrix
the matrix for the solver
Helper class for iteration statistics collection.
void destroy()
destroy the objects contents (and generate Statistics::expression) before the actual destructor call
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 _update_defect(const DataType def_cur_norm)
Internal function: sets the new (next) defect norm.
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.
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< GroppPCG< Matrix_, Filter_ > > new_gropppcg(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new GroppPCG solver object.