DUNE-ACFEM (unstable)

expressiontraits.hh
1#ifndef __DUNE_ACFEM_TENSORS_EXPRESSIONTRAITS_HH__
2#define __DUNE_ACFEM_TENSORS_EXPRESSIONTRAITS_HH__
3
4#include "../expressions/expressiontraits.hh"
5#include "../expressions/traitsdefault.hh"
6#include "../expressions/runtimeequal.hh"
7#include "tensorbase.hh"
8#include "modules/constant.hh"
9
10namespace Dune
11{
12 namespace ACFem
13 {
14
15 namespace Tensor
16 {
17 // forward
18 template<class Field, class Seq>
19 class ConstantTensor;
20
22 template<class T>
23 using IsNonTensorTensorOperand = BoolConstant<(IsTensorOperand<T>::value && !IsTensor<T>::value)>;
24
25 template<class T, class SFINAE = void>
26 struct ShouldIgnoreUnaryOperand
27 : FalseType
28 {};
29
30 template<class T>
31 struct ShouldIgnoreUnaryOperand<
32 T,
33 std::enable_if_t<(// ignore non-tensors-likes
34 !IsTensorOperand<T>::value
35 // ignore scalars
36 || IsScalar<T>::value
37 )> >
38 : TrueType
39 {};
40
44 template<class T>
46 : BoolConstant<(!Expressions::IsClosure<T>::value
47 && IsTensorOperand<T>::value
48 && !ShouldIgnoreUnaryOperand<std::decay_t<T> >::value)>
49 {};
50
51 template<class T>
52 struct IsProperTensor
53 : BoolConstant<(IsTensor<T>::value && !IsPromotedTopLevel<T>::value)>
54 {};
55
56 template<class T0, class T1>
57 struct AreProperTensors
58 : BoolConstant<(IsProperTensor<T0>::value && IsProperTensor<T1>::value)>
59 {};
60
64 template<class T1, class T2, class SFINAE = void>
66 : FalseType
67 {};
68
72 template<class T1, class T2>
74 T1, T2,
75 std::enable_if_t<(!(IsClosure<T1>::value || IsClosure<T2>::value)
76 && IsTensorOperand<T1>::value
77 && IsTensorOperand<T2>::value
78 && (IsTensor<T1>::value || IsTensor<T2>::value)
79 )> >
80 : TrueType
81 {};
82
84 template<std::size_t N, class T, class SFINAE = void>
86 : IndexConstant<TensorTraits<Operand<N, T> >::rank>
87 {};
88
90 template<std::size_t N, class T>
91 struct OperandRank<N, T, std::enable_if_t<(N >= Arity<T>::value)> >
92 : IndexConstant<std::numeric_limits<std::size_t>::max()>
93 {};
94
98 template<class T1, class T2>
101 typename TensorTraits<T2>::TensorType>;
102
104 template<class Int, Int N, Int D>
105 struct TensorTraits<TypedValue::FractionConstant<Int, N, D> >
106 : public TensorTraits<ConstantTensor<TypedValue::FractionConstant<Int, N, D>, Seq<> > >
107 {
108 //static_assert(!IsFieldObject<T>::value, "");
109
110 template<class Fraction>
111 static constexpr auto toTensor(Fraction)
112 {
113 return ConstantTensor<Fraction, Seq<> >();
114 }
115 };
116
118 template<class Int, Int N, Int D>
119 struct IsTensorOperand<TypedValue::FractionConstant<Int, N, D> >
120 : TrueType
121 {};
122
124 template<class T, char... Name>
125 struct TensorTraits<TypedValue::NamedConstant<T, Name...> >
126 : public TensorTraits<ConstantTensor<TypedValue::NamedConstant<T, Name...>, Seq<> > >
127 {
128 template<class C>
129 static constexpr auto toTensor(C)
130 {
131 return ConstantTensor<C, Seq<> >();
132 }
133 };
134
136 template<class T, char... Name>
137 struct IsTensorOperand<TypedValue::NamedConstant<T, Name...> >
138 : TrueType
139 {};
140
142 template<class T>
143 using IsUnaryTensorExpression = BoolConstant<IsTensor<T>::value && IsUnaryExpression<T>::value>;
144
146 template<class T>
147 using IsBinaryTensorExpression = BoolConstant<IsTensor<T>::value && IsBinaryExpression<T>::value>;
148
149#define SPECIALIZEDTRAITS_DEFINED 1
153 template<class T, class SFINAE = void>
155 : FalseType
156 {};
157
158 } // NS Tensor
159
160 template<class T>
161 struct ExpressionTraits<
162 T,
163 std::enable_if_t<(!Tensor::HasSpecializedExpressionTraits<T>::value
164 && Tensor::IsTensorNotZero<T>::value
165 && Expressions::IsSelfExpression<T>::value
166 )> >
167 {
168 using ExpressionType = std::decay_t<T>;
169 private:
170 using Traits = TensorTraits<T>;
171 using DefaultTraits = Expressions::TraitsOfTags<T>;
173 public:
174 static constexpr bool isZero = DefaultTraits::isZero || FieldTraits::isZero;
175 static constexpr bool isNonZero = DefaultTraits::isNonZero || FieldTraits::isNonZero;
176 static constexpr bool isOne = (DefaultTraits::isOne || FieldTraits::isOne) && Traits::rank == 0;
177 static constexpr bool isMinusOne = (DefaultTraits::isMinusOne || FieldTraits::isMinusOne) && Traits::rank == 0;
178 static constexpr bool isSemiPositive = DefaultTraits::isSemiPositive || FieldTraits::isSemiPositive;
179 static constexpr bool isSemiNegative = DefaultTraits::isSemiNegative || FieldTraits::isSemiNegative;
180 static constexpr bool isPositive = DefaultTraits::isPositive || FieldTraits::isPositive;
181 static constexpr bool isNegative = DefaultTraits::isNegative || FieldTraits::isNegative;
182
183 static constexpr bool isVolatile = DefaultTraits::isVolatile;
184 static constexpr bool isIndependent = DefaultTraits::isIndependent;
185 static constexpr bool isTypedValue = DefaultTraits::isTypedValue || FieldTraits::isTypedValue;
186 static constexpr bool isConstant = DefaultTraits::isConstant;
187
189 };
190
191 template<class T>
192 struct ExpressionTraits<
193 T,
194 std::enable_if_t<(!Tensor::HasSpecializedExpressionTraits<T>::value
195 && Tensor::IsTensorZero<T>::value
196 )> >
197 : ZeroExpressionTraits<T>
198 {};
199
200 namespace Expressions
201 {
202
203 template<class T>
204 struct IsOperand<
205 T, std::enable_if_t<(IsDecay<T>::value
206 && !IsExpression<T>::value
207 && Tensor::IsTensorOperand<T>::value
208 )> >
209 : TrueType
210 {};
211
212 template<class T>
213 struct InjectionTraits<T, std::enable_if_t<Tensor::IsTensorOperand<T>::value> >
214 : ExpressionTraits<T>
215 {
216 using ExpressionType = typename TensorTraits<T>::TensorType;
217
218 template<class E>
219 static decltype(auto) asExpression(E&& e)
220 {
221 return Tensor::tensor(std::forward<E>(e));
222 }
223 };
224
225 } // NS Expressions
226
227 } // NS ACFem
228
229} // NS Dune
230
231#endif // __DUNE_ACFEM_TENSORS_EXPRESSIONTRAITS_HH__
constexpr decltype(auto) asExpression(T &&t)
Return a non-closure expression as is.
Definition: interface.hh:122
decltype(operate(std::declval< OptOrF >(), std::declval< Rest >()...)) ExpressionType
Generate the type of an expression by calling operate().
Definition: optimizationbase.hh:256
constexpr bool isConstant(Sequence< T, T0, Ts... >)
Definition: compare.hh:285
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
BoolConstant< true > TrueType
Alias for std::true_type.
Definition: types.hh:107
STL namespace.
Default expression traits definition is a recursion in order to ease disambiguation.
Definition: expressiontraits.hh:54
FalseType by default.
Definition: runtimeequal.hh:103
A class mainting the sign of an expression during operations.
Definition: sign.hh:30
TrueType if T is an expression of arity 2, otherwise FalseType.
Definition: storage.hh:566
TrueType if T is an expression of arity 1, otherwise FalseType.
Definition: storage.hh:560
Deduce ExpressionTraits from tag-class overrides.
Definition: traitsdefault.hh:20
Helper class for specializing Dune::FieldTraits.
Definition: typetraits.hh:96
Definition: expressiontraits.hh:67
Should be specialized to TrueType if for a specific tensor ExpressionTraits need to be re-implemented...
Definition: expressiontraits.hh:156
Definition: tensorbase.hh:117
We should not inject scalars into unary expressions as this very easily will lead to ambiguities.
Definition: expressiontraits.hh:49
Generate the rank of the N-th operand if applicable.
Definition: expressiontraits.hh:87
A class implementing compile-time constant fractions of integers.
Definition: fractionconstant.hh:27
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)