DUNE-ACFEM (2.5.1)

functor.hh
1#ifndef __DUNE_ACFEM_FUNCTOR_HH__
2#define __DUNE_ACFEM_FUNCTOR_HH__
3
4namespace Dune {
5
6 namespace ACFem {
7
16 template<class LocalArray, class GlobalArray>
18 {
19 explicit ExtractFunctor(LocalArray& localArray,
20 const GlobalArray& globalArray)
21 : localArray_(localArray), globalArray_(globalArray)
22 {}
23
24 template<class GlobalKey>
25 void operator()(const std::size_t local, const GlobalKey &global) const
26 {
27 localArray_[local] = globalArray_[global];
28 }
29
30 private:
31 LocalArray& localArray_;
32 const GlobalArray& globalArray_;
33 };
34
39 template<class T, class GlobalArray>
40 struct ExtractFunctor<T *, GlobalArray>
41 {
42 explicit ExtractFunctor(T *localArray,
43 const GlobalArray& globalArray)
44 : localArray_(localArray), globalArray_(globalArray)
45 {}
46
47 template<class GlobalKey>
48 void operator()(const std::size_t local, const GlobalKey &global) const
49 {
50 localArray_[local] = globalArray_[global];
51 }
52
53 private:
54 T* localArray_;
55 const GlobalArray& globalArray_;
56 };
57
61 template<class FunctorOne, class FunctorTwo>
63 {
64 explicit PairFunctor(FunctorOne&& one, FunctorTwo&& two)
65 : one_(one), two_(two)
66 {}
67
68 template<class Value>
69 void operator()(const std::size_t local, const Value& value) const
70 {
71 one_(local, value);
72 two_(local, value);
73 }
74
75 private:
76 FunctorOne& one_;
77 FunctorTwo& two_;
78 };
79
86 template<class FunctorOne, class FunctorTwo>
87 PairFunctor<FunctorOne, FunctorTwo> makePairFunctor(FunctorOne&& func1, FunctorTwo&& func2)
88 {
89 return PairFunctor<FunctorOne, FunctorTwo>(std::forward<FunctorOne>(func1),
90 std::forward<FunctorTwo>(func2));
91 }
92
97 template<class... Types>
99 {
100 typedef std::tuple<Types&...> TupleType;
101
102 TupleFunctor(const TupleType& arg)
103 : functorTuple_(arg)
104 {}
105
106 template<class Value>
107 void operator()(const std::size_t local, const Value& value) const
108 {
109 FunctorHelper<TupleType, std::tuple_size<TupleType>::value-1>::apply(
110 functorTuple_, local, value);
111 }
112
113 private:
114 template<class Tuple, unsigned index>
115 struct FunctorHelper
116 {
117 template<class Value>
118 static void apply(const Tuple& tuple, const std::size_t local, const Value& value)
119 {
120 FunctorHelper<Tuple, index - 1>::apply(tuple, local, value);
121 std::get<index>(tuple)(local, value);
122 }
123 };
124 template<class Tuple>
125 struct FunctorHelper<Tuple, 0>
126 {
127 template<class Value>
128 static void apply(const Tuple& tuple, const std::size_t local, const Value& value)
129 {
130 std::get<0>(tuple)(local, value);
131 }
132 };
133
134 const TupleType functorTuple_;
135 };
136
141 template<class... Types>
142 TupleFunctor<Types...> makeTupleFunctor(Types&&... args)
143 {
144 //return TupleFunctor<Types...>(std::tuple<Types&&...>(std::forward<Types>(args)...));
145 return TupleFunctor<Types...>(std::forward_as_tuple(args...));
146 }
147
149
150 } // ACFem::
151
152} // Dune::
153
154#endif // __DUNE_ACFEM_FUNCTOR_HH__
TupleFunctor< Types... > makeTupleFunctor(Types &&... args)
Combine several functors into one.
Definition: functor.hh:142
PairFunctor< FunctorOne, FunctorTwo > makePairFunctor(FunctorOne &&func1, FunctorTwo &&func2)
Combine two functors into one.
Definition: functor.hh:87
A functor which extracts values from a global array and copies them to a local array.
Definition: functor.hh:18
Generate a compound functor out of two functors.
Definition: functor.hh:63
Generate a compound functor out of a tuple of functors.
Definition: functor.hh:99
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)