AMDiS 2.11-git
The Adaptive Multi-Dimensional Simulation Toolbox
 
Loading...
Searching...
No Matches
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
9namespace 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
22 {
23 template <class F>
24 auto require(F&& f, std::vector<int> o = {}) -> decltype( order(f, o) );
25 };
26 }
27
28 template <class F, int N>
29 constexpr bool HasFunctorOrder = models<Definition::HasFunctorOrder(F, std::make_integer_sequence<int,N>)>;
30
31 template <class F>
32 constexpr bool HasFunctorVectorOrder = models<Definition::HasFunctorVectorOrder(F)>;
33
34 template <class F, int N>
35 using HasFunctorOrder_t = bool_t<HasFunctorOrder<F,N>>;
36 }
37
38 namespace Operation
39 {
45 template <class T, T value>
47 {
48 template <class... Ts>
49 constexpr T operator()(Ts const&... /*args*/) const
50 {
51 return value;
52 }
53 };
54
57
58 template <class T, T value, class... Int>
59 constexpr int order(StaticConstant<T,value> const&, Int... /*orders*/)
60 {
61 return 0;
62 }
63
64 template <class T, T value, std::size_t J>
65 constexpr auto partial(StaticConstant<T,value> const&, index_t<J>)
66 {
67 return Zero{};
68 }
69
70 // -------------------------------------------------------------------------
71
73 struct Id
74 {
75 template <class T>
76 constexpr T const& operator()(T const& x) const
77 {
78 return x;
79 }
80
81 friend constexpr int order(Id const&, int d)
82 {
83 return d;
84 }
85
86 friend auto partial(Id const&, index_t<0>)
87 {
88 return One{};
89 }
90 };
91
92 // -------------------------------------------------------------------------
93
95 template <class T>
96 struct Constant
97 {
98 constexpr Constant(T value)
99 : value_(value)
100 {}
101
102 template <class... Ts>
103 constexpr T const& operator()(Ts const&... /*args*/) const
104 {
105 return value_;
106 }
107
108 private:
109 T value_;
110 };
111
112 template <class T, class... Int>
113 constexpr int order(Constant<T> const&, Int... /*orders*/)
114 {
115 return 0;
116 }
117
118 template <class T, std::size_t J>
119 constexpr auto partial(Constant<T> const&, index_t<J>)
120 {
121 return Zero{};
122 }
123
124 // -------------------------------------------------------------------------
125
127 template <class T>
129 {
130 constexpr Reference(T& value)
131 : value_(&value)
132 {}
133
134 template <class... Ts>
135 constexpr T const& operator()(Ts const&... /*args*/) const
136 {
137 return *value_;
138 }
139
140 private:
141 T* value_;
142 };
143
144 template <class T, class... Int>
145 constexpr int order(Reference<T> const&, Int... /*orders*/)
146 {
147 return 0;
148 }
149
150 template <class T, std::size_t J>
151 constexpr auto partial(Reference<T> const&, index_t<J>)
152 {
153 return Zero{};
154 }
155
156 // -------------------------------------------------------------------------
157
158
159 template <class T0, class... Ts>
160 inline constexpr decltype(auto) get_element(index_t<0>, T0&& t0, Ts&&... /*ts*/)
161 {
162 return FWD(t0);
163 }
164
165 template <std::size_t J, class T0, class... Ts>
166 inline constexpr decltype(auto) get_element(index_t<J>, T0&& /*t0*/, Ts&&... ts)
167 {
168 static_assert(J <= sizeof...(Ts), "");
169 return get_element(index_t<J-1>{}, FWD(ts)...);
170 }
171
172 template <std::size_t I>
173 struct Arg
174 {
175 template <class... Ts>
176 constexpr auto&& operator()(Ts&&... args) const
177 {
178 return get_element(index_t<I>{}, FWD(args)...);
179 }
180 };
181
182 template <std::size_t I, class... Int>
183 constexpr int order(Arg<I> const&, Int... orders)
184 {
185 return get_element(index_t<I>{}, orders...);
186 }
187
188 template <std::size_t I, std::size_t J>
189 constexpr auto partial(Arg<I> const&, index_t<J>)
190 {
191 return StaticConstant<int,(I==J ? 1 : 0)>{};
192 }
193
194 // -------------------------------------------------------------------------
195
196 template <std::size_t I>
197 struct Get
198 {
199 template <class T, int N>
200 constexpr T const& operator()(Dune::FieldVector<T,N> const& vec) const
201 {
202 return vec[I];
203 }
204
205 friend constexpr int order(Get const&, int d)
206 {
207 return d;
208 }
209 };
210
211 struct Get_
212 {
213 explicit constexpr Get_(std::size_t i)
214 : i_(i)
215 {}
216
217 template <class T, int N>
218 constexpr T const& operator()(Dune::FieldVector<T,N> const& vec) const
219 {
220 return vec[i_];
221 }
222
223 friend constexpr int order(Get_ const&, int d)
224 {
225 return d;
226 }
227
228 std::size_t i_;
229 };
230
233 } // end namespace Operation
234} // end namespace AMDiS
Definition Basic.hpp:174
Functor representing a constant value.
Definition Basic.hpp:97
Definition Basic.hpp:212
Definition Basic.hpp:198
(Unary-)Functor representing the identity
Definition Basic.hpp:74
Functor representing a constant value.
Definition Basic.hpp:129
Functor representing a static constant value.
Definition Basic.hpp:47