Classes | |
class | ExcInvalidTensorIndex |
Public Types | |
typedef Tensor< rank_-1, dim > | value_type |
typedef Tensor< rank_-1, dim > ::array_type | array_type [dim] |
Public Member Functions | |
Tensor () | |
Tensor (const array_type &initializer) | |
Tensor< rank_-1, dim > & | operator[] (const unsigned int i) |
const Tensor< rank_-1, dim > & | operator[] (const unsigned int i) const |
Tensor & | operator= (const Tensor< rank_, dim > &) |
Tensor< rank_, dim > & | operator= (const double d) |
bool | operator== (const Tensor< rank_, dim > &) const |
bool | operator!= (const Tensor< rank_, dim > &) const |
Tensor< rank_, dim > & | operator+= (const Tensor< rank_, dim > &) |
Tensor< rank_, dim > & | operator-= (const Tensor< rank_, dim > &) |
Tensor< rank_, dim > & | operator*= (const double factor) |
Tensor< rank_, dim > & | operator/= (const double factor) |
Tensor< rank_, dim > | operator+ (const Tensor< rank_, dim > &) const |
Tensor< rank_, dim > | operator- (const Tensor< rank_, dim > &) const |
Tensor< rank_, dim > | operator- () const |
double | norm () const |
double | norm_square () const |
void | unroll (Vector< double > &result) const |
void | clear () |
Static Public Member Functions | |
static unsigned int | memory_consumption () |
Static Public Attributes | |
static const unsigned int | dimension = dim |
static const unsigned int | rank = rank_ |
Private Member Functions | |
void | unroll_recursion (Vector< double > &result, unsigned int &start_index) const |
Private Attributes | |
Tensor< rank_-1, dim > | subtensor [dim] |
Friends | |
class | Tensor |
Related Functions | |
(Note that these are not member functions.) | |
template<int dim> | |
double | contract (const Tensor< 1, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
double | operator* (const Tensor< 1, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
void | contract (Tensor< 1, dim > &dest, const Tensor< 2, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
Tensor< 1, dim > | operator* (const Tensor< 2, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
void | contract (Tensor< 1, dim > &dest, const Tensor< 1, dim > &src1, const Tensor< 2, dim > &src2) |
template<int dim> | |
Tensor< 1, dim > | operator* (const Tensor< 1, dim > &src1, const Tensor< 2, dim > &src2) |
template<int dim> | |
void | contract (Tensor< 2, dim > &dest, const Tensor< 2, dim > &src1, const Tensor< 2, dim > &src2) |
template<int dim> | |
Tensor< 2, dim > | operator* (const Tensor< 2, dim > &src1, const Tensor< 2, dim > &src2) |
template<int dim> | |
void | contract (Tensor< 2, dim > &dest, const Tensor< 2, dim > &src1, const unsigned int index1, const Tensor< 2, dim > &src2, const unsigned int index2) |
template<int dim> | |
void | contract (Tensor< 2, dim > &dest, const Tensor< 3, dim > &src1, const unsigned int index1, const Tensor< 1, dim > &src2) |
template<int dim> | |
double | contract3 (const Tensor< 1, dim > &u, const Tensor< 2, dim > &A, const Tensor< 1, dim > &v) |
template<int dim> | |
void | outer_product (Tensor< 2, dim > &dst, const Tensor< 1, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
void | outer_product (Tensor< 3, dim > &dst, const Tensor< 1, dim > &src1, const Tensor< 2, dim > &src2) |
template<int dim> | |
void | outer_product (Tensor< 3, dim > &dst, const Tensor< 2, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
void | outer_product (Tensor< 1, dim > &dst, const double src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
void | outer_product (Tensor< 1, dim > &dst, const Tensor< 1, dim > src1, const double src2) |
template<int dim> | |
void | cross_product (Tensor< 1, dim > &dst, const Tensor< 1, dim > &src) |
template<int dim> | |
void | cross_product (Tensor< 1, dim > &dst, const Tensor< 1, dim > &src1, const Tensor< 1, dim > &src2) |
template<int dim> | |
double | scalar_product (const Tensor< 2, dim > &t1, const Tensor< 2, dim > &t2) |
template<int dim> | |
std::ostream & | operator<< (std::ostream &out, const Tensor< 1, dim > &p) |
template<int dim> | |
Tensor< 1, dim > | operator* (const Tensor< 1, dim > &t, const double factor) |
template<int dim> | |
Tensor< 1, dim > | operator* (const double factor, const Tensor< 1, dim > &t) |
template<int dim> | |
Tensor< 1, dim > | operator/ (const Tensor< 1, dim > &t, const double factor) |
Provide a general tensor class with an arbitrary rank, i.e. with an arbitrary number of indices. The Tensor class provides an indexing operator and a bit of infrastructure, but most functionality is recursively handed down to tensors of rank 1 or put into external templated functions, e.g. the contract
family.
Using this tensor class for objects of rank 2 has advantages over matrices in many cases since the dimension is known to the compiler as well as the location of the data. It is therefore possible to produce far more efficient code than for matrices with runtime-dependent dimension.
typedef Tensor<rank_-1,dim> Tensor< rank_, dim >::value_type |
Type of stored objects. This is a tensor of lower rank.
typedef Tensor<rank_-1,dim>::array_type Tensor< rank_, dim >::array_type[dim] |
Declare an array type which can be used to initialize an object of this type statically.
Constructor. Initialize all entries to zero.
Tensor< rank_, dim >::Tensor | ( | const array_type & | initializer | ) |
Copy constructor, where the data is copied from a C-style array.
Tensor<rank_-1,dim>& Tensor< rank_, dim >::operator[] | ( | const unsigned int | i | ) |
Read-Write access operator.
const Tensor<rank_-1,dim>& Tensor< rank_, dim >::operator[] | ( | const unsigned int | i | ) | const |
Read-only access operator.
Tensor& Tensor< rank_, dim >::operator= | ( | const Tensor< rank_, dim > & | ) |
Assignment operator.
This operator assigns a scalar to a tensor. To avoid confusion with what exactly it means to assign a scalar value to a tensor, zero is the only value allowed for d
, allowing the intuitive notation t=0
to reset all elements of the tensor to zero.
bool Tensor< rank_, dim >::operator== | ( | const Tensor< rank_, dim > & | ) | const |
Test for equality of two tensors.
bool Tensor< rank_, dim >::operator!= | ( | const Tensor< rank_, dim > & | ) | const |
Test for inequality of two tensors.
Tensor<rank_,dim>& Tensor< rank_, dim >::operator+= | ( | const Tensor< rank_, dim > & | ) |
Add another tensor.
Tensor<rank_,dim>& Tensor< rank_, dim >::operator-= | ( | const Tensor< rank_, dim > & | ) |
Subtract another tensor.
Tensor<rank_,dim>& Tensor< rank_, dim >::operator*= | ( | const double | factor | ) |
Scale the tensor by factor
, i.e. multiply all components by factor
.
Tensor<rank_,dim>& Tensor< rank_, dim >::operator/= | ( | const double | factor | ) |
Scale the vector by 1/factor
.
Tensor<rank_,dim> Tensor< rank_, dim >::operator+ | ( | const Tensor< rank_, dim > & | ) | const |
Add two tensors. If possible, you should use operator +=
instead since this does not need the creation of a temporary.
Tensor<rank_,dim> Tensor< rank_, dim >::operator- | ( | const Tensor< rank_, dim > & | ) | const |
Subtract two tensors. If possible, you should use operator -=
instead since this does not need the creation of a temporary.
Unary minus operator. Negate all entries of a tensor.
Return the Frobenius-norm of a tensor, i.e. the square root of the sum of squares of all entries.
Return the square of the Frobenius-norm of a tensor, i.e. the square root of the sum of squares of all entries.
This function mainly exists because it makes computing the norm simpler recursively, but may also be useful in other contexts.
Fill a vector with all tensor elements.
This function unrolls all tensor entries into a single, linearly numbered vector. As usual in C++, the rightmost index of the tensor marches fastest.
void Tensor< rank_, dim >::clear | ( | ) |
Reset all values to zero.
Note that this is partly inconsistent with the semantics of the clear()
member functions of the STL and of several other classes within deal.II which not only reset the values of stored elements to zero, but release all memory and return the object into a virginial state. However, since the size of objects of the present type is determined by its template parameters, resizing is not an option, and indeed the state where all elements have a zero value is the state right after construction of such an object.
Referenced by Tensor< rank_, dim >::contract().
static unsigned int Tensor< rank_, dim >::memory_consumption | ( | ) | [static] |
Determine an estimate for the memory consumption (in bytes) of this object.
void Tensor< rank_, dim >::unroll_recursion | ( | Vector< double > & | result, | |
unsigned int & | start_index | |||
) | const [private] |
Help function for unroll.
friend class Tensor [friend] |
double contract | ( | const Tensor< 1, dim > & | src1, | |
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Contract a tensor of rank 1 with a tensor of rank 1. The result is sum_j src1[j] src2[j]
.
Referenced by Tensor< rank_, dim >::operator*().
double operator* | ( | const Tensor< 1, dim > & | src1, | |
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Multiplication operator performing a contraction of the last index of the first argument and the first index of the second argument. This function therefore does the same as the corresponding contract
function, but returns the result as a return value, rather than writing it into the reference given as the first argument to the contract
function.
Note that for the Tensor
class, the multiplication operator only performs a contraction over a single pair of indices. This is in contrast to the multiplication operator for symmetric tensors, which does the double contraction.
References Tensor< rank_, dim >::contract().
void contract | ( | Tensor< 1, dim > & | dest, | |
const Tensor< 2, dim > & | src1, | |||
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Contract a tensor of rank 2 with a tensor of rank 1. The result is dest[i] = sum_j src1[i][j] src2[j]
.
References Tensor< 1, dim >::clear().
Tensor< 1, dim > operator* | ( | const Tensor< 2, dim > & | src1, | |
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Multiplication operator performing a contraction of the last index of the first argument and the first index of the second argument. This function therefore does the same as the corresponding contract
function, but returns the result as a return value, rather than writing it into the reference given as the first argument to the contract
function.
Note that for the Tensor
class, the multiplication operator only performs a contraction over a single pair of indices. This is in contrast to the multiplication operator for symmetric tensors, which does the double contraction.
void contract | ( | Tensor< 1, dim > & | dest, | |
const Tensor< 1, dim > & | src1, | |||
const Tensor< 2, dim > & | src2 | |||
) | [related] |
Contract a tensor of rank 1 with a tensor of rank 2. The result is dest[i] = sum_j src1[j] src2[j][i]
.
References Tensor< 1, dim >::clear().
Tensor< 1, dim > operator* | ( | const Tensor< 1, dim > & | src1, | |
const Tensor< 2, dim > & | src2 | |||
) | [related] |
Multiplication operator performing a contraction of the last index of the first argument and the first index of the second argument. This function therefore does the same as the corresponding contract
function, but returns the result as a return value, rather than writing it into the reference given as the first argument to the contract
function.
Note that for the Tensor
class, the multiplication operator only performs a contraction over a single pair of indices. This is in contrast to the multiplication operator for symmetric tensors, which does the double contraction.
void contract | ( | Tensor< 2, dim > & | dest, | |
const Tensor< 2, dim > & | src1, | |||
const Tensor< 2, dim > & | src2 | |||
) | [related] |
Contract a tensor of rank 2 with a tensor of rank 2. The result is dest[i][k] = sum_j src1[i][j] src2[j][k]
.
Contract a tensor of rank 3 with a tensor of rank 2. The result is dest[i][j][l] = sum_k src1[i][j][k] src2[k][l]
.
Contract a tensor of rank 2 with a tensor of rank 3. The result is dest[i][j][l] = sum_k src1[i][k] src2[k][j][l]
.
References Tensor< rank_, dim >::clear().
Tensor< 4, dim > operator* | ( | const Tensor< 2, dim > & | src1, | |
const Tensor< 2, dim > & | src2 | |||
) | [related] |
Multiplication operator performing a contraction of the last index of the first argument and the first index of the second argument. This function therefore does the same as the corresponding contract
function, but returns the result as a return value, rather than writing it into the reference given as the first argument to the contract
function.
Note that for the Tensor
class, the multiplication operator only performs a contraction over a single pair of indices. This is in contrast to the multiplication operator for symmetric tensors, which does the double contraction.
Contract a tensor of rank 3 with a tensor of rank 3. The result is dest[i][j][k][l] = sum_m src1[i][j][m] src2[m][k][l]
.
void contract | ( | Tensor< 2, dim > & | dest, | |
const Tensor< 2, dim > & | src1, | |||
const unsigned int | index1, | |||
const Tensor< 2, dim > & | src2, | |||
const unsigned int | index2 | |||
) | [related] |
Contract a tensor of rank 2 with a tensor of rank 2. The contraction is performed over index index1
of the first tensor, and index2
of the second tensor. Thus, if index1==2
, index2==1
, the result is the usual contraction, but if for example index1==1
, index2==2
, then the result is dest[i][k] = sum_j src1[j][i] src2[k][j]
.
Note that the number of the index is counted from 1 on, not from zero as usual.
Contract a tensor of rank 3 with a tensor of rank 2. The contraction is performed over index index1
of the first tensor, and index2
of the second tensor. Thus, if index1==3
, index2==1
, the result is the usual contraction, but if for example index1==1
, index2==2
, then the result is dest[i][j][k] = sum_l src1[l][i][j] src2[k][l]
.
Note that the number of the index is counted from 1 on, not from zero as usual.
References Assert, and Tensor< rank_, dim >::clear().
void contract | ( | Tensor< 2, dim > & | dest, | |
const Tensor< 3, dim > & | src1, | |||
const unsigned int | index1, | |||
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Contract a tensor of rank 3 with a tensor of rank 1. The contraction is performed over index index1
of the first tensor.
Note that the number of the index is counted from 1 on, not from zero as usual.
References Assert, and Tensor< rank_, dim >::clear().
double contract3 | ( | const Tensor< 1, dim > & | u, | |
const Tensor< 2, dim > & | A, | |||
const Tensor< 1, dim > & | v | |||
) | [related] |
Contract three tensors, corresponding to the matrix vector product uT A v.
void outer_product | ( | Tensor< 2, dim > & | dst, | |
const Tensor< 1, dim > & | src1, | |||
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Form the outer product of two tensors of rank 1 and 1, i.e. dst[i][j] = src1[i] * src2[j]
.
void outer_product | ( | Tensor< 3, dim > & | dst, | |
const Tensor< 1, dim > & | src1, | |||
const Tensor< 2, dim > & | src2 | |||
) | [related] |
Form the outer product of two tensors of rank 1 and 2, i.e. dst[i][j][k] = src1[i] * src2[j][k]
.
void outer_product | ( | Tensor< 3, dim > & | dst, | |
const Tensor< 2, dim > & | src1, | |||
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Form the outer product of two tensors of rank 2 and 1, i.e. dst[i][j][k] = src1[i][j] * src2[k]
.
void outer_product | ( | Tensor< 1, dim > & | dst, | |
const double | src1, | |||
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Form the outer product of two tensors of rank 0 and 1, i.e. dst[i] = src1 * src2[i]
. Of course, this is only a scaling of src2
, but we consider this an outer product for completeness of these functions and since this is sometimes needed when writing templates that depend on the rank of a tensor, which may sometimes be zero (i.e. a scalar).
void outer_product | ( | Tensor< 1, dim > & | dst, | |
const Tensor< 1, dim > | src1, | |||
const double | src2 | |||
) | [related] |
Form the outer product of two tensors of rank 1 and 0, i.e. dst[i] = src1[i] * src2
. Of course, this is only a scaling of src1
, but we consider this an outer product for completeness of these functions and since this is sometimes needed when writing templates that depend on the rank of a tensor, which may sometimes be zero (i.e. a scalar).
void cross_product | ( | Tensor< 1, dim > & | dst, | |
const Tensor< 1, dim > & | src | |||
) | [related] |
Cross-product in 2d. This is just a rotation by 90 degrees clockwise to compute the outer normal from a tangential vector. This function is defined for all space dimensions to allow for dimension independent programming (e.g. within switches over the space dimenion), but may only be called if the actual dimension of the arguments is two (e.g. from the dim==2
case in the switch).
References Assert.
void cross_product | ( | Tensor< 1, dim > & | dst, | |
const Tensor< 1, dim > & | src1, | |||
const Tensor< 1, dim > & | src2 | |||
) | [related] |
Cross-product of 2 vectors in 3d. This function is defined for all space dimensions to allow for dimension independent programming (e.g. within switches over the space dimenion), but may only be called if the actual dimension of the arguments is three (e.g. from the dim==3
case in the switch).
References Assert.
double scalar_product | ( | const Tensor< 2, dim > & | t1, | |
const Tensor< 2, dim > & | t2 | |||
) | [related] |
Compute the scalar product between two tensors
of rank 2. We don't use
operator*
for this operation since the product between two tensors is usually assumed to be the contraction over the last index of the first tensor and the first index of the second tensor, for example .
std::ostream & operator<< | ( | std::ostream & | out, | |
const Tensor< 1, dim > & | p | |||
) | [related] |
Output operator for tensors of rank 1. Print the elements consecutively, with a space in between.
<1,dim>
Tensor< 1, dim > operator* | ( | const Tensor< 1, dim > & | t, | |
const double | factor | |||
) | [related] |
Multiplication of a tensor of rank 1 with a scalar double from the right.
<1,dim>
Tensor< 1, dim > operator* | ( | const double | factor, | |
const Tensor< 1, dim > & | t | |||
) | [related] |
Multiplication of a tensor of rank 1 with a scalar double from the left.
<1,dim>
Tensor< 1, dim > operator/ | ( | const Tensor< 1, dim > & | t, | |
const double | factor | |||
) | [related] |
Division of a tensor of rank 1 by a scalar double.
<1,dim>
Provide a way to get the dimension of an object without explicit knowledge of it's data type. Implementation is this way instead of providing a function dimension()
because now it is possible to get the dimension at compile time without the expansion and preevaluation of an inlined function; the compiler may therefore produce more efficient code and you may use this value to declare other data types.
Publish the rank of this tensor to the outside world.
Array of tensors holding the subelements.