v0.16.0
Loading...
Searching...
No Matches
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>
5using namespace FTensor;
6using namespace std;
7
9{
10 Index<'i', 3> i;
11
12 Tensor1<double, 3> t_v(1.5, -2., 4.25);
13 One<> t_one;
14 test_for_zero(t_v(i) * t_one(i) - (t_v(0) + t_v(1) + t_v(2)),
15 "T1(i)*One(i)");
16
17 Number<0> N0;
18 Number<1> N1;
19 Number<2> N2;
20
21 /* Tensor1 test cases. */
22 test_ostream(Tensor1<double, 3>(3., 7., 11.), "[3,7,11]",
23 "operator<<(T1<3>)");
24 test_ostream(Tensor1<double, 1>(13.), "[13]", "operator<<(T1<1>)");
25
26 std::stringstream ss("[3,7,11]");
27 ss >> t1_1;
28 test_for_zero(t1_1(0) - 3, "operator>>(T1<3>)(0)");
29 test_for_zero(t1_1(1) - 7, "operator>>(T1<3>)(1)");
30 test_for_zero(t1_1(2) - 11, "operator>>(T1<3>)(2)");
31
32 t1_1(i) = 2 * t1_2(i);
33 test_for_zero(t1_1(0) - 2 * t1_2(0), "T*T1(0)");
34 test_for_zero(t1_1(1) - 2 * t1_2(1), "T*T1(1)");
35 test_for_zero(t1_1(2) - 2 * t1_2(2), "T*T1(2)");
36 t1_1(i) += 3 * t1_2(i);
37 test_for_zero(t1_1(0) - 5 * t1_2(0), "T1+=T1(0)");
38 test_for_zero(t1_1(1) - 5 * t1_2(1), "T1+=T1(1)");
39 test_for_zero(t1_1(2) - 5 * t1_2(2), "T1+=T1(2)");
40 t1_1(i) -= t1_2(i) / 2;
41 test_for_zero(t1_1(0) - 4.5 * t1_2(0), "T1-=T1(0)");
42 test_for_zero(t1_1(1) - 4.5 * t1_2(1), "T1-=T1(1)");
43 test_for_zero(t1_1(2) - 4.5 * t1_2(2), "T1-=T1(2)");
44 t1_1(i) *= 3;
45 test_for_zero(t1_1(0) - 13.5 * t1_2(0), "T1(0)*=T");
46 test_for_zero(t1_1(1) - 13.5 * t1_2(1), "T1(1)*=T");
47 test_for_zero(t1_1(2) - 13.5 * t1_2(2), "T1(2)*=T");
48 t1_1(i) /= 4.5;
49 test_for_zero(t1_1(0) - 3 * t1_2(0), "T1(0)/=T");
50 test_for_zero(t1_1(1) - 3 * t1_2(1), "T1(1)/=T");
51 test_for_zero(t1_1(2) - 3 * t1_2(2), "T1(2)/=T");
52 t1_1(i) += 10;
53 test_for_zero(t1_1(0) - 3 * t1_2(0) - 10, "T1(0)+=T");
54 test_for_zero(t1_1(1) - 3 * t1_2(1) - 10, "T1(1)+=T");
55 test_for_zero(t1_1(2) - 3 * t1_2(2) - 10, "T1(2)+=T");
56 t1_1(i) -= 7;
57 test_for_zero(t1_1(0) - 3 * t1_2(0) - 3, "T1(0)-=T");
58 test_for_zero(t1_1(1) - 3 * t1_2(1) - 3, "T1(1)-=T");
59 test_for_zero(t1_1(2) - 3 * t1_2(2) - 3, "T1(2)-=T");
60 t1_1(i) = t1_2(i) + t1_1(i);
61 test_for_zero(t1_1(0) - 4 * t1_2(0) - 3, "T1+T1(0)");
62 test_for_zero(t1_1(1) - 4 * t1_2(1) - 3, "T1+T1(1)");
63 test_for_zero(t1_1(2) - 4 * t1_2(2) - 3, "T1+T1(2)");
64 t1_1(i) = -t1_2(i) - t1_1(i);
65 test_for_zero(t1_1(0) + 5 * t1_2(0) + 3, "-T1-T1(0)");
66 test_for_zero(t1_1(1) + 5 * t1_2(1) + 3, "-T1-T1(1)");
67 test_for_zero(t1_1(2) + 5 * t1_2(2) + 3, "-T1-T1(2)");
68 t1_1(i) = t1_2(i) + 10;
69 test_for_zero(t1_1(0) - t1_2(0) - 10, "T1(0)+T");
70 test_for_zero(t1_1(1) - t1_2(1) - 10, "T1(1)+T");
71 test_for_zero(t1_1(2) - t1_2(2) - 10, "T1(2)+T");
72 t1_1(i) = t1_2(i) - 10;
73 test_for_zero(t1_1(0) - t1_2(0) + 10, "T1(0)-T");
74 test_for_zero(t1_1(1) - t1_2(1) + 10, "T1(1)-T");
75 test_for_zero(t1_1(2) - t1_2(2) + 10, "T1(2)-T");
76 test_for_zero(t1_1(i) * t1_2(i)
77 - (t1_2(0) * (t1_2(0) - 10) + t1_2(1) * (t1_2(1) - 10)
78 + t1_2(2) * (t1_2(2) - 10)),
79 "T1(i)*T1(i)");
80 t1_1(i) = 10 - t1_2(i);
81 test_for_zero(t1_1(0) + t1_2(0) - 10, "T-T1(0)");
82 test_for_zero(t1_1(1) + t1_2(1) - 10, "T-T1(1)");
83 test_for_zero(t1_1(2) + t1_2(2) - 10, "T-T1(2)");
84 t1_1(i) = t1_2(i);
85 test_for_zero(t1_1(0) - t1_2(0), "T1=T1(0)");
86 test_for_zero(t1_1(1) - t1_2(1), "T1=T1(1)");
87 test_for_zero(t1_1(2) - t1_2(2), "T1=T1(2)");
88 t1_1(i) = 10;
89 test_for_zero(t1_1(0) - 10, "T1(0)=T");
90 test_for_zero(t1_1(1) - 10, "T1(1)=T");
91 test_for_zero(t1_1(2) - 10, "T1(2)=T");
92
93 t1_1(i) = (t1_1(i) & t1_2(i));
94 test_for_zero(t1_1(0) - 10 * t1_2(0), "T1&T1(0)");
95 test_for_zero(t1_1(1) - 10 * t1_2(1), "T1&T1(1)");
96 test_for_zero(t1_1(2) - 10 * t1_2(2), "T1&T1(2)");
97
99 t1_1.l2()
100 - sqrt(t1_1(0) * t1_1(0) + t1_1(1) * t1_1(1) + t1_1(2) * t1_1(2)),
101 "T1.l2()");
103 t1_3(i) = t1_1(i);
104 t1_3.normalize();
105 test_for_zero(t1_3(0) - t1_1(0) / t1_1.l2(), "T1.normalize()(0)");
106 test_for_zero(t1_3(1) - t1_1(1) / t1_1.l2(), "T1.normalize()(1)");
107 test_for_zero(t1_3(2) - t1_1(2) / t1_1.l2(), "T1.normalize()(2)");
108}
Stateless vector whose components are all equal to one.
Definition One.hpp:22
Tensor1< T, Tensor_Dim > normalize()
FTensor::Index< 'i', SPACE_DIM > i
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51
void test_T1(Tensor1< double, 3 > &t1_1, const Tensor1< double, 3 > &t1_2)
Definition test_T1.cpp:8
void test_for_zero(const T &t, const std::string &s)
void test_ostream(const T &t, const std::string &expected, const std::string &test_name)