Loading...
Searching...
No Matches
localfunction.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_LOCAL_FUNCTION_HH
#define DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
#include <type_traits>
#include <dune/common/typeutilities.hh>
#include <dune/functions/common/defaultderivativetraits.hh>
#include <dune/functions/common/differentiablefunction.hh>
#include <dune/functions/common/localfunction_imp.hh>
#include <dune/functions/common/typeerasure.hh>
#include <dune/functions/common/functionconcepts.hh>
namespace Dune {
namespace Functions {
/*
* Default implementation is empty
* The actual implementation is only given if Signature is an type
* describing a function signature as Range(Domain).
*/
template<class Signature, class LocalContext, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
class LocalFunction
{};
namespace Imp
{
template<class S, class L, template<class> class DerivativeTraits, size_t bufferSize>
struct LocalFunctionTraits :
DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>
{
protected:
using Base=DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>;
public:
using LocalContext = L;
using DerivativeSignature = typename Base::DerivativeSignature;
using DerivativeInterface = LocalFunction<DerivativeSignature, L, DerivativeTraits, bufferSize>;
using Concept = LocalFunctionWrapperInterface<S, DerivativeInterface, L>;
template<class B>
using Model = LocalFunctionWrapperImplementation<S, DerivativeInterface, L, B>;
};
}
template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits, size_t bufferSize>
class LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize> :
public TypeErasureBase<
typename Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>::Concept,
Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>::template Model>
{
using Traits = Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>;
using Base = TypeErasureBase<typename Traits::Concept, Traits::template Model>;
using DerivativeInterface = typename Traits::DerivativeInterface;
public:
template<class F, disableCopyMove<LocalFunction, F> = 0 >
LocalFunction(F&& f) :
Base(std::forward<F>(f))
{
static_assert(Dune::Functions::Concept::isLocalFunction<F, Range(Domain), LocalContext>(), "Trying to construct a LocalFunction from type that does not model the LocalFunction concept");
}
LocalFunction() = default;
Range operator() (const Domain& x) const
{
return this->asInterface().operator()(x);
}
friend DerivativeInterface derivative(const LocalFunction& t)
{
return t.asInterface().derivative();
}
void bind(const LocalContext& context)
{
this->asInterface().bind(context);
}
void unbind()
{
this->asInterface().unbind();
}
bool bound() const
{
return this->asInterface().bound();
}
const LocalContext& localContext() const
{
return this->asInterface().localContext();
}
};
}} // namespace Dune::Functions
#endif // DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
localfunction_imp.hh
differentiablefunction.hh
defaultderivativetraits.hh
functionconcepts.hh
typeerasure.hh
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::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::derivative
friend DerivativeInterface derivative(const LocalFunction &t)
Get derivative of wrapped function.
Definition localfunction.hh:139
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::LocalFunction
Definition localfunction.hh:34
Dune::Functions::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::localContext
const LocalContext & localContext() const
Obtain local context this LocalFunction is bound to.
Definition localfunction.hh:173
Dune::Functions::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::LocalFunction
LocalFunction(F &&f)
Construct from function.
Definition localfunction.hh:116
Dune::Functions::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::unbind
void unbind()
Unbind from local context.
Definition localfunction.hh:158
Dune::Functions::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::bound
bool bound() const
Return if the local function is bound to a grid element.
Definition localfunction.hh:165
Dune::Functions::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::bind
void bind(const LocalContext &context)
Bind function to a local context.
Definition localfunction.hh:150
Dune::Functions::LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::LocalFunction
LocalFunction()=default
Dune::Functions::TypeErasureBase< Imp::LocalFunctionTraits< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::Concept, Imp::LocalFunctionTraits< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::template Model >::TypeErasureBase
TypeErasureBase(T &&t)
Definition typeerasure.hh:174
Dune::Functions::TypeErasureBase< Imp::LocalFunctionTraits< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::Concept, Imp::LocalFunctionTraits< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::template Model >::asInterface
Imp::LocalFunctionTraits< Range(Domain), LocalContext, DerivativeTraits, bufferSize >::Concept & asInterface()
Definition typeerasure.hh:182