AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Solvers.hpp
1 #pragma once
2 
3 #include <memory>
4 
5 #include <dune/common/classname.hh>
6 #include <dune/common/version.hh>
7 
8 #include <dune/common/ftraits.hh>
9 
10 #include <amdis/CreatorMap.hpp>
11 #include <amdis/Output.hpp>
12 
13 #include <amdis/linearalgebra/istl/ISTLSolverCreator.hpp>
14 #include <amdis/linearalgebra/istl/precompiled/Solvers.hpp>
15 
16 namespace AMDiS
17 {
19 
35  template <class Traits>
36  class DefaultCreators<tag::solver<Traits>>
37  {
38  using M = typename Traits::M;
39  using X = typename Traits::X;
40  using Y = typename Traits::Y;
41 
42  using FTraits = Dune::FieldTraits<typename M::field_type>;
43 
44  template <class S>
45  using Creator = ISTLSolverCreator<S,Traits>;
46 
48 
49  public:
50  static void init()
51  {
52  auto cg = new Creator<Dune::CGSolver<X>>;
53  Map::addCreator("cg", cg);
54 
55  // Generalized preconditioned conjugate gradient solver.
56  auto pcg = new Creator<Dune::GeneralizedPCGSolver<X>>;
57  Map::addCreator("pcg", pcg);
58 
59  auto bicgstab = new Creator<Dune::BiCGSTABSolver<X>>;
60  Map::addCreator("bicgstab", bicgstab);
61  Map::addCreator("bcgs", bicgstab);
62  Map::addCreator("default", bicgstab);
63 
64  auto minres = new Creator<Dune::MINRESSolver<X>>;
65  Map::addCreator("minres", minres);
66 
67  auto gmres = new Creator<Dune::RestartedGMResSolver<X,Y>>;
68  Map::addCreator("gmres", gmres);
69 
70  init_direct(std::is_same<typename FTraits::real_type, double>{});
71  }
72 
73  static void init_direct(std::false_type)
74  {
75  warning("Direct solvers not created for the matrix with real_type = {}.",
76  Dune::className<typename FTraits::real_type>());
77  }
78 
79  static void init_direct(std::true_type)
80  {
81 #if HAVE_SUITESPARSE_UMFPACK
82  auto umfpack = new Creator<Dune::UMFPack<M>>;
83  Map::addCreator("umfpack", umfpack);
84 #endif
85 
86 #if HAVE_SUITESPARSE_LDL
87  auto ldl = new Creator<Dune::LDL<M>>;
88  Map::addCreator("ldl", ldl);
89 #endif
90 
91 #if HAVE_SUITESPARSE_SPQR
92  auto spqr = new Creator<Dune::SPQR<M>>;
93  Map::addCreator("spqr", spqr);
94 #endif
95 
96 #if HAVE_SUPERLU
97  auto superlu = new Creator<Dune::SuperLU<M>>;
98  Map::addCreator("superlu", superlu);
99 #endif
100 
101  // default direct solvers
102 #if HAVE_SUITESPARSE_UMFPACK
103  Map::addCreator("direct", umfpack);
104 #elif HAVE_SUPERLU
105  Map::addCreator("direct", superlu);
106 #endif
107  }
108  };
109 
110 
111  // extern template declarations:
113 
114 } // end namespace AMDiS
A CreatorMap is used to construct objects, which types depends on key words determined at run time...
Definition: CreatorMap.hpp:29
Definition: AdaptBase.hpp:6
Definition: CreatorMap.hpp:16