DUNE PDELab (2.7)

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
10
11
12
13namespace Dune {
14
15 namespace Impl {
16
17 // Concept for function supporting f.evaluate(Domain, Range&)
18 template<class Domain, class Range>
19 struct FunctionWithEvaluate
20 {
21 template<class F>
22 auto require(F&& f) -> decltype(
23 f.evaluate(std::declval<Domain>(), std::declval<Range&>())
24 );
25 };
26
27 // Concept for function supporting f(Domain)
28 template<class Domain>
29 struct FunctionWithCallOperator
30 {
31 template<class F>
32 auto require(F&& f) -> decltype(
33 f(std::declval<Domain>())
34 );
35 };
36
37 // Create function supporting f.evaluate(Domain, Range&)
38 // If the argument already does this, just forward it.
39 template<class Domain, class Range, class F,
40 std::enable_if_t<models<FunctionWithEvaluate<Domain, Range>, F>(), int> = 0>
41 decltype(auto) makeFunctionWithEvaluate(const F& f)
42 {
43 return f;
44 }
45
46 // Create function supporting f.evaluate(Domain, Range&)
47 // If the argument does not support this, wrap it as VirtualFunction
48 template<class Domain, class Range, class F,
49 std::enable_if_t<not models<FunctionWithEvaluate<Domain, Range>, F>(), int> = 0>
50 decltype(auto) makeFunctionWithEvaluate(const F& f)
51 {
52 return makeVirtualFunction<Domain, Range>(std::cref(f));
53 }
54
55 // Create function supporting Range = f(Domain)
56 // If the argument already does this, just forward it.
57 template<class Domain, class F,
58 std::enable_if_t<models<FunctionWithCallOperator<Domain>, F>(), int> = 0>
59 decltype(auto) makeFunctionWithCallOperator(const F& f)
60 {
61 return f;
62 }
63
64 // Create function supporting Range = f(Domain)
65 // If the argument does not support this, wrap it in a lambda
66 template<class Domain, class F,
67 std::enable_if_t<not models<FunctionWithCallOperator<std::decay_t<Domain> >, F>(), int> = 0>
68 decltype(auto) makeFunctionWithCallOperator(const F& f)
69 {
70 return [&](auto&& x) {
71 typename std::decay_t<F>::Traits::RangeType y;
72 f.evaluate(x,y);
73 return y;
74 };
75 }
76
77 } // namespace Impl
78
79} // namespace Dune
80#endif
Infrastructure for concepts.
Simple base class templates for functions.
Dune namespace.
Definition: alignedallocator.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)