dune-functions  2.7.1
differentiablefunctionfromcallables.hh
Go to the documentation of this file.
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 
7 #include <dune/common/typeutilities.hh>
8 #include <dune/common/hybridutilities.hh>
9 
11 
14 
15 
16 
17 namespace Dune {
18 namespace Functions {
19 
20 
21 
22 template<class Signature, template<class> class DerivativeTraits, class... Callables>
24 
25 
26 
43 template<class Range, class Domain, template<class> class DerivativeTraits, class F>
44 class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F>
45 {
46 public:
47 
49  using Signature = Range(Domain);
50 
52 
54  using DerivativeSignature = typename DerivativeTraits<RawSignature>::Range(Domain);
55 
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 
77  {
78  DUNE_THROW(Dune::NotImplemented, "Derivative not implemented");
79  }
80 
81 private:
82  F f_;
83 };
84 
85 
86 
103 template<class Range, class Domain, template<class> class DerivativeTraits, class F, class DF, class... Derivatives>
104 class DifferentiableFunctionFromCallables<Range(Domain), DerivativeTraits, F, DF, Derivatives...>
105 {
106 public:
107 
108  using Signature = Range(Domain);
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 
138  {
139  return t.df_;
140  }
141 
142 private:
143  F f_;
144  Derivative df_;
145 };
146 
147 
162 template<class Signature, template<class> class DerivativeTraits, class... F>
163 DifferentiableFunctionFromCallables<Signature, DerivativeTraits, 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< Signature, DerivativeTraits, F... > makeDifferentiableFunctionFromCallables(const SignatureTag< Signature, DerivativeTraits > &signatureTag, F &&... f)
Create a DifferentiableFunction from callables.
Definition: differentiablefunctionfromcallables.hh:164
friend Derivative derivative(const DifferentiableFunctionFromCallables &t)
Get derivative of DifferentiableFunctionFromCallables.
Definition: differentiablefunctionfromcallables.hh:76
Definition: polynomial.hh:10
Definition: differentiablefunction.hh:29
Definition: differentiablefunctionfromcallables.hh:23
DifferentiableFunctionFromCallables(FF &&f)
Constructor copying the given function.
Definition: differentiablefunctionfromcallables.hh:61
typename SignatureTraits< Signature >::RawSignature RawSignature
Definition: differentiablefunctionfromcallables.hh:51
Range(Domain) Signature
Signature of function.
Definition: differentiablefunctionfromcallables.hh:49
typename DerivativeTraits< RawSignature >::Range(Domain) DerivativeSignature
Signature of derivative.
Definition: differentiablefunctionfromcallables.hh:54
typename DerivativeTraits< RawSignature >::Range(Domain) DerivativeSignature
Definition: differentiablefunctionfromcallables.hh:110
typename SignatureTraits< Signature >::RawSignature RawSignature
Definition: differentiablefunctionfromcallables.hh:109
DifferentiableFunctionFromCallables(FF &&f, DFF &&df, DDFF &&... ddf)
Constructor copying the given functions.
Definition: differentiablefunctionfromcallables.hh:121
Helper class to deduce the signature of a callable.
Definition: signature.hh:60
Definition: signature.hh:106