AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Preconditioner.hpp
1 #pragma once
2 
3 #include <amdis/linearalgebra/mtl/PreconditionerInterface.hpp>
4 
5 namespace AMDiS
6 {
12  template <class Mat, class Vec, template <class> class PreconImpl>
14  : public PreconditionerInterface<Mat, Vec>
15  {
16  using M = typename Mat::BaseMatrix;
17  using X = typename Vec::BaseVector;
18  using Y = typename Vec::BaseVector;
19 
20  using Self = Preconditioner;
22  using Precon = PreconImpl<M>;
23 
24  public:
26  struct Creator : CreatorInterfaceName<Super>
27  {
28  std::unique_ptr<Super> createWithString(std::string) override
29  {
30  return std::make_unique<Self>();
31  }
32  };
33 
34  public:
36  void init(M const& A) override
37  {
38  precon_ = std::make_shared<Precon>(A);
39  }
40 
42  void exit() override
43  {
44  precon_.reset();
45  }
46 
48  void solve(X const& x, Y& y) const override
49  {
50  test_exit_dbg(bool(precon_), "No preconditioner initialized!");
51  precon_->solve(x, y);
52  }
53 
55  void adjoint_solve(X const& x, Y& y) const override
56  {
57  test_exit_dbg(bool(precon_), "No preconditioner initialized!");
58  precon_->adjoint_solve(x, y);
59  }
60 
61  private:
62  std::shared_ptr<Precon> precon_;
63  };
64 
65 } // namespace AMDiS
void solve(X const &x, Y &y) const override
Implementation of PreconditionerInterface::solve()
Definition: Preconditioner.hpp:48
void exit() override
Implementation of PreconditionerInterface::exit()
Definition: Preconditioner.hpp:42
A creator to be used instead of the constructor.
Definition: Preconditioner.hpp:26
void test_exit_dbg(bool condition, Args &&... args)
call assert_msg, in debug mode only
Definition: Output.hpp:205
Interface for creators with name.
Definition: CreatorInterface.hpp:42
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
void adjoint_solve(X const &x, Y &y) const override
Implementation of PreconditionerInterface::adjointSolve()
Definition: Preconditioner.hpp:55
Interface for Preconditioner y = M*x.
Definition: PreconditionerInterface.hpp:9
void init(M const &A) override
Implementation of PreconditionerInterface::init()
Definition: Preconditioner.hpp:36
Wrapper for using ITL preconditioners in AMDiS.
Definition: Preconditioner.hpp:13
std::unique_ptr< Super > createWithString(std::string) override
Must be implemented by sub classes of CreatorInterfaceName. Creates a new instance of the sub class o...
Definition: Preconditioner.hpp:28