DUNE-FEM (unstable)

tuple.hh
1#ifndef DUNE_FEM_OPERATOR_COMMON_TUPLE_HH
2#define DUNE_FEM_OPERATOR_COMMON_TUPLE_HH
3
4#include <tuple>
5#include <utility>
6
7#include <dune/fem/function/tuplediscretefunction.hh>
8#include <dune/fem/operator/common/operator.hh>
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 >
56 class TupleOperator
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;
64 typedef Operator< typename Traits::DomainFunctionType, typename Traits::RangeFunctionType > BaseType;
65 typedef std::tuple< Operators ... > TupleType;
66
67 public:
68 typedef typename BaseType::DomainFunctionType DomainFunctionType;
69 typedef typename BaseType::RangeFunctionType RangeFunctionType;
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 >
104 class RowTupleOperator
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;
112 typedef Operator< typename Traits::DomainFunctionType, typename Traits::RangeFunctionType > BaseType;
113 typedef std::tuple< Operators ... > TupleType;
114
115 public:
116 typedef typename BaseType::DomainFunctionType DomainFunctionType;
117 typedef typename BaseType::RangeFunctionType RangeFunctionType;
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
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)