DUNE PDELab (git)

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
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
8#define DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
9
10#include <type_traits>
11
13
14#include <dune/functions/common/defaultderivativetraits.hh>
15#include <dune/functions/common/differentiablefunction.hh>
16#include <dune/functions/common/localfunction_imp.hh>
17#include <dune/functions/common/typeerasure.hh>
18#include <dune/functions/common/functionconcepts.hh>
19
20
21
22namespace Dune {
23namespace Functions {
24
25
26
27/*
28 * Default implementation is empty
29 * The actual implementation is only given if Signature is an type
30 * describing a function signature as Range(Domain).
31 */
32template<class Signature, class LocalContext, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
33class LocalFunction
34{};
35
36
37
38namespace Imp
39{
40
42 template<class S, class L, template<class> class DerivativeTraits, size_t bufferSize>
43 struct LocalFunctionTraits :
44 DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>
45 {
46 protected:
47 using Base=DifferentiableFunctionTraits<S, DerivativeTraits, bufferSize>;
48
49 public:
51 using LocalContext = L;
52
54 using DerivativeSignature = typename Base::DerivativeSignature;
55
57 using DerivativeInterface = LocalFunction<DerivativeSignature, L, DerivativeTraits, bufferSize>;
58
60 using Concept = LocalFunctionWrapperInterface<S, DerivativeInterface, L>;
61
63 template<class B>
64 using Model = LocalFunctionWrapperImplementation<S, DerivativeInterface, L, B>;
65 };
66}
67
68
69
90template<class Range, class Domain, class LocalContext, template<class> class DerivativeTraits, size_t bufferSize>
91class LocalFunction< Range(Domain), LocalContext, DerivativeTraits, bufferSize> :
92 public TypeErasureBase<
93 typename Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>::Concept,
94 Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>::template Model>
95{
96 using Traits = Imp::LocalFunctionTraits<Range(Domain), LocalContext, DerivativeTraits, bufferSize>;
97
99
100 using DerivativeInterface = typename Traits::DerivativeInterface;
101
102public:
103
115 template<class F, disableCopyMove<LocalFunction, F> = 0 >
117 Base(std::forward<F>(f))
118 {
119 static_assert(Dune::Functions::Concept::isLocalFunction<F, Range(Domain), LocalContext>(), "Trying to construct a LocalFunction from type that does not model the LocalFunction concept");
120 }
121
122 LocalFunction() = default;
123
127 Range operator() (const Domain& x) const
128 {
129 return this->asInterface().operator()(x);
130 }
131
139 friend DerivativeInterface derivative(const LocalFunction& t)
140 {
141 return t.asInterface().derivative();
142 }
143
150 void bind(const LocalContext& context)
151 {
152 this->asInterface().bind(context);
153 }
154
158 void unbind()
159 {
160 this->asInterface().unbind();
161 }
162
165 bool bound() const
166 {
167 return this->asInterface().bound();
168 }
169
173 const LocalContext& localContext() const
174 {
175 return this->asInterface().localContext();
176 }
177};
178
179
180
181}} // namespace Dune::Functions
182
183
184
185#endif // DUNE_FUNCTIONS_COMMON_LOCAL_FUNCTION_HH
const LocalContext & localContext() const
Obtain local context this LocalFunction is bound to.
Definition: localfunction.hh:173
LocalFunction(F &&f)
Construct from function.
Definition: localfunction.hh:116
void unbind()
Unbind from local context.
Definition: localfunction.hh:158
bool bound() const
Return if the local function is bound to a grid element.
Definition: localfunction.hh:165
void bind(const LocalContext &context)
Bind function to a local context.
Definition: localfunction.hh:150
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:169
friend DerivativeInterface derivative(const LocalFunction &t)
Get derivative of wrapped function.
Definition: localfunction.hh:139
Dune namespace.
Definition: alignedallocator.hh:13
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 13, 23:29, 2024)