Documentation

Introduction: Example # 1

To use Tensors, the following files can be included:

```#include <tensors/tensor1.h>
#include <tensors/tensor2.h>
#include <tensors/tensor3.h>
#include <tensors/tensor4.h>
#include <tensors/operators.h>
```

Tensors are template classes requiring the type of components and the space dimension. For instance, `Tensor1<double,3> T1;` declares a first order tensor in 3D with double precision float point components. In the code below, some tensors are created and printed.

```Tensor1<double,3> T1;
Tensor2<double,3> T2;
Tensor3<double,3> T3;
Tensor4<double,3> T4;
for (int i=0; i < 3; ++i) {
T1[i] = i;
for (int j=0; j < 3; ++j) {
T2[i][j] = i*10 + j;
for (int k=0; k < 3; ++k) {
T3[i][j][k] = i*100 + j*10 + k;
for (int l=0; l < 3; ++l) {
T4[i][j][k][l] = i*1000 + j*100 + k*10 + l;
}
}
}
}
```

The output of the code above is:

```T1 =
1    2    3

T2 =
11   12   13
21   22   23
31   32   33

T3 =
111  112  113  211  212  213  311  312  313
121  122  123  221  222  223  321  322  323
131  132  133  231  232  233  331  332  333

T4 =
1111 1112 1113 | 1211 1212 1213 | 1311 1312 1313
1121 1122 1123 | 1221 1222 1223 | 1321 1322 1323
1131 1132 1133 | 1231 1232 1233 | 1331 1332 1333
------------------------------------------------
2111 2112 2113 | 2211 2212 2213 | 2311 2312 2313
2121 2122 2123 | 2221 2222 2223 | 2321 2322 2323
2131 2132 2133 | 2231 2232 2233 | 2331 2332 2333
------------------------------------------------
3111 3112 3113 | 3211 3212 3213 | 3311 3312 3313
3121 3122 3123 | 3221 3222 3223 | 3321 3322 3323
3131 3132 3133 | 3231 3232 3233 | 3331 3332 3333
```

Symbolic manipulation using GiNaC and Maxima: Example # 2

Suppose we want to code the previous fourth order tensor T4 in Fortran. First, we'll use GiNaC to handle symbolic data within tensors. Second, we'll convert the tensor orthonormal components to Mandel's basis (rendering a square matrix) and then pass the output to Maxima for further processing. This is accomplished with , as illustrated below.

```Tensor4<GiNaC::ex,3> T4;
for (int i=0; i < 3; ++i) {
for (int j=0; j < 3; ++j) {
for (int k=0; k < 3; ++k) {
for (int l=0; l < 3; ++l) {
std::ostringstream oss;
oss << "D" << (i+1)*1000 + (j+1)*100 + (k+1)*10 + l+1;
T4[i][j][k][l] = GiNaC::symbol(oss.str().c_str());
}
}
}
}
Tensor2<GiNaC::ex,9> T4m;
T4m.SetMaxima();
T4.GetMandel(T4m);
cout << "T4m : " << T4m << "\n";
```

Now, the code is run with:

```./doc02 | maxima
```

which generates the "doc02.f90" file. In the end, the following Fortran90 code is obtained:

```T4(1,1) = D1111
T4(1,2) = D1122
T4(1,3) = D1133
T4(1,4) = (sqrt(2)*D1121+sqrt(2)*D1112)/2.0
T4(1,5) = (sqrt(2)*D1132+sqrt(2)*D1123)/2.0
T4(1,6) = (sqrt(2)*D1131+sqrt(2)*D1113)/2.0
T4(1,7) = (sqrt(2)*D1121-sqrt(2)*D1112)/2.0
T4(1,8) = (sqrt(2)*D1132-sqrt(2)*D1123)/2.0
T4(1,9) = (sqrt(2)*D1131-sqrt(2)*D1113)/2.0
T4(2,1) = D2211
T4(2,2) = D2222
T4(2,3) = D2233
T4(2,4) = (sqrt(2)*D2221+sqrt(2)*D2212)/2.0
T4(2,5) = (sqrt(2)*D2232+sqrt(2)*D2223)/2.0
T4(2,6) = (sqrt(2)*D2231+sqrt(2)*D2213)/2.0
T4(2,7) = (sqrt(2)*D2221-sqrt(2)*D2212)/2.0
T4(2,8) = (sqrt(2)*D2232-sqrt(2)*D2223)/2.0
T4(2,9) = (sqrt(2)*D2231-sqrt(2)*D2213)/2.0
T4(3,1) = D3311
T4(3,2) = D3322
T4(3,3) = D3333
T4(3,4) = (sqrt(2)*D3321+sqrt(2)*D3312)/2.0
T4(3,5) = (sqrt(2)*D3332+sqrt(2)*D3323)/2.0
T4(3,6) = (sqrt(2)*D3331+sqrt(2)*D3313)/2.0
T4(3,7) = (sqrt(2)*D3321-sqrt(2)*D3312)/2.0
T4(3,8) = (sqrt(2)*D3332-sqrt(2)*D3323)/2.0
T4(3,9) = (sqrt(2)*D3331-sqrt(2)*D3313)/2.0
T4(4,1) = (sqrt(2)*D2111+sqrt(2)*D1211)/2.0
T4(4,2) = (sqrt(2)*D2122+sqrt(2)*D1222)/2.0
T4(4,3) = (sqrt(2)*D2133+sqrt(2)*D1233)/2.0
T4(4,4) = (D2121+D2112+D1221+D1212)/2.0
T4(4,5) = (D2132+D2123+D1232+D1223)/2.0
T4(4,6) = (D2131+D2113+D1231+D1213)/2.0
T4(4,7) = (D2121-D2112+D1221-D1212)/2.0
T4(4,8) = (D2132-D2123+D1232-D1223)/2.0
T4(4,9) = (D2131-D2113+D1231-D1213)/2.0
T4(5,1) = (sqrt(2)*D3211+sqrt(2)*D2311)/2.0
T4(5,2) = (sqrt(2)*D3222+sqrt(2)*D2322)/2.0
T4(5,3) = (sqrt(2)*D3233+sqrt(2)*D2333)/2.0
T4(5,4) = (D3221+D3212+D2321+D2312)/2.0
T4(5,5) = (D3232+D3223+D2332+D2323)/2.0
T4(5,6) = (D3231+D3213+D2331+D2313)/2.0
T4(5,7) = (D3221-D3212+D2321-D2312)/2.0
T4(5,8) = (D3232-D3223+D2332-D2323)/2.0
T4(5,9) = (D3231-D3213+D2331-D2313)/2.0
T4(6,1) = (sqrt(2)*D3111+sqrt(2)*D1311)/2.0
T4(6,2) = (sqrt(2)*D3122+sqrt(2)*D1322)/2.0
T4(6,3) = (sqrt(2)*D3133+sqrt(2)*D1333)/2.0
T4(6,4) = (D3121+D3112+D1321+D1312)/2.0
T4(6,5) = (D3132+D3123+D1332+D1323)/2.0
T4(6,6) = (D3131+D3113+D1331+D1313)/2.0
T4(6,7) = (D3121-D3112+D1321-D1312)/2.0
T4(6,8) = (D3132-D3123+D1332-D1323)/2.0
T4(6,9) = (D3131-D3113+D1331-D1313)/2.0
T4(7,1) = (sqrt(2)*D2111-sqrt(2)*D1211)/2.0
T4(7,2) = (sqrt(2)*D2122-sqrt(2)*D1222)/2.0
T4(7,3) = (sqrt(2)*D2133-sqrt(2)*D1233)/2.0
T4(7,4) = (D2121+D2112-D1221-D1212)/2.0
T4(7,5) = (D2132+D2123-D1232-D1223)/2.0
T4(7,6) = (D2131+D2113-D1231-D1213)/2.0
T4(7,7) = (D2121-D2112-D1221+D1212)/2.0
T4(7,8) = (D2132-D2123-D1232+D1223)/2.0
T4(7,9) = (D2131-D2113-D1231+D1213)/2.0
T4(8,1) = (sqrt(2)*D3211-sqrt(2)*D2311)/2.0
T4(8,2) = (sqrt(2)*D3222-sqrt(2)*D2322)/2.0
T4(8,3) = (sqrt(2)*D3233-sqrt(2)*D2333)/2.0
T4(8,4) = (D3221+D3212-D2321-D2312)/2.0
T4(8,5) = (D3232+D3223-D2332-D2323)/2.0
T4(8,6) = (D3231+D3213-D2331-D2313)/2.0
T4(8,7) = (D3221-D3212-D2321+D2312)/2.0
T4(8,8) = (D3232-D3223-D2332+D2323)/2.0
T4(8,9) = (D3231-D3213-D2331+D2313)/2.0
T4(9,1) = (sqrt(2)*D3111-sqrt(2)*D1311)/2.0
T4(9,2) = (sqrt(2)*D3122-sqrt(2)*D1322)/2.0
T4(9,3) = (sqrt(2)*D3133-sqrt(2)*D1333)/2.0
T4(9,4) = (D3121+D3112-D1321-D1312)/2.0
T4(9,5) = (D3132+D3123-D1332-D1323)/2.0
T4(9,6) = (D3131+D3113-D1331-D1313)/2.0
T4(9,7) = (D3121-D3112-D1321+D1312)/2.0
T4(9,8) = (D3132-D3123-D1332+D1323)/2.0
T4(9,9) = (D3131-D3113-D1331+D1313)/2.0
```