Dune Core Modules (2.9.0)

differentiablefunctionfromcallables.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_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
4#define DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
5
6
8#include <dune/common/hybridutilities.hh>
9
10#include <dune/functions/common/signature.hh>
11
12#include <dune/functions/common/differentiablefunction.hh>
13#include <dune/functions/common/functionconcepts.hh>
14
15
16
17namespace Dune {
18namespace Functions {
19
20
21
22template<class Signature, template<class> class DerivativeTraits, class... Callables>
23class DifferentiableFunctionFromCallables;
24
25
26
43template<class Range, class Domain, template<class> class DerivativeTraits, class F>
44class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F>
45{
46public:
47
49 using Signature = Range(Domain);
50
51 using RawSignature = typename SignatureTraits<Signature>::RawSignature;
52
54 using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
55
57 using Derivative = DifferentiableFunction<DerivativeSignature, DerivativeTraits>;
58
60 template<class FF, disableCopyMove<DifferentiableFunctionFromCallables, FF> = 0>
62 f_(std::forward<FF>(f))
63 {}
64
66 Range operator() (const Domain& x) const
67 {
68 return f_(x);
69 }
70
76 friend Derivative derivative(const DifferentiableFunctionFromCallables& t)
77 {
78 DUNE_THROW(Dune::NotImplemented, "Derivative not implemented");
79 }
80
81private:
82 F f_;
83};
84
85
86
103template<class Range, class Domain, template<class> class DerivativeTraits, class F, class DF, class... Derivatives>
104class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F, DF, Derivatives...>
105{
106public:
107
108 using Signature = Range(Domain);
109 using RawSignature = typename SignatureTraits<Signature>::RawSignature;
110 using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
111
112 using Derivative = DifferentiableFunctionFromCallables<DerivativeSignature, DerivativeTraits, DF, Derivatives...>;
113
120 template<class FF, class DFF, class... DDFF>
121 DifferentiableFunctionFromCallables(FF&& f, DFF&& df, DDFF&&... ddf) :
122 f_(std::forward<FF>(f)),
123 df_(std::forward<DFF>(df), std::forward<DDFF>(ddf)...)
124 {}
125
127 Range operator() (const Domain& x) const
128 {
129 return f_(x);
130 }
131
137 friend Derivative derivative(const DifferentiableFunctionFromCallables& t)
138 {
139 return t.df_;
140 }
141
142private:
143 F f_;
144 Derivative df_;
145};
146
147
162template<class Signature, template<class> class DerivativeTraits, class... F>
163DifferentiableFunctionFromCallables<Signature, DerivativeTraits, F...>
164 makeDifferentiableFunctionFromCallables(const SignatureTag<Signature, DerivativeTraits>& signatureTag, F&&... f)
165{
166 return DifferentiableFunctionFromCallables<Signature, DerivativeTraits, F...>(f...);
167}
168
169
170
171} // namespace Functions
172} // namespace Dune
173
174#endif //DUNE_FUNCTIONS_COMMON_DIFFEREENTIONABEFUNCTIONFROMCALLABLES_HH
DifferentiableFunctionFromCallables(FF &&f, DFF &&df, DDFF &&... ddf)
Constructor copying the given functions.
Definition: differentiablefunctionfromcallables.hh:121
DifferentiableFunction< DerivativeSignature, DerivativeTraits > Derivative
Type of derivative.
Definition: differentiablefunctionfromcallables.hh:57
DifferentiableFunctionFromCallables(FF &&f)
Constructor copying the given function.
Definition: differentiablefunctionfromcallables.hh:61
Range(Domain) Signature
Signature of function.
Definition: differentiablefunctionfromcallables.hh:49
typename DerivativeTraits< RawSignature >::Range(Domain) DerivativeSignature
Signature of derivative.
Definition: differentiablefunctionfromcallables.hh:54
Default exception for dummy implementations.
Definition: exceptions.hh:263
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
friend Derivative derivative(const DifferentiableFunctionFromCallables &t)
Get derivative of DifferentiableFunctionFromCallables.
Definition: differentiablefunctionfromcallables.hh:76
DifferentiableFunctionFromCallables< Signature, DerivativeTraits, F... > makeDifferentiableFunctionFromCallables(const SignatureTag< Signature, DerivativeTraits > &signatureTag, F &&... f)
Create a DifferentiableFunction from callables.
Definition: differentiablefunctionfromcallables.hh:164
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Helper class to deduce the signature of a callable.
Definition: signature.hh:56
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)