DUNE-ACFEM (unstable)

functiontraits.hh
1#ifndef __DUNE_ACFEM_FUNCTIONS_FUNCTIONTRAITS_HH__
2#define __DUNE_ACFEM_FUNCTIONS_FUNCTIONTRAITS_HH__
3
4#include "../common/types.hh"
5#include "../expressions/find.hh"
6#include "../expressions/treeoperand.hh"
7#include "../expressions/extract.hh"
8#include "../tensors/expressions.hh"
9
10#include "localfunctiontraits.hh"
11
12namespace Dune {
13
14 namespace ACFem {
15
16 namespace GridFunction {
17
18 using Expressions::TreeFind;
19
20 // forward
21 template<class Expr, class GridPart, std::size_t AutoDiffOrder, std::size_t IndeterminateId>
22 class BindableTensorFunction;
23
24 template<class T>
25 constexpr std::size_t autoDiffOrder()
26 {
27 return decltype(std::decay_t<T>::autoDiffOrder())::value;
28 }
29
31 template<class T>
33 : FalseType
34 {};
35
37 template<class T>
40 {};
41
43 template<class T>
44 struct IsTensorFunction<T&&>
46 {};
47
49 template<class Expr, class GridPart, std::size_t AutoDiffOrder, std::size_t IndeterminateId>
50 struct IsTensorFunction<BindableTensorFunction<Expr, GridPart, AutoDiffOrder, IndeterminateId>>
51 : TrueType
52 {};
53
54 template<class T, class SFINAE = void>
55 struct RangeTensorTraits
56 : TensorTraits<void>
57 {};
58
59 template<class T>
60 struct RangeTensorTraits<T, std::enable_if_t<!IsDecay<T>::value> >
61 : RangeTensorTraits<std::decay_t<T> >
62 {};
63
64 template<class Expr, class GridPart, std::size_t AutoDiffOrder, std::size_t IndeterminateId>
65 struct RangeTensorTraits<BindableTensorFunction<Expr, GridPart, AutoDiffOrder, IndeterminateId> >
66 : TensorTraits<Expr>
67 {};
68
69 template<class T>
70 struct RangeTensorTraits<
71 T,
72 std::enable_if_t<(IsDecay<T>::value
73 && IsWrappableByConstLocalFunction<T>::value
74 && !IsTensorFunction<T>::value
75 && T::FunctionSpaceType::dimRange == 1
76 )> >
77 : TensorTraits<typename T::FunctionSpaceType::RangeFieldType>
78 {};
79
80 template<class T>
81 struct RangeTensorTraits<
82 T,
83 std::enable_if_t<(IsDecay<T>::value
84 && IsWrappableByConstLocalFunction<T>::value
85 && !IsTensorFunction<T>::value
86 && T::FunctionSpaceType::dimRange > 1
87 )> >
88 : TensorTraits<typename T::RangeType>
89 {};
90
91 template<class T>
92 using RangeTensorType = typename RangeTensorTraits<T>::TensorType;
93
95 template<class T, std::size_t AtLeastRequestedOrder = 0UL, std::size_t AtMostRequestedOrder = ~0UL>
98 {};
99
100 template<class T, std::size_t AtLeastRequestedOrder, std::size_t AtMostRequestedOrder>
101 struct HasRegularity<T&, AtLeastRequestedOrder, AtMostRequestedOrder>
102 : HasRegularity<std::decay_t<T>, AtLeastRequestedOrder, AtMostRequestedOrder>
103 {};
104
105 template<class T, std::size_t AtLeastRequestedOrder, std::size_t AtMostRequestedOrder>
106 struct HasRegularity<T&&, AtLeastRequestedOrder, AtMostRequestedOrder>
107 : HasRegularity<std::decay_t<T>, AtLeastRequestedOrder, AtMostRequestedOrder>
108 {};
109
115 template<class Expr, class GridPart, std::size_t AutoDiffOrder, std::size_t IndeterminateId,
116 std::size_t AtLeastRequestedOrder, std::size_t AtMostRequestedOrder>
117 struct HasRegularity<BindableTensorFunction<Expr, GridPart, AutoDiffOrder, IndeterminateId>,
118 AtLeastRequestedOrder, AtMostRequestedOrder>
119 : BoolConstant<(AutoDiffOrder >= AtLeastRequestedOrder && AutoDiffOrder <= AtMostRequestedOrder)>
120 {};
121
123 template<class T, class SFINAE = void>
125 : FalseType
126 {};
127
129 template<class T>
130 struct HasGridPartMethod<T, VoidType<decltype(std::declval<T>().gridPart())> >
131 : TrueType
132 {};
133
135 template<class T, class SFINAE = void>
137 : FalseType
138 {};
139
141 template<class T>
142 struct HasRangeType<T, VoidType<typename std::decay_t<T>::RangeType> >
143 : TrueType
144 {};
145
146 template<class T, class SFINAE = void>
147 struct IsGridPartProvider
148 : FalseType
149 {};
150
151 template<class T>
152 struct IsGridPartProvider<T, std::enable_if_t<HasGridPartMethod<T>::value> >
153 : TrueType
154 {};
155
156 template<class T>
157 struct IsGridPartProvider<
158 T,
159 std::enable_if_t<(!HasGridPartMethod<T>::value
160 && !std::is_same<FalseType, TreeFind<HasGridPartMethod, T> >::value
161 )> >
162 : TrueType
163 {};
164
165 template<class T, std::enable_if_t<HasGridPartMethod<T>::value, int> = 0>
166 const auto& gridPart(T&& t)
167 {
168 return t.gridPart();
169 }
170
171 template<class T, std::enable_if_t<!HasGridPartMethod<T>::value && IsGridPartProvider<T>::value, int> = 0>
172 const auto& gridPart(T&& t)
173 {
174 using TreePos = typename TreeFind<HasGridPartMethod, T>::Second;
175 return treeOperand(std::forward<T>(t), TreePos{}).gridPart();
176 }
177
178 template<class T, class SFINAE = void>
179 struct HasSkeletonSupport
180 : FalseType
181 {};
182
183 template<class T>
184 struct HasSkeletonSupport<
185 T, VoidType<decltype(std::declval<T>().classifyIntersection(FalseType{}))> >
186 : TrueType
187 {};
188
189 template<class T>
190 constexpr bool hasSkeletonSupport()
191 {
192 return HasSkeletonSupport<T>::value;
193 }
194
195 template<class T>
196 constexpr bool hasSkeletonSupport(T&&)
197 {
198 return HasSkeletonSupport<T>::value;
199 }
200
202 template<class T, std::enable_if_t<(IsTensorFunction<T>::value && !Expressions::IsClosure<T>::value), int> = 0>
203 constexpr decltype(auto) expressionClosure(T&& t)
204 {
205 return std::forward<T>(t);
206 }
207
208 } // NS GridFunction
209
210 using GridFunction::IsTensorFunction;
211
212 } // NS ACFem
213
214} // NS Dune
215
216#endif // __DUNE_ACFEM_FUNCTIONS_FUNCTIONTRAITS_HH__
Wrap a tensor into a Fem::BindableGridFunction.
Definition: bindabletensorfunction.hh:55
constexpr decltype(auto) expressionClosure(T &&t)
Do-nothing default implementation for pathologic cases.
Definition: interface.hh:93
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
typename MakeType< void, Other... >::Type VoidType
Generate void regardless of the template argument list.
Definition: types.hh:151
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.
Definition: functiontraits.hh:126
Definition: functiontraits.hh:138
Definition: functiontraits.hh:98
Definition: functiontraits.hh:34
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)