Dune Core Modules (2.8.0)

localinterpolation.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_LOCALFUNCTIONS_COMMON_LOCALINTERPOLATION_HH
4#define DUNE_LOCALFUNCTIONS_COMMON_LOCALINTERPOLATION_HH
5
6#include <functional>
7
9
10
11
12namespace Dune {
13
14 namespace Impl {
15
16 // Concept for function supporting f.evaluate(Domain, Range&)
17 template<class Domain, class Range>
18 struct FunctionWithEvaluate
19 {
20 template<class F>
21 auto require(F&& f) -> decltype(
22 f.evaluate(std::declval<Domain>(), std::declval<Range&>())
23 );
24 };
25
26 // Concept for function supporting f(Domain)
27 template<class Domain>
28 struct FunctionWithCallOperator
29 {
30 template<class F>
31 auto require(F&& f) -> decltype(
32 f(std::declval<Domain>())
33 );
34 };
35
36 // Create function supporting Range = f(Domain)
37 // If the argument already does this, just forward it.
38 template<class Domain, class F,
39 std::enable_if_t<models<FunctionWithCallOperator<Domain>, F>(), int> = 0>
40 decltype(auto) makeFunctionWithCallOperator(const F& f)
41 {
42 return f;
43 }
44
45 // Create function supporting Range = f(Domain)
46 // If the argument does not support this, wrap it in a lambda
47 template<class Domain, class F,
48 std::enable_if_t<not models<FunctionWithCallOperator<std::decay_t<Domain> >, F>(), int> = 0>
49#ifndef DUNE_DEPRECATED_INTERPOLATE_CHECK
50 [[deprecated( "Passing functions only supporting 'f.evaluate(x,y)' to interpolate() is deprecated."
51 "Use functions supporting operator(), i.e. f(x) instead!")]]
52#endif
53 decltype(auto) makeFunctionWithCallOperator(const F& f)
54 {
55 return [&](auto&& x) {
56 typename std::decay_t<F>::Traits::RangeType y;
57 f.evaluate(x,y);
58 return y;
59 };
60 }
61
62 } // namespace Impl
63
64} // namespace Dune
65#endif
Infrastructure for concepts.
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)