Dune Core Modules (2.9.0)

differentiablefunction.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
4#define DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
5
6#include <type_traits>
7
9
10#include <dune/functions/common/type_traits.hh>
11#include <dune/functions/common/defaultderivativetraits.hh>
12#include <dune/functions/common/differentiablefunction_imp.hh>
13#include <dune/functions/common/signature.hh>
14#include <dune/functions/common/typeerasure.hh>
15#include <dune/functions/common/functionconcepts.hh>
16
17namespace Dune {
18namespace Functions {
19
20
21
22/*
23 * Default implementation is empty
24 * The actual implementation is only given if Signature is an type
25 * describing a function signature as Range(Domain).
26 */
27template<class Signature, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
28class DifferentiableFunction
29{};
30
31
32
33namespace Imp
34{
35
37 template<class S, template<class> class DerivativeTraits, size_t bufferSize>
38 struct DifferentiableFunctionTraits
39 {
41 using Signature = S;
42
44 using Range = typename SignatureTraits<Signature>::Range;
45
47 using Domain = typename SignatureTraits<Signature>::Domain;
48
50 using DerivativeSignature = typename SignatureTraits<Signature>::template DerivativeSignature<DerivativeTraits>;
51
53 using DerivativeInterface = DifferentiableFunction<DerivativeSignature, DerivativeTraits, bufferSize>;
54
56 using Concept = DifferentiableFunctionWrapperInterface<Signature, DerivativeInterface>;
57
59 template<class B>
60 using Model = DifferentiableFunctionWrapperImplementation<Signature, DerivativeInterface, B>;
61 };
62}
63
64
65
80template<class Range, class Domain, template<class> class DerivativeTraits, size_t bufferSize>
81class DifferentiableFunction< Range(Domain), DerivativeTraits, bufferSize> :
82 public TypeErasureBase<
83 typename Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>::Concept,
84 Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>::template Model>
85{
86 using Traits = Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>;
87
89
90 using DerivativeInterface = typename Traits::DerivativeInterface;
91
92public:
93
105 template<class F, disableCopyMove<DifferentiableFunction, F> = 0 >
107 Base(std::forward<F>(f))
108 {
109 static_assert(Dune::Functions::Concept::isFunction<F, Range(Domain)>(), "Trying to construct a DifferentiableFunction from type that does not model the Function concept");
110 }
111
114
118 Range operator() (const Domain& x) const
119 {
120 return this->asInterface().operator()(x);
121 }
122
130 friend DerivativeInterface derivative(const DifferentiableFunction& t)
131 {
132 return t.asInterface().derivative();
133 }
134};
135
136
137
138}} // namespace Dune::Functions
139
140
141
142#endif // DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
DifferentiableFunction(F &&f)
Construct from function.
Definition: differentiablefunction.hh:106
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:165
friend DerivativeInterface derivative(const DifferentiableFunction &t)
Get derivative of wrapped function.
Definition: differentiablefunction.hh:130
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)