1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
(* Run this script with:
math -run 'Get["TestTensorTools.m"]; Quit[]'
*)
(* Initialise *)
$Path = Join[{"../Tools/CodeGen", "../Tools/MathematicaMisc"}, $Path];
SetOptions["stdout", PageWidth -> Infinity];
Print["Loading tensortools"];
<< TensorTools`;
enhancedTimes = False;
SetEnhancedTimes[enhancedTimes];
(* Definitions *)
SetAttributes[test, HoldFirst]
test[t_, r1_] :=
Module[
{r},
Print["Input: ", HoldForm[InputForm@t]];
r = If[enhancedTimes, r1 /. Times -> TensorProduct, r1];
Print["Expected: ", Expand@r//InputForm];
If[Expand[Evaluate[t]] === Expand[r],
testsPassed++;
Print["Result: ", Expand[r]//InputForm];
Print["Pass"],
(* else *)
testsFailed++;
Print["Result:", Expand@Evaluate[t]//InputForm];
Print["Fail"]];
Print[]];
reportResults[] :=
If[testsFailed > 0,
Print[ToString[testsFailed] <> " test" <>
If[testsFailed > 1, "s", ""] <> " failed"],
Print["All " <> ToString[testsPassed] <> " test" <>
If[testsPassed > 1, "s", ""] <> " passed"]];
(* Tests *)
testsPassed = 0; testsFailed = 0;
DefineTensor /@ {S, T, u, v, w};
(* We currently only test with correct input as it is CheckTensor's
responsibility to check that the input is correct. This should be
changed. *)
Print["Running tests"];
Print[];
(****************************************************************)
(* makeSum *)
(****************************************************************)
makeSum = TensorTools`Private`makeSum
test[makeSum[1], 1];
test[makeSum[x], x];
test[makeSum[x^2], x^2];
test[makeSum[x^2 + 1], 1 + x^2];
test[makeSum[S[ua]], S[ua]];
test[makeSum[SS[la]], SS[la]];
test[makeSum[x S[ua]], x S[ua]];
test[makeSum[x S[ua] + T[ua]], x S[ua] + T[ua]];
(* test[makeSum[S[ua] T[la]], S[1] T[1] + S[2] T[2] + S[3] T[3]]; *)
(* test[makeSum[u[ua] v[la]], u[1] v[1] + u[2] v[2] + u[3] v[3]]; *)
(* test[makeSum[a S[ua] T[la] + 1], a (S[1] T[1] + S[2] T[2] + S[3] T[3]) + 1]; *)
(* test[makeSum[S[ua] T[la] + u[ua] v[la]], *)
(* S[1] T[1] + S[2] T[2] + S[3] T[3] + u[1] v[1] + u[2] v[2] + u[3] v[3]]; *)
(* test[makeSum[a (S[ua] T[la] + x) + b (u[ua] v[la] + y)], *)
(* a (S[1] T[1] + S[2] T[2] + S[3] T[3] + x) + *)
(* b (u[1] v[1] + u[2] v[2] + u[3] v[3] + y)]; *)
(* test[makeSum[ *)
(* S[ua] T[la] u[ub] v[lb]], (S[1] T[1] + S[2] T[2] + S[3] T[3]) (u[1] v[1] + *)
(* u[2] v[2] + u[3] v[3])]; *)
(* test[makeSum[f[S[la]]], f[S[la]]]; *)
(* test[makeSum[f[S[la] T[ua]]], f[S[1] T[1] + S[2] T[2] + S[3] T[3]]]; *)
(* test[makeSum[f[g[S[la] T[ua]]]], f[g[S[1] T[1] + S[2] T[2] + S[3] T[3]]]]; *)
(* test[makeSum[T[ua] f[S[la]]], T[1] f[S[1]] + T[2] f[S[2]] + T[3] f[S[3]]]; *)
(* test[makeSum[Sqrt[T[la] S[ua]]], Sqrt[S[1] T[1] + S[2] T[2] + S[3] T[3]]]; *)
(* test[makeSum[IfThen[cond, T[la] S[ua], 0]], *)
(* IfThen[cond, S[1] T[1] + S[2] T[2] + S[3] T[3], 0]]; *)
(* test[makeSum[IfThen[cond, T[la] S[ua], u[la] v[ua]]], *)
(* IfThen[cond, S[1] T[1] + S[2] T[2] + S[3] T[3], *)
(* u[1] v[1] + u[2] v[2] + u[3] v[3]]]; *)
(* (\****************************************************************\) *)
(* (\* makeSplit *\) *)
(* (\****************************************************************\) *)
(* makeSplit = TensorTools`Private`makeSplit; *)
(* test[makeSplit[S[la]], {S[1], S[2], S[3]}]; *)
(* test[makeSplit[S[la, lb]], {S[1, 1], S[1, 2], S[1, 3], S[2, 1], S[2, 2], *)
(* S[2, 3], S[3, 1], S[3, 2], S[3, 3]}]; *)
(* test[makeSplit[S[la] T[lb]], {S[1] T[1], S[1] T[2], S[1] T[3], S[2] T[1], *)
(* S[2] T[2], S[2] T[3], S[3] T[1], S[3] T[2], S[3] T[3]}]; *)
(* test[makeSplit[S[la] -> T[la]], {S[1] -> T[1], S[2] -> T[2], S[3] -> T[3]}]; *)
(* (\****************************************************************\) *)
(* (\* MakeExplicit *\) *)
(* (\****************************************************************\) *)
(* test[MakeExplicit[S[la] T[ua] v[lb]], (S1 T1 + S2 T2 + S3 T3) {v1, v2, v3}]; *)
(* test[MakeExplicit[S[la] -> v[la]], {S1 -> v1, S2 -> v2, S3 -> v3}]; *)
(* test[MakeExplicit[ *)
(* S[la] IfThen[1, T[ua], v[ua]]], {S1 IfThen[1, T1, v1] + *)
(* S2 IfThen[1, T2, v2] + S3 IfThen[1, T3, v3]}]; *)
(* test[MakeExplicit[Sqrt[S[ua] T[la]]], {Sqrt[S1 T1 + S2 T2 + S3 T3]}]; *)
(* test[MakeExplicit[Sqrt[u[ua] v[la]]], {Sqrt[u1 v1 + u2 v2 + u3 v3]}]; *)
(* test[FullSimplify[MakeExplicit[MatrixInverse[u[ua, ub]] u[lb, lc]]], *)
(* {1, 0, 0, 0, 1, 0, 0, 0, 1}]; *)
(* (\****************************************************************\) *)
(* (\* Partial derivatives *\) *)
(* (\****************************************************************\) *)
(* test[MakeExplicit[PD[u[la], lb]], {PD[u1, 1], PD[u1, 2], PD[u1, 3], PD[u2, 1], *)
(* PD[u2, 2], PD[u2, 3], PD[u3, 1], PD[u3, 2], PD[u3, 3]}]; *)
(* test[MakeExplicit[PD[u[ua], la]], {PD[u1, 1], PD[u2, 2], PD[u3, 3]}]; *)
(* test[Simplify[MakeExplicit[PD[MatrixInverse[u[ua, ub]] u[lb, lc], ld]]], {0, *)
(* 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, *)
(* 0}]; *)
(* test[FullSimplify[MakeExplicit[PD[MatrixInverse[u[ua, ub]], ld] u[lb, lc]] + *)
(* MakeExplicit[MatrixInverse[u[ua, ub]] PD[u[lb, lc], ld]]], *)
(* {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, *)
(* 0, 0}]; *)
reportResults[];
|