dune-functions 2.9.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
18namespace Dune {
19namespace 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 */
28template<class Signature, class LocalContext, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
30{};
31
32
33
34namespace Imp
35{
36
38 template<class S, class L, template<class> class DerivativeTraits, size_t bufferSize>
39 struct LocalFunctionTraits :
40 DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>
41 {
42 protected:
43 using Base=DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>;
44
45 public:
47 using LocalContext = L;
48
50 using DerivativeSignature = typename Base::DerivativeSignature;
51
54
56 using Concept = LocalFunctionWrapperInterface<S, DerivativeInterface, L>;
57
59 template<class B>
60 using Model = LocalFunctionWrapperImplementation<S, DerivativeInterface, L, B>;
61 };
62}
63
64
65
86template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits, size_t bufferSize>
87class 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{
92 using Traits = Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>;
93
95
96 using DerivativeInterface = typename Traits::DerivativeInterface;
97
98public:
99
111 template<class F, disableCopyMove<LocalFunction, F> = 0 >
113 Base(std::forward<F>(f))
114 {
115 static_assert(Dune::Functions::Concept::isLocalFunction<F, Range(Domain), LocalContext>(), "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
161 bool bound() const
162 {
163 return this->asInterface().bound();
164 }
165
169 const LocalContext& localContext() const
170 {
171 return this->asInterface().localContext();
172 }
173};
174
175
176
177}} // namespace Dune::Functions
178
179
180
181#endif // DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
friend DerivativeInterface derivative(const LocalFunction &t)
Get derivative of wrapped function.
Definition: localfunction.hh:135
Definition: polynomial.hh:10
Definition: localfunction.hh:30
const LocalContext & localContext() const
Obtain local context this LocalFunction is bound to.
Definition: localfunction.hh:169
LocalFunction(F &&f)
Construct from function.
Definition: localfunction.hh:112
void unbind()
Unbind from local context.
Definition: localfunction.hh:154
bool bound() const
Return if the local function is bound to a grid element.
Definition: localfunction.hh:161
void bind(const LocalContext &context)
Bind function to a local context.
Definition: localfunction.hh:146
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:165