10#include <kernel/solver/adp_solver_base.hpp>
12#if defined(FEAT_HAVE_HYPRE) || defined(DOXYGEN)
25 typedef double HypreDataType;
28#ifdef FEAT_TPL_HYPRE_INT64
29 typedef long long HypreIndexType;
31 typedef int HypreIndexType;
57 void* create_core(
const void* comm, Index dof_offset, Index num_owned_dofs, Index num_nonzeros);
59 void destroy_core(
void* core);
61 HypreIndexType* get_row_ptr(
void* core);
62 HypreIndexType* get_col_idx(
void* core);
63 HypreDataType* get_mat_val(
void* core);
65 HypreDataType* get_vec_def(
void* core);
66 HypreDataType* get_vec_cor(
void* core);
68 void upload_symbolic(
void* core);
69 void upload_mat_val(
void* core);
70 void upload_vec_def(
void* core);
71 void download_vec_cor(
void* core);
72 void format_vec_cor(
void* core);
75 void* create_parasails(
void* core,
int* iparam,
double* dparam);
76 void destroy_parasails(
void* solver);
77 void solve_parasails(
void* core,
void* solver);
80 void* create_euclid(
void* core,
int* iparam,
double* dparam);
81 void destroy_euclid(
void* solver);
82 void solve_euclid(
void* core,
void* solver);
85 void* create_boomeramg(
void* core,
int* iparam,
double* dparam);
86 void destroy_boomeramg(
void* solver);
87 void solve_boomeramg(
void* core,
void* solver);
104 template<
typename Matrix_,
typename Filter_,
typename SolverBase_ = Solver::SolverBase<
typename Matrix_::VectorTypeL>>
118 explicit HypreSolverBase(
const Matrix_& matrix,
const Filter_& filter) :
135 this->
_upload_vector(Hypre::get_vec_def(this->_core), vec_def.local());
136 Hypre::upload_vec_def(this->_core);
150 Hypre::download_vec_cor(this->_core);
160 Hypre::format_vec_cor(this->_core);
177 XASSERT(this->_core ==
nullptr);
180 this->_core = Hypre::create_core(
193 Hypre::upload_symbolic(this->_core);
206 XASSERT(this->_core !=
nullptr);
210 Hypre::get_row_ptr(this->_core), Hypre::get_col_idx(this->_core));
212 Hypre::upload_mat_val(this->_core);
223 XASSERT(this->_core !=
nullptr);
225 Hypre::destroy_core(this->_core);
226 this->_core =
nullptr;
243 template<
typename Matrix_,
typename Filter_>
280 const Matrix_& matrix,
const Filter_& filter)
284 auto level_p = section->
query(
"level");
285 if(level_p.second && !level_p.first.parse(
_iparam[0]))
286 throw ParseError(section_name +
".level", level_p.first,
"a non-negative integer");
288 auto sym_p = section->
query(
"sym");
289 if(sym_p.second && !sym_p.first.parse(
_iparam[1]))
290 throw ParseError(section_name +
".sym", sym_p.first,
"a non-negative integer");
292 auto thresh_p = section->
query(
"thresh");
293 if(thresh_p.second && !thresh_p.first.parse(
_dparam[0]))
294 throw ParseError(section_name +
".thresh", thresh_p.first,
"a positive float");
296 auto filter_p = section->
query(
"filter");
297 if(filter_p.second && !filter_p.first.parse(
_dparam[1]))
298 throw ParseError(section_name +
".filter", filter_p.first,
"a positive float");
303 return "ParaSailsPrecond";
311 this->_solver = Hypre::create_parasails(this->
_core, this->_iparam, this->_dparam);
318 Hypre::destroy_parasails(
_solver);
332 Hypre::solve_parasails(this->
_core, this->_solver);
354 template<
typename Matrix_,
typename Filter_>
356 const Matrix_& matrix,
const Filter_& filter)
358 return std::make_shared<ParaSailsPrecond<Matrix_, Filter_>>(matrix, filter);
379 template<
typename Matrix_,
typename Filter_>
382 const Matrix_& matrix,
const Filter_& filter)
384 return std::make_shared<ParaSailsPrecond<Matrix_, Filter_>>(section_name, section, matrix, filter);
398 template<
typename Matrix_,
typename Filter_>
421 explicit EuclidPrecond(
const Matrix_& matrix,
const Filter_& filter) :
430 const Matrix_& matrix,
const Filter_& filter)
434 auto level_p = section->
query(
"level");
435 if(level_p.second && !level_p.first.parse(
_iparam[0]))
436 throw ParseError(section_name +
".level", level_p.first,
"a non-negative integer");
438 auto drop_p = section->
query(
"drop");
439 if(drop_p.second && !drop_p.first.parse(
_dparam[0]))
440 throw ParseError(section_name +
".drop", drop_p.first,
"a non-negative float");
445 return "EuclidPrecond";
453 this->_solver = Hypre::create_euclid(this->
_core, this->_iparam, this->_dparam);
460 Hypre::destroy_euclid(
_solver);
472 Hypre::solve_euclid(this->
_core, this->_solver);
494 template<
typename Matrix_,
typename Filter_>
496 const Matrix_& matrix,
const Filter_& filter)
498 return std::make_shared<EuclidPrecond<Matrix_, Filter_>>(matrix, filter);
519 template<
typename Matrix_,
typename Filter_>
522 const Matrix_& matrix,
const Filter_& filter)
524 return std::make_shared<EuclidPrecond<Matrix_, Filter_>>(section_name, section, matrix, filter);
536 template<
typename Matrix_,
typename Filter_>
559 explicit BoomerAMG(
const Matrix_& matrix,
const Filter_& filter) :
570 const Matrix_& matrix,
const Filter_& filter)
587 this->_solver = Hypre::create_boomeramg(this->
_core, this->_iparam, this->_dparam);
594 Hypre::destroy_boomeramg(
_solver);
606 Hypre::solve_boomeramg(this->
_core, this->_solver);
628 template<
typename Matrix_,
typename Filter_>
630 const Matrix_& matrix,
const Filter_& filter)
632 return std::make_shared<BoomerAMG<Matrix_, Filter_>>(matrix, filter);
653 template<
typename Matrix_,
typename Filter_>
656 const Matrix_& matrix,
const Filter_& filter)
658 return std::make_shared<BoomerAMG<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.
Base-Class for solvers based on Algebraic-DOF-Partitioning.
const Dist::Comm * _get_comm() const
const FilterType & _system_filter
the system filter
void _upload_symbolic(RPT_ *row_ptr, CIT_ *col_idx)
Uploads the ADP matrix structure to the given arrays.
Index _get_num_owned_dofs() const
Index _get_global_dof_offset() const
void _download_vector(LocalVectorType &vector, const DTV_ *val)
Downloads the ADP vector values from the given array.
void _upload_vector(DTV_ *val, const LocalVectorType &vector)
Uploads the ADP vector values to the given array.
MatrixType::VectorTypeL VectorType
the (local) vector type
Index _get_adp_matrix_num_nzes() const
void _upload_numeric(DTV_ *val, const RPT_ *row_ptr, const CIT_ *col_idx)
Uploads the (filtered) ADP matrix values to the given array.
HYPRE BoomerAMGWrapper class template.
BoomerAMG(const String §ion_name, const PropertyMap *section, const Matrix_ &matrix, const Filter_ &filter)
virtual void init_numeric() override
Numeric Initialization.
void * _solver
the HYPRE solver object
virtual void done_numeric() override
Numeric finalization method.
virtual String name() const override
Returns a descriptive string.
BaseClass::VectorType VectorType
the vector type
HypreSolverBase< Matrix_, Filter_ > BaseClass
our base-class
HYPRE Euclid Preconditioner Wrapper class template.
void * _solver
the HYPRE solver object
virtual void done_numeric() override
Numeric finalization method.
BaseClass::VectorType VectorType
the vector type
int _iparam[1]
integer parameters:
double _dparam[1]
double parameters:
virtual void init_numeric() override
Numeric Initialization.
virtual String name() const override
Returns a descriptive string.
HypreSolverBase< Matrix_, Filter_ > BaseClass
our base-class
Base-Class for solvers/preconditioners borrowed from HYPRE library.
ADPSolverBase< Matrix_, Filter_, SolverBase_ > BaseClass
our base-class
virtual void init_numeric() override
Numeric Initialization.
void _download_cor(VectorType &vec_cor)
Downloads the HYPRE correction vector.
virtual void done_symbolic() override
Symbolic Finalization.
void * _core
a pointer to our opaque core wrapper object
virtual void init_symbolic() override
Symbolic Initialization.
void _upload_def(const VectorType &vec_def)
Uploads the HYPRE defect vector.
void _format_cor()
Formats the HYPRE correction vector to zero.
HYPRE ParaSails Preconditioner Wrapper class template.
int _iparam[2]
integer parameters:
void * _solver
the HYPRE solver object
virtual void done_numeric() override
Numeric finalization method.
double _dparam[2]
double parameters:
BaseClass::VectorType VectorType
the vector type
HypreSolverBase< Matrix_, Filter_ > BaseClass
our base-class
virtual String name() const override
Returns a descriptive string.
virtual void init_numeric() override
Numeric Initialization.
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.
std::shared_ptr< EuclidPrecond< Matrix_, Filter_ > > new_euclid_precond(const Matrix_ &matrix, const Filter_ &filter)
Creates a new EuclidPrecond solver object.
std::shared_ptr< BoomerAMG< Matrix_, Filter_ > > new_boomeramg(const Matrix_ &matrix, const Filter_ &filter)
Creates a new BoomerAMG solver object.
std::shared_ptr< ParaSailsPrecond< Matrix_, Filter_ > > new_parasails_precond(const Matrix_ &matrix, const Filter_ &filter)
Creates a new ParaSailsPrecond solver object.
Status
Solver status return codes enumeration.
@ success
solving successful (convergence criterion fulfilled)