3#if AMDIS_HAS_HYPRE && HAVE_MPI
7#include <amdis/Initfile.hpp>
8#include <amdis/linearalgebra/mtl/PreconditionerInterface.hpp>
9#include <amdis/linearalgebra/mtl/itl/hypre.hpp>
55 template <
class M,
class X,
class Y>
57 :
public PreconditionerInterface<M,X,Y>
59 using Self = HyprePrecon;
60 using Super = PreconditionerInterface<M,X,Y>;
64 struct Creator : CreatorInterfaceName<Super>
66 std::unique_ptr<Super> createWithString(std::string prefix)
override
68 return std::make_unique<Self>(prefix);
73 HyprePrecon(std::string
const& prefix)
76 int maxIter = 1, cycleMode = -1, interpolation = -1, relaxation = -1, info = 1;
83 config_.maxIter(maxIter);
84 config_.interpolationType(interpolation);
85 config_.relaxType(relaxation);
86 config_.cycle(cycleMode);
87 config_.printLevel(info);
91 void init(M
const& mat)
override
93 hypreMatrix_.init(mat);
94 HYPRE_IJMatrixGetObject(hypreMatrix_, (
void**)(&matrix_));
95 HYPRE_BoomerAMGCreate(&solver_);
100 mtl::dense_vector<double> swap(1, 0.0);
101 mtl::HypreParVector x(swap);
102 HYPRE_BoomerAMGSetup(solver_, matrix_, x, x);
104 solverCreated_ =
true;
108 void finish()
override
111 HYPRE_BoomerAMGDestroy(solver_);
112 solverCreated_ =
false;
116 void solve(X
const& in, Y& out)
const override
118 assert(solverCreated_);
119 mtl::HypreParVector x(in);
120 mtl::HypreParVector b(in);
122 [[maybe_unused]]
int error = HYPRE_BoomerAMGSolve(solver_, matrix_, b, x);
126 mtl::convert(x.getHypreVector(), out);
130 void adjoint_solve(X
const& in, Y& out)
const override
132 assert(solverCreated_);
133 mtl::HypreParVector x(in);
134 mtl::HypreParVector b(in);
136 [[maybe_unused]]
int error = HYPRE_BoomerAMGSolveT(solver_, matrix_, b, x);
140 mtl::convert(x.getHypreVector(), out);
144 mtl::HypreMatrix hypreMatrix_;
145 HYPRE_ParCSRMatrix matrix_;
146 HYPRE_Solver solver_;
148 mtl::AMGConfigurator config_;
149 bool solverCreated_ =
false;
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25