Preconditioner.hpp 1.57 KB
Newer Older
1
2
3
4
/** \file ITL_Preconditioner.h */

#pragma once

5
#include <amdis/linear_algebra/PreconditionerInterface.hpp>
6
7

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

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

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  public:
    /// Implementation of \ref PreconditionerBase::init()
    virtual void init(Matrix const& fullMatrix) override
    {
      precon.reset(new PreconRunner(fullMatrix));
    }

    /// Implementation of \ref PreconditionerInterface::exit()
    virtual void exit() override
    {
      precon.reset();
    }

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

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

  private:
58
    std::shared_ptr<PreconRunner> precon;
59
60
61
  };

} // namespace AMDiS