DUNE-ACFEM (unstable)

operandpromotion.hh
1#ifndef __DUNE_ACFEM_FUNCTIONS_OPERANDPROMOTION_HH__
2#define __DUNE_ACFEM_FUNCTIONS_OPERANDPROMOTION_HH__
3
4#include "../common/literals.hh"
5#include "../mpl/compare.hh"
6#include "../expressions/interface.hh"
7#include "../tensors/tensorbase.hh"
8
9#include "policy.hh"
10#include "localfunctiontraits.hh"
11#include "functiontraits.hh"
12#include "placeholders/localfunctionplaceholder.hh"
13
14namespace Dune
15{
16 namespace ACFem
17 {
18 namespace GridFunction
19 {
20 using namespace Literals;
21 using Expressions::IsClosure;
22 using Expressions::IsPromotedTopLevel;
23
27 template<class... T>
29 : BoolConstant<(// Handled top-level
30 !AnyIs<IsPromotedTopLevel, T...>::value
31 // Don't if all arguments are allready tensor functions
32 && !AllAre<IsTensorFunction, T...>::value
33 // One is already a function
34 && AnyIs<IsTensorFunction, T...>::value
35 // All are admissible in principle
36 && AllAre<OrPredicate<
37 IsTensorOperand, IsTensorFunction>::template Predicate, T...>::value
38 )>
39 {};
40
45 template<std::size_t N, class... T,
46 std::enable_if_t<(PromoteTensorOperands<T...>::value
47 && NthIs<N, IsTensorFunction, T...>::value
48 ), int> = 0>
49 constexpr decltype(auto) operandPromotion(T&&... t)
50 {
51 return std::forward<TypePackElement<N, T...> >(
52 get<N>(std::forward_as_tuple(std::forward<T>(t)...))
53 );
54 }
55
61 template<std::size_t N, class... T,
62 std::enable_if_t<(PromoteTensorOperands<T...>::value
63 && !NthIs<N, IsTensorFunction, T...>::value
64 ), int> = 0>
65 constexpr decltype(auto) operandPromotion(T&&... t)
66 {
67 const auto& fct = get<IndexOfMatching<IsTensorFunction, T...>::value>(std::forward_as_tuple(std::forward<T>(t)...));
68
69 return gridFunction(
70 fct.gridPart(),
71 tensor(std::forward<TypePackElement<N, T...> >(
72 get<N>(std::forward_as_tuple(std::forward<T>(t)...))
73 )),
74 fct.autoDiffOrder(),
75 fct.indeterminateId()
76 );
77 }
78
80
85 template<class... T>
87 : BoolConstant<(// Don't if all arguments are allready tensor functions
88 !AllAre<IsTensorFunction, T...>::value
89 // One is already a function
90 && AnyIs<IsTensorFunction, T...>::value
91 // Any is admissible
92 && AllAre<OrPredicate<
93 IsConstLocalFunctionOperand, IsTensorFunction>::template Predicate, T...>::value
94 )>
95 {};
96
101 template<std::size_t N, class... T,
102 std::enable_if_t<(PromoteFunctionOperands<T...>::value
103 && NthIs<N, IsTensorFunction, T...>::value
104 ), int> = 0>
105 constexpr decltype(auto) operandPromotion(T&&... t)
106 {
107 return std::forward<TupleElement<N, std::tuple<T...> > >(
108 get<N>(std::forward_as_tuple(std::forward<T>(t)...))
109 );
110 }
111
117 template<std::size_t N, class... T,
118 std::enable_if_t<(PromoteFunctionOperands<T...>::value
119 && !NthIs<N, IsTensorFunction, T...>::value
120 ), int> = 0>
121 constexpr decltype(auto) operandPromotion(T&&... t)
122 {
123 const auto& fct = get<IndexOfMatching<IsTensorFunction, T...>::value>(std::forward_as_tuple(std::forward<T>(t)...));
124
125 return gridFunction(
126 fct.gridPart(),
128 std::forward<TupleElement<N, std::tuple<T...> > >(
129 get<N>(std::forward_as_tuple(std::forward<T>(t)...))
130 )),
131 fct.autoDiffOrder(),
132 fct.indeterminateId()
133 );
134 }
135
137
143 template<std::size_t N, class... T>
145 : BoolConstant<(// Handled top-level
146 !AnyIs<IsClosure, T...>::value
147 // None is already a tensor function (handled elsewhere)
148 && !AnyIs<IsTensorFunction, T...>::value
149 // One is a Fem::ConstLocalFunction or similar
150 && AnyIs<IsConstLocalFunctionOperand, T...>::value
151 // All are admissible as tensors in principle or are Fem::LocalFunction's
152 && AllAre<OrPredicate<
153 IsTensorOperand, IsConstLocalFunctionOperand>::template Predicate, T...>::value
154 )>
155 {};
156
160 template<std::size_t N, class... T,
161 std::enable_if_t<(PromoteAllFunctionOperands<N, T...>::value
162 && NthIs<N, IsConstLocalFunctionOperand, T...>::value
163 ), int> = 0>
164 constexpr decltype(auto) operandPromotion(T&&... t)
165 {
166 return gridFunction(
168 std::forward<TupleElement<N, std::tuple<T...> > >(
169 get<N>(std::forward_as_tuple(std::forward<T>(t)...))
170 )),
171 Policy::IndeterminateId{}
172 );
173 }
174
180 template<std::size_t N, class... T,
181 std::enable_if_t<(PromoteAllFunctionOperands<N, T...>::value
182 && !NthIs<N, IsConstLocalFunctionOperand, T...>::value
183 ), int> = 0>
184 constexpr decltype(auto) operandPromotion(T&&... t)
185 {
186 const auto& fct = get<IndexOfMatching<IsConstLocalFunctionOperand, T...>::value>(std::forward_as_tuple(std::forward<T>(t)...));
187
188 return gridFunction(
189 fct.gridPart(),
190 tensor(std::forward<TupleElement<N, std::tuple<T...> > >(
191 get<N>(std::forward_as_tuple(std::forward<T>(t)...))
192 )),
193 Policy::IndeterminateId{}
194 );
195 }
196
197 template<
198 class T,
199 std::enable_if_t<(sizeof(derivative(operandPromotion<0>(std::declval<T>()))) >= 0), int> = 0>
200 constexpr decltype(auto) derivative(T&& t)
201 {
202 return derivative(operandPromotion<0>(std::forward<T>(t)));
203 }
204
205 template<
206 std::size_t N, class T,
207 std::enable_if_t<(sizeof(derivative<N>(operandPromotion<0>(std::declval<T>()))) >= 0), int> = 0>
208 constexpr decltype(auto) derivative(T&& t)
209 {
210 return derivative<N>(operandPromotion<0>(std::forward<T>(t)));
211 }
212
213 template<
214 class T,
215 std::enable_if_t<(sizeof(ternary(operandPromotion<0>(std::declval<T>()))) >= 0), int> = 0>
216 constexpr decltype(auto) ternary(T&& t)
217 {
218 return ternary(operandPromotion<0>(std::forward<T>(t)));
219 }
220
221 } // NS GridFunction
222
223 using GridFunction::derivative;
224
225 } // NS ACFem
226
227 namespace Fem {
228
230
231 }
232
233} // NS Dune
234
235#endif // __DUNE_ACFEM_FUNCTIONS_OPERANDPROMOTION_HH__
constexpr decltype(auto) operandPromotion(T &&... t)
The purpose of this function is to promote operands to other types, e.g.
Definition: interface.hh:154
auto gridFunction(const GridPart &gridPart, T &&t, IndexConstant< MaxOrder > maxOrder=IndexConstant< MaxOrder >{}, IndexConstant< IndeterminateId > id=IndexConstant< IndeterminateId >{})
Generate a BindableGridFunction which wraps a copy of T.
Definition: gridfunction.hh:23
auto localFunctionPlaceholder(F &&f, IndexConstant< IndeterminateId > id=IndexConstant< IndeterminateId >{}, Closure closure=Closure{})
Generate a LocalFunctionPlaceholder for a Fem::ConstLocalFunction.
Definition: localfunctionplaceholder.hh:192
constexpr decltype(auto) get(T &&t, IndexConstant< I >=IndexConstant< I >{})
Access to the i-the element.
Definition: access.hh:129
std::tuple_element_t< N, std::decay_t< TupleLike > > TupleElement
Forward to std::tuple_element<N, std::decay_t<T> >
Definition: access.hh:125
Predicate< TypePackElement< N, T... > > NthIs
Instantiates to Predicate applied to the N-th element of T...
Definition: compare.hh:470
IndexConstant< PredicateMatch< std::tuple< T... >, Predicate >::index_ > IndexOfMatching
Obtain the index of the first matching tuple type.
Definition: compare.hh:458
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
TrueType if T can be passed through constLocalFunction().
Definition: localfunctiontraits.hh:112
Definition: functiontraits.hh:34
Definition: operandpromotion.hh:95
Definition: operandpromotion.hh:39
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)