AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
SolverWrapper.hpp
1 #pragma once
2 
3 #include <memory>
4 #include <utility>
5 
6 #include <dune/common/shared_ptr.hh>
7 #include <dune/istl/operators.hh>
8 #include <dune/istl/preconditioner.hh>
9 #include <dune/istl/scalarproducts.hh>
10 #include <dune/istl/solver.hh>
11 #include <dune/istl/solvercategory.hh>
12 
13 #include <amdis/common/TypeTraits.hpp>
14 
15 namespace AMDiS
16 {
19  template <class S>
21  : public Dune::InverseOperator<typename S::domain_type, typename S::range_type>
22  {
23  using Solver = S;
24 
25  public:
26  using domain_type = typename S::domain_type;
27  using range_type = typename S::range_type;
28 
29  using LinOp = Dune::LinearOperator<domain_type,range_type>;
30  using Prec = Dune::Preconditioner<domain_type,range_type>;
31  using ScalProd = Dune::ScalarProduct<domain_type>;
32 
33  public:
34  template <class... Args>
35  IterativeSolverWrapper(LinOp& linOp, Prec& prec, Args&&... args)
36  : linOp_(Dune::stackobject_to_shared_ptr(linOp))
37  , prec_(Dune::stackobject_to_shared_ptr(prec))
38  , solver_(*linOp_, *prec_, FWD(args)...)
39  {}
40 
41  template <class... Args>
42  IterativeSolverWrapper(std::shared_ptr<LinOp> linOp, std::shared_ptr<Prec> prec, Args&&... args)
43  : linOp_(std::move(linOp))
44  , prec_(std::move(prec))
45  , solver_(*linOp_, *prec_, FWD(args)...)
46  {}
47 
48  template <class... Args>
49  IterativeSolverWrapper(LinOp& linOp, ScalProd& sp, Prec& prec, Args&&... args)
50  : linOp_(Dune::stackobject_to_shared_ptr(linOp))
51  , sp_(Dune::stackobject_to_shared_ptr(sp))
52  , prec_(Dune::stackobject_to_shared_ptr(prec))
53  , solver_(*linOp_, *sp_, *prec_, FWD(args)...)
54  {}
55 
56  template <class... Args>
57  IterativeSolverWrapper(std::shared_ptr<LinOp> linOp, std::shared_ptr<ScalProd> sp, std::shared_ptr<Prec> prec, Args&&... args)
58  : linOp_(std::move(linOp))
59  , sp_(std::move(sp))
60  , prec_(std::move(prec))
61  , solver_(*linOp_, *sp_, *prec_, FWD(args)...)
62  {}
63 
65  void apply(domain_type& x, range_type& b, Dune::InverseOperatorResult& res) override
66  {
67  solver_.apply(x, b, res);
68  }
69 
71  void apply(domain_type& x, range_type& b, double reduction, Dune::InverseOperatorResult& res) override
72  {
73  solver_.apply(x, b, reduction, res);
74  }
75 
77  Dune::SolverCategory::Category category() const override
78  {
79  return solver_.category();
80  }
81 
82  private:
83  std::shared_ptr<LinOp> linOp_;
84  std::shared_ptr<ScalProd> sp_;
85  std::shared_ptr<Prec> prec_;
86 
87  Solver solver_;
88  };
89 
90 } // end namespace AMDiS
Definition: SolverWrapper.hpp:20
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Dune::SolverCategory::Category category() const override
Category of the solver.
Definition: SolverWrapper.hpp:77
void apply(domain_type &x, range_type &b, Dune::InverseOperatorResult &res) override
Apply inverse operator.
Definition: SolverWrapper.hpp:65
void apply(domain_type &x, range_type &b, double reduction, Dune::InverseOperatorResult &res) override
Apply inverse operator with given reduction factor.
Definition: SolverWrapper.hpp:71