dune-functions 2.9.0
functionconcepts.hh
Go to the documentation of this file.
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>
7#include <dune/common/concept.hh>
8
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>
94{ return models<Concept::Function<Signature>, F>(); }
95
96
97
98// DifferentiableFunction concept ##############################################
99template<class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
101
113template<class Range, class Domain, template<class> class DerivativeTraits>
114struct DifferentiableFunction<Range(Domain), DerivativeTraits> : Refines<Dune::Functions::Concept::Function<Range(Domain)> >
115{
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>
133{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
134
135
136
137// LocalFunction concept ##############################################
138template<class Signature, class LocalContext>
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>
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>
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>
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>
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>
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>
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
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 isFunction()
Check if F models the Function concept with given signature.
Definition: functionconcepts.hh:88
static constexpr bool isDifferentiableGridViewFunction()
Check if F models the DifferentiableGridViewFunction concept with given signature.
Definition: functionconcepts.hh:376
static constexpr bool isDifferentiableFunction()
Check if F models the DifferentiableFunction concept with given signature.
Definition: functionconcepts.hh:127
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
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition: trigonometricfunction.hh:39
static constexpr auto isCallable()
Check if f is callable with given argument list.
Definition: functionconcepts.hh:47
Definition: polynomial.hh:10
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:37
Concept objects that can be called with given argument list.
Definition: functionconcepts.hh:33
auto require(F &&f) -> decltype(f(std::declval< Args >()...))
Definition: functionconcepts.hh:66
auto require(F &&f) -> decltype(requireConvertible< Range >(f(std::declval< Domain >())))
Definition: functionconcepts.hh:100
typename SignatureTraits< Range(Domain)>::template DerivativeSignature< DerivativeTraits > DerivativeSignature
Definition: functionconcepts.hh:116
auto require(F &&f) -> decltype(derivative(f), requireConcept< Function< DerivativeSignature > >(derivative(f)))
Definition: functionconcepts.hh:139
auto require(F &&f) -> decltype(f.bind(std::declval< LocalContext >()), f.unbind(), requireConvertible< bool >(f.bound()), f.localContext(), requireConvertible< LocalContext >(f.localContext()))
auto require(F &&f) -> decltype(f.bind(std::declval< LocalContext >()), f.unbind(), f.localContext(), requireConvertible< LocalContext >(f.localContext()))
Concept for an entity set for a Concept::GridFunction<Range(Domain), EntitySet, DerivativeTraits>
Definition: functionconcepts.hh:220
auto require(E &&f) -> decltype(requireType< typename E::Element >(), requireType< typename E::LocalCoordinate >(), requireType< typename E::GlobalCoordinate >())
Definition: functionconcepts.hh:238
typename EntitySet::Element LocalContext
Definition: functionconcepts.hh:254
Range(typename EntitySet::LocalCoordinate) LocalSignature
Definition: functionconcepts.hh:253
auto require(F &&f) -> decltype(localFunction(f), f.entitySet(), requireConcept< LocalFunction< LocalSignature, LocalContext > >(localFunction(f)), requireConcept< Concept::EntitySet, EntitySet >(), requireConvertible< EntitySet >(f.entitySet()), requireConvertible< typename EntitySet::GlobalCoordinate, Domain >())
Definition: functionconcepts.hh:275
typename Dune::Functions::LocalDerivativeTraits< EntitySet, DerivativeTraits >::template Traits< R > LocalDerivativeTraits
Definition: functionconcepts.hh:300
auto require(F &&f) -> decltype(requireConcept< DifferentiableLocalFunction< LocalSignature, LocalContext, LocalDerivativeTraits > >(localFunction(f)))
Range(typename EntitySet::LocalCoordinate) LocalSignature
Definition: functionconcepts.hh:296
typename EntitySet::Element LocalContext
Definition: functionconcepts.hh:297
Definition: functionconcepts.hh:317
Helper class to deduce the signature of a callable.
Definition: signature.hh:56
Definition: signature.hh:102
Derivative traits for local functions.
Definition: localderivativetraits.hh:28