DUNE PDELab (git)

differentiablefunction.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_DIFFERENTIABLE_FUNCTION_HH
8#define DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
9
10#include <type_traits>
11
13
14#include <dune/functions/common/type_traits.hh>
15#include <dune/functions/common/defaultderivativetraits.hh>
16#include <dune/functions/common/differentiablefunction_imp.hh>
17#include <dune/functions/common/signature.hh>
18#include <dune/functions/common/typeerasure.hh>
19#include <dune/functions/common/functionconcepts.hh>
20
21namespace Dune {
22namespace Functions {
23
24
25
26/*
27 * Default implementation is empty
28 * The actual implementation is only given if Signature is an type
29 * describing a function signature as Range(Domain).
30 */
31template<class Signature, template<class> class DerivativeTraits=DefaultDerivativeTraits, size_t bufferSize=56>
32class DifferentiableFunction
33{};
34
35
36
37namespace Imp
38{
39
41 template<class S, template<class> class DerivativeTraits, size_t bufferSize>
42 struct DifferentiableFunctionTraits
43 {
45 using Signature = S;
46
48 using Range = typename SignatureTraits<Signature>::Range;
49
51 using Domain = typename SignatureTraits<Signature>::Domain;
52
54 using DerivativeSignature = typename SignatureTraits<Signature>::template DerivativeSignature<DerivativeTraits>;
55
57 using DerivativeInterface = DifferentiableFunction<DerivativeSignature, DerivativeTraits, bufferSize>;
58
60 using Concept = DifferentiableFunctionWrapperInterface<Signature, DerivativeInterface>;
61
63 template<class B>
64 using Model = DifferentiableFunctionWrapperImplementation<Signature, DerivativeInterface, B>;
65 };
66}
67
68
69
84template<class Range, class Domain, template<class> class DerivativeTraits, size_t bufferSize>
85class DifferentiableFunction< Range(Domain), DerivativeTraits, bufferSize> :
86 public TypeErasureBase<
87 typename Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>::Concept,
88 Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>::template Model>
89{
90 using Traits = Imp::DifferentiableFunctionTraits<Range(Domain), DerivativeTraits, bufferSize>;
91
93
94 using DerivativeInterface = typename Traits::DerivativeInterface;
95
96public:
97
109 template<class F, disableCopyMove<DifferentiableFunction, F> = 0 >
111 Base(std::forward<F>(f))
112 {
113 static_assert(Dune::Functions::Concept::isFunction<F, Range(Domain)>(), "Trying to construct a DifferentiableFunction from type that does not model the Function concept");
114 }
115
118
122 Range operator() (const Domain& x) const
123 {
124 return this->asInterface().operator()(x);
125 }
126
134 friend DerivativeInterface derivative(const DifferentiableFunction& t)
135 {
136 return t.asInterface().derivative();
137 }
138};
139
140
141
142}} // namespace Dune::Functions
143
144
145
146#endif // DUNE_FUNCTIONS_COMMON_DIFFERENTIABLE_FUNCTION_HH
DifferentiableFunction(F &&f)
Construct from function.
Definition: differentiablefunction.hh:110
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:169
friend DerivativeInterface derivative(const DifferentiableFunction &t)
Get derivative of wrapped function.
Definition: differentiablefunction.hh:134
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 24, 23:30, 2024)