9#include <kernel/solver/iterative.hpp>
10#include <kernel/solver/ilu_precond.hpp>
49 typedef Matrix_ MatrixType;
50 typedef Filter_ FilterType;
51 typedef typename MatrixType::VectorTypeR VectorType;
52 typedef typename MatrixType::DataType DataType;
53 typedef typename MatrixType::IndexType IndexType;
64 VectorType
_vec_r, _vec_p, _vec_q, _vec_s, _vec_t;
68 Intern::ILUCoreScalar<DataType, IndexType>
_ilu;
83 explicit PCGNRILU(
const MatrixType& matrix,
const FilterType& filter,
int ilu_p = -1) :
110 const MatrixType& matrix,
const FilterType& filter) :
111 BaseClass(
"PCGNRILU", section_name, section),
119 auto fill_in_param_p = section->
query(
"fill_in_param");
120 if(fill_in_param_p.second && !fill_in_param_p.first.parse(
_ilu_p))
121 throw ParseError(section_name +
".fill_in_param", fill_in_param_p.first,
"a non-negative integer");
152 _vec_p = this->_system_matrix.create_vector_r();
153 _vec_q = this->_system_matrix.create_vector_r();
154 _vec_r = this->_system_matrix.create_vector_r();
155 _vec_s = this->_system_matrix.create_vector_r();
156 _vec_t = this->_system_matrix.create_vector_r();
160 _ilu.set_struct(this->_system_matrix);
170 this->_vec_t.clear();
171 this->_vec_s.clear();
172 this->_vec_r.clear();
173 this->_vec_q.clear();
174 this->_vec_p.clear();
187 _ilu.factorize_numeric_il_du();
191 virtual Status apply(VectorType& vec_cor,
const VectorType& vec_def)
override
194 this->_vec_r.copy(vec_def);
209 virtual Status correct(VectorType& vec_sol,
const VectorType& vec_rhs)
override
212 this->_system_matrix.apply(this->_vec_r, vec_sol, vec_rhs, -DataType(1));
213 this->_system_filter.filter_def(this->_vec_r);
226 void _precond_l(VectorType& vec_c,
const VectorType& vec_q)
231 DataType* x = vec_c.elements();
233 _ilu.solve_ilt(x, x);
237 void _precond_r(VectorType& vec_c,
const VectorType& vec_q)
242 DataType* x = vec_c.elements();
243 _ilu.solve_dut(x, x);
250 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
252 const MatrixType& matrix(this->_system_matrix);
253 const MatrixType& transp(this->_transp_matrix);
254 const FilterType& filter(this->_system_filter);
256 VectorType& vec_p(this->_vec_p);
257 VectorType& vec_q(this->_vec_q);
258 VectorType& vec_r(this->_vec_r);
259 VectorType& vec_s(this->_vec_s);
260 VectorType& vec_t(this->_vec_t);
261 VectorType& vec_y(this->_vec_s);
262 VectorType& vec_z(this->_vec_t);
269 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
275 this->_precond_l(vec_p, vec_r);
276 filter.filter_cor(vec_p);
280 transp.apply(vec_s, vec_p);
281 filter.filter_def(vec_s);
285 this->_precond_r(vec_q, vec_s);
286 filter.filter_cor(vec_q);
290 DataType gamma = vec_s.dot(vec_q);
298 matrix.apply(vec_y, vec_q);
299 filter.filter_def(vec_y);
302 this->_precond_l(vec_z, vec_y);
303 filter.filter_cor(vec_z);
307 DataType alpha = gamma / vec_y.dot(vec_z);
311 vec_x.axpy(vec_q, alpha);
315 vec_r.axpy(vec_y, -alpha);
321 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
326 vec_p.axpy(vec_z, -alpha);
329 transp.apply(vec_s, vec_p);
330 filter.filter_def(vec_s);
333 this->_precond_r(vec_t, vec_s);
334 filter.filter_cor(vec_t);
338 DataType gamma2 = gamma;
339 gamma = vec_s.dot(vec_t);
343 DataType beta = gamma / gamma2;
347 vec_q.scale(vec_q, beta);
372 template<
typename Matrix_,
typename Filter_>
374 const Matrix_& matrix,
const Filter_& filter,
int ilu_p = -1)
376 return std::make_shared<PCGNRILU<Matrix_, Filter_>>(matrix, filter, ilu_p);
397 template<
typename Matrix_,
typename Filter_>
400 const Matrix_& matrix,
const Filter_& filter)
402 return std::make_shared<PCGNRILU<Matrix_, Filter_>>(section_name, section, matrix, filter);
#define XASSERT(expr)
Assertion macro definition.
Class for parser related errors.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
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.
ILU(p)-preconditioned Conjugate-Gradient on Normal Equations solver implementation.
PCGNRILU(const String §ion_name, const PropertyMap *section, const MatrixType &matrix, const FilterType &filter)
Constructor using a PropertyMap.
VectorType _vec_r
temporary vectors
MatrixType _transp_matrix
the transposed system matrix
const FilterType & _system_filter
the filter for the solver
Intern::ILUCoreScalar< DataType, IndexType > _ilu
ilu factorization data
void set_fill_in_param(int p)
Sets the fill-in parameter.
const MatrixType & _system_matrix
the matrix for the solver
virtual void init_symbolic() override
Symbolic initialization method.
virtual String name() const override
Returns a descriptive string.
virtual Status _apply_intern(VectorType &vec_x)
virtual void done_symbolic() override
Symbolic finalization method.
PCGNRILU(const MatrixType &matrix, const FilterType &filter, int ilu_p=-1)
Constructor.
virtual ~PCGNRILU()
Empty virtual destructor.
virtual void init_numeric() override
Numeric initialization method.
virtual void init_symbolic()
Symbolic initialization method.
virtual void init_numeric()
Numeric initialization method.
virtual void done_symbolic()
Symbolic finalization method.
String class implementation.
Status
Solver status return codes enumeration.
@ progress
continue iteration (internal use only)
@ undefined
undefined status
std::shared_ptr< PCGNRILU< Matrix_, Filter_ > > new_pcgnrilu(const Matrix_ &matrix, const Filter_ &filter, int ilu_p=-1)
Creates a new PCGNRILU solver object.