Dune Core Modules (2.8.0)

localfunction.hh
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
9
10#include <dune/functions/common/defaultderivativetraits.hh>
11#include <dune/functions/common/differentiablefunction.hh>
12#include <dune/functions/common/localfunction_imp.hh>
13#include <dune/functions/common/typeerasure.hh>
14#include <dune/functions/common/functionconcepts.hh>
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>
29class LocalFunction
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
53 using DerivativeInterface = LocalFunction<DerivativeSignature, L, DerivativeTraits, bufferSize>;
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
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
LocalFunction(F &&f)
Construct from function.
Definition: localfunction.hh:112
void unbind()
Unbind from local context.
Definition: localfunction.hh:154
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
friend DerivativeInterface derivative(const LocalFunction &t)
Get derivative of wrapped function.
Definition: localfunction.hh:135
Dune namespace.
Definition: alignedallocator.hh:11
STL namespace.
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)