LinearSolverInterface.hpp 1.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once

/** \file LinearSolverInterface.h */

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

14
#include <amdis/common/TypeTraits.hpp>
15

16
17
18
#include <amdis/linearalgebra/PreconditionerInterface.hpp>
#include <amdis/linearalgebra/RunnerInterface.hpp>
#include <amdis/linearalgebra/SolverInfo.hpp>
19

20
namespace AMDiS
21
{
22
  /// Abstract base class for linear solvers
23
  template <class Traits>
24
  class LinearSolverInterface
25
  {
26
  protected:
27
28
29
30
31
    using RunnerBase = RunnerInterface<Traits>;
    using Mat = typename Traits::Mat;
    using Sol = typename Traits::Sol;
    using Rhs = typename Traits::Rhs;
    using Comm = typename Traits::Comm;
32

33
  public:
34
    /// Destructor.
35
    virtual ~LinearSolverInterface() = default;
36

37
38
39
40
    /// 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.
41
     *
42
     * The parameters correspond to
43
44
45
     *  \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.
46
     **/
47
    void solve(Mat const& A, Sol& x, Rhs const& b, Comm& comm, SolverInfo& solverInfo)
48
    {
49
      solveImpl(A, x, b, comm, solverInfo);
50
    }
51

52
    // return the runner/worker corresponding to this solver (optional)
53
    virtual std::shared_ptr<RunnerBase> runner() { return {}; };
54
55
56

  private:
    /// main methods that all solvers must implement
57
    virtual void solveImpl(Mat const& A, Sol& x, Rhs const& b, Comm& comm, SolverInfo& solverInfo) = 0;
58
  };
59
60


61
62
  template <class Matrix, class Vector>
  struct SolverCreator;
63
64

} // end namespace AMDiS