9#include <kernel/solver/iterative.hpp>
48 typedef Matrix_ MatrixType;
49 typedef Filter_ FilterType;
50 typedef typename MatrixType::VectorTypeR VectorType;
51 typedef typename MatrixType::DataType DataType;
68 VectorType
_vec_r, _vec_p, _vec_q, _vec_s, _vec_t;
89 explicit PCGNR(
const MatrixType& matrix,
const FilterType& filter,
90 std::shared_ptr<PrecondType> precond_l =
nullptr,
91 std::shared_ptr<PrecondType> precond_r =
nullptr) :
121 const MatrixType& matrix,
const FilterType& filter,
122 std::shared_ptr<PrecondType> precond_l =
nullptr,
123 std::shared_ptr<PrecondType> precond_r =
nullptr) :
124 BaseClass(
"PCGNR", section_name, section),
150 _vec_p = this->_system_matrix.create_vector_r();
151 _vec_q = this->_system_matrix.create_vector_r();
152 _vec_r = this->_system_matrix.create_vector_r();
153 _vec_s = this->_system_matrix.create_vector_r();
154 _vec_t = this->_system_matrix.create_vector_r();
159 this->_vec_t.clear();
160 this->_vec_s.clear();
161 this->_vec_r.clear();
162 this->_vec_q.clear();
163 this->_vec_p.clear();
185 this->_transp_matrix = this->_system_matrix.transpose();
191 this->_transp_matrix.clear();
202 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
205 this->_vec_r.copy(vec_def);
220 virtual Status correct(VectorType& vec_sol,
const VectorType& vec_rhs)
override
223 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -DataType(1));
224 this->_system_filter.filter_def(this->_vec_r);
237 bool _apply_precond_l(VectorType& vec_cor,
const VectorType& vec_def)
241 Statistics::add_solver_expression(std::make_shared<ExpressionCallPrecond>(this->
name(), this->_precond_l->name()));
244 vec_cor.copy(vec_def);
245 this->_system_filter.filter_cor(vec_cor);
249 bool _apply_precond_r(VectorType& vec_cor,
const VectorType& vec_def)
253 Statistics::add_solver_expression(std::make_shared<ExpressionCallPrecond>(this->
name(), this->_precond_r->name()));
256 vec_cor.copy(vec_def);
257 this->_system_filter.filter_cor(vec_cor);
263 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
265 const MatrixType& matrix(this->_system_matrix);
266 const MatrixType& transp(this->_transp_matrix);
267 const FilterType& filter(this->_system_filter);
269 VectorType& vec_p(this->_vec_p);
270 VectorType& vec_q(this->_vec_q);
271 VectorType& vec_r(this->_vec_r);
272 VectorType& vec_s(this->_vec_s);
273 VectorType& vec_t(this->_vec_t);
274 VectorType& vec_y(this->_vec_s);
275 VectorType& vec_z(this->_vec_t);
282 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
288 if(!this->_apply_precond_l(vec_p, vec_r))
296 transp.apply(vec_s, vec_p);
300 if(!this->_apply_precond_r(vec_q, vec_s))
308 DataType gamma = vec_s.dot(vec_q);
316 matrix.apply(vec_y, vec_q);
317 filter.filter_def(vec_y);
320 if(!this->_apply_precond_l(vec_z, vec_y))
328 DataType alpha = gamma / vec_y.dot(vec_z);
332 vec_sol.axpy(vec_q, alpha);
336 vec_r.axpy(vec_y, -alpha);
342 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
347 vec_p.axpy(vec_z, -alpha);
350 transp.apply(vec_s, vec_p);
351 filter.filter_def(vec_s);
354 if(!this->_apply_precond_r(vec_t, vec_s))
362 DataType gamma2 = gamma;
363 gamma = vec_s.dot(vec_t);
367 DataType beta = gamma / gamma2;
371 vec_q.scale(vec_q, beta);
399 template<
typename Matrix_,
typename Filter_>
400 inline std::shared_ptr<PCGNR<Matrix_, Filter_>>
new_pcgnr(
401 const Matrix_& matrix,
const Filter_& filter,
405 return std::make_shared<PCGNR<Matrix_, Filter_>>(matrix, filter, precond_l, precond_r);
432 template<
typename Matrix_,
typename Filter_>
433 inline std::shared_ptr<PCGNR<Matrix_, Filter_>>
new_pcgnr(
435 const Matrix_& matrix,
const Filter_& filter,
439 return std::make_shared<PCGNR<Matrix_, Filter_>>(section_name, section, matrix, filter, precond_l, precond_r);
A class organizing a tree of key-value pairs.
Helper class for iteration statistics collection.
Abstract base-class for iterative solvers.
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 on Normal Equations solver implementation
virtual void done_symbolic() override
Symbolic finalization method.
PCGNR(const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond_l=nullptr, std::shared_ptr< PrecondType > precond_r=nullptr)
Constructor.
virtual void init_symbolic() override
Symbolic initialization method.
MatrixType _transp_matrix
the transposed system matrix
VectorType _vec_r
temporary vectors
virtual void init_numeric() override
Numeric initialization method.
const FilterType & _system_filter
the filter for the solver
virtual void done_numeric() override
Numeric finalization method.
std::shared_ptr< PrecondType > _precond_l
left preconditioner
const MatrixType & _system_matrix
the matrix for the solver
virtual String name() const override
Returns a descriptive string.
PCGNR(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter, std::shared_ptr< PrecondType > precond_l=nullptr, std::shared_ptr< PrecondType > precond_r=nullptr)
Constructor using a PropertyMap.
std::shared_ptr< PrecondType > _precond_r
right preconditioner
virtual Status _apply_intern(VectorType &vec_sol)
Polymorphic solver interface.
virtual void init_symbolic()
Symbolic initialization method.
virtual void init_numeric()
Numeric initialization method.
virtual void done_symbolic()
Symbolic finalization method.
virtual void done_numeric()
Numeric finalization method.
String class implementation.
bool status_success(Status status)
Status success check function.
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< PCGNR< Matrix_, Filter_ > > new_pcgnr(const Matrix_ &matrix, const Filter_ &filter, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond_l=nullptr, std::shared_ptr< SolverBase< typename Matrix_::VectorTypeL > > precond_r=nullptr)
Creates a new PCGNR solver object.