AMDiS  2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Preconditioners.hpp
1 #pragma once
2 
3 #include <type_traits>
4 
5 #include <amdis/CreatorInterface.hpp>
6 #include <amdis/CreatorMap.hpp>
7 #include <amdis/common/TypeTraits.hpp>
8 #include <amdis/linearalgebra/istl/AMGPrecon.hpp>
9 #include <amdis/linearalgebra/istl/ISTLPreconCreator.hpp>
10 #include <amdis/linearalgebra/istl/precompiled/Preconditioners.hpp>
11 
12 namespace AMDiS
13 {
15 
29  template <class Traits>
30  class DefaultCreators<tag::preconditioner<Traits>>
31  {
32  using M = typename Traits::M;
33  using X = typename Traits::X;
34  using Y = typename Traits::Y;
35 
36  template <class Precon>
38 
40  using FTraits = Dune::FieldTraits<typename M::field_type>;
41 
42  public:
43  static void init()
44  {
45  auto jacobi = new Creator<Dune::SeqJac<M,X,Y>>;
46  Map::addCreator("diag", jacobi);
47  Map::addCreator("jacobi", jacobi);
48 
49  auto gs = new Creator<Dune::SeqGS<M,X,Y>>;
50  Map::addCreator("gs", gs);
51  Map::addCreator("gauss_seidel", gs);
52 
53  auto sor = new Creator<Dune::SeqSOR<M,X,Y>>;
54  Map::addCreator("sor", sor);
55 
56  auto ssor = new Creator<Dune::SeqSSOR<M,X,Y>>;
57  Map::addCreator("ssor", ssor);
58 
59  init_ilu(std::is_arithmetic<typename FTraits::field_type>{});
60  init_amg(std::is_same<typename FTraits::real_type, double>{});
61 
62  auto richardson = new Creator<Dune::Richardson<X,Y>>;
63  Map::addCreator("richardson", richardson);
64  Map::addCreator("default", richardson);
65 
66  auto solver = new Creator<tag::solver<Traits>>;
67  Map::addCreator("solver", solver);
68 
69  init_bjacobi(Types<TYPEOF(std::declval<typename Traits::Comm>().impl())>{}, Dune::PriorityTag<10>{});
70  }
71 
72  static void init_ilu(std::false_type)
73  {
74  warning("ILU preconditioners not created for the matrix with field_type = {}.",
75  Dune::className<typename FTraits::field_type>());
76  }
77 
78  static void init_ilu(std::true_type)
79  {
80  auto ilu = new Creator<Dune::SeqILU<M,X,Y>>;
81  Map::addCreator("ilu", ilu);
82  Map::addCreator("ilu0", ilu);
83 
84  auto ildl = new Creator<Dune::SeqILDL<M,X,Y>>;
85  Map::addCreator("ildl", ildl);
86  }
87 
88  static void init_amg(std::false_type)
89  {
90  warning("AMG preconditioners not created for the matrix with real_type = {}.",
91  Dune::className<typename FTraits::real_type>());
92  }
93 
94  static void init_amg(std::true_type)
95  {
97  Map::addCreator("amg", amg);
99  Map::addCreator("fastamg", fastamg);
101  Map::addCreator("kamg", kamg);
102  }
103 
104  static void init_bjacobi(Types<Dune::Amg::SequentialInformation>, Dune::PriorityTag<2>) {}
105 
106  template <class Comm>
107  static void init_bjacobi(Types<Comm>, Dune::PriorityTag<1>)
108  {
109  auto pssor = new Creator<Dune::ParSSOR<M,X,Y,Comm>>;
110  Map::addCreator("pssor", pssor);
111 
112  auto bjacobi = new Creator<tag::bjacobi>;
113  Map::addCreator("bjacobi", bjacobi);
114  }
115  };
116 
117  // extern template declarations:
119 
120 } // end namespace AMDiS
A variadic type list.
Definition: TypeTraits.hpp:146
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
Definition: AMGPrecon.hpp:186
Default precon creator.
Definition: ISTLPreconCreator.hpp:70