Dune Core Modules (2.8.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&& f, Args&&... 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 f.localContext(),
159 requireConvertible<LocalContext>(f.localContext())
160 );
161};
162
164template<class F, class Signature, class LocalContext>
165static constexpr bool isLocalFunction()
166{ return models<Concept::LocalFunction<Signature, LocalContext>, F>(); }
167
168
169// DifferentiableLocalFunction concept ##############################################
170template<class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
171struct DifferentiableLocalFunction;
172
185template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits>
186struct DifferentiableLocalFunction<Range(Domain), LocalContext, DerivativeTraits> :
187 Refines<
188 Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
189 Dune::Functions::Concept::LocalFunction<Range(Domain),LocalContext>
190 >
191{
192 template<class F>
193 auto require(F&& f) -> decltype(
194 f.bind(std::declval<LocalContext>()),
195 f.unbind(),
196 f.localContext(),
197 requireConvertible<LocalContext>(f.localContext())
198 );
199};
200
202template<class F, class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
203static constexpr bool isDifferentiableLocalFunction()
204{ return models<Concept::DifferentiableLocalFunction<Signature, LocalContext, DerivativeTraits>, F>(); }
205
206
207// EntitySet concept ##############################################
208
219{
220 template<class E>
221 auto require(E&& f) -> decltype(
222 requireType<typename E::Element>(),
223 requireType<typename E::LocalCoordinate>(),
224 requireType<typename E::GlobalCoordinate>()
225 );
226};
227
229template<class E>
230static constexpr bool isEntitySet()
231{ return models<Concept::EntitySet, E>(); }
232
233
234
235// GridFunction concept ##############################################
236template<class Signature, class EntitySet>
237struct GridFunction;
238
248template<class Range, class Domain, class EntitySet>
249struct GridFunction<Range(Domain), EntitySet> :
250 Refines<Dune::Functions::Concept::Function<Range(Domain)> >
251{
252 using LocalSignature = Range(typename EntitySet::LocalCoordinate);
253 using LocalContext = typename EntitySet::Element;
254
255 template<class F>
256 auto require(F&& f) -> decltype(
257 localFunction(f),
258 f.entitySet(),
259 requireConcept<LocalFunction<LocalSignature, LocalContext>>(localFunction(f)),
260 requireConcept<Concept::EntitySet, EntitySet>(),
261 requireConvertible<EntitySet>(f.entitySet()),
262 requireConvertible<typename EntitySet::GlobalCoordinate, Domain>()
263 );
264};
265
267template<class F, class Signature, class EntitySet>
268static constexpr bool isGridFunction()
269{ return models<Concept::GridFunction<Signature, EntitySet>, F>(); }
270
271
272// DifferentiableGridFunction concept ##############################################
273template<class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
274struct DifferentiableGridFunction;
275
288template<class Range, class Domain, class EntitySet, template<class> class DerivativeTraits>
289struct DifferentiableGridFunction<Range(Domain), EntitySet, DerivativeTraits> :
290 Refines<
291 Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
292 Dune::Functions::Concept::GridFunction<Range(Domain),EntitySet>
293 >
294{
295 using LocalSignature = Range(typename EntitySet::LocalCoordinate);
296 using LocalContext = typename EntitySet::Element;
297
298 template<class R>
299 using LocalDerivativeTraits = typename Dune::Functions::LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits<R>;
300
301 template<class F>
302 auto require(F&& f) -> decltype(
303 requireConcept<DifferentiableLocalFunction<LocalSignature, LocalContext, LocalDerivativeTraits>>(localFunction(f))
304 );
305};
306
308template<class F, class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
309static constexpr bool isDifferentiableGridFunction()
310{ return models<Concept::DifferentiableGridFunction<Signature, EntitySet, DerivativeTraits>, F>(); }
311
312
313
314// GridViewFunction concept ##############################################
315template<class Signature, class GridView>
316struct GridViewFunction;
317
330template<class Range, class Domain, class GridView>
331struct GridViewFunction<Range(Domain), GridView> :
332 Refines<Dune::Functions::Concept::GridFunction<Range(Domain), GridViewEntitySet<GridView,0>>>
333{
334 template<class F>
335 auto require(F&& f) -> decltype(
336 0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
337 );
338};
339
341template<class F, class Signature, class GridView>
342static constexpr bool isGridViewFunction()
343{ return models<Concept::GridViewFunction<Signature, GridView>, F>(); }
344
345
346// DifferentiableGridViewFunction concept ##############################################
347template<class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
348struct DifferentiableGridViewFunction;
349
363template<class Range, class Domain, class GridView, template<class> class DerivativeTraits>
364struct DifferentiableGridViewFunction<Range(Domain), GridView, DerivativeTraits> :
365 Refines<Dune::Functions::Concept::DifferentiableGridFunction<Range(Domain), GridViewEntitySet<GridView,0>, DerivativeTraits>>
366{
367 template<class F>
368 auto require(F&& f) -> decltype(
369 0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
370 );
371};
372
374template<class F, class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
375static constexpr bool isDifferentiableGridViewFunction()
376{ return models<Concept::DifferentiableGridViewFunction<Signature, GridView, DerivativeTraits>, F>(); }
377
378
379
380}}} // namespace Dune::Functions::Concept
381
382#endif // DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
Base class template for function classes.
Definition: function.hh:39
Grid view abstract base class.
Definition: gridview.hh:63
Infrastructure for concepts.
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:182
static constexpr bool isGridFunction()
Check if F models the GridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:268
static constexpr bool isDifferentiableLocalFunction()
Check if F models the DifferentiableLocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:203
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:375
static constexpr bool isGridViewFunction()
Check if F models the GridViewFunction concept with given signature.
Definition: functionconcepts.hh:342
static constexpr bool isEntitySet()
Check if F models the GridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:230
static constexpr bool isDifferentiableGridFunction()
Check if F models the DifferentiableGridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:309
static constexpr bool isLocalFunction()
Check if F models the LocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:165
static constexpr bool isFunction(F &&f, SignatureTag< Signature, DerivativeTraits >)
Check if f models the Function concept with given signature.
Definition: functionconcepts.hh:93
void localFunction(DiscreteGlobalBasisFunction< TT... > &&t)=delete
Construction of local functions from a temporary DiscreteGlobalBasisFunction (forbidden)
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 &&f, Args &&... args)
Check if f is callable with given argument list.
Definition: functionconcepts.hh:57
Namespace for concepts.
Definition: concept.hh:32
Dune namespace.
Definition: alignedallocator.hh:11
Base class for refined concepts.
Definition: concept.hh:52
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:219
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 (Nov 22, 23:33, 2024)