AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
LinearSolver.hpp
1 #pragma once
2 
3 #include <string>
4 
5 #include <dune/common/timer.hh>
6 
7 // AMDiS includes
8 #include <amdis/CreatorInterface.hpp>
9 #include <amdis/Output.hpp>
10 #include <amdis/linearalgebra/LinearSolverInterface.hpp>
11 #include <amdis/linearalgebra/SolverInfo.hpp>
12 
13 namespace AMDiS
14 {
24  template <class Mat, class Vec, class Runner>
26  : public LinearSolverInterface<Mat,Vec>
27  {
28  using Self = LinearSolver;
30 
31  public:
33  struct Creator : CreatorInterfaceName<Super>
34  {
35  std::unique_ptr<Super> createWithString(std::string prefix) override
36  {
37  return std::make_unique<Self>(prefix);
38  }
39  };
40 
41  public:
43  template <class... Args>
44  explicit LinearSolver(std::string prefix, Args&&... args)
45  : runner_(prefix, FWD(args)...)
46  {}
47 
48  Runner* runner() override
49  {
50  return &runner_;
51  }
52 
53  protected:
55  void solveImpl(Mat const& A, Vec& x, Vec const& b, SolverInfo& solverInfo) override
56  {
57  Dune::Timer t;
58  if (solverInfo.doCreateMatrixData()) {
59  // init matrix or wrap block-matrix or ...
60  runner_.init(A.matrix());
61  }
62 
63  if (solverInfo.info() > 0)
64  msg("prepare solver needed {} seconds", t.elapsed());
65 
66  int error = runner_.solve(A.matrix(), x.vector(), b.vector(), solverInfo);
67  solverInfo.setError(error);
68 
69  if (!solverInfo.doStoreMatrixData())
70  runner_.exit();
71  }
72 
73  private:
75  Runner runner_;
76  };
77 
78 } // end namespace AMDiS
A creator to be used instead of the constructor.
Definition: LinearSolver.hpp:33
bool doCreateMatrixData() const
Returns createMatrixData.
Definition: SolverInfo.hpp:56
Interface for creators with name.
Definition: CreatorInterface.hpp:42
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
int info() const
Returns info.
Definition: SolverInfo.hpp:38
void msg(std::string const &str, Args &&... args)
print a message
Definition: Output.hpp:98
Abstract base class for linear solvers.
Definition: LinearSolverInterface.hpp:27
Wrapper class for various solvers. These solvers are parametrized by MatrixType and VectorType...
Definition: LinearSolver.hpp:25
bool doStoreMatrixData() const
Returns storeMatrixData.
Definition: SolverInfo.hpp:62
LinearSolver(std::string prefix, Args &&... args)
Constructor.
Definition: LinearSolver.hpp:44
void setError(int e)
Sets error_.
Definition: SolverInfo.hpp:98
void solveImpl(Mat const &A, Vec &x, Vec const &b, SolverInfo &solverInfo) override
Implements LinearSolverInterface::solveImpl()
Definition: LinearSolver.hpp:55
std::unique_ptr< Super > createWithString(std::string prefix) override
Must be implemented by sub classes of CreatorInterfaceName. Creates a new instance of the sub class o...
Definition: LinearSolver.hpp:35
Definition: SolverInfo.hpp:11