6#include <amdis/Initfile.hpp>
7#include <amdis/linearalgebra/LinearSolverInterface.hpp>
8#include <amdis/linearalgebra/petsc/Interface.hpp>
9#include <amdis/linearalgebra/petsc/SolverConfig.hpp>
39 template <
class Matrix,
class VectorX,
class VectorY = VectorX>
41 :
public LinearSolverInterface<Matrix,VectorX,VectorY>
43 using Vector = VectorX;
67 void init(Matrix
const& A)
override
70 KSPCreate(A.comm(), &ksp_);
72 PETSc::KSPSetOperators(ksp_, A.matrix(), A.matrix());
73 initKSP(ksp_, prefix_);
86 void apply(VectorX& x, VectorY
const& b, Dune::InverseOperatorResult& stat)
override
88 KSPSolve(ksp_, b.vector(), x.vector());
91 PETSc::KSPConvergedReasonView(ksp_, PETSC_VIEWER_STDOUT_WORLD);
93 KSPConvergedReason reason;
94 KSPGetConvergedReason(ksp_, &reason);
96 stat.converged = (reason > 0);
99 KSP ksp() {
return ksp_; }
103 virtual void initKSP(KSP ksp, std::string prefix)
const
105 PETSc::configKSP(ksp, prefix);
109 KSPView(ksp, PETSC_VIEWER_STDOUT_WORLD);
117 bool initialized_ =
false;
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
Implementation of LinearSolverInterface for EIGEN solvers.
Definition: LinearSolver.hpp:16
void init(Matrix const &A) override
Implements LinearSolverInterface::init()
Definition: LinearSolver.hpp:67
void finish() override
Implements LinearSolverInterface::finish()
Definition: LinearSolver.hpp:35
void apply(VectorX &x, VectorY const &b, Dune::InverseOperatorResult &stat) override
Implements LinearSolverInterface::apply()
Definition: LinearSolver.hpp:86
LinearSolver(std::string const &, std::string const &prefix)
Constructor.
Definition: LinearSolver.hpp:55