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

#include <algorithm>
#include <string>

6
7
#include <dune/common/ftraits.hh>

8
#include <amdis/Output.hpp>
9
10
#include <amdis/linearalgebra/RunnerInterface.hpp>
#include <amdis/linearalgebra/SolverInfo.hpp>
11
12
13
14

namespace AMDiS
{
  /**
15
16
17
18
19
  * \ingroup Solver
  * \class AMDiS::DirectRunner
  * \brief \implements RunnerInterface for the (external) direct solvers
  */
  template <template <class> class Solver, class Mat, class Sol, class Rhs>
20
  class DirectRunner
21
      : public RunnerInterface<Mat, Sol, Rhs>
22
23
  {
  protected:
24
25
26
    using Super = RunnerInterface<Mat, Sol, Rhs>;
    using BaseSolver  = Dune::InverseOperator<Sol, Rhs>;
    using ISTLSolver = Solver<Mat>;
27
28
29

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

    /// Implementes \ref RunnerInterface::init()
35
    void init(Mat const& A) override
36
37
38
39
40
    {
      solver_ = solverCreator_.create(A);
    }

    /// Implementes \ref RunnerInterface::exit()
41
    void exit() override
42
43
44
45
46
    {
      solver_.reset();
    }

    /// Implementes \ref RunnerInterface::solve()
47
48
    int solve(Mat const& A, Sol& x, Rhs const& b,
              SolverInfo& solverInfo) override
49
50
51
52
53
    {
      // storing some statistics
      Dune::InverseOperatorResult statistics;

      // solve the linear system
54
      Rhs _b = b;
55
56
57
58
59
60
61
62
      solver_->apply(x, _b, statistics);

      solverInfo.setRelResidual(statistics.reduction);

      return 0;
    }

  private:
63
    ISTLSolverCreator<Solver<Mat>> solverCreator_;
64
65
66
    std::shared_ptr<BaseSolver> solver_;
  };
}