DUNE PDELab (git)

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
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
8#define DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
9
10#include <dune/common/typelist.hh>
12
13#include <dune/functions/common/signature.hh>
14#include <dune/functions/gridfunctions/localderivativetraits.hh>
15#include <dune/functions/gridfunctions/gridviewentityset.hh>
16
17namespace Dune {
18namespace Functions {
19namespace Concept {
20
21using namespace Dune::Concept;
22
23
24
25// Callable concept ############################################################
26
27
35template<class... Args>
37{
38 template<class F>
39 auto require(F&& f) -> decltype(
40 f(std::declval<Args>()...)
41 );
42};
43
50template<class F, class... Args>
51static constexpr auto isCallable()
52{ return models<Concept::Callable<Args...>, F>(); }
53
60template<class F, class... Args>
61static constexpr auto isCallable(F&&, Args&&...)
62{
63 return models<Concept::Callable<Args&&...>, F>();
64}
65
66
67
68// Function concept ############################################################
69template<class Signature>
70struct Function;
71
80template<class Range, class Domain>
81struct Function<Range(Domain)> : Refines<Callable<Domain> >
82{
83 template<class F>
84 auto require(F&& f) -> decltype(
85 // F models Function<Range(Domain)> if the result of F(Domain) is implicitly convertible to Range
86 requireConvertible<Range>(f(std::declval<Domain>()))
87 );
88};
89
91template<class F, class Signature>
92static constexpr bool isFunction()
93{ return models<Concept::Function<Signature>, F>(); }
94
96template<class F, class Signature, template<class> class DerivativeTraits>
97static constexpr bool isFunction(F&& f, SignatureTag<Signature, DerivativeTraits>)
98{ return models<Concept::Function<Signature>, F>(); }
99
100
101
102// DifferentiableFunction concept ##############################################
103template<class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
104struct DifferentiableFunction;
105
117template<class Range, class Domain, template<class> class DerivativeTraits>
118struct DifferentiableFunction<Range(Domain), DerivativeTraits> : Refines<Dune::Functions::Concept::Function<Range(Domain)> >
119{
120 using DerivativeSignature = typename SignatureTraits<Range(Domain)>::template DerivativeSignature<DerivativeTraits>;
121
122 template<class F>
123 auto require(F&& f) -> decltype(
124 derivative(f),
125 requireConcept<Function<DerivativeSignature>>(derivative(f))
126 );
127};
128
130template<class F, class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
131static constexpr bool isDifferentiableFunction()
132{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
133
135template<class F, class Signature, template<class> class DerivativeTraits>
136static constexpr bool isDifferentiableFunction(F&& f, SignatureTag<Signature, DerivativeTraits>)
137{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
138
139
140
141// LocalFunction concept ##############################################
142template<class Signature, class LocalContext>
143struct LocalFunction;
144
154template<class Range, class Domain, class LocalContext>
155struct LocalFunction<Range(Domain), LocalContext> :
156 Refines<Dune::Functions::Concept::Function<Range(Domain)> >
157{
158 template<class F>
159 auto require(F&& f) -> decltype(
160 f.bind(std::declval<LocalContext>()),
161 f.unbind(),
162 requireConvertible<bool>(f.bound()),
163 f.localContext(),
164 requireConvertible<LocalContext>(f.localContext())
165 );
166};
167
169template<class F, class Signature, class LocalContext>
170static constexpr bool isLocalFunction()
171{ return models<Concept::LocalFunction<Signature, LocalContext>, F>(); }
172
173
174// DifferentiableLocalFunction concept ##############################################
175template<class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
176struct DifferentiableLocalFunction;
177
190template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits>
191struct DifferentiableLocalFunction<Range(Domain), LocalContext, DerivativeTraits> :
192 Refines<
193 Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
194 Dune::Functions::Concept::LocalFunction<Range(Domain),LocalContext>
195 >
196{
197 template<class F>
198 auto require(F&& f) -> decltype(
199 f.bind(std::declval<LocalContext>()),
200 f.unbind(),
201 f.localContext(),
202 requireConvertible<LocalContext>(f.localContext())
203 );
204};
205
207template<class F, class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
208static constexpr bool isDifferentiableLocalFunction()
209{ return models<Concept::DifferentiableLocalFunction<Signature, LocalContext, DerivativeTraits>, F>(); }
210
211
212// EntitySet concept ##############################################
213
224{
225 template<class E>
226 auto require(E&& f) -> decltype(
227 requireType<typename E::Element>(),
228 requireType<typename E::LocalCoordinate>(),
229 requireType<typename E::GlobalCoordinate>()
230 );
231};
232
234template<class E>
235static constexpr bool isEntitySet()
236{ return models<Concept::EntitySet, E>(); }
237
238
239
240// GridFunction concept ##############################################
241template<class Signature, class EntitySet>
242struct GridFunction;
243
253template<class Range, class Domain, class EntitySet>
254struct GridFunction<Range(Domain), EntitySet> :
255 Refines<Dune::Functions::Concept::Function<Range(Domain)> >
256{
257 using LocalSignature = Range(typename EntitySet::LocalCoordinate);
258 using LocalContext = typename EntitySet::Element;
259
260 template<class F>
261 auto require(F&& f) -> decltype(
262 localFunction(f),
263 f.entitySet(),
264 requireConcept<LocalFunction<LocalSignature, LocalContext>>(localFunction(f)),
265 requireConcept<Concept::EntitySet, EntitySet>(),
266 requireConvertible<EntitySet>(f.entitySet()),
267 requireConvertible<typename EntitySet::GlobalCoordinate, Domain>()
268 );
269};
270
272template<class F, class Signature, class EntitySet>
273static constexpr bool isGridFunction()
274{ return models<Concept::GridFunction<Signature, EntitySet>, F>(); }
275
276
277// DifferentiableGridFunction concept ##############################################
278template<class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
279struct DifferentiableGridFunction;
280
293template<class Range, class Domain, class EntitySet, template<class> class DerivativeTraits>
294struct DifferentiableGridFunction<Range(Domain), EntitySet, DerivativeTraits> :
295 Refines<
296 Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
297 Dune::Functions::Concept::GridFunction<Range(Domain),EntitySet>
298 >
299{
300 using LocalSignature = Range(typename EntitySet::LocalCoordinate);
301 using LocalContext = typename EntitySet::Element;
302
303 template<class R>
304 using LocalDerivativeTraits = typename Dune::Functions::LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits<R>;
305
306 template<class F>
307 auto require(F&& f) -> decltype(
308 requireConcept<DifferentiableLocalFunction<LocalSignature, LocalContext, LocalDerivativeTraits>>(localFunction(f))
309 );
310};
311
313template<class F, class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
314static constexpr bool isDifferentiableGridFunction()
315{ return models<Concept::DifferentiableGridFunction<Signature, EntitySet, DerivativeTraits>, F>(); }
316
317
318
319// GridViewFunction concept ##############################################
320template<class Signature, class GridView>
321struct GridViewFunction;
322
335template<class Range, class Domain, class GridView>
336struct GridViewFunction<Range(Domain), GridView> :
337 Refines<Dune::Functions::Concept::GridFunction<Range(Domain), GridViewEntitySet<GridView,0>>>
338{
339 template<class F>
340 auto require(F&& f) -> decltype(
341 0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
342 );
343};
344
346template<class F, class Signature, class GridView>
347static constexpr bool isGridViewFunction()
348{ return models<Concept::GridViewFunction<Signature, GridView>, F>(); }
349
350
351// DifferentiableGridViewFunction concept ##############################################
352template<class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
353struct DifferentiableGridViewFunction;
354
368template<class Range, class Domain, class GridView, template<class> class DerivativeTraits>
369struct DifferentiableGridViewFunction<Range(Domain), GridView, DerivativeTraits> :
370 Refines<Dune::Functions::Concept::DifferentiableGridFunction<Range(Domain), GridViewEntitySet<GridView,0>, DerivativeTraits>>
371{
372 template<class F>
373 auto require(F&& f) -> decltype(
374 0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
375 );
376};
377
379template<class F, class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
380static constexpr bool isDifferentiableGridViewFunction()
381{ return models<Concept::DifferentiableGridViewFunction<Signature, GridView, DerivativeTraits>, F>(); }
382
383
384
385}}} // namespace Dune::Functions::Concept
386
387#endif // DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
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:273
static constexpr bool isDifferentiableLocalFunction()
Check if F models the DifferentiableLocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:208
static constexpr bool isDifferentiableFunction(F &&f, SignatureTag< Signature, DerivativeTraits >)
Check if f models the DifferentiableFunction concept with given signature.
Definition: functionconcepts.hh:136
static constexpr bool isDifferentiableGridViewFunction()
Check if F models the DifferentiableGridViewFunction concept with given signature.
Definition: functionconcepts.hh:380
static constexpr bool isGridViewFunction()
Check if F models the GridViewFunction concept with given signature.
Definition: functionconcepts.hh:347
static constexpr bool isEntitySet()
Check if F models the GridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:235
static constexpr bool isDifferentiableGridFunction()
Check if F models the DifferentiableGridFunction concept with given signature and entity set.
Definition: functionconcepts.hh:314
static constexpr bool isLocalFunction()
Check if F models the LocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:170
static constexpr bool isFunction(F &&f, SignatureTag< Signature, DerivativeTraits >)
Check if f models the Function concept with given signature.
Definition: functionconcepts.hh:97
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition: trigonometricfunction.hh:43
static constexpr auto isCallable(F &&, Args &&...)
Check if f is callable with given argument list.
Definition: functionconcepts.hh:61
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:37
Concept for an entity set for a Concept::GridFunction<Range(Domain), EntitySet, DerivativeTraits>
Definition: functionconcepts.hh:224
Default implementation for derivative traits.
Definition: defaultderivativetraits.hh:41
Derivative traits for local functions.
Definition: localderivativetraits.hh:32
Helper class to deduce the signature of a callable.
Definition: signature.hh:60
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)