AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
DirectRunner.hpp
1#pragma once
2
3#include <memory>
4#include <string>
5
6#include <amdis/CreatorInterface.hpp>
7#include <amdis/Initfile.hpp>
8#include <amdis/linearalgebra/LinearSolverInterface.hpp>
9#include <amdis/linearalgebra/eigen/SolverConfig.hpp>
10
11namespace AMDiS
12{
18 template <class M, class X, class Y, template <class> class Solver>
20 : public LinearSolverInterface<M,X,Y>
21 {
22 using Self = DirectRunner;
23 using EigenSolver = Solver<M>;
24
25 public:
26 struct Creator final : CreatorInterfaceName<LinearSolverInterface<M,X,Y>>
27 {
28 std::unique_ptr<LinearSolverInterface<M,X,Y>>
29 createWithString(std::string prefix) final
30 {
31 return std::make_unique<Self>(prefix);
32 }
33 };
34
35 public:
37 DirectRunner(std::string const& prefix)
38 : solver_{}
39 {
40 SolverConfig<EigenSolver>::init(prefix, solver_);
41 Parameters::get(prefix + "->reuse pattern", reusePattern_);
42 }
43
45 void init(M const& A) override
46 {
47 if (!reusePattern_ || !initialized_) {
48 solver_.analyzePattern(A);
49 initialized_ = true;
50 }
51 solver_.factorize(A);
52
53 test_exit(solver_.info() == Eigen::Success, "Error in solver.compute(matrix)");
54 }
55
57 void finish() override
58 {
59 initialized_ = false;
60 }
61
63 void apply(X& x, Y const& b, Dune::InverseOperatorResult& stat) override
64 {
65 Dune::Timer t;
66 x = solver_.solve(b);
67
68 stat.converged = (solver_.info() == Eigen::Success);
69 stat.elapsed = t.elapsed();
70 }
71
72 private:
73 EigenSolver solver_;
74 bool reusePattern_ = false;
75 bool initialized_ = false;
76 };
77
78} // end namespace AMDiS
Interface for creators with name.
Definition: CreatorInterface.hpp:44
for the (external) direct solvers
Definition: DirectRunner.hpp:21
void init(M const &A) override
initialize the matrix and maybe compute factorization
Definition: DirectRunner.hpp:45
DirectRunner(std::string const &prefix)
Constructor.
Definition: DirectRunner.hpp:37
void apply(X &x, Y const &b, Dune::InverseOperatorResult &stat) override
Implements LinearSolverInterface::apply()
Definition: DirectRunner.hpp:63
void finish() override
Implements LinearSolverInterface::finish()
Definition: DirectRunner.hpp:57
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
Definition: LinearSolverInterface.hpp:9
Definition: DirectRunner.hpp:27
std::unique_ptr< LinearSolverInterface< M, X, Y > > createWithString(std::string prefix) final
Must be implemented by sub classes of CreatorInterfaceName. Creates a new instance of the sub class o...
Definition: DirectRunner.hpp:29
Definition: SolverConfig.hpp:14