Preconditioner.hpp 1.63 KB
Newer Older
1
2
#pragma once

Praetorius, Simon's avatar
Praetorius, Simon committed
3
#include <amdis/linearalgebra/mtl/PreconditionerInterface.hpp>
4
5

namespace AMDiS
6
{
7
8
9
10
11
  /**
   * \ingroup Solver
   *
   * \brief Wrapper for using ITL preconditioners in AMDiS.
   */
Praetorius, Simon's avatar
Praetorius, Simon committed
12
  template <class Mat, class Vec, template <class> class PreconImpl>
13
  class Preconditioner
Praetorius, Simon's avatar
Praetorius, Simon committed
14
      : public PreconditionerInterface<Mat, Vec>
15
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
16
17
18
19
    using M = typename Mat::BaseMatrix;
    using X = typename Vec::BaseVector;
    using Y = typename Vec::BaseVector;

20
    using Self = Preconditioner;
Praetorius, Simon's avatar
Praetorius, Simon committed
21
22
    using Super = PreconditionerInterface<Mat, Vec>;
    using Precon = PreconImpl<M>;
23

24
25
  public:
    /// A creator to be used instead of the constructor.
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:
Praetorius, Simon's avatar
Praetorius, Simon committed
35
36
    /// Implementation of \ref PreconditionerInterface::init()
    void init(M const& A) override
37
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
38
      precon_ = std::make_shared<Precon>(A);
39
40
41
    }

    /// Implementation of \ref PreconditionerInterface::exit()
42
    void exit() override
43
    {
44
      precon_.reset();
45
46
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
47
48
    /// Implementation of \ref PreconditionerInterface::solve()
    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
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
54
55
    /// Implementation of \ref PreconditionerInterface::adjointSolve()
    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:
Praetorius, Simon's avatar
Praetorius, Simon committed
62
    std::shared_ptr<Precon> precon_;
63
64
65
  };

} // namespace AMDiS