9#include <kernel/solver/iterative.hpp>
30 template<
typename Matrix_,
typename Filter_>
42 typedef typename MatrixType::DataType
DataType;
74 std::shared_ptr<PrecondType> precond =
nullptr) :
103 const MatrixType& matrix,
const FilterType& filter, std::shared_ptr<PrecondType> precond =
nullptr) :
104 BaseClass(
"PCG", section_name, section, precond),
123 _vec_r = this->_system_matrix.create_vector_r();
124 _vec_p = this->_system_matrix.create_vector_r();
125 _vec_t = this->_system_matrix.create_vector_r();
131 this->_vec_t.clear();
132 this->_vec_p.clear();
133 this->_vec_r.clear();
141 this->_vec_r.copy(vec_def);
160 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -
DataType(1));
161 this->_system_filter.filter_def(this->_vec_r);
189 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
191 const MatrixType& matrix(this->_system_matrix);
192 const FilterType& filter(this->_system_filter);
211 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
226 DataType gamma = vec_r.dot(vec_p);
236 matrix.apply(vec_q, vec_p);
237 filter.filter_def(vec_q);
241 DataType alpha = gamma / vec_q.dot(vec_p);
245 vec_sol.axpy(vec_p, alpha);
249 vec_r.axpy(vec_q, -alpha);
256 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
271 DataType gamma2 = gamma;
272 gamma = vec_r.dot(vec_z);
280 vec_p.scale(vec_p, beta);
305 template<
typename Matrix_,
typename Filter_>
306 inline std::shared_ptr<PCG<Matrix_, Filter_>>
new_pcg(
307 const Matrix_& matrix,
const Filter_& filter,
310 return std::make_shared<PCG<Matrix_, Filter_>>(matrix, filter, precond);
334 template<
typename Matrix_,
typename Filter_>
335 inline std::shared_ptr<PCG<Matrix_, Filter_>>
new_pcg(
337 const Matrix_& matrix,
const Filter_& filter,
340 return std::make_shared<PCG<Matrix_, Filter_>>(section_name, section, matrix, filter, precond);
A class organizing a tree of key-value pairs.
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 _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-Gradient solver implementation
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
PCG(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
MatrixType::VectorTypeR VectorType
The vector type this solver can be applied to.
VectorType _vec_t
Temporary vector, used for e.g. the preconditioned defect.
virtual void init_symbolic() override
Symbolic initialization method.
MatrixType::DataType DataType
The floating point precision.
Filter_ FilterType
The filter for projecting solution, rhs, defect and correction vectors to subspaces.
PCG(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond=nullptr)
Constructor.
PreconditionedIterativeSolver< VectorType > BaseClass
Our base class.
VectorType _vec_r
The defect vector.
const FilterType & _system_filter
the filter for the solver
SolverBase< VectorType > PrecondType
The type of the preconditioner that can be used.
const MatrixType & _system_matrix
the matrix for the solver
virtual Status _apply_intern(VectorType &vec_sol)
Internal function, applies the solver.
virtual void done_symbolic() override
Symbolic finalization method.
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver correction method.
virtual String name() const override
Returns a descriptive string.
VectorType _vec_p
The update (or search) direction.
Matrix_ MatrixType
The type of matrix this solver can be applied to.
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< PCG< Matrix_, Filter_ > > new_pcg(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond=nullptr)
Creates a new PCG solver object.