dune-functions  2.7.1
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>
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 
54 
56  using Concept = DifferentiableFunctionWrapperInterface<Signature, DerivativeInterface>;
57 
59  template<class B>
60  using Model = DifferentiableFunctionWrapperImplementation<Signature, DerivativeInterface, 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 {
86  using Traits = Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>;
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 
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
static constexpr bool isFunction()
Check if F models the Function concept with given signature.
Definition: functionconcepts.hh:88
friend DerivativeInterface derivative(const DifferentiableFunction &t)
Get derivative of wrapped function.
Definition: differentiablefunction.hh:130
Definition: polynomial.hh:10
Definition: differentiablefunction.hh:29
DifferentiableFunction(F &&f)
Construct from function.
Definition: differentiablefunction.hh:106
Helper class to deduce the signature of a callable.
Definition: signature.hh:60
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:165