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