Dune Core Modules (2.9.0)

functionconcepts.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
4#define DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
5
6#include <dune/common/typelist.hh>
8
9#include <dune/functions/common/signature.hh>
10#include <dune/functions/gridfunctions/localderivativetraits.hh>
11#include <dune/functions/gridfunctions/gridviewentityset.hh>
12
13namespace Dune {
14namespace Functions {
15namespace Concept {
16
17using namespace Dune::Concept;
18
19
20
21// Callable concept ############################################################
22
23
31template<class... Args>
33{
34 template<class F>
35 auto require(F&& f) -> decltype(
36 f(std::declval<Args>()...)
37 );
38};
39
46template<class F, class... Args>
47static constexpr auto isCallable()
48{ return models<Concept::Callable<Args...>, F>(); }
49
56template<class F, class... Args>
57static constexpr auto isCallable(F&&, Args&&...)
58{
59 return models<Concept::Callable<Args&&...>, F>();
60}
61
62
63
64// Function concept ############################################################
65template<class Signature>
66struct Function;
67
76template<class Range, class Domain>
77struct Function<Range(Domain)> : Refines<Callable<Domain> >
78{
79 template<class F>
80 auto require(F&& f) -> decltype(
81 // F models Function<Range(Domain)> if the result of F(Domain) is implicitly convertible to Range
82 requireConvertible<Range>(f(std::declval<Domain>()))
83 );
84};
85
87template<class F, class Signature>
88static constexpr bool isFunction()
89{ return models<Concept::Function<Signature>, F>(); }
90
92template<class F, class Signature, template<class> class DerivativeTraits>
93static constexpr bool isFunction(F&& f, SignatureTag<Signature, DerivativeTraits>)
94{ return models<Concept::Function<Signature>, F>(); }
95
96
97
98// DifferentiableFunction concept ##############################################
99template<class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
100struct DifferentiableFunction;
101
113template<class Range, class Domain, template<class> class DerivativeTraits>
114struct DifferentiableFunction<Range(Domain), DerivativeTraits> : Refines<Dune::Functions::Concept::Function<Range(Domain)> >
115{
116 using DerivativeSignature = typename SignatureTraits<Range(Domain)>::template DerivativeSignature<DerivativeTraits>;
117
118 template<class F>
119 auto require(F&& f) -> decltype(
120 derivative(f),
121 requireConcept<Function<DerivativeSignature>>(derivative(f))
122 );
123};
124
126template<class F, class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
127static constexpr bool isDifferentiableFunction()
128{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
129
131template<class F, class Signature, template<class> class DerivativeTraits>
132static constexpr bool isDifferentiableFunction(F&& f, SignatureTag<Signature, DerivativeTraits>)
133{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
134
135
136
137// LocalFunction concept ##############################################
138template<class Signature, class LocalContext>
139struct LocalFunction;
140
150template<class Range, class Domain, class LocalContext>
151struct LocalFunction<Range(Domain), LocalContext> :
152 Refines<Dune::Functions::Concept::Function<Range(Domain)> >
153{
154 template<class F>
155 auto require(F&& f) -> decltype(
156 f.bind(std::declval<LocalContext>()),
157 f.unbind(),
158 requireConvertible<bool>(f.bound()),
159 f.localContext(),
160 requireConvertible<LocalContext>(f.localContext())
161 );
162};
163
165template<class F, class Signature, class LocalContext>
166static constexpr bool isLocalFunction()
167{ return models<Concept::LocalFunction<Signature, LocalContext>, F>(); }
168
169
170// DifferentiableLocalFunction concept ##############################################
171template<class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
172struct DifferentiableLocalFunction;
173
186template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits>
187struct DifferentiableLocalFunction<Range(Domain), LocalContext, DerivativeTraits> :
188 Refines<
189 Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
190 Dune::Functions::Concept::LocalFunction<Range(Domain),LocalContext>
191 >
192{
193 template<class F>
194 auto require(F&& f) -> decltype(
195 f.bind(std::declval<LocalContext>()),
196 f.unbind(),
197 f.localContext(),
198 requireConvertible<LocalContext>(f.localContext())
199 );
200};
201
203template<class F, class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
204static constexpr bool isDifferentiableLocalFunction()
205{ return models<Concept::DifferentiableLocalFunction<Signature, LocalContext, DerivativeTraits>, F>(); }
206
207
208// EntitySet concept ##############################################
209
220{
221 template<class E>
222 auto require(E&& f) -> decltype(
223 requireType<typename E::Element>(),
224 requireType<typename E::LocalCoordinate>(),
225 requireType<typename E::GlobalCoordinate>()
226 );
227};
228
230template<class E>
231static constexpr bool isEntitySet()
232{ return models<Concept::EntitySet, E>(); }
233
234
235
236// GridFunction concept ##############################################
237template<class Signature, class EntitySet>
238struct GridFunction;
239
249template<class Range, class Domain, class EntitySet>
250struct GridFunction<Range(Domain), EntitySet> :
251 Refines<Dune::Functions::Concept::Function<Range(Domain)> >
252{
253 using LocalSignature = Range(typename EntitySet::LocalCoordinate);
254 using LocalContext = typename EntitySet::Element;
255
256 template<class F>
257 auto require(F&& f) -> decltype(
258 localFunction(f),
259 f.entitySet(),
260 requireConcept<LocalFunction<LocalSignature, LocalContext>>(localFunction(f)),
261 requireConcept<Concept::EntitySet, EntitySet>(),
262 requireConvertible<EntitySet>(f.entitySet()),
263 requireConvertible<typename EntitySet::GlobalCoordinate, Domain>()
264 );
265};
266
268template<class F, class Signature, class EntitySet>
269static constexpr bool isGridFunction()
270{ return models<Concept::GridFunction<Signature, EntitySet>, F>(); }
271
272
273// DifferentiableGridFunction concept ##############################################
274template<class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
275struct DifferentiableGridFunction;
276
289template<class Range, class Domain, class EntitySet, template<class> class DerivativeTraits>
290struct DifferentiableGridFunction<Range(Domain), EntitySet, DerivativeTraits> :
291 Refines<
292 Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
293 Dune::Functions::Concept::GridFunction<Range(Domain),EntitySet>
294 >
295{
296 using LocalSignature = Range(typename EntitySet::LocalCoordinate);
297 using LocalContext = typename EntitySet::Element;
298
299 template<class R>
300 using LocalDerivativeTraits = typename Dune::Functions::LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits<R>;
301
302 template<class F>
303 auto require(F&& f) -> decltype(
304 requireConcept<DifferentiableLocalFunction<LocalSignature, LocalContext, LocalDerivativeTraits>>(localFunction(f))
305 );
306};
307
309template<class F, class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
310static constexpr bool isDifferentiableGridFunction()
311{ return models<Concept::DifferentiableGridFunction<Signature, EntitySet, DerivativeTraits>, F>(); }
312
313
314
315// GridViewFunction concept ##############################################
316template<class Signature, class GridView>
317struct GridViewFunction;
318
331template<class Range, class Domain, class GridView>
332struct GridViewFunction<Range(Domain), GridView> :
333 Refines<Dune::Functions::Concept::GridFunction<Range(Domain), GridViewEntitySet<GridView,0>>>
334{
335 template<class F>
336 auto require(F&& f) -> decltype(
337 0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
338 );
339};
340
342template<class F, class Signature, class GridView>
343static constexpr bool isGridViewFunction()
344{ return models<Concept::GridViewFunction<Signature, GridView>, F>(); }
345
346
347// DifferentiableGridViewFunction concept ##############################################
348template<class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
349struct DifferentiableGridViewFunction;
350
364template<class Range, class Domain, class GridView, template<class> class DerivativeTraits>
365struct DifferentiableGridViewFunction<Range(Domain), GridView, DerivativeTraits> :
366 Refines<Dune::Functions::Concept::DifferentiableGridFunction<Range(Domain), GridViewEntitySet<GridView,0>, DerivativeTraits>>
367{
368 template<class F>
369 auto require(F&& f) -> decltype(
370 0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
371 );
372};
373
375template<class F, class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
376static constexpr bool isDifferentiableGridViewFunction()
377{ return models<Concept::DifferentiableGridViewFunction<Signature, GridView, DerivativeTraits>, F>(); }
378
379
380
381}}} // namespace Dune::Functions::Concept
382
383#endif // DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
Base class template for function classes.
Definition: function.hh:41
Grid view abstract base class.
Definition: gridview.hh:66
Infrastructure for concepts.
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:184
static constexpr bool isGridFunction()
Check if F models the GridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:269
static constexpr bool isDifferentiableLocalFunction()
Check if F models the DifferentiableLocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:204
static constexpr bool isDifferentiableFunction(F &&f, SignatureTag< Signature, DerivativeTraits >)
Check if f models the DifferentiableFunction concept with given signature.
Definition: functionconcepts.hh:132
static constexpr bool isDifferentiableGridViewFunction()
Check if F models the DifferentiableGridViewFunction concept with given signature.
Definition: functionconcepts.hh:376
static constexpr bool isGridViewFunction()
Check if F models the GridViewFunction concept with given signature.
Definition: functionconcepts.hh:343
static constexpr bool isEntitySet()
Check if F models the GridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:231
static constexpr bool isDifferentiableGridFunction()
Check if F models the DifferentiableGridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:310
static constexpr bool isLocalFunction()
Check if F models the LocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:166
static constexpr bool isFunction(F &&f, SignatureTag< Signature, DerivativeTraits >)
Check if f models the Function concept with given signature.
Definition: functionconcepts.hh:93
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition: trigonometricfunction.hh:39
static constexpr auto isCallable(F &&, Args &&...)
Check if f is callable with given argument list.
Definition: functionconcepts.hh:57
Namespace for concepts.
Definition: concept.hh:34
Dune namespace.
Definition: alignedallocator.hh:13
Base class for refined concepts.
Definition: concept.hh:54
Concept objects that can be called with given argument list.
Definition: functionconcepts.hh:33
Concept for an entity set for a Concept::GridFunction<Range(Domain), EntitySet, DerivativeTraits>
Definition: functionconcepts.hh:220
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
Derivative traits for local functions.
Definition: localderivativetraits.hh:28
Helper class to deduce the signature of a callable.
Definition: signature.hh:56
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)