Tensors
Header file tensor.h
General tensor class
-
Name
-
Tensor
-
Purpose
-
Representation of tensors, i.e. arrays of objects of the same type, with
rules for arithmetic operations.
-
Inheritance
-
Arithmetic_matrix of objects (template class).
Constituents
-
Type of each index, Array<int> index_type (0: contravariant,
1: covariant).
(As for Arithmetic_matrix, plus index_type. )
Methods
(Extending Arithmetic_matrix)
-
Creation
-
Null tensor (no elements):
Tensor()
-
Tensor of zeros, all indices the same type:
Tensor(const Array<int>& nreq, const int it)
where nreq gives the number of dimensions and entries in each
dimension, and it is the index type used for all indices.
-
Copy from an existing Arithmetic_matrix, with a single index type:
Tensor(const Arithmetic_matrix<type>& a, const int it =
0)
-
Copy from an existing Arithmetic_matrix, with a separate type
for each index:
Tensor(const Arithmetic_matrix<type>& a, const Array<int>
it)
-
Input and output
-
The << and >> operators can be used.
The class also provides Read_elements and Write_elements
methods to read and write the elements only, without the number of rows
and columns.) e.g.
Tensor x; cin >> x; cout << x << endl; x.Write_elements(cout);
-
Assignment
-
=
e.g. Tensor x,y; cin >> x; y = x;
-
Inner and outer products
-
Where a contraction is performed over a pair of indices, the tensors
must have the same number of entries in those indices.
-
friend Tensor outer_product(const Tensor& a, const Tensor&
b)
-
friend Tensor inner_product(const Tensor& a, const int ia,
const Tensor& b, const int ib,
const Tensor& metric)
- inner product using a metric tensor to raise and lower indices as
necessary. ia and ib are the indices of a
and b respectively over which to contract.
-
Tensor contract(const int i, const int j, const Tensor& metric)
e.g.
Tensor x,y; cin >> x >> y;
General tensor class (fixed dimension)
-
Name
-
Tensor_fixed_dimension
-
Inheritance
-
tensor
A Tensor_fixed is exactly the same as a
Tensor, except
that the Read and Write methods are redefined to omit
the number of elements. (This means that the number of elements must be
set before a Tensor_fixed_dimension is read.)
This class is the base for tensors of a specific dimension.