3 #if AMDIS_HAS_HYPRE && HAVE_MPI 7 #include <dune/common/unused.hh> 8 #include <amdis/linearalgebra/mtl/PreconditionerInterface.hpp> 9 #include <amdis/linearalgebra/mtl/itl/hypre.hpp> 55 template <
class Mat,
class Vec>
57 :
public PreconditionerInterface<Mat, Vec>
59 using M =
typename Mat::BaseMatrix;
60 using X =
typename Vec::BaseVector;
61 using Y =
typename Vec::BaseVector;
63 using Self = HyprePrecon;
64 using Super = PreconditionerInterface<Mat, Vec>;
68 struct Creator : CreatorInterfaceName<Super>
70 std::unique_ptr<Super> createWithString(std::string prefix)
override 72 return std::make_unique<Self>(prefix);
77 HyprePrecon(std::string
const& prefix)
80 int maxIter = 1, cycleMode = -1, interpolation = -1, relaxation = -1,
info = 1;
87 config_.maxIter(maxIter);
88 config_.interpolationType(interpolation);
89 config_.relaxType(relaxation);
90 config_.cycle(cycleMode);
91 config_.printLevel(
info);
95 void init(M
const& mat)
override 97 hypreMatrix_.init(mat);
98 HYPRE_IJMatrixGetObject(hypreMatrix_, (
void**)(&matrix_));
99 HYPRE_BoomerAMGCreate(&solver_);
104 mtl::dense_vector<double> swap(1, 0.0);
105 mtl::HypreParVector x(swap);
106 HYPRE_BoomerAMGSetup(solver_, matrix_, x, x);
108 solverCreated_ =
true;
115 HYPRE_BoomerAMGDestroy(solver_);
116 solverCreated_ =
false;
120 void solve(
X const& in, Y& out)
const override 122 assert(solverCreated_);
123 mtl::HypreParVector x(in);
124 mtl::HypreParVector b(in);
126 [[maybe_unused]]
int error = HYPRE_BoomerAMGSolve(solver_, matrix_, b, x);
130 mtl::convert(x.getHypreVector(), out);
134 void adjoint_solve(
X const& in, Y& out)
const override 136 assert(solverCreated_);
137 mtl::HypreParVector x(in);
138 mtl::HypreParVector b(in);
140 [[maybe_unused]]
int error = HYPRE_BoomerAMGSolveT(solver_, matrix_, b, x);
144 mtl::convert(x.getHypreVector(), out);
148 mtl::HypreMatrix hypreMatrix_;
149 HYPRE_ParCSRMatrix matrix_;
150 HYPRE_Solver solver_;
152 mtl::AMGConfigurator config_;
153 bool solverCreated_ =
false;
158 #endif // AMDIS_HAS_HYPRE && HAVE_MPI Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
void info(int noInfoLevel, std::string const &str, Args &&... args)
prints a message, if Environment::infoLevel() >= noInfoLevel
Definition: Output.hpp:105
void init(int &argc, char **&argv, std::string const &initFileName="")
Initialized the Environment for MPI.
Definition: AMDiS.hpp:29
auto X()
Generator for CoordsFunction.
Definition: CoordsGridFunction.hpp:123