dune-functions  2.5.0
localfunction.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_LOCAL_FUNCTION_HH
4 #define DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
5 
6 #include <type_traits>
7 
8 #include <dune/common/typeutilities.hh>
9 
15 
16 
17 
18 namespace Dune {
19 namespace Functions {
20 
21 
22 
23 /*
24  * Default implementation is empty
25  * The actual implementation is only given if Signature is an type
26  * describing a function signature as Range(Domain).
27  */
28 template<class Signature, class LocalContext, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
30 {};
31 
32 
33 
34 namespace Imp
35 {
36 
38  template<class S, class L, template<class> class DerivativeTraits, size_t bufferSize>
40  DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>
41  {
42  protected:
44 
45  public:
47  using LocalContext = L;
48 
51 
54 
57 
59  template<class B>
61  };
62 }
63 
64 
65 
86 template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits, size_t bufferSize>
87 class LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize> :
88  public TypeErasureBase<
89  typename Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>::Concept,
90  Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>::template Model>
91 {
93 
95 
96  using DerivativeInterface = typename Traits::DerivativeInterface;
97 
98 public:
99 
111  template<class F, disableCopyMove<LocalFunction, F> = 0 >
112  LocalFunction(F&& f) :
113  Base(std::forward<F>(f))
114  {
115  static_assert(Dune::Functions::Concept::isLocalFunction<F, Range(Domain), LocalContext, DerivativeTraits>(), "Trying to construct a LocalFunction from type that does not model the LocalFunction concept");
116  }
117 
118  LocalFunction() = default;
119 
123  Range operator() (const Domain& x) const
124  {
125  return this->asInterface().operator()(x);
126  }
127 
135  friend DerivativeInterface derivative(const LocalFunction& t)
136  {
137  return t.asInterface().derivative();
138  }
139 
146  void bind(const LocalContext& context)
147  {
148  this->asInterface().bind(context);
149  }
150 
154  void unbind()
155  {
156  this->asInterface().unbind();
157  }
158 
162  const LocalContext& localContext() const
163  {
164  return this->asInterface().localContext();
165  }
166 };
167 
168 
169 
170 }} // namespace Dune::Functions
171 
172 
173 
174 #endif // DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
const LocalContext & localContext() const
Obtain local contex this LocalFunction is bound to.
Definition: localfunction.hh:162
void bind(const LocalContext &context)
Bind function to a local context.
Definition: localfunction.hh:146
LocalFunction(F &&f)
Construct from function.
Definition: localfunction.hh:112
Definition: differentiablefunction.hh:28
void unbind()
Unbind from local context.
Definition: localfunction.hh:154
Traits class providing type information for DifferentiableFunction.
Definition: localfunction.hh:39
Definition: polynomial.hh:7
Definition: differentiablefunction_imp.hh:69
STL namespace.
typename SignatureTraits< Signature >::template DerivativeSignature< DerivativeTraits > DerivativeSignature
Signature of the derivative.
Definition: differentiablefunction.hh:50
Definition: localfunction.hh:29
Definition: differentiablefunction_imp.hh:50
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:164
Traits class providing type information for DifferentiableFunction.
Definition: differentiablefunction.hh:38
static constexpr bool isLocalFunction()
Check if F models the LocalFunction concept with given signature and local context.
Definition: functionconcepts.hh:156
Definition: localfunction_imp.hh:20
L LocalContext
LocalContext type.
Definition: localfunction.hh:47
friend DerivativeInterface derivative(const LocalFunction &t)
Get derivative of wrapped function.
Definition: localfunction.hh:135