DUNE-ACFEM (unstable)

tensorresult.hh
1#ifndef __DUNE_ACFEM_TENSORS_TENSORRESULT_HH__
2#define __DUNE_ACFEM_TENSORS_TENSORRESULT_HH__
3
4#include "../../../expressions/storage.hh"
5#include "../../../common/literals.hh"
6#include "../../tensorbase.hh"
7#include "densevectorview.hh"
8
9namespace Dune
10{
11 namespace ACFem
12 {
13 namespace Tensor
14 {
15
30 template<class Tensor>
31 class TensorResult;
32
33 template<class T>
35 : public DenseVectorView<T, Expressions::Storage<OperationTraits<IdentityOperation>, T> >
36 , public TensorBase<typename TensorTraits<T>::FieldType, typename TensorTraits<T>::Signature, TensorResult<T> >
37 {
38 static_assert(IsTensor<T>::value,
39 "TensorResult should only be applied to tensors.");
40
41 using TensorType = std::decay_t<T>;
42 using BaseType = TensorBase<typename TensorTraits<T>::FieldType, typename TensorTraits<T>::Signature, TensorResult>;
44 public:
45 using StorageType::operation;
46 using StorageType::operand;
47 using StorageType::arity;
48 using StorageType::OperandType;
49 using typename StorageType::FunctorType;
50 using typename StorageType::OperationType;
51 using ExpressionType = std::decay_t<T>;
52 using BaseType::rank;
53 using typename BaseType::FieldType;
54 using BaseType::dim;
55
56 explicit TensorResult(T&& t)
57 : StorageType(std::forward<T>(t))
58 {}
59
60 TensorResult(const TensorResult& other)
61 : StorageType(other)
62 {}
63
64 template<class Other,
65 std::enable_if_t<(IsTensorOperand<Other>::value
66 && std::is_assignable<typename TensorTraits<T>::ElementZero,
67 typename TensorTraits<Other>::FieldType>::value
68 ), int> = 0>
69 TensorResult& operator=(Other&& other)
70 {
71 operand(0_c) = std::forward<Other>(other);
72 return *this;
73 }
74
75 protected:
76 using StorageType::t0_;
77 public:
78
79 ExpressionType* operator->()
80 {
81 return &t0_;
82 }
83
84 const ExpressionType* operator->() const
85 {
86 return &t0_;
87 }
88
89 decltype(auto) storage() &
90 {
91 return static_cast<StorageType&>(*this);
92 }
93
94 decltype(auto) storage() &&
95 {
96 return static_cast<StorageType&&>(*this);
97 }
98
99 decltype(auto) storage() const&
100 {
101 return static_cast<const StorageType&>(*this);
102 }
103
105 template<class... Dims,
106 std::enable_if_t<(sizeof...(Dims) == rank
107 &&
109 , int> = 0>
110 decltype(auto) operator()(Dims... indices)
111 {
112 return operand(0_c)(indices...);
113 }
114
116 template<class... Dims,
117 std::enable_if_t<(sizeof...(Dims) == rank
118 &&
120 , int> = 0>
121 decltype(auto) operator()(Dims... indices) const
122 {
123 return operand(0_c)(indices...);
124 }
125
127 template<std::size_t... Indices, std::enable_if_t<sizeof...(Indices) == rank, int> = 0>
128 decltype(auto) constexpr operator()(Seq<Indices...>)
129 {
130 return operand(0_c)(Seq<Indices...>{});
131 }
132
134 template<std::size_t... Indices, std::enable_if_t<sizeof...(Indices) == rank, int> = 0>
135 decltype(auto) constexpr operator()(Seq<Indices...>) const
136 {
137 return operand(0_c)(Seq<Indices...>{});
138 }
139
141 template<std::size_t I>
142 decltype(auto) operator[](IndexConstant<I> i)&&
143 {
144 return operand(0_c)[i];
145 }
146
148 template<std::size_t I>
149 decltype(auto) operator[](IndexConstant<I> i)&
150 {
151 return operand(0_c)[i];
152 }
153
155 template<std::size_t I>
156 decltype(auto) operator[](IndexConstant<I> i)const&
157 {
158 return operand(0_c)[i];
159 }
160
162 template<std::size_t... Indices, class Pos = MakeIndexSequence<sizeof...(Indices)> >
163 static bool constexpr isZero(Seq<Indices...> = Seq<Indices...>{}, Pos = Pos{})
164 {
165 return TensorType::isZero(Seq<Indices...>{}, Pos{});
166 }
167
168 std::string name() const
169 {
170 std::string pfx = std::is_reference<T>::value ? (RefersConst<T>::value ? "cref" : "ref") : "";
171 return "<cls "+pfx+operand(0_c).name()+"/>";
172// return pfx+operand(0_c).name();
173 }
174
175 operator auto () &&
176 {
177 return std::move(operand(0_c));
178 }
179
180 operator decltype(auto) () const&
181 {
182 return operand(0_c);
183 }
184
185 operator decltype(auto) ()&
186 {
187 return operand(0_c);
188 }
189
190 };
191
192 } // NS Tensor
193
194 } // NS ACFem
195
196 template<class T>
197 struct FieldTraits<ACFem::Tensor::TensorResult<T> >
198 : FieldTraits<std::decay_t<T> >
199 {};
200
201} // NS Dune
202
203#endif // __DUNE_ACFEM_TENSORS_TENSORBASE_HH__
Definition: densevectorview.hh:113
The wrapper class wrapped around each expression result.
Definition: tensorresult.hh:37
decltype(auto) constexpr operator()(Seq< Indices... >) const
Compile-time constant access from index-sequence.
Definition: tensorresult.hh:135
decltype(auto) constexpr operator()(Seq< Indices... >)
Compile-time constant access from index-sequence.
Definition: tensorresult.hh:128
static bool constexpr isZero(Seq< Indices... >=Seq< Indices... >{}, Pos=Pos{})
Compile-time constant access from index-sequence.
Definition: tensorresult.hh:163
MakeSequence< std::size_t, N, Offset, Stride, Repeat > MakeIndexSequence
Make a sequence of std::size_t elements.
Definition: generators.hh:34
decltype(isIntegralPack(std::declval< T >()...)) IsIntegralPack
Decide whether the given parameter pack contains only integral types.
Definition: compare.hh:377
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
Definition: tensorbase.hh:117
Base class for all tensors.
Definition: tensorbase.hh:144
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)