DirectRunner.hpp 1.49 KB
Newer Older
1
2
3
4
5
6
#pragma once

#include <algorithm>
#include <string>

#include <amdis/Output.hpp>
7
8
#include <amdis/linearalgebra/RunnerInterface.hpp>
#include <amdis/linearalgebra/SolverInfo.hpp>
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

namespace AMDiS
{
  /**
   * \ingroup Solver
   * \class AMDiS::DirectRunner
   * \brief \implements RunnerInterface for the (external) direct solvers
   */
  template <class Solver, class Matrix, class VectorX, class VectorB>
  class DirectRunner
      : public RunnerInterface<Matrix, VectorX, VectorB>
  {
  protected:
    using Super = RunnerInterface<Matrix, VectorX, VectorB>;
    using BaseSolver  = Dune::InverseOperator<VectorX, VectorB>;

  public:
    /// Constructor.
Praetorius, Simon's avatar
Praetorius, Simon committed
27
    DirectRunner(std::string const& prefix)
28
29
30
31
      : solverCreator_(prefix)
    {}

    /// Implementes \ref RunnerInterface::init()
32
    void init(Matrix const& A) override
33
34
35
36
37
    {
      solver_ = solverCreator_.create(A);
    }

    /// Implementes \ref RunnerInterface::exit()
38
    void exit() override
39
40
41
42
43
    {
      solver_.reset();
    }

    /// Implementes \ref RunnerInterface::solve()
44
    int solve(Matrix const& A, VectorX& x, VectorB const& b,
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                      SolverInfo& solverInfo) override
    {
      // storing some statistics
      Dune::InverseOperatorResult statistics;

      // solve the linear system
      VectorB _b = b;
      solver_->apply(x, _b, statistics);

      solverInfo.setRelResidual(statistics.reduction);

      return 0;
    }

  private:
    ISTLSolverCreator<Solver> solverCreator_;
    std::shared_ptr<BaseSolver> solver_;
  };
}