Loading...
Searching...
No Matches
differentiablefunctionfromcallables.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_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
#define DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
#include <dune/common/typeutilities.hh>
#include <dune/common/hybridutilities.hh>
#include <dune/functions/common/signature.hh>
#include <dune/functions/common/differentiablefunction.hh>
#include <dune/functions/common/functionconcepts.hh>
namespace Dune {
namespace Functions {
template<class Signature, template<class> class DerivativeTraits, class... Callables>
class DifferentiableFunctionFromCallables;
template<class Range, class Domain, template<class> class DerivativeTraits, class F>
class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F>
{
public:
using Signature = Range(Domain);
using RawSignature = typename SignatureTraits<Signature>::RawSignature;
using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
using Derivative = DifferentiableFunction<DerivativeSignature, DerivativeTraits>;
template<class FF, disableCopyMove<DifferentiableFunctionFromCallables, FF> = 0>
DifferentiableFunctionFromCallables(FF&& f) :
f_(std::forward<FF>(f))
{}
Range operator() (const Domain& x) const
{
return f_(x);
}
friend Derivative derivative(const DifferentiableFunctionFromCallables& t)
{
DUNE_THROW(Dune::NotImplemented, "Derivative not implemented");
}
private:
F f_;
};
template<class Range, class Domain, template<class> class DerivativeTraits, class F, class DF, class... Derivatives>
class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F, DF, Derivatives...>
{
public:
using Signature = Range(Domain);
using RawSignature = typename SignatureTraits<Signature>::RawSignature;
using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
using Derivative = DifferentiableFunctionFromCallables<DerivativeSignature, DerivativeTraits, DF, Derivatives...>;
template<class FF, class DFF, class... DDFF>
DifferentiableFunctionFromCallables(FF&& f, DFF&& df, DDFF&&... ddf) :
f_(std::forward<FF>(f)),
df_(std::forward<DFF>(df), std::forward<DDFF>(ddf)...)
{}
Range operator() (const Domain& x) const
{
return f_(x);
}
friend Derivative derivative(const DifferentiableFunctionFromCallables& t)
{
return t.df_;
}
private:
F f_;
Derivative df_;
};
template<class Signature, template<class> class DerivativeTraits, class... F>
DifferentiableFunctionFromCallables<Signature, DerivativeTraits, F...>
makeDifferentiableFunctionFromCallables(const SignatureTag<Signature, DerivativeTraits>& signatureTag, F&&... f)
{
return DifferentiableFunctionFromCallables<Signature, DerivativeTraits, F...>(f...);
}
} // namespace Functions
} // namespace Dune
#endif //DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
signature.hh
differentiablefunction.hh
functionconcepts.hh
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F >::derivative
friend Derivative derivative(const DifferentiableFunctionFromCallables &t)
Get derivative of DifferentiableFunctionFromCallables.
Definition differentiablefunctionfromcallables.hh:80
Dune::Functions::makeDifferentiableFunctionFromCallables
DifferentiableFunctionFromCallables< Signature, DerivativeTraits, F... > makeDifferentiableFunctionFromCallables(const SignatureTag< Signature, DerivativeTraits > &signatureTag, F &&... f)
Create a DifferentiableFunction from callables.
Definition differentiablefunctionfromcallables.hh:168
Dune
Definition monomialset.hh:19
Dune::Functions
Definition monomialset.hh:19
Dune::Functions::DifferentiableFunction
Definition differentiablefunction.hh:33
Dune::Functions::DifferentiableFunctionFromCallables
Definition differentiablefunctionfromcallables.hh:27
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F >::Derivative
DifferentiableFunction< DerivativeSignature, DerivativeTraits > Derivative
Type of derivative.
Definition differentiablefunctionfromcallables.hh:61
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F >::DifferentiableFunctionFromCallables
DifferentiableFunctionFromCallables(FF &&f)
Constructor copying the given function.
Definition differentiablefunctionfromcallables.hh:65
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F >::RawSignature
typename SignatureTraits< Signature >::RawSignature RawSignature
Definition differentiablefunctionfromcallables.hh:55
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F >::Signature
Range(Domain) Signature
Signature of function.
Definition differentiablefunctionfromcallables.hh:53
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F >::DerivativeSignature
typename DerivativeTraits< RawSignature >::Range(Domain) DerivativeSignature
Signature of derivative.
Definition differentiablefunctionfromcallables.hh:58
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F, DF, Derivatives... >::DerivativeSignature
typename DerivativeTraits< RawSignature >::Range(Domain) DerivativeSignature
Definition differentiablefunctionfromcallables.hh:114
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F, DF, Derivatives... >::Derivative
DifferentiableFunctionFromCallables< DerivativeSignature, DerivativeTraits, DF, Derivatives... > Derivative
Definition differentiablefunctionfromcallables.hh:116
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F, DF, Derivatives... >::Signature
Range(Domain) Signature
Definition differentiablefunctionfromcallables.hh:112
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F, DF, Derivatives... >::RawSignature
typename SignatureTraits< Signature >::RawSignature RawSignature
Definition differentiablefunctionfromcallables.hh:113
Dune::Functions::DifferentiableFunctionFromCallables< Range(Domain), DerivativeTraits, F, DF, Derivatives... >::DifferentiableFunctionFromCallables
DifferentiableFunctionFromCallables(FF &&f, DFF &&df, DDFF &&... ddf)
Constructor copying the given functions.
Definition differentiablefunctionfromcallables.hh:125
Dune::Functions::SignatureTraits
Helper class to deduce the signature of a callable.
Definition signature.hh:60
Dune::Functions::SignatureTag
Definition signature.hh:106