dune-fem 2.8.0
Loading...
Searching...
No Matches
operator/common/tuple.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_OPERATOR_COMMON_TUPLE_HH
2#define DUNE_FEM_OPERATOR_COMMON_TUPLE_HH
3
4#include <tuple>
5#include <utility>
6
9
10
11namespace Dune
12{
13
14 namespace Fem
15 {
16
17 // forward declaration
18 template< class ... Operators >
19 class TupleOperator;
20
21
22 namespace __TupleOperatorImp
23 {
24
25 // ColTraits
26 // ---------
27
28 template< class ... Operators >
29 struct ColTraits
30 {
31 static_assert( Std::are_all_same< typename Operators::DomainFunctionType ... >::value,
32 "TupleOperator< ColTraits > needs a common DomainFunction Type." );
33 typedef typename std::tuple_element< 0, std::tuple< Operators ... > >::type::DomainFunctionType DomainFunctionType;
34 typedef TupleDiscreteFunction< typename Operators::RangeFunctionType ... > RangeFunctionType;
35 };
36
37 // RowTraits
38 // ---------
39
40 template< class ... Operators >
41 struct RowTraits
42 {
43 typedef TupleDiscreteFunction< typename Operators::DomainFunctionType ... > DomainFunctionType;
44 static_assert( Std::are_all_same< typename Operators::RangeFunctionType ... >::value,
45 "TupleOperator< RowTraits > needs a common RangeFunction Type." );
46 typedef typename std::tuple_element< 0, std::tuple< Operators ... > >::type::RangeFunctionType RangeFunctionType;
47 };
48
49 }
50
51
52 // TupleOperator
53 // -------------
54
55 template< class ... Operators >
57 : public Operator< typename __TupleOperatorImp::RowTraits< Operators ... >::DomainFunctionType,
58 typename __TupleOperatorImp::RowTraits< Operators ... >::RangeFunctionType >,
59 public std::tuple< Operators ... >
60 {
61 typedef TupleOperator< Operators ... > ThisType;
62 // Note we have to check the rows of each column for consistency
63 typedef typename __TupleOperatorImp::RowTraits< Operators ... > Traits;
65 typedef std::tuple< Operators ... > TupleType;
66
67 public:
70
71 template< class ... Args >
72 TupleOperator ( Args&& ... args )
73 : TupleType( std::forward< Args >( args ) ... )
74 {}
75
76 void operator() ( const DomainFunctionType &arg, RangeFunctionType &dest ) const
77 {
78 dest.clear();
79 RangeFunctionType tmp( dest );
80 apply( arg, dest, tmp, std::integral_constant< std::size_t, 0 >() );
81 }
82
83 protected:
84 template< std::size_t I >
85 void apply ( const DomainFunctionType &arg, RangeFunctionType &dest,
86 RangeFunctionType &tmp, std::integral_constant< std::size_t, I > ) const
87 {
88 std::get< I >( *this )( std::get< I >( arg ), tmp );
89 dest += tmp;
90 apply( arg, dest, tmp, std::integral_constant< std::size_t, I + 1 >() );
91 }
92
93 void apply ( const DomainFunctionType &arg, RangeFunctionType &dest,
94 RangeFunctionType &tmp, std::integral_constant< std::size_t, sizeof ... (Operators ) > ) const
95 {}
96 };
97
98
99
100 // RowTupleOperator
101 // ----------------
102
103 template< class ... Operators >
105 : public Operator< typename __TupleOperatorImp::ColTraits< Operators ... >::DomainFunctionType,
106 typename __TupleOperatorImp::ColTraits< Operators ... >::RangeFunctionType >,
107 public std::tuple< Operators ... >
108 {
109 typedef RowTupleOperator< Operators ... > ThisType;
110 // Note we have to check the columns of each row for consistency
111 typedef typename __TupleOperatorImp::ColTraits< Operators ... > Traits;
113 typedef std::tuple< Operators ... > TupleType;
114
115 public:
118
119 template< class ... Args >
120 RowTupleOperator ( Args&& ... args )
121 : TupleType( std::forward< Args >( args ) ... )
122 {}
123
124 void operator() ( const DomainFunctionType &arg, RangeFunctionType &dest ) const
125 {
126 dest.clear();
127 apply( arg, dest, std::integral_constant< std::size_t, 0 >() );
128 }
129
130 protected:
131 template< std::size_t I >
132 void apply ( const DomainFunctionType &arg, RangeFunctionType &dest, std::integral_constant< std::size_t, I > ) const
133 {
134 std::get< I >( *this )( arg, std::get< I >( dest ) );
135 apply( arg, dest, std::integral_constant< std::size_t, I + 1 >() );
136 }
137
138 void apply ( const DomainFunctionType &arg, RangeFunctionType &dest, std::integral_constant< std::size_t, sizeof ... (Operators ) > ) const
139 {}
140 };
141
142 } // namespace Fem
143
144} // namespace Dune
145
146#endif // #ifndef DUNE_FEM_OPERATOR_COMMON_TUPLE_HH
STL namespace.
Definition: bindguard.hh:11
Definition: utility.hh:147
forward declaration
Definition: tuplediscretefunction/discretefunction.hh:51
abstract operator
Definition: operator.hh:34
DomainFunction DomainFunctionType
type of discrete function in the operator's domain
Definition: operator.hh:36
RangeFunction RangeFunctionType
type of discrete function in the operator's range
Definition: operator.hh:38
Definition: operator/common/tuple.hh:60
BaseType::DomainFunctionType DomainFunctionType
Definition: operator/common/tuple.hh:68
void apply(const DomainFunctionType &arg, RangeFunctionType &dest, RangeFunctionType &tmp, std::integral_constant< std::size_t, sizeof ...(Operators) >) const
Definition: operator/common/tuple.hh:93
void operator()(const DomainFunctionType &arg, RangeFunctionType &dest) const
Definition: operator/common/tuple.hh:76
BaseType::RangeFunctionType RangeFunctionType
Definition: operator/common/tuple.hh:69
void apply(const DomainFunctionType &arg, RangeFunctionType &dest, RangeFunctionType &tmp, std::integral_constant< std::size_t, I >) const
Definition: operator/common/tuple.hh:85
TupleOperator(Args &&... args)
Definition: operator/common/tuple.hh:72
Definition: operator/common/tuple.hh:30
std::tuple_element< 0, std::tuple< Operators... > >::type::DomainFunctionType DomainFunctionType
Definition: operator/common/tuple.hh:33
TupleDiscreteFunction< typename Operators::RangeFunctionType ... > RangeFunctionType
Definition: operator/common/tuple.hh:34
Definition: operator/common/tuple.hh:42
std::tuple_element< 0, std::tuple< Operators... > >::type::RangeFunctionType RangeFunctionType
Definition: operator/common/tuple.hh:46
TupleDiscreteFunction< typename Operators::DomainFunctionType ... > DomainFunctionType
Definition: operator/common/tuple.hh:43
Definition: operator/common/tuple.hh:108
BaseType::RangeFunctionType RangeFunctionType
Definition: operator/common/tuple.hh:117
void apply(const DomainFunctionType &arg, RangeFunctionType &dest, std::integral_constant< std::size_t, I >) const
Definition: operator/common/tuple.hh:132
void apply(const DomainFunctionType &arg, RangeFunctionType &dest, std::integral_constant< std::size_t, sizeof ...(Operators) >) const
Definition: operator/common/tuple.hh:138
void operator()(const DomainFunctionType &arg, RangeFunctionType &dest) const
Definition: operator/common/tuple.hh:124
BaseType::DomainFunctionType DomainFunctionType
Definition: operator/common/tuple.hh:116
RowTupleOperator(Args &&... args)
Definition: operator/common/tuple.hh:120