Loading...
Searching...
No Matches
functionconcepts.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
#ifndef DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
#define DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
#include <dune/common/typelist.hh>
#include <dune/common/concept.hh>
#include <dune/functions/common/signature.hh>
#include <dune/functions/gridfunctions/localderivativetraits.hh>
#include <dune/functions/gridfunctions/gridviewentityset.hh>
namespace Dune {
namespace Functions {
namespace Concept {
using namespace Dune::Concept;
// Callable concept ############################################################
template<class... Args>
struct Callable
{
template<class F>
auto require(F&& f) -> decltype(
f(std::declval<Args>()...)
);
};
template<class F, class... Args>
static constexpr auto isCallable()
{ return models<Concept::Callable<Args...>, F>(); }
template<class F, class... Args>
static constexpr auto isCallable(F&&, Args&&...)
{
return models<Concept::Callable<Args&&...>, F>();
}
// Function concept ############################################################
template<class Signature>
struct Function;
template<class Range, class Domain>
struct Function<Range(Domain)> : Refines<Callable<Domain> >
{
template<class F>
auto require(F&& f) -> decltype(
// F models Function<Range(Domain)> if the result of F(Domain) is implicitly convertible to Range
requireConvertible<Range>(f(std::declval<Domain>()))
);
};
template<class F, class Signature>
static constexpr bool isFunction()
{ return models<Concept::Function<Signature>, F>(); }
template<class F, class Signature, template<class> class DerivativeTraits>
static constexpr bool isFunction(F&& f, SignatureTag<Signature, DerivativeTraits>)
{ return models<Concept::Function<Signature>, F>(); }
// DifferentiableFunction concept ##############################################
template<class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
struct DifferentiableFunction;
template<class Range, class Domain, template<class> class DerivativeTraits>
struct DifferentiableFunction<Range(Domain), DerivativeTraits> : Refines<Dune::Functions::Concept::Function<Range(Domain)> >
{
using DerivativeSignature = typename SignatureTraits<Range(Domain)>::template DerivativeSignature<DerivativeTraits>;
template<class F>
auto require(F&& f) -> decltype(
derivative(f),
requireConcept<Function<DerivativeSignature>>(derivative(f))
);
};
template<class F, class Signature, template<class> class DerivativeTraits = DefaultDerivativeTraits>
static constexpr bool isDifferentiableFunction()
{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
template<class F, class Signature, template<class> class DerivativeTraits>
static constexpr bool isDifferentiableFunction(F&& f, SignatureTag<Signature, DerivativeTraits>)
{ return models<Concept::DifferentiableFunction<Signature, DerivativeTraits>, F>(); }
// LocalFunction concept ##############################################
template<class Signature, class LocalContext>
struct LocalFunction;
template<class Range, class Domain, class LocalContext>
struct LocalFunction<Range(Domain), LocalContext> :
Refines<Dune::Functions::Concept::Function<Range(Domain)> >
{
template<class F>
auto require(F&& f) -> decltype(
f.bind(std::declval<LocalContext>()),
f.unbind(),
requireConvertible<bool>(f.bound()),
f.localContext(),
requireConvertible<LocalContext>(f.localContext())
);
};
template<class F, class Signature, class LocalContext>
static constexpr bool isLocalFunction()
{ return models<Concept::LocalFunction<Signature, LocalContext>, F>(); }
// DifferentiableLocalFunction concept ##############################################
template<class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
struct DifferentiableLocalFunction;
template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits>
struct DifferentiableLocalFunction<Range(Domain), LocalContext, DerivativeTraits> :
Refines<
Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
Dune::Functions::Concept::LocalFunction<Range(Domain),LocalContext>
>
{
template<class F>
auto require(F&& f) -> decltype(
f.bind(std::declval<LocalContext>()),
f.unbind(),
f.localContext(),
requireConvertible<LocalContext>(f.localContext())
);
};
template<class F, class Signature, class LocalContext, template<class> class DerivativeTraits = DefaultDerivativeTraits>
static constexpr bool isDifferentiableLocalFunction()
{ return models<Concept::DifferentiableLocalFunction<Signature, LocalContext, DerivativeTraits>, F>(); }
// EntitySet concept ##############################################
struct EntitySet
{
template<class E>
auto require(E&& f) -> decltype(
requireType<typename E::Element>(),
requireType<typename E::LocalCoordinate>(),
requireType<typename E::GlobalCoordinate>()
);
};
template<class E>
static constexpr bool isEntitySet()
{ return models<Concept::EntitySet, E>(); }
// GridFunction concept ##############################################
template<class Signature, class EntitySet>
struct GridFunction;
template<class Range, class Domain, class EntitySet>
struct GridFunction<Range(Domain), EntitySet> :
Refines<Dune::Functions::Concept::Function<Range(Domain)> >
{
using LocalSignature = Range(typename EntitySet::LocalCoordinate);
using LocalContext = typename EntitySet::Element;
template<class F>
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>()
);
};
template<class F, class Signature, class EntitySet>
static constexpr bool isGridFunction()
{ return models<Concept::GridFunction<Signature, EntitySet>, F>(); }
// DifferentiableGridFunction concept ##############################################
template<class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
struct DifferentiableGridFunction;
template<class Range, class Domain, class EntitySet, template<class> class DerivativeTraits>
struct DifferentiableGridFunction<Range(Domain), EntitySet, DerivativeTraits> :
Refines<
Dune::Functions::Concept::DifferentiableFunction<Range(Domain), DerivativeTraits>,
Dune::Functions::Concept::GridFunction<Range(Domain),EntitySet>
>
{
using LocalSignature = Range(typename EntitySet::LocalCoordinate);
using LocalContext = typename EntitySet::Element;
template<class R>
using LocalDerivativeTraits = typename Dune::Functions::LocalDerivativeTraits<EntitySet, DerivativeTraits>::template Traits<R>;
template<class F>
auto require(F&& f) -> decltype(
requireConcept<DifferentiableLocalFunction<LocalSignature, LocalContext, LocalDerivativeTraits>>(localFunction(f))
);
};
template<class F, class Signature, class EntitySet, template<class> class DerivativeTraits = DefaultDerivativeTraits>
static constexpr bool isDifferentiableGridFunction()
{ return models<Concept::DifferentiableGridFunction<Signature, EntitySet, DerivativeTraits>, F>(); }
// GridViewFunction concept ##############################################
template<class Signature, class GridView>
struct GridViewFunction;
template<class Range, class Domain, class GridView>
struct GridViewFunction<Range(Domain), GridView> :
Refines<Dune::Functions::Concept::GridFunction<Range(Domain), GridViewEntitySet<GridView,0>>>
{
template<class F>
auto require(F&& f) -> decltype(
0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
);
};
template<class F, class Signature, class GridView>
static constexpr bool isGridViewFunction()
{ return models<Concept::GridViewFunction<Signature, GridView>, F>(); }
// DifferentiableGridViewFunction concept ##############################################
template<class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
struct DifferentiableGridViewFunction;
template<class Range, class Domain, class GridView, template<class> class DerivativeTraits>
struct DifferentiableGridViewFunction<Range(Domain), GridView, DerivativeTraits> :
Refines<Dune::Functions::Concept::DifferentiableGridFunction<Range(Domain), GridViewEntitySet<GridView,0>, DerivativeTraits>>
{
template<class F>
auto require(F&& f) -> decltype(
0 // We don't need to check any further expressions, because a GridViewFunction is just a GridFunction with a special EntitySet
);
};
template<class F, class Signature, class GridView, template<class> class DerivativeTraits = DefaultDerivativeTraits>
static constexpr bool isDifferentiableGridViewFunction()
{ return models<Concept::DifferentiableGridViewFunction<Signature, GridView, DerivativeTraits>, F>(); }
}}} // namespace Dune::Functions::Concept
#endif // DUNE_FUNCTIONS_COMMON_FUNCTIONCONCEPT_HH
localderivativetraits.hh
gridviewentityset.hh
signature.hh
Dune::Functions::Concept::isGridFunction
static constexpr bool isGridFunction()
Check if F models the GridFunction concept with given signature and entity set.
Definition functionconcepts.hh:273
Dune::Functions::Concept::isDifferentiableLocalFunction
static constexpr bool isDifferentiableLocalFunction()
Check if F models the DifferentiableLocalFunction concept with given signature and local context.
Definition functionconcepts.hh:208
Dune::Functions::Concept::isFunction
static constexpr bool isFunction()
Check if F models the Function concept with given signature.
Definition functionconcepts.hh:92
Dune::Functions::Concept::isDifferentiableGridViewFunction
static constexpr bool isDifferentiableGridViewFunction()
Check if F models the DifferentiableGridViewFunction concept with given signature.
Definition functionconcepts.hh:380
Dune::Functions::Concept::isDifferentiableFunction
static constexpr bool isDifferentiableFunction()
Check if F models the DifferentiableFunction concept with given signature.
Definition functionconcepts.hh:131
Dune::Functions::Concept::isGridViewFunction
static constexpr bool isGridViewFunction()
Check if F models the GridViewFunction concept with given signature.
Definition functionconcepts.hh:347
Dune::Functions::Concept::isEntitySet
static constexpr bool isEntitySet()
Check if F models the GridFunction concept with given signature and entity set.
Definition functionconcepts.hh:235
Dune::Functions::Concept::isDifferentiableGridFunction
static constexpr bool isDifferentiableGridFunction()
Check if F models the DifferentiableGridFunction concept with given signature and entity set.
Definition functionconcepts.hh:314
Dune::Functions::Concept::isLocalFunction
static constexpr bool isLocalFunction()
Check if F models the LocalFunction concept with given signature and local context.
Definition functionconcepts.hh:170
Dune::Functions::derivative
TrigonometricFunction< K, -cosFactor, sinFactor > derivative(const TrigonometricFunction< K, sinFactor, cosFactor > &f)
Obtain derivative of TrigonometricFunction function.
Definition trigonometricfunction.hh:43
Dune::Functions::Concept::isCallable
static constexpr auto isCallable()
Check if f is callable with given argument list.
Definition functionconcepts.hh:51
Dune
Definition monomialset.hh:19
Dune::Functions
Definition monomialset.hh:19
Dune::Functions::Concept
Definition backends/concepts.hh:17
Dune::Functions::DefaultDerivativeTraits
Default implementation for derivative traits.
Definition defaultderivativetraits.hh:41
Dune::Functions::Concept::Callable
Concept objects that can be called with given argument list.
Definition functionconcepts.hh:37
Dune::Functions::Concept::Callable::require
auto require(F &&f) -> decltype(f(std::declval< Args >()...))
Dune::Functions::Concept::Function
Definition functionconcepts.hh:70
Dune::Functions::Concept::Function< Range(Domain)>::require
auto require(F &&f) -> decltype(requireConvertible< Range >(f(std::declval< Domain >())))
Dune::Functions::Concept::DifferentiableFunction
Definition functionconcepts.hh:104
Dune::Functions::Concept::DifferentiableFunction< Range(Domain), DerivativeTraits >::DerivativeSignature
typename SignatureTraits< Range(Domain)>::template DerivativeSignature< DerivativeTraits > DerivativeSignature
Definition functionconcepts.hh:120
Dune::Functions::Concept::DifferentiableFunction< Range(Domain), DerivativeTraits >::require
auto require(F &&f) -> decltype(derivative(f), requireConcept< Function< DerivativeSignature > >(derivative(f)))
Dune::Functions::Concept::LocalFunction
Definition functionconcepts.hh:143
Dune::Functions::Concept::LocalFunction< Range(Domain), LocalContext >::require
auto require(F &&f) -> decltype(f.bind(std::declval< LocalContext >()), f.unbind(), requireConvertible< bool >(f.bound()), f.localContext(), requireConvertible< LocalContext >(f.localContext()))
Dune::Functions::Concept::DifferentiableLocalFunction
Definition functionconcepts.hh:176
Dune::Functions::Concept::DifferentiableLocalFunction< Range(Domain), LocalContext, DerivativeTraits >::require
auto require(F &&f) -> decltype(f.bind(std::declval< LocalContext >()), f.unbind(), f.localContext(), requireConvertible< LocalContext >(f.localContext()))
Dune::Functions::Concept::EntitySet
Concept for an entity set for a Concept::GridFunction<Range(Domain), EntitySet, DerivativeTraits>.
Definition functionconcepts.hh:224
Dune::Functions::Concept::EntitySet::require
auto require(E &&f) -> decltype(requireType< typename E::Element >(), requireType< typename E::LocalCoordinate >(), requireType< typename E::GlobalCoordinate >())
Dune::Functions::Concept::GridFunction
Definition functionconcepts.hh:242
Dune::Functions::Concept::GridFunction< Range(Domain), EntitySet >::LocalContext
typename EntitySet::Element LocalContext
Definition functionconcepts.hh:258
Dune::Functions::Concept::GridFunction< Range(Domain), EntitySet >::LocalSignature
Range(typename EntitySet::LocalCoordinate) LocalSignature
Definition functionconcepts.hh:257
Dune::Functions::Concept::GridFunction< Range(Domain), EntitySet >::require
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 >())
Dune::Functions::Concept::DifferentiableGridFunction
Definition functionconcepts.hh:279
Dune::Functions::Concept::DifferentiableGridFunction< Range(Domain), EntitySet, DerivativeTraits >::LocalDerivativeTraits
typename Dune::Functions::LocalDerivativeTraits< EntitySet, DerivativeTraits >::template Traits< R > LocalDerivativeTraits
Definition functionconcepts.hh:304
Dune::Functions::Concept::DifferentiableGridFunction< Range(Domain), EntitySet, DerivativeTraits >::require
auto require(F &&f) -> decltype(requireConcept< DifferentiableLocalFunction< LocalSignature, LocalContext, LocalDerivativeTraits > >(localFunction(f)))
Dune::Functions::Concept::DifferentiableGridFunction< Range(Domain), EntitySet, DerivativeTraits >::LocalSignature
Range(typename EntitySet::LocalCoordinate) LocalSignature
Definition functionconcepts.hh:300
Dune::Functions::Concept::DifferentiableGridFunction< Range(Domain), EntitySet, DerivativeTraits >::LocalContext
typename EntitySet::Element LocalContext
Definition functionconcepts.hh:301
Dune::Functions::Concept::GridViewFunction
Definition functionconcepts.hh:321
Dune::Functions::Concept::GridViewFunction< Range(Domain), GridView >::require
auto require(F &&f) -> decltype(0)
Dune::Functions::Concept::DifferentiableGridViewFunction
Definition functionconcepts.hh:353
Dune::Functions::Concept::DifferentiableGridViewFunction< Range(Domain), GridView, DerivativeTraits >::require
auto require(F &&f) -> decltype(0)
Dune::Functions::SignatureTraits
Helper class to deduce the signature of a callable.
Definition signature.hh:60
Dune::Functions::SignatureTag
Definition signature.hh:106
Dune::Functions::LocalDerivativeTraits
Derivative traits for local functions.
Definition localderivativetraits.hh:32