v0.14.0
test_T1.cpp
Go to the documentation of this file.
1 #include "../../src/FTensor.hpp"
2 #include "test_for_zero.hpp"
3 #include "test_ostream.hpp"
4 #include <iostream>
5 using namespace FTensor;
6 using namespace std;
7 
9 {
11 
12  Number<0> N0;
13  Number<1> N1;
14  Number<2> N2;
15 
16  /* Tensor1 test cases. */
17  test_ostream(Tensor1<double, 3>(3., 7., 11.), "[3,7,11]",
18  "operator<<(T1<3>)");
19  test_ostream(Tensor1<double, 1>(13.), "[13]", "operator<<(T1<1>)");
20 
21  std::stringstream ss("[3,7,11]");
22  ss >> t1_1;
23  test_for_zero(t1_1(0) - 3, "operator>>(T1<3>)(0)");
24  test_for_zero(t1_1(1) - 7, "operator>>(T1<3>)(1)");
25  test_for_zero(t1_1(2) - 11, "operator>>(T1<3>)(2)");
26 
27  t1_1(i) = 2 * t1_2(i);
28  test_for_zero(t1_1(0) - 2 * t1_2(0), "T*T1(0)");
29  test_for_zero(t1_1(1) - 2 * t1_2(1), "T*T1(1)");
30  test_for_zero(t1_1(2) - 2 * t1_2(2), "T*T1(2)");
31  t1_1(i) += 3 * t1_2(i);
32  test_for_zero(t1_1(0) - 5 * t1_2(0), "T1+=T1(0)");
33  test_for_zero(t1_1(1) - 5 * t1_2(1), "T1+=T1(1)");
34  test_for_zero(t1_1(2) - 5 * t1_2(2), "T1+=T1(2)");
35  t1_1(i) -= t1_2(i) / 2;
36  test_for_zero(t1_1(0) - 4.5 * t1_2(0), "T1-=T1(0)");
37  test_for_zero(t1_1(1) - 4.5 * t1_2(1), "T1-=T1(1)");
38  test_for_zero(t1_1(2) - 4.5 * t1_2(2), "T1-=T1(2)");
39  t1_1(i) *= 3;
40  test_for_zero(t1_1(0) - 13.5 * t1_2(0), "T1(0)*=T");
41  test_for_zero(t1_1(1) - 13.5 * t1_2(1), "T1(1)*=T");
42  test_for_zero(t1_1(2) - 13.5 * t1_2(2), "T1(2)*=T");
43  t1_1(i) /= 4.5;
44  test_for_zero(t1_1(0) - 3 * t1_2(0), "T1(0)/=T");
45  test_for_zero(t1_1(1) - 3 * t1_2(1), "T1(1)/=T");
46  test_for_zero(t1_1(2) - 3 * t1_2(2), "T1(2)/=T");
47  t1_1(i) += 10;
48  test_for_zero(t1_1(0) - 3 * t1_2(0) - 10, "T1(0)+=T");
49  test_for_zero(t1_1(1) - 3 * t1_2(1) - 10, "T1(1)+=T");
50  test_for_zero(t1_1(2) - 3 * t1_2(2) - 10, "T1(2)+=T");
51  t1_1(i) -= 7;
52  test_for_zero(t1_1(0) - 3 * t1_2(0) - 3, "T1(0)-=T");
53  test_for_zero(t1_1(1) - 3 * t1_2(1) - 3, "T1(1)-=T");
54  test_for_zero(t1_1(2) - 3 * t1_2(2) - 3, "T1(2)-=T");
55  t1_1(i) = t1_2(i) + t1_1(i);
56  test_for_zero(t1_1(0) - 4 * t1_2(0) - 3, "T1+T1(0)");
57  test_for_zero(t1_1(1) - 4 * t1_2(1) - 3, "T1+T1(1)");
58  test_for_zero(t1_1(2) - 4 * t1_2(2) - 3, "T1+T1(2)");
59  t1_1(i) = -t1_2(i) - t1_1(i);
60  test_for_zero(t1_1(0) + 5 * t1_2(0) + 3, "-T1-T1(0)");
61  test_for_zero(t1_1(1) + 5 * t1_2(1) + 3, "-T1-T1(1)");
62  test_for_zero(t1_1(2) + 5 * t1_2(2) + 3, "-T1-T1(2)");
63  t1_1(i) = t1_2(i) + 10;
64  test_for_zero(t1_1(0) - t1_2(0) - 10, "T1(0)+T");
65  test_for_zero(t1_1(1) - t1_2(1) - 10, "T1(1)+T");
66  test_for_zero(t1_1(2) - t1_2(2) - 10, "T1(2)+T");
67  t1_1(i) = t1_2(i) - 10;
68  test_for_zero(t1_1(0) - t1_2(0) + 10, "T1(0)-T");
69  test_for_zero(t1_1(1) - t1_2(1) + 10, "T1(1)-T");
70  test_for_zero(t1_1(2) - t1_2(2) + 10, "T1(2)-T");
71  test_for_zero(t1_1(i) * t1_2(i)
72  - (t1_2(0) * (t1_2(0) - 10) + t1_2(1) * (t1_2(1) - 10)
73  + t1_2(2) * (t1_2(2) - 10)),
74  "T1(i)*T1(i)");
75  t1_1(i) = 10 - t1_2(i);
76  test_for_zero(t1_1(0) + t1_2(0) - 10, "T-T1(0)");
77  test_for_zero(t1_1(1) + t1_2(1) - 10, "T-T1(1)");
78  test_for_zero(t1_1(2) + t1_2(2) - 10, "T-T1(2)");
79  t1_1(i) = t1_2(i);
80  test_for_zero(t1_1(0) - t1_2(0), "T1=T1(0)");
81  test_for_zero(t1_1(1) - t1_2(1), "T1=T1(1)");
82  test_for_zero(t1_1(2) - t1_2(2), "T1=T1(2)");
83  t1_1(i) = 10;
84  test_for_zero(t1_1(0) - 10, "T1(0)=T");
85  test_for_zero(t1_1(1) - 10, "T1(1)=T");
86  test_for_zero(t1_1(2) - 10, "T1(2)=T");
87 
88  t1_1(i) = (t1_1(i) & t1_2(i));
89  test_for_zero(t1_1(0) - 10 * t1_2(0), "T1&T1(0)");
90  test_for_zero(t1_1(1) - 10 * t1_2(1), "T1&T1(1)");
91  test_for_zero(t1_1(2) - 10 * t1_2(2), "T1&T1(2)");
92 
94  t1_1.l2()
95  - sqrt(t1_1(0) * t1_1(0) + t1_1(1) * t1_1(1) + t1_1(2) * t1_1(2)),
96  "T1.l2()");
97  Tensor1<double, 3> t1_3;
98  t1_3(i) = t1_1(i);
99  t1_3.normalize();
100  test_for_zero(t1_3(0) - t1_1(0) / t1_1.l2(), "T1.normalize()(0)");
101  test_for_zero(t1_3(1) - t1_1(1) / t1_1.l2(), "T1.normalize()(1)");
102  test_for_zero(t1_3(2) - t1_1(2) / t1_1.l2(), "T1.normalize()(2)");
103 }
FTensor
JSON compatible output.
Definition: Christof_constructor.hpp:6
FTensor::Tensor1< double, 3 >
test_ostream.hpp
FTensor::Tensor1::l2
T l2() const
Definition: Tensor1_value.hpp:84
test_ostream
void test_ostream(const T &t, const std::string &expected, const std::string &test_name)
Definition: test_ostream.hpp:7
FTensor::Number< 0 >
test_T1
void test_T1(Tensor1< double, 3 > &t1_1, const Tensor1< double, 3 > &t1_2)
Definition: test_T1.cpp:8
test_for_zero
void test_for_zero(const T &t, const std::string &s)
Definition: test_for_zero.hpp:7
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
FTensor::Index< 'i', 3 >
test_for_zero.hpp
FTensor::Tensor1::normalize
Tensor1< T, Tensor_Dim > normalize()
Definition: Tensor1_value.hpp:77
std
Definition: enable_if.hpp:5