DUNE-ACFEM (unstable)

containertuple.hh
1#ifndef __DUNE_ACFEM_COMMON_TUPLETHINGS_HH__
2#define __DUNE_ACFEM_COMMON_TUPLETHINGS_HH__
3
4#include <tuple>
5#include <dune/common/fvector.hh>
6#include <dune/fem/storage/subvector.hh>
7
8namespace Dune {
9
10 namespace ACFem {
11
33 template<class... Containers>
35 {
36 using ContainerTupleType = std::tuple<Containers&...>;
37 public:
38 enum {
39 tupleSize = std::tuple_size<ContainerTupleType>::value
40 };
41 ContainerTuple(Containers&... containers)
42 : containers_(containers...)
43 {}
44
45 ContainerTuple(const ContainerTuple& other)
46 : containers_(other.containers_)
47 {}
48
49 // Just get the type of the const random access operator
50 template<class Data, class = void>
51 struct ConstValueTraits
52 {
53 typedef Data type;
54 };
55
56 // Just get the type of the random access operator
57 template<class Data, class = void>
58 struct ValueTraits
59 {
60 typedef Data& type;
61 };
62
63 // For one-level Fem::SubVector stuff the following might do it
64 template<class Base, class Mapper>
65 struct ConstValueTraits<Fem::SubVector<Base, Mapper>, void>
66 {
67 private:
68 typedef Fem::SubVector<Base, Mapper> DataType;
69 typedef typename DenseMatVecTraits<DataType>::value_type ValueType;
70 static const size_t size = Mapper::size();
71 public:
72 typedef FieldVector<ValueType, size> type;
73 };
74
75 // For one-level Fem::SubVector stuff the following might do
76 // it. The subvector already stores references, so we must not
77 // store a reference to a temporary containing references, but a
78 // copy of the sub-vector.
79 template<class Base, class Mapper>
80 struct ValueTraits<Fem::SubVector<Base, Mapper>, void>
81 {
82 typedef Fem::SubVector<Base, Mapper> type;
83 };
84
85 typedef
86 std::tuple<
87 typename ValueTraits<
88 std::decay_t<
89 decltype(std::declval<Containers>()[0])> >::type...> ValueType;
90
91 typedef
92 std::tuple<
93 typename ConstValueTraits<
94 std::decay_t<
95 decltype(std::declval<const Containers>()[0])> >::type...> ConstValueType;
96
97 private:
98 // helper dingsbums. This is just here to support Dune::Fem
99 // SubVector for ApaptiveDiscreteFunction. Oh well. Why?
100 template<class Tuple, size_t... Is>
101 auto mutableValueTuple(size_t idx, const Tuple& tuple, std::index_sequence<Is...>)
102 {
103 return ValueType(std::get<Is>(tuple)[idx]...);
104 }
105 template<class Tuple, size_t... Is>
106 auto valueTuple(size_t idx, const Tuple& tuple, std::index_sequence<Is...>) const
107 {
108 return std::make_tuple(std::get<Is>(tuple)[idx]...);
109 }
110 public:
111 ValueType operator[](size_t idx)
112 {
113 return mutableValueTuple(idx, containers_, std::make_index_sequence<tupleSize>{});
114 }
115 // give a damn ...
116 const ConstValueType operator[](size_t idx) const
117 {
118 return valueTuple(idx, containers_, std::make_index_sequence<tupleSize>{});
119 }
120 private:
121 ContainerTupleType containers_;
122 };
123
125
126 } // ACFem::
127
128} // Dune::
129
130#endif // __DUNE_ACFEM_COMMON_TUPLETHINGS_HH__
Create a tuple of values from a tuple of containers.
Definition: containertuple.hh:35
constexpr std::size_t size()
Gives the number of elements in tuple-likes and std::integer_sequence.
Definition: size.hh:73
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)