AMDiS  2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Preconditioners.hpp
1 #pragma once
2 
3 // MTL4 headers
4 #include <boost/numeric/itl/itl.hpp>
5 #include <boost/numeric/itl/pc/ilu_0.hpp>
6 #include <boost/numeric/itl/pc/ic_0.hpp>
7 #include <boost/numeric/mtl/vector/assigner.hpp>
8 
9 #include <amdis/CreatorMap.hpp>
10 #include <amdis/linearalgebra/mtl/HyprePrecon.hpp>
11 #include <amdis/linearalgebra/mtl/Preconditioner.hpp>
12 #include <amdis/linearalgebra/mtl/SolverPrecon.hpp>
13 #include <amdis/linearalgebra/mtl/Traits.hpp>
14 #include <amdis/linearalgebra/mtl/itl/masslumping.hpp>
15 
16 namespace AMDiS
17 {
26  template <class Matrix>
27  using DiagonalPreconditioner = itl::pc::diagonal<Matrix>;
28 
37  template <class Matrix>
38  using MassLumpingPreconditioner = itl::pc::masslumping<Matrix>;
39 
40 
49  template <class Matrix>
50  using IdentityPreconditioner = itl::pc::identity<Matrix>;
51 
52 
63  template <class Matrix>
64  using ILUPreconditioner = itl::pc::ilu_0<Matrix>;
65 
66 
75  template <class Matrix>
76  using ICPreconditioner = itl::pc::ic_0<Matrix>;
77 
78 
79  template <class M, class X, class Y>
81  {
83 
84  template <template <class> class ITLPrecon>
85  using PreconCreator = typename Preconditioner<M,X,Y,ITLPrecon>::Creator;
86 
88 
89  public:
90  static void init()
91  {
92  auto pc_diag = new PreconCreator<DiagonalPreconditioner>;
93  Map::addCreator("diag", pc_diag);
94  Map::addCreator("jacobi", pc_diag);
95 
96  auto pc_mass = new PreconCreator<MassLumpingPreconditioner>;
97  Map::addCreator("masslumping", pc_mass);
98 
99  auto pc_ilu = new PreconCreator<ILUPreconditioner>;
100  Map::addCreator("ilu", pc_ilu);
101  Map::addCreator("ilu0", pc_ilu);
102 
103  auto pc_ic = new PreconCreator<ICPreconditioner>;
104  Map::addCreator("ic", pc_ic);
105  Map::addCreator("ic0", pc_ic);
106 
107  auto pc_id = new PreconCreator<IdentityPreconditioner>;
108  Map::addCreator("identity", pc_id);
109  Map::addCreator("no", pc_id);
110 
111  auto pc_solver = new typename SolverPrecon<M,X,Y>::Creator;
112  Map::addCreator("solver", pc_solver);
113 
114  Map::addCreator("default", pc_id);
115 
116  init_hypre(std::is_same<typename Dune::FieldTraits<typename M::value_type>::real_type, double>{});
117  }
118 
119  static void init_hypre(std::false_type) {}
120  static void init_hypre(std::true_type)
121  {
122 #if AMDIS_HAS_HYPRE && HAVE_MPI
123  auto pc_hypre = new typename HyprePrecon<M,X,Y>::Creator;
124  Map::addCreator("hypre", pc_hypre);
125 #endif
126  }
127  };
128 
129  template <class M, class X, class Y>
130  itl::pc::solver<PreconditionerInterface<M,X,Y>, X, false>
131  solve(PreconditionerInterface<M,X,Y> const& P, X const& vin)
132  {
133  return {P, vin};
134  }
135 
136  template <class M, class X, class Y>
137  itl::pc::solver<PreconditionerInterface<M,X,Y>, X, true>
138  adjoint_solve(PreconditionerInterface<M,X,Y> const& P, X const& vin)
139  {
140  return {P, vin};
141  }
142 
143 } // namespace AMDiS
A creator to be used instead of the constructor.
Definition: SolverPrecon.hpp:29
A creator to be used instead of the constructor.
Definition: Preconditioner.hpp:22
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
Interface for Preconditioner y = M*x.
Definition: PreconditionerInterface.hpp:9