Loading [MathJax]/extensions/TeX/AMSsymbols.js

DUNE-ACFEM (unstable)

operandpromotion.hh
1#ifndef __DUNE_ACFEM_OPERATORS_FUNCTIONALS_OPERANDPROMOTION_HH__
2#define __DUNE_ACFEM_OPERATORS_FUNCTIONALS_OPERANDPROMOTION_HH__
3
4#include "../../common/types.hh"
5#include "../../expressions/interface.hh"
6#include "../../tensors/tensor.hh"
7#include "../../functions/functions.hh"
8
9#include "linearfunctional.hh"
10#include "functionaltraits.hh"
11#include "modules/dofstorage.hh"
12
13namespace Dune {
14
15 namespace ACFem {
16
17 namespace LinearFunctional {
18
19 using Expressions::Operand;
20 using namespace Literals;
21
22 template<class... T>
23 using PromoteTensorOperands =
24 BoolConstant<(// Handled top-level
25 !AnyIs<Expressions::IsPromotedTopLevel, T...>::value
26 // Something to do?
27 && AnyIs<Tensor::IsNonTensorTensorOperand, T...>::value
28 // One is already a PDE model
29 && AnyIs<IsLinearFunctional, T...>::value)>;
30
32 template<std::size_t N, class... T,
33 std::enable_if_t<(PromoteTensorOperands<T...>::value
34 && !NthIs<N, Tensor::IsNonTensorTensorOperand, T...>::value
35 ), int> = 0>
36 constexpr decltype(auto) operandPromotion(T&&... t)
37 {
38 return std::forward<TupleElement<N, std::tuple<T...> > >(
39 get<N>(std::forward_as_tuple(t...))
40 );
41 }
42
44 template<std::size_t N, class... T,
45 std::enable_if_t<(PromoteTensorOperands<T...>::value
46 && NthIs<N, Tensor::IsNonTensorTensorOperand, T...>::value
47 ), int> = 0>
48 constexpr auto operandPromotion(T&&... t)
49 {
50 return tensor(std::forward<TupleElement<N, std::tuple<T...> > >(
51 get<N>(std::forward_as_tuple(t...))
52 ));
53 }
54
55 template<class... T>
56 using PromoteDiscreteFunctionOperands =
57 BoolConstant<(// Handled top-level
58 !AnyIs<Expressions::IsPromotedTopLevel, T...>::value
59 // Something to do?
60 && AnyIs<IsDiscreteFunction, T...>::value
61 // One is already a PDE model
62 && AnyIs<IsLinearFunctional, T...>::value)>;
63
65 template<std::size_t N, class... T,
66 std::enable_if_t<(PromoteDiscreteFunctionOperands<T...>::value
67 && !NthIs<N, IsDiscreteFunction, T...>::value
68 ), int> = 0>
69 constexpr decltype(auto) operandPromotion(T&&... t)
70 {
71 return std::forward<TupleElement<N, std::tuple<T...> > >(
72 get<N>(std::forward_as_tuple(t...))
73 );
74 }
75
77 template<std::size_t N, class... T,
78 std::enable_if_t<(PromoteDiscreteFunctionOperands<T...>::value
79 && NthIs<N, IsDiscreteFunction, T...>::value
80 ), int> = 0>
81 constexpr auto operandPromotion(T&&... t)
82 {
83 return dofStorageFunctional(
84 std::forward<TupleElement<N, std::tuple<T...> > >(
85 get<N>(std::forward_as_tuple(t...))
86 ));
87 }
88
89 template<class T, class SFINAE = void>
90 struct IsProductWithDiscreteFunction
91 : FalseType
92 {};
93
94 template<class T>
95 struct IsProductWithDiscreteFunction<
96 T,
97 std::enable_if_t<(IsTensorFunction<T>::value
98 && IsProductExpression<GridFunction::RangeTensorType<T> >::value
99 )> >
100 : BoolConstant<(TensorTraits<Operand<0, GridFunction::RangeTensorType<T>> >::rank == 0
101 && IsLocalFunctionPlaceholder<Operand<1, GridFunction::RangeTensorType<T> > >::value
102 && IsDiscreteFunction<typename Operand<1, GridFunction::RangeTensorType<T> >::GridFunctionType>::value)>
103 {};
104
105 template<class... T>
106 using PromoteScaledDiscreteFunctionOperands =
107 BoolConstant<(// Handled top-level
108 !AnyIs<Expressions::IsPromotedTopLevel, T...>::value
109 // Something to do?
110 && AnyIs<IsProductWithDiscreteFunction, T...>::value
111 // One is already a PDE model
112 && AnyIs<IsLinearFunctional, T...>::value)>;
113
115 template<std::size_t N, class... T,
116 std::enable_if_t<(PromoteScaledDiscreteFunctionOperands<T...>::value
117 && !NthIs<N, IsProductWithDiscreteFunction, T...>::value
118 ), int> = 0>
119 constexpr decltype(auto) operandPromotion(T&&... t)
120 {
121 return std::forward<TupleElement<N, std::tuple<T...> > >(
122 get<N>(std::forward_as_tuple(t...))
123 );
124 }
125
127 template<std::size_t N, class... T,
128 std::enable_if_t<(PromoteScaledDiscreteFunctionOperands<T...>::value
129 && NthIs<N, IsProductWithDiscreteFunction, T...>::value
130 ), int> = 0>
131 constexpr auto operandPromotion(T&&... t)
132 {
133 decltype(auto) einsum = std::forward<TupleElement<N, std::tuple<T...> > >(
134 get<N>(std::forward_as_tuple(t...))
135 ).expression();
136 return einsum.operand(0_c)*dofStorageFunctional(einsum.operand(1_c).gridFunction());
137 }
138
139 }
140
141 } // ACFem::
142
143} // Dune::
144
145#endif // __DUNE_ACFEM_OPERATORS_FUNCTIONALS_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
std::tuple_element_t< N, std::decay_t< TupleLike > > TupleElement
Forward to std::tuple_element<N, std::decay_t<T> >
Definition: access.hh:125
constexpr decltype(auto) einsum(T1 &&t1, T2 &&t2)
Tensor contraction for proper tensors.
Definition: einsum.hh:561
Predicate< TypePackElement< N, T... > > NthIs
Instantiates to Predicate applied to the N-th element of T...
Definition: compare.hh:470
BoolConstant<(...||Predicate< T >::value)> AnyIs
TrueType if any type matches the predicate.
Definition: compare.hh:462
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
BoolConstant< false > FalseType
Alias for std::false_type.
Definition: types.hh:110
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 12, 23:28, 2025)