AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Basic.hpp
1 #pragma once
2 
3 #include <algorithm>
4 #include <utility>
5 
6 #include <amdis/common/Index.hpp>
7 #include <amdis/common/ConceptsBase.hpp>
8 
9 namespace AMDiS
10 {
11  namespace Concepts
12  {
13  namespace Definition
14  {
16  {
17  template <class F, int... I>
18  auto require(F&& f, std::integer_sequence<int,I...>) -> decltype( order(f, I...) );
19  };
20  }
21 
22  template <class F, int N>
23  constexpr bool HasFunctorOrder = models<Definition::HasFunctorOrder(F, std::make_integer_sequence<int,N>)>;
24 
25  template <class F, int N>
26  using HasFunctorOrder_t = bool_t<HasFunctorOrder<F,N>>;
27  }
28 
29  namespace Operation
30  {
35  template <class T, T value>
38  {
39  template <class... Ts>
40  constexpr T operator()(Ts const&... /*args*/) const
41  {
42  return value;
43  }
44  };
45 
48 
49  template <class T, T value, class... Int>
50  constexpr int order(StaticConstant<T,value> const&, Int... /*orders*/)
51  {
52  return 0;
53  }
54 
55  template <class T, T value, std::size_t J>
56  constexpr auto partial(StaticConstant<T,value> const&, index_t<J>)
57  {
58  return Zero{};
59  }
60 
61  // -------------------------------------------------------------------------
62 
64  struct Id
65  {
66  template <class T>
67  constexpr T const& operator()(T const& x) const
68  {
69  return x;
70  }
71 
72  friend constexpr int order(Id const&, int d)
73  {
74  return d;
75  }
76 
77  friend auto partial(Id const&, index_t<0>)
78  {
79  return One{};
80  }
81  };
82 
83  // -------------------------------------------------------------------------
84 
86  template <class T>
87  struct Constant
88  {
89  constexpr Constant(T value)
90  : value_(value)
91  {}
92 
93  template <class... Ts>
94  constexpr T const& operator()(Ts const&... /*args*/) const
95  {
96  return value_;
97  }
98 
99  private:
100  T value_;
101  };
102 
103  template <class T, class... Int>
104  constexpr int order(Constant<T> const&, Int... /*orders*/)
105  {
106  return 0;
107  }
108 
109  template <class T, std::size_t J>
110  constexpr auto partial(Constant<T> const&, index_t<J>)
111  {
112  return Zero{};
113  }
114 
115  // -------------------------------------------------------------------------
116 
117 
118  template <class T0, class... Ts>
119  inline constexpr decltype(auto) get_element(index_t<0>, T0&& t0, Ts&&... /*ts*/)
120  {
121  return FWD(t0);
122  }
123 
124  template <std::size_t J, class T0, class... Ts>
125  inline constexpr decltype(auto) get_element(index_t<J>, T0&& /*t0*/, Ts&&... ts)
126  {
127  static_assert(J <= sizeof...(Ts), "");
128  return get_element(index_t<J-1>{}, FWD(ts)...);
129  }
130 
131  template <std::size_t I>
132  struct Arg
133  {
134  template <class... Ts>
135  constexpr auto&& operator()(Ts&&... args) const
136  {
137  return get_element(index_t<I>{}, FWD(args)...);
138  }
139  };
140 
141  template <std::size_t I, class... Int>
142  constexpr int order(Arg<I> const&, Int... orders)
143  {
144  return get_element(index_t<I>{}, orders...);
145  }
146 
147  template <std::size_t I, std::size_t J>
148  constexpr auto partial(Arg<I> const&, index_t<J>)
149  {
151  }
152 
153  // -------------------------------------------------------------------------
154 
155  template <std::size_t I>
156  struct Get
157  {
158  template <class T, int N>
159  constexpr T const& operator()(Dune::FieldVector<T,N> const& vec) const
160  {
161  return vec[I];
162  }
163 
164  friend constexpr int order(Get const&, int d)
165  {
166  return d;
167  }
168  };
169 
170  struct Get_
171  {
172  explicit constexpr Get_(std::size_t i)
173  : i_(i)
174  {}
175 
176  template <class T, int N>
177  constexpr T const& operator()(Dune::FieldVector<T,N> const& vec) const
178  {
179  return vec[i_];
180  }
181 
182  friend constexpr int order(Get_ const&, int d)
183  {
184  return d;
185  }
186 
187  std::size_t i_;
188  };
189 
192  } // end namespace Operation
193 } // end namespace AMDiS
Definition: Basic.hpp:132
Definition: Basic.hpp:170
Definition: Basic.hpp:156
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Functor representing a static constant value.
Definition: Basic.hpp:37
auto order(F const &f) -> decltype(&F::operator(), f.order())
polynomial order of functions
Definition: Order.hpp:11
std::integral_constant< std::size_t, I > index_t
A wrapper for std::size_t type.
Definition: Index.hpp:31
std::integral_constant< bool, B > bool_t
A wrapper for bool types.
Definition: Logical.hpp:12
Functor representing a constant value.
Definition: Basic.hpp:87
(Unary-)Functor representing the identity
Definition: Basic.hpp:64