LinearSolverInterface.hpp 1.7 KB
Newer Older
1
2
#pragma once

Praetorius, Simon's avatar
Praetorius, Simon committed
3
4
#include <amdis/Output.hpp>
#include <amdis/linearalgebra/RunnerInterface.hpp>
5
6
7
8
9
10
11
12
13
14

/**
 * \defgroup Solver Solver module
 * @{ <img src="solver.png"> @}
 *
 * \brief
 * Contains all classes needed for solving linear and non linear equation
 * systems.
 */

15
namespace AMDiS
16
{
17
18
  class SolverInfo;

Praetorius, Simon's avatar
Praetorius, Simon committed
19
20
21
22
23
24
  template <class T, template <class> class MatrixImpl>
  class MatrixFacade;

  template <class T, template <class> class VectorImpl>
  class VectorFacade;

25
  /// Abstract base class for linear solvers
Praetorius, Simon's avatar
Praetorius, Simon committed
26
  template <class Mat, class Vec>
27
  class LinearSolverInterface
28
  {
29
  public:
30
    /// Destructor.
31
    virtual ~LinearSolverInterface() = default;
32

33
34
35
36
    /// Public method to call in order to solve a linear system Ax = b.
    /**
     * The method redirects to the specific linear solver and prints statistics
     * and error estimations at the end.
37
     *
38
     * The parameters correspond to
39
40
41
     *  \p A     A [block-]matrix that represents the system-matrix.
     *  \p x     A [block-]vector for the unknown components.
     *  \p b     A [block-]vector for the right-hand side of the linear system.
42
     **/
Praetorius, Simon's avatar
Praetorius, Simon committed
43
44
    template <class TA, class TX, class TY, template <class> class MI, template <class> class VI>
    void solve(MatrixFacade<TA,MI> const& A, VectorFacade<TX,VI>& x, VectorFacade<TY,VI> const& b, SolverInfo& solverInfo)
45
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
46
      solveImpl(A.impl(), x.impl(), b.impl(), solverInfo);
47
    }
48

Praetorius, Simon's avatar
Praetorius, Simon committed
49
50
51
52
53
54
55
    virtual RunnerInterface<Mat,Vec>* runner()
    {
      error_exit("Must be implemented by derived class.");
      return nullptr;
    }

  protected:
56
    /// main methods that all solvers must implement
Praetorius, Simon's avatar
Praetorius, Simon committed
57
    virtual void solveImpl(Mat const& A, Vec& x, Vec const& b, SolverInfo& solverInfo) = 0;
58
  };
59

60
} // end namespace AMDiS