v0.14.0
Searching...
No Matches
Tensor2_carat_Tensor2.hpp
Go to the documentation of this file.
1/* Creates a Tensor2_symmetric expression by contracting two Tensor2's
2 together. There are different versions, depending on where the
3 contracting indices are located (i.e. whether it is A(i,j)^B(j,k)
4 or A(i,j)^B(k,j)). The classes are numbered to differentiate
5 between these. Thus, A(i,j)^B(j,k) has 10 appended to the name
6 because I count from 0. */
7
8#pragma once
9
10namespace FTensor
11{
12 /* Base Template */
13 template <class A, class B, class T, class U, int Dim0_0, int Dim1_0,
14 int Dim0_1, int Dim1_1, char i0, char j0, char i1, char j1>
16 {};
17
18 /* A(i,j)^B(j,k) */
19
20 template <class A, class B, class T, class U, int Dim, int Dim1, char i,
21 char j, char k>
22 class Tensor2_carat_Tensor2<A, B, T, U, Dim, Dim1, Dim1, Dim, i, j, j, k>
23 {
26
27 template <int Current_Dim>
28 typename promote<T, U>::V
29 eval(const int N1, const int N2, const Number<Current_Dim> &) const
30 {
31 return iterA(N1, Current_Dim - 1) * iterB(Current_Dim - 1, N2)
32 + eval(N1, N2, Number<Current_Dim - 1>());
33 }
34 typename promote<T, U>::V
35 eval(const int N1, const int N2, const Number<1> &) const
36 {
37 return iterA(N1, 0) * iterB(0, N2);
38 }
39
40 public:
43 : iterA(a), iterB(b)
44 {}
45 typename promote<T, U>::V operator()(const int N1, const int N2) const
46 {
47 return eval(N1, N2, Number<Dim1>());
48 }
49 };
50
51 /* A(i,j)^B(k,j) */
52
53 template <class A, class B, class T, class U, int Dim, int Dim1, char i,
54 char j, char k>
55 class Tensor2_carat_Tensor2<A, B, T, U, Dim, Dim1, Dim, Dim1, i, j, k, j>
56 {
59
60 template <int Current_Dim>
61 typename promote<T, U>::V
62 eval(const int N1, const int N2, const Number<Current_Dim> &) const
63 {
64 return iterA(N1, Current_Dim - 1) * iterB(N2, Current_Dim - 1)
65 + eval(N1, N2, Number<Current_Dim - 1>());
66 }
67 typename promote<T, U>::V
68 eval(const int N1, const int N2, const Number<1> &) const
69 {
70 return iterA(N1, 0) * iterB(N2, 0);
71 }
72
73 public:
76 : iterA(a), iterB(b)
77 {}
78 typename promote<T, U>::V operator()(const int N1, const int N2) const
79 {
80 return eval(N1, N2, Number<Dim1>());
81 }
82 };
83
84 /* A(j,i)^B(j,k) */
85
86 template <class A, class B, class T, class U, int Dim, int Dim1, char i,
87 char j, char k>
88 class Tensor2_carat_Tensor2<A, B, T, U, Dim1, Dim, Dim1, Dim, j, i, j, k>
89 {
92
93 template <int Current_Dim>
94 typename promote<T, U>::V
95 eval(const int N1, const int N2, const Number<Current_Dim> &) const
96 {
97 return iterA(Current_Dim - 1, N1) * iterB(Current_Dim - 1, N2)
98 + eval(N1, N2, Number<Current_Dim - 1>());
99 }
100 typename promote<T, U>::V
101 eval(const int N1, const int N2, const Number<1> &) const
102 {
103 return iterA(0, N1) * iterB(0, N2);
104 }
105
106 public:
109 : iterA(a), iterB(b)
110 {}
111 typename promote<T, U>::V operator()(const int N1, const int N2) const
112 {
113 return eval(N1, N2, Number<Dim1>());
114 }
115 };
116
117 /* A(j,i)^B(k,j) */
118
119 template <class A, class B, class T, class U, int Dim, int Dim1, char i,
120 char j, char k>
121 class Tensor2_carat_Tensor2<A, B, T, U, Dim1, Dim, Dim, Dim1, j, i, k, j>
122 {
125
126 template <int Current_Dim>
127 typename promote<T, U>::V
128 eval(const int N1, const int N2, const Number<Current_Dim> &) const
129 {
130 return iterA(Current_Dim - 1, N1) * iterB(N2, Current_Dim - 1)
131 + eval(N1, N2, Number<Current_Dim - 1>());
132 }
133 typename promote<T, U>::V
134 eval(const int N1, const int N2, const Number<1> &) const
135 {
136 return iterA(0, N1) * iterB(N2, 0);
137 }
138
139 public:
142 : iterA(a), iterB(b)
143 {}
144 typename promote<T, U>::V operator()(const int N1, const int N2) const
145 {
146 return eval(N1, N2, Number<Dim1>());
147 }
148 };
149
150 template <class A, class B, class T, class U, int Dim0_0, int Dim1_0,
151 int Dim0_1, int Dim1_1, char i0, char j0, char i1, char j1>
154 {
155 using TensorExpr = Tensor2_carat_Tensor2<A, B, T, U, Dim0_0, Dim1_0,
156 Dim0_1, Dim1_1, i0, j0, i1, j1>;
157 static_assert(
158 !std::is_empty<TensorExpr>::value,
159 "Indexes or Dimensions are not compatible with the ^ operator");
160
161 // Definition of Helper constexpr variables
162 constexpr int Dim = (i0 == i1 || i0 == j1) ? Dim1_0 : Dim0_0;
163 constexpr char i = (i0 == i1 || i0 == j1) ? j0 : i0,
164 j = (i1 == i0 || i1 == j0) ? j1 : i1;
165
167 i, j>(TensorExpr(a, b));
168 }
169
170 /* I don't think that this product actually gives a Ddg. */
171
172 // /* A(i,j)^B(k,l) -> Ddg(i,k,j,l) */
173
174 // template<class A, class B, class T, class U, int Dim, int Dim1,
175 // char i, char j, char k>
176 // class Tensor2_carat_Tensor2_0213
177 // {
178 // const Tensor2_Expr<A,T,Dim01,Dim23,i,j> iterA;
179 // const Tensor2_Expr<B,U,Dim01,Dim23,k,l> iterB;
180 // public:
181 // Tensor2_carat_Tensor2_0213(const Tensor2_Expr<A,T,Dim01,Dim23,i,j> &a,
182 // const Tensor2_Expr<B,U,Dim01,Dim23,k,l> &b):
183 // iterA(a), iterB(b) {}
184 // typename promote<T,U>::V operator()(const int N1, const int N2, const
185 // int N3,
186 // const int N4) const
187 // {
188 // return iterA(N1,N3)*iterB(N2,N4);
189 // }
190 // };
191
192 // template<class A, class B, class T, class U, int Dim01, int Dim23,
193 // char i, char j, char k, char l>
194 // const Ddg_Expr<const
195 // Tensor2_carat_Tensor2_0213<A,B,T,U,Dim01,Dim23,i,j,k,l>,typename
196 // promote<T,U>::V,Dim01,Dim23,i,k,j,l> operator^(const
197 // Tensor2_Expr<A,T,Dim01,Dim23,i,j> &a, const
198 // Tensor2_Expr<B,U,Dim01,Dim23,k,l> &b)
199 // {
200 // typedef Tensor2_carat_Tensor2_0213<A,B,T,U,Dim01,Dim23,i,j,k,l>
201 // TensorExpr;
202 // return Ddg_Expr<TensorExpr,typename promote<T,U>::V,Dim01,Dim23,i,k,j,l>
203 // (TensorExpr(a,b));
204 // }
205}
static Number< 2 > N2
static Number< 1 > N1
constexpr double a
promote< T, U >::V eval(const int N1, const int N2, const Number< Current_Dim > &) const
promote< T, U >::V eval(const int N1, const int N2, const Number< 1 > &) const
Tensor2_carat_Tensor2(const Tensor2_Expr< A, T, Dim1, Dim, j, i > &a, const Tensor2_Expr< B, U, Dim, Dim1, k, j > &b)
promote< T, U >::V eval(const int N1, const int N2, const Number< Current_Dim > &) const
Tensor2_carat_Tensor2(const Tensor2_Expr< A, T, Dim1, Dim, j, i > &a, const Tensor2_Expr< B, U, Dim1, Dim, j, k > &b)
promote< T, U >::V eval(const int N1, const int N2, const Number< 1 > &) const
Tensor2_carat_Tensor2(const Tensor2_Expr< A, T, Dim, Dim1, i, j > &a, const Tensor2_Expr< B, U, Dim, Dim1, k, j > &b)
promote< T, U >::V eval(const int N1, const int N2, const Number< Current_Dim > &) const
promote< T, U >::V eval(const int N1, const int N2, const Number< 1 > &) const
Tensor2_carat_Tensor2(const Tensor2_Expr< A, T, Dim, Dim1, i, j > &a, const Tensor2_Expr< B, U, Dim1, Dim, j, k > &b)
promote< T, U >::V eval(const int N1, const int N2, const Number< Current_Dim > &) const
promote< T, U >::V eval(const int N1, const int N2, const Number< 1 > &) const
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
const double T
Tensors class implemented by Walter Landry.
Definition: FTensor.hpp:51
Ddg_Expr< Ddg_carat_Ddg_13< A, B, T, U, Dim, Dim23, i, j, k, l, m, n >, typename promote< T, U >::V, Dim, Dim23, i, k, m, n > operator^(const Ddg_Expr< A, T, Dim, Dim, i, j, k, l > &a, const Ddg_Expr< B, U, Dim, Dim23, j, l, m, n > &b)
constexpr AssemblyType A