AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
LinearSolver.hpp
1#pragma once
2
3#include <dune/istl/solver.hh>
4
5#include <amdis/linearalgebra/LinearSolverInterface.hpp>
6#include <amdis/linearalgebra/istl/ISTLSolverCreator.hpp>
7#include <amdis/linearalgebra/istl/Preconditioners.hpp>
8#include <amdis/linearalgebra/istl/Solvers.hpp>
9#include <amdis/linearalgebra/istl/Traits.hpp>
10
11namespace AMDiS
12{
14 template <class Mat, class VecX, class VecY = VecX>
15 class LinearSolver
16 : public LinearSolverInterface<Mat,VecX,VecY>
17 {
18 using Traits = SolverTraits<Mat,VecX,VecY>;
19 using Map = CreatorMap<tag::solver<Traits>>;
20 using Creator = ISTLSolverCreatorBase<Traits>;
21
22 public:
23 LinearSolver(std::string const& name, std::string const& prefix)
24 : solverCreator_(dynamic_cast<Creator*>(Map::get(name, prefix)))
25 {
26 assert(solverCreator_ != nullptr);
27 solverCreator_->init(prefix);
28 }
29
30 void init(Mat const& A) override
31 {
32 assert(solverCreator_ != nullptr);
33 solver_ = solverCreator_->createSolver(A.matrix(), A.comm());
34 }
35
36 void finish() override
37 {
38 solver_.reset();
39 }
40
42 void apply(VecX& x, VecY const& b, Dune::InverseOperatorResult& stat) override
43 {
44 assert(!!solver_);
45 auto rhs = b.vector();
46 solver_->apply(x.vector(), rhs, stat);
47 }
48
49 private:
50 ISTLSolverCreatorBase<Traits>* solverCreator_ = nullptr;
51 std::shared_ptr<typename Traits::Solver> solver_;
52 };
53
54} // end namespace AMDiS
Base class for solver creators,.
Definition: ISTLSolverCreator.hpp:56
void apply(VecX &x, VecY const &b, Dune::InverseOperatorResult &stat) override
Implements Dune::InverseOperator::apply()
Definition: LinearSolver.hpp:42
void init(Mat const &A) override
Prepare the solve (and preconditioner), e.g. make a factorization of the matrix, or extract its diago...
Definition: LinearSolver.hpp:30
void finish() override
Cleanup the solver, e.g. free the previously created factorization.
Definition: LinearSolver.hpp:36