Loading...
Searching...
No Matches
differentiablefunction.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_DIFFERENTIABLE_FUNCTION_HH
#define DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
#include <type_traits>
#include <dune/common/typeutilities.hh>
#include <dune/functions/common/type_traits.hh>
#include <dune/functions/common/defaultderivativetraits.hh>
#include <dune/functions/common/differentiablefunction_imp.hh>
#include <dune/functions/common/signature.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, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
class DifferentiableFunction
{};
namespace Imp
{
template<class S, template<class> class DerivativeTraits, size_t bufferSize>
struct DifferentiableFunctionTraits
{
using Signature = S;
using Range = typename SignatureTraits<Signature>::Range;
using Domain = typename SignatureTraits<Signature>::Domain;
using DerivativeSignature = typename SignatureTraits<Signature>::template DerivativeSignature<DerivativeTraits>;
using DerivativeInterface = DifferentiableFunction<DerivativeSignature, DerivativeTraits, bufferSize>;
using Concept = DifferentiableFunctionWrapperInterface<Signature, DerivativeInterface>;
template<class B>
using Model = DifferentiableFunctionWrapperImplementation<Signature, DerivativeInterface, B>;
};
}
template<class Range, class Domain, template<class> class DerivativeTraits, size_t bufferSize>
class DifferentiableFunction< Range(Domain), DerivativeTraits, bufferSize> :
public TypeErasureBase<
typename Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>::Concept,
Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>::template Model>
{
using Traits = Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>;
using Base = TypeErasureBase<typename Traits::Concept, Traits::template Model>;
using DerivativeInterface = typename Traits::DerivativeInterface;
public:
template<class F, disableCopyMove<DifferentiableFunction, F> = 0 >
DifferentiableFunction(F&& f) :
Base(std::forward<F>(f))
{
static_assert(Dune::Functions::Concept::isFunction<F, Range(Domain)>(), "Trying to construct a DifferentiableFunction from type that does not model the Function concept");
}
DifferentiableFunction() = default;
Range operator() (const Domain& x) const
{
return this->asInterface().operator()(x);
}
friend DerivativeInterface derivative(const DifferentiableFunction& t)
{
return t.asInterface().derivative();
}
};
}} // namespace Dune::Functions
#endif // DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
signature.hh
type_traits.hh
defaultderivativetraits.hh
functionconcepts.hh
typeerasure.hh
differentiablefunction_imp.hh
Dune::Functions::Concept::isFunction
static constexpr bool isFunction()
Check if F models the Function concept with given signature.
Definition functionconcepts.hh:92
Dune::Functions::DifferentiableFunction< Range(Domain), DerivativeTraits, bufferSize >::derivative
friend DerivativeInterface derivative(const DifferentiableFunction &t)
Get derivative of wrapped function.
Definition differentiablefunction.hh:134
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::DifferentiableFunction
Definition differentiablefunction.hh:33
Dune::Functions::DifferentiableFunction< Range(Domain), DerivativeTraits, bufferSize >::DifferentiableFunction
DifferentiableFunction(F &&f)
Construct from function.
Definition differentiablefunction.hh:110
Dune::Functions::DifferentiableFunction< Range(Domain), DerivativeTraits, bufferSize >::DifferentiableFunction
DifferentiableFunction()=default
Default constructor.
Dune::Functions::SignatureTraits
Helper class to deduce the signature of a callable.
Definition signature.hh:60
Dune::Functions::TypeErasureBase< Imp::DifferentiableFunctionTraits< Range(Domain), DerivativeTraits, bufferSize >::Concept, Imp::DifferentiableFunctionTraits< Range(Domain), DerivativeTraits, bufferSize >::template Model >::TypeErasureBase
TypeErasureBase(T &&t)
Definition typeerasure.hh:174
Dune::Functions::TypeErasureBase< Imp::DifferentiableFunctionTraits< Range(Domain), DerivativeTraits, bufferSize >::Concept, Imp::DifferentiableFunctionTraits< Range(Domain), DerivativeTraits, bufferSize >::template Model >::asInterface
Imp::DifferentiableFunctionTraits< Range(Domain), DerivativeTraits, bufferSize >::Concept & asInterface()
Definition typeerasure.hh:182