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

3
#include <amdis/linearalgebra/PreconditionerInterface.hpp>
4
5

namespace AMDiS
6
{
7
8
9
10
11
12
  /**
   * \ingroup Solver
   *
   * \brief Wrapper for using ITL preconditioners in AMDiS.
   */
  template <class Matrix, class Vector, class PreconRunner>
13
14
  class Preconditioner
      : public PreconditionerInterface<Matrix, Vector>
15
  {
16
17
    using Self = Preconditioner;
    using Super = PreconditionerInterface<Matrix, Vector>;
18

19
20
21
22
  public:
    /// A creator to be used instead of the constructor.
    struct Creator : CreatorInterface<Super>
    {
23
      std::unique_ptr<Super> create() override
24
      {
25
        return std::make_unique<Self>();
26
27
      }
    };
28

29
30
  public:
    /// Implementation of \ref PreconditionerBase::init()
31
    void init(Matrix const& fullMatrix) override
32
    {
33
      precon_.reset(new PreconRunner(fullMatrix));
34
35
36
    }

    /// Implementation of \ref PreconditionerInterface::exit()
37
    void exit() override
38
    {
39
      precon_.reset();
40
41
42
    }

    /// Implementation of \ref PreconditionerBase::solve()
43
    void solve(Vector const& vin, Vector& vout) const override
44
    {
45
46
      test_exit_dbg(bool(precon_), "No preconditioner initialized!");
      precon_->solve(vin, vout);
47
48
49
    }

    /// Implementation of \ref PreconditionerBase::adjoint_solve()
50
    void adjoint_solve(Vector const& vin, Vector& vout) const override
51
    {
52
53
      test_exit_dbg(bool(precon_), "No preconditioner initialized!");
      precon_->adjoint_solve(vin, vout);
54
55
56
    }

  private:
57
    std::shared_ptr<PreconRunner> precon_;
58
59
60
  };

} // namespace AMDiS