DUNE-ACFEM (unstable)

explodesum.hh
1#ifndef __DUNE_ACFEM_EXPRESSIONS_EXPLODESUM_HH_
2#define __DUNE_ACFEM_EXPRESSIONS_EXPLODESUM_HH_
3
4#include "optimizesums.hh"
5
6namespace Dune::ACFem::Expressions
7{
8
9 namespace Sums
10 {
11
12 using ExplodeTag = DontOptimize;//OptimizeTag<9>;//OptimizeTag<7>;
13
14 template<class F, class E, class TreePos, class Tuple0, class Tuple1>
15 struct ExplodeProduct;
16
17 template<class F, class E, class TreePos>
18 struct ExplodeProduct<F, E, TreePos, MPL::TypeTuple<>, MPL::TypeTuple<> >
19 {
20 using Type = MPL::TypeTuple<>;
21 };
22
23 template<class F, class E, std::size_t... TreePos, class T10, class... T1>
24 struct ExplodeProduct<F, E, TreePosition<TreePos...>, MPL::TypeTuple<>, MPL::TypeTuple<T10, T1...> >
25 {
26 using Data0 = TreeData<PlusFunctor, Operand<0, E>, TreePosition<TreePos..., 0> >;
27 using Type = MPL::TypeTuple<
28 OperationPair<typename T10::Sign, F, Data0, T10, ExplodeTag>,
29 OperationPair<typename T1::Sign, F, Data0, T1, ExplodeTag>...
30 >;
31 };
32
33 template<class F, class E, std::size_t... TreePos, class T00, class... T0>
34 struct ExplodeProduct<F, E, TreePosition<TreePos...>, MPL::TypeTuple<T00, T0...>, MPL::TypeTuple<> >
35 {
36 using Data1 = TreeData<PlusFunctor, Operand<1, E>, TreePosition<TreePos..., 1> >;
37 using Type = MPL::TypeTuple<
38 OperationPair<typename T00::Sign, F, T00, Data1, ExplodeTag>,
39 OperationPair<typename T0::Sign, F, T0, Data1, ExplodeTag>...
40 >;
41 };
42
43 template<class F, class E, class TreePos, class T00, class... T1>
44 struct ExplodeProduct<F, E, TreePos, MPL::TypeTuple<T00>, MPL::TypeTuple<T1...> >
45 {
46 using Type = MPL::TypeTuple<
47 OperationPair<NestedSumFunctor<typename T00::Sign, typename T1::Sign>, F, T00, T1, ExplodeTag>...
48 >;
49 };
50
51 template<class F, class E, class TreePos, class T00, class T01, class... T0, class... T1>
52 struct ExplodeProduct<F, E, TreePos, MPL::TypeTuple<T00, T01, T0...>, MPL::TypeTuple<T1...> >
53 {
54 using Type = MPL::TypeTupleCat<
55 typename ExplodeProduct<F, E, TreePos, MPL::TypeTuple<T01, T0...>, MPL::TypeTuple<T1...> >::Type,
56 MPL::TypeTuple<
57 OperationPair<NestedSumFunctor<typename T00::Sign, typename T1::Sign>, F, T00, T1, ExplodeTag>...
58 >
59 >;
60 };
61
63 template<class F, class E, class...>
65
66 template<class F, class E, class TreePos, class Tuple0, class Tuple1>
68 {
69 static_assert(FunctorHas<IsProductOperation, F>::value, "");
70
71 using Type = typename ExplodeProduct<F, E, TreePos, Tuple0, Tuple1>::Type;
72 };
73
74 template<class E, class TreePos, class T0, class... TRest>
75 struct ProcessExplodeHelper<SquareFunctor, E, TreePos, MPL::TypeTuple<T0, TRest...> >
76 {
77 using Type = typename ExplodeProduct<typename SquareTraits<T0>::ExplodeFunctor, E, TreePos, MPL::TypeTuple<T0, TRest...>, MPL::TypeTuple<T0, TRest...> >::Type;
78 };
79
80 template<class E, class TreePos, class... T0, class... T1>
81 struct ProcessExplodeHelper<PlusFunctor, E, TreePos, MPL::TypeTuple<T0...>, MPL::TypeTuple<T1...> >
82 {
83 using Type = MPL::TypeTuple<T0..., T1...>;
84 };
85
86 template<class E, class TreePos, class... T0, class... T1>
87 struct ProcessExplodeHelper<MinusFunctor, E, TreePos, MPL::TypeTuple<T0...>, MPL::TypeTuple<T1...> >
88 {
89 using Type = MPL::TypeTuple<
90 T0...,
91 MergeTreeNodeSign<MinusFunctor, T1>...
92 >;
93 };
94
95 template<class E, class TreePos, class... T0>
96 struct ProcessExplodeHelper<MinusFunctor, E, TreePos, MPL::TypeTuple<T0...> >
97 {
98 using Type = MPL::TypeTuple<MergeTreeNodeSign<MinusFunctor, T0>...>;
99 };
100
102 template<class E, class TreePos, class... T>
103 using ProcessExplode = typename ProcessExplodeHelper<Functor<E>, E, TreePos, T...>::Type;
104
106 template<class E>
107 using ExplodeIgnore = BoolConstant<!(IsPlusOrMinusOperation<Operation<E> >::value || IsProductExpression<E>::value || IsSquareExpression<E>::value)>;
108
110 template<class E, class Parent>
112 : BoolConstant<!ExplodeIgnore<Parent>::value && ExplodeIgnore<E>::value>
113 {};
114
115 template<class E>
116 struct IsExplodeOperand<E, void>
117 : BoolConstant<ExplodeIgnore<E>::value>
118 {};
119
121 template<class T, class TreePos, class Parent>
122 using ExplodePackIt = TreeData<PlusFunctor, T, TreePos>;
123
125 template<class Expr, class TreePos = TreePosition<>, template<class E, class Pos, class...> class Process = ProcessExplode>
126 using Explode = Expressions::TreeExtract<IsExplodeOperand, Expr, ExplodePackIt, TreePos, ExplodeIgnore, Process>;
127
128 } // Sums::
129
130} // Dune::ACFem::Expressions::
131
132#endif // __DUNE_ACFEM_EXPRESSIONS_EXPLODESUM_HH_
OptimizeTag< 0 > DontOptimize
Bottom level is overloaded to do nothing.
Definition: optimizationbase.hh:74
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
Collect type, sign and the position in an expression of one operand.
Definition: operationpair.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 4, 22:38, 2025)