BlockPreconditioner.hpp 1.65 KB
Newer Older
1
2
#pragma once

3
4
#include <amdis/AMDiS.hpp>
#include <amdis/LinearAlgebra.hpp>
5

6
namespace AMDiS
7
8
9
{
  /// Basis preconditioner structure for block-preconditioners
  template <class Matrix, class Vector>
10
11
  class BlockPreconditioner
      : public PreconditionerInterface<Matrix, Vector>
12
  {
13
14
15
16
  public:
    using Self = BlockPreconditioner;
    using Super = PreconditionerInterface<Matrix, Vector>;
    using PreconBase = Super;
17

18
  public:
19
    BlockPreconditioner() = default;
20

21
22
23
24
    /// extract iranges from BlockMatrix to be used to extract sub-vectors and sub-matrices.
    virtual void init(Matrix const& A_) override
    {
      A = &A_;
25

26
      A_.getRanges(rows, cols);
27
      initialized = true;
28
    }
29

30
    virtual void solve(Vector const& b, Vector& x) const override
31
32
    {
      error_exit("Must be implemented in derived classes!\n");
33
    }
34

35
    virtual void adjoint_solve(Vector const& x, Vector& y) const override
36
37
    {
      error_exit("Must be implemented in derived classes!\n");
38
    }
39

40
    template <size_t I>
41
    mtl::irange const& getRowRange(const index_t<I> i = {}) const
42
    {
43
44
      test_exit_dbg(initialized,
                    "BlockPreconditioner not initialized. Call init() before.");
45
      return std::get<I>(rows);
46
    }
47

48
    template <size_t I>
49
    mtl::irange const& getColRange(const index_t<I> i = {}) const
50
    {
51
52
      test_exit_dbg(initialized,
                    "BlockPreconditioner not initialized. Call init() before.");
53
      return std::get<I>(cols);
54
55
    }

56
  protected:
57
    Matrix const* A = NULL;
58
    bool initialized = false;
59

60
61
62
    std::array<mtl::irange, Matrix::N()> rows;
    std::array<mtl::irange, Matrix::M()> cols;
  };
63

64
} // end namespace AMDiS