v0.14.0
test_T4_007.cpp
Go to the documentation of this file.
1 #include "../../../src/FTensor.hpp"
2 #include "../test_for_zero.hpp"
3 #include <iostream>
4 using namespace FTensor;
5 using namespace std;
6 
8  const Tensor3<double, 2, 3, 4> &t3_2) {
14 
15  Number<0> N0;
16  Number<1> N1;
17  Number<2> N2;
18 
20  t32(j, k, l) = 0.;
21 
22  // Yield tensor 4 setting 4th slot
23  {
25  t_4(j, k, l, N0) = t3_2(j, k, l);
26  t_4(j, k, l, N1) = t32(j, k, l);
27  t_4(j, k, l, N2) = t32(j, k, l);
28  for (int ii = 0; ii != 2; ++ii)
29  for (int jj = 0; jj != 3; ++jj)
30  for (int kk = 0; kk != 4; ++kk) {
31  test_for_zero(t_4(ii, jj, kk, 0) - t3_2(ii, jj, kk),
32  "T4(i,j,k,N0)(" + to_string(ii) + "," + to_string(jj) +
33  "," + to_string(kk) + ")");
34  for (int ll : {1, 2}) {
35  test_for_zero(t_4(ii, jj, kk, ll), "T4(i,j,k,ll)(" + to_string(ii) +
36  "," + to_string(jj) + "," +
37  to_string(kk) + "," +
38  to_string(ll) + ")");
39  }
40  }
41  }
42  {
44  t_4(j, k, l, N0) = t32(j, k, l);
45  t_4(j, k, l, N1) = t3_2(j, k, l);
46  t_4(j, k, l, N2) = t32(j, k, l);
47  for (int ii = 0; ii != 2; ++ii)
48  for (int jj = 0; jj != 3; ++jj)
49  for (int kk = 0; kk != 4; ++kk) {
50  test_for_zero(t_4(ii, jj, kk, 1) - t3_2(ii, jj, kk),
51  "T4(i,j,k,N1)(" + to_string(ii) + "," + to_string(jj) +
52  "," + to_string(kk) + ")");
53  for (int ll : {0, 2}) {
54  test_for_zero(t_4(ii, jj, kk, ll), "T4(i,j,k,ll)(" + to_string(ii) +
55  "," + to_string(jj) + "," +
56  to_string(kk) + "," +
57  to_string(ll) + ")");
58  }
59  }
60  }
61  {
63  t_4(j, k, l, N0) = t32(j, k, l);
64  t_4(j, k, l, N1) = t32(j, k, l);
65  t_4(j, k, l, N2) = t3_2(j, k, l);
66  for (int ii = 0; ii != 2; ++ii)
67  for (int jj = 0; jj != 3; ++jj)
68  for (int kk = 0; kk != 4; ++kk) {
69  test_for_zero(t_4(ii, jj, kk, 2) - t3_2(ii, jj, kk),
70  "T4(i,j,k,N2)(" + to_string(ii) + "," + to_string(jj) +
71  "," + to_string(kk) + ")");
72  for (int ll : {0, 1}) {
73  test_for_zero(t_4(ii, jj, kk, ll), "T4(i,j,k,ll)(" + to_string(ii) +
74  "," + to_string(jj) + "," +
75  to_string(kk) + "," +
76  to_string(ll) + ")");
77  }
78  }
79  }
80 
81  // Yield tensor 4 setting 3th slot
82  {
84  t_4(j, k, N0, l) = t3_2(j, k, l);
85  t_4(j, k, N1, l) = t32(j, k, l);
86  t_4(j, k, N2, l) = t32(j, k, l);
87  for (int ii = 0; ii != 2; ++ii)
88  for (int jj = 0; jj != 3; ++jj)
89  for (int kk = 0; kk != 4; ++kk) {
90  test_for_zero(t_4(ii, jj, 0, kk) - t3_2(ii, jj, kk),
91  "T4(i,j,N0,k)(" + to_string(ii) + "," + to_string(jj) +
92  "," + to_string(kk) + ")");
93  for (int ll : {1, 2}) {
94  test_for_zero(t_4(ii, jj, ll, kk), "T4(i,j,l, k)(" + to_string(ii) +
95  "," + to_string(jj) + "," +
96  to_string(ll) + "," +
97  to_string(kk) + ")");
98  }
99  }
100  }
101  {
103  t_4(j, k, N0, l) = t32(j, k, l);
104  t_4(j, k, N1, l) = t3_2(j, k, l);
105  t_4(j, k, N2, l) = t32(j, k, l);
106  for (int ii = 0; ii != 2; ++ii)
107  for (int jj = 0; jj != 3; ++jj)
108  for (int kk = 0; kk != 4; ++kk) {
109  test_for_zero(t_4(ii, jj, 1, kk) - t3_2(ii, jj, kk),
110  "T4(i,j,N1,k)(" + to_string(ii) + "," + to_string(jj) +
111  "," + to_string(kk) + ")");
112  for (int ll : {0, 2}) {
113  test_for_zero(t_4(ii, jj, ll, kk), "T4(i,j,k,ll)(" + to_string(ii) +
114  "," + to_string(jj) + "," +
115  to_string(ll) + "," +
116  to_string(kk) + ")");
117  }
118  }
119  }
120  {
122  t_4(j, k, N0, l) = t32(j, k, l);
123  t_4(j, k, N1, l) = t32(j, k, l);
124  t_4(j, k, N2, l) = t3_2(j, k, l);
125  for (int ii = 0; ii != 2; ++ii)
126  for (int jj = 0; jj != 3; ++jj)
127  for (int kk = 0; kk != 4; ++kk) {
128  test_for_zero(t_4(ii, jj, 2, kk) - t3_2(ii, jj, kk),
129  "T4(i,j,N2,k)(" + to_string(ii) + "," + to_string(jj) +
130  "," + to_string(kk) + ")");
131  for (int ll : {0, 1}) {
132  test_for_zero(t_4(ii, jj, ll, kk), "T4(i,j,k,ll)(" + to_string(ii) +
133  "," + to_string(jj) + "," +
134  to_string(ll) + "," +
135  to_string(kk) + ")");
136  }
137  }
138  }
139 
140  // Tensor4 to a Tensor4, yielding a Ddg.
141  {
146  Ddg<double, 3, 2> t_ddg;
148  for (int ii = 0; ii != 3; ++ii)
149  for (int jj = 0; jj != 3; ++jj)
150  for (int kk = 0; kk != 2; ++kk)
151  for (int ll = 0; ll != 2; ++ll) {
152  t_4(ii, jj, kk, ll) = 1 + ii + 10. * jj + 100 * kk + 1000 * ll;
153  }
154  t_ddg(i, j, k, l) = t_4(i, j, k, l) || t_4(j, i, l, k);
155  for (int ii = 0; ii != 3; ++ii)
156  for (int jj = 0; jj != 3; ++jj)
157  for (int kk = 0; kk != 2; ++kk)
158  for (int ll = 0; ll != 2; ++ll) {
159  test_for_zero(t_ddg(ii, jj, ll, kk) - t_4(ii, jj, kk, ll) -
160  t_4(jj, ii, ll, kk),
161  "T4(i,j,k,l)||T4(j,i,l,k)(" + to_string(ii) + "," +
162  to_string(jj) + "," + to_string(ll) + "," +
163  to_string(kk) + ")");
164  }
165  }
166 
167  // Tensor4 times tensor 3 yields tensor 3
168  {
170  Tensor2<double, 1, 2> t_2_1;
171  Tensor2<double, 3, 4> t_2_2;
172  for (int ii = 0; ii != 1; ++ii)
173  for (int jj = 0; jj != 2; ++jj) {
174  t_2_1(ii, jj) = 1 + ii + 10. * jj;
175  }
176  for (int kk = 0; kk != 3; ++kk)
177  for (int ll = 0; ll != 4; ++ll) {
178  t_2_2(kk, ll) = 1 + 100 * kk + 1000 * ll;
179  }
180  t_4(i, j, k, l) = t_2_1(i, j) * t_2_2(k, l);
182  for (int kk = 0; kk != 3; ++kk)
183  for (int ll = 0; ll != 4; ++ll)
184  for (int mm = 0; mm != 3; ++mm) {
185  t_3_1(kk, ll, mm) = 1 + 100 * kk + 1000 * ll + 10000 * mm;
186  }
189  t_3_2(i, j, m) = t_4(i, j, k, l) * t_3_1(k, l, m) -
190  t_2_1(i, j) * (t_3_1(k, l, m) * t_2_2(k, l));
191  for (int ii = 0; ii != 1; ++ii)
192  for (int jj = 0; jj != 2; ++jj)
193  for (int mm = 0; mm != 3; ++mm) {
194  test_for_zero(t_3_2(ii, jj, mm),
195  "T4(i,j,k,l)*T3(k,l,m)(" + to_string(ii) + "," +
196  to_string(jj) + "," + to_string(mm) + ")");
197  }
198  }
199 
200  // Tensor4 times tensor 3 yields tensor 3
201  {
203  Tensor2<double, 1, 4> t_2_1;
204  Tensor2<double, 2, 3> t_2_2;
205  for (int ii = 0; ii != 1; ++ii)
206  for (int ll = 0; ll != 4; ++ll) {
207  t_2_1(ii, ll) = 1 + ii + 10. * ll;
208  }
209  for (int jj = 0; jj != 2; ++jj)
210  for (int kk = 0; kk != 3; ++kk) {
211  t_2_2(jj, kk) = 1 + 100 * jj + 1000 * kk;
212  }
213  t_4(i, j, k, l) = t_2_1(i, l) * t_2_2(j, k);
215  for (int mm = 0; mm != 3; ++mm)
216  for (int kk = 0; kk != 3; ++kk)
217  for (int jj = 0; jj != 2; ++jj) {
218  t_3_1(mm, kk, jj) = 1 + 100 * mm + 1000 * kk + 10000 * jj;
219  }
222  t_3_2(i, l, m) = t_4(i, j, k, l) * t_3_1(m, k, j) -
223  t_2_1(i, l) * (t_3_1(m, k, j) * t_2_2(j, k));
224  for (int ii = 0; ii != 1; ++ii)
225  for (int ll = 0; ll != 4; ++ll)
226  for (int mm = 0; mm != 3; ++mm) {
227  test_for_zero(t_3_2(ii, ll, mm),
228  "T4(i,j,k,l)*T3(m,k,j)(" + to_string(ii) + "," +
229  to_string(ll) + "," + to_string(mm) + ")");
230  }
231  }
232 
233 }
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::Tensor2
Definition: Tensor2_value.hpp:16
FTensor::Number< 0 >
FTensor::Tensor3
Definition: Tensor3_value.hpp:12
test_for_zero
void test_for_zero(const T &t, const std::string &s)
Definition: test_for_zero.hpp:7
FTensor::Tensor4
Definition: Tensor4_value.hpp:18
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Index
Definition: Index.hpp:23
convert.n
n
Definition: convert.py:82
std
Definition: enable_if.hpp:5
j
FTensor::Index< 'j', 3 > j
Definition: matrix_function.cpp:19
FTensor::Ddg
Definition: Ddg_value.hpp:7
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
k
FTensor::Index< 'k', 3 > k
Definition: matrix_function.cpp:20
l
FTensor::Index< 'l', 3 > l
Definition: matrix_function.cpp:21
test_T4_007
void test_T4_007(const Tensor4< double, 1, 2, 3, 4 > &t4, const Tensor3< double, 2, 3, 4 > &t3_2)
Definition: test_T4_007.cpp:7