dune-functions  2.5-dev
differentiablefunction.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_DIFFERENTIABLE_FUNCTION_HH
4 #define DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
5 
6 #include <type_traits>
7 
8 #include <dune/common/typeutilities.hh>
9 
16 
17 namespace Dune {
18 namespace 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  */
27 template<class Signature, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
29 {};
30 
31 
32 
33 namespace Imp
34 {
35 
37  template<class S, template<class> class DerivativeTraits, size_t bufferSize>
39  {
41  using Signature = S;
42 
45 
48 
51 
54 
57 
59  template<class B>
61  };
62 }
63 
64 
65 
80 template<class Range, class Domain, template<class> class DerivativeTraits, size_t bufferSize>
81 class 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 {
87 
89 
90  using DerivativeInterface = typename Traits::DerivativeInterface;
91 
92 public:
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 
113  DifferentiableFunction() = default;
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
typename SignatureTraits< Signature >::Domain Domain
Domain type.
Definition: differentiablefunction.hh:47
static constexpr bool isFunction()
Check if F models the Function concept with given signature.
Definition: functionconcepts.hh:76
typename SignatureTraits< Signature >::Range Range
Range type.
Definition: differentiablefunction.hh:44
Definition: differentiablefunction.hh:28
Definition: polynomial.hh:7
Definition: differentiablefunction_imp.hh:69
STL namespace.
S Signature
Signature type.
Definition: differentiablefunction.hh:41
friend DerivativeInterface derivative(const DifferentiableFunction &t)
Get derivative of wrapped function.
Definition: differentiablefunction.hh:130
DifferentiableFunction(F &&f)
Construct from function.
Definition: differentiablefunction.hh:106
typename SignatureTraits< Signature >::template DerivativeSignature< DerivativeTraits > DerivativeSignature
Signature of the derivative.
Definition: differentiablefunction.hh:50
Definition: differentiablefunction_imp.hh:50
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:164
Helper class to deduce the signature of a callable.
Definition: signature.hh:60
Traits class providing type information for DifferentiableFunction.
Definition: differentiablefunction.hh:38