Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | Related Functions | List of all members
Tensor< rank_, dim, Number > Singleton Reference

#include <tensor.h>

Inheritance diagram for Tensor< rank_, dim, Number >:
[legend]

Public Types

typedef Tensor< rank_-1, dim,
Number > 
value_type
 
typedef numbers::NumberTraits
< Number >::real_type 
real_type
 
typedef Tensor< rank_-1, dim,
Number >::array_type 
array_type [dim]
 

Public Member Functions

 Tensor ()
 
 Tensor (const array_type &initializer)
 
 Tensor (const Tensor< 1, dim, Tensor< rank_-1, dim, Number > > &tensor_in)
 
 operator Tensor< 1, dim, Tensor< rank_-1, dim, Number > > () const
 
Tensor< rank_-1, dim, Number > & operator[] (const unsigned int i)
 
const Tensor< rank_-1, dim,
Number > & 
operator[] (const unsigned int i) const
 
Number operator[] (const TableIndices< rank_ > &indices) const
 
Number & operator[] (const TableIndices< rank_ > &indices)
 
Tensoroperator= (const Tensor< rank_, dim, Number > &)
 
Tensor< rank_, dim, Number > & operator= (const Number d)
 
bool operator== (const Tensor< rank_, dim, Number > &) const
 
bool operator!= (const Tensor< rank_, dim, Number > &) const
 
Tensor< rank_, dim, Number > & operator+= (const Tensor< rank_, dim, Number > &)
 
Tensor< rank_, dim, Number > & operator-= (const Tensor< rank_, dim, Number > &)
 
Tensor< rank_, dim, Number > & operator*= (const Number factor)
 
Tensor< rank_, dim, Number > & operator/= (const Number factor)
 
Tensor< rank_, dim, Number > operator+ (const Tensor< rank_, dim, Number > &) const
 
Tensor< rank_, dim, Number > operator- (const Tensor< rank_, dim, Number > &) const
 
Tensor< rank_, dim, Number > operator- () const
 
real_type norm () const
 
real_type norm_square () const
 
template<typename Number2 >
void unroll (Vector< Number2 > &result) const
 
void clear ()
 
 DeclException1 (ExcInvalidTensorIndex, int,<< "Invalid tensor index "<< arg1)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Static Public Member Functions

static unsigned int component_to_unrolled_index (const TableIndices< rank_ > &indices)
 
static TableIndices< rank_ > unrolled_to_component_indices (const unsigned int i)
 
static std::size_t memory_consumption ()
 

Static Public Attributes

static const unsigned int dimension = dim
 
static const unsigned int rank = rank_
 
static const unsigned int n_independent_components = Tensor<rank_-1,dim>::n_independent_components *dim
 

Private Member Functions

template<typename Number2 >
void unroll_recursion (Vector< Number2 > &result, unsigned int &start_index) const
 

Private Attributes

Tensor< rank_-1, dim, Number > subtensor [dim]
 

Friends

template<int , int , typename >
class Tensor
 

Related Functions

(Note that these are not member functions.)

template<int rank_, int dim, typename Number >
std::ostream & operator<< (std::ostream &out, const Tensor< rank_, dim, Number > &p)
 
template<int dim, typename Number >
Number contract (const Tensor< 1, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
Number operator* (const Tensor< 1, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
Number double_contract (const Tensor< 2, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 1, dim, Number > &dest, const Tensor< 2, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
Tensor< 1, dim, Number > operator* (const Tensor< 2, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 1, dim, Number > &dest, const Tensor< 1, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
Tensor< 1, dim, Number > operator* (const Tensor< 1, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 2, dim, Number > &dest, const Tensor< 2, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
Tensor< 2, dim, Number > operator* (const Tensor< 2, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 2, dim, Number > &dest, const Tensor< 2, dim, Number > &src1, const unsigned int index1, const Tensor< 2, dim, Number > &src2, const unsigned int index2)
 
template<int dim, typename Number >
void contract (Tensor< 2, dim, Number > &dest, const Tensor< 3, dim, Number > &src1, const unsigned int index1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 3, dim, Number > &dest, const Tensor< 3, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 3, dim, Number > &dest, const Tensor< 3, dim, Number > &src1, const unsigned int index1, const Tensor< 2, dim, Number > &src2, const unsigned int index2)
 
template<int dim, typename Number >
Tensor< 3, dim, Number > operator* (const Tensor< 3, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
void contract (Tensor< 3, dim, Number > &dest, const Tensor< 2, dim, Number > &src1, const Tensor< 3, dim, Number > &src2)
 
template<int dim, typename Number >
Tensor< 3, dim, Number > operator* (const Tensor< 2, dim, Number > &src1, const Tensor< 3, dim, Number > &src2)
 
template<int dim, typename Number >
Tensor< 4, dim, Number > operator* (const Tensor< 3, dim, Number > &src1, const Tensor< 3, dim, Number > &src2)
 
template<int dim, typename Number >
void double_contract (Tensor< 2, dim, Number > &dest, const Tensor< 4, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
Number contract3 (const Tensor< 1, dim, Number > &u, const Tensor< 2, dim, Number > &A, const Tensor< 1, dim, Number > &v)
 
template<int dim, typename Number >
Number contract3 (const Tensor< 1, dim, Number > &t1, const Tensor< 3, dim, Number > &t2, const Tensor< 2, dim, Number > &t3)
 
template<int dim, typename Number >
Number contract3 (const Tensor< 2, dim, Number > &t1, const Tensor< 3, dim, Number > &t2, const Tensor< 1, dim, Number > &t3)
 
template<int dim, typename Number >
Number contract3 (const Tensor< 2, dim, Number > &t1, const Tensor< 4, dim, Number > &t2, const Tensor< 2, dim, Number > &t3)
 
template<int dim, typename Number >
void outer_product (Tensor< 2, dim, Number > &dst, const Tensor< 1, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
void outer_product (Tensor< 3, dim, Number > &dst, const Tensor< 1, dim, Number > &src1, const Tensor< 2, dim, Number > &src2)
 
template<int dim, typename Number >
void outer_product (Tensor< 3, dim, Number > &dst, const Tensor< 2, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
void outer_product (Tensor< 1, dim, Number > &dst, const Number src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
void outer_product (Tensor< 1, dim, Number > &dst, const Tensor< 1, dim, Number > src1, const Number src2)
 
template<int dim, typename Number >
void cross_product (Tensor< 1, dim, Number > &dst, const Tensor< 1, dim, Number > &src)
 
template<int dim, typename Number >
void cross_product (Tensor< 1, dim, Number > &dst, const Tensor< 1, dim, Number > &src1, const Tensor< 1, dim, Number > &src2)
 
template<int dim, typename Number >
Number scalar_product (const Tensor< 2, dim, Number > &t1, const Tensor< 2, dim, Number > &t2)
 
template<int rank, typename Number >
Number determinant (const Tensor< rank, 1, Number > &t)
 
template<typename Number >
Number determinant (const Tensor< 1, 1, Number > &t)
 
template<typename Number >
Number determinant (const Tensor< 2, 1, Number > &t)
 
template<typename Number >
Number determinant (const Tensor< 2, 2, Number > &t)
 
template<typename Number >
Number determinant (const Tensor< 2, 3, Number > &t)
 
template<int dim, typename Number >
Number determinant (const Tensor< 2, dim, Number > &t)
 
template<int dim, typename Number >
Number trace (const Tensor< 2, dim, Number > &d)
 
template<int dim, typename Number >
Tensor< 2, dim, Number > invert (const Tensor< 2, dim, Number > &t)
 
template<int dim, typename Number >
Tensor< 2, dim, Number > transpose (const Tensor< 2, dim, Number > &t)
 
template<int dim, typename Number >
double l1_norm (const Tensor< 2, dim, Number > &t)
 
template<int dim, typename Number >
double linfty_norm (const Tensor< 2, dim, Number > &t)
 
template<int rank, int dim, typename Number >
Tensor< rank, dim, Number > operator* (const Tensor< rank, dim, Number > &t, const Number factor)
 
template<int rank, int dim, typename Number >
Tensor< rank, dim, Number > operator* (const Number factor, const Tensor< rank, dim, Number > &t)
 
template<int rank, int dim, typename Number >
Tensor< rank, dim, Number > operator/ (const Tensor< rank, dim, Number > &t, const Number factor)
 
template<int rank, int dim>
Tensor< rank, dim > operator* (const Tensor< rank, dim > &t, const double factor)
 
template<int rank, int dim>
Tensor< rank, dim > operator* (const double factor, const Tensor< rank, dim > &t)
 
template<int rank, int dim>
Tensor< rank, dim > operator/ (const Tensor< rank, dim > &t, const double factor)
 
template<int dim, typename Number >
std::ostream & operator<< (std::ostream &out, const Tensor< 0, dim, Number > &p)
 
template<int dim, typename Number >
std::ostream & operator<< (std::ostream &out, const Tensor< 1, dim, Number > &p)
 
std::ostream & operator<< (std::ostream &out, const Tensor< 1, 1, double > &p)
 
template<int dim, typename Number >
Tensor< 1, dim, Number > operator* (const Tensor< 1, dim, Number > &t, const Number factor)
 
template<int dim, typename Number >
Tensor< 1, dim, Number > operator* (const Number factor, const Tensor< 1, dim, Number > &t)
 
template<int dim, typename Number >
Tensor< 1, dim, Number > operator/ (const Tensor< 1, dim, Number > &t, const Number factor)
 
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)
 

Detailed Description

template<int rank_, int dim, typename Number>
singleton Tensor< rank_, dim, Number >

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.

This class provides an optional template argument for the type of the underlying data. It defaults to double values. It can be used to base tensors on float or complex numbers or any other data type that implements basic arithmetic operations.

Author
Wolfgang Bangerth, 1998-2005

Definition at line 26 of file tensor.h.

Member Typedef Documentation

template<int rank_, int dim, typename Number>
typedef Tensor<rank_-1,dim,Number> Tensor< rank_, dim, Number >::value_type

Type of stored objects. This is a tensor of lower rank.

Definition at line 91 of file tensor.h.

template<int rank_, int dim, typename Number>
typedef numbers::NumberTraits<Number>::real_type Tensor< rank_, dim, Number >::real_type

Declare a type that has holds real-valued numbers with the same precision as the template argument to this class. For std::complex<number>, this corresponds to type number, and it is equal to Number for all other cases. See also the respective field in Vector<Number>.

This typedef is used to represent the return type of norms.

Definition at line 107 of file tensor.h.

template<int rank_, int dim, typename Number>
typedef Tensor<rank_-1,dim,Number>::array_type Tensor< rank_, dim, Number >::array_type[dim]

Declare an array type which can be used to initialize an object of this type statically.

Definition at line 115 of file tensor.h.

Constructor & Destructor Documentation

template<int rank_, int dim, typename Number>
Tensor< rank_, dim, Number >::Tensor ( )

Constructor. Initialize all entries to zero.

template<int rank_, int dim, typename Number>
Tensor< rank_, dim, Number >::Tensor ( const array_type initializer)

Copy constructor, where the data is copied from a C-style array.

template<int rank_, int dim, typename Number>
Tensor< rank_, dim, Number >::Tensor ( const Tensor< 1, dim, Tensor< rank_-1, dim, Number > > &  tensor_in)

Conversion operator from tensor of tensors.

Member Function Documentation

template<int rank_, int dim, typename Number>
Tensor< rank_, dim, Number >::operator Tensor< 1, dim, Tensor< rank_-1, dim, Number > > ( ) const

Conversion operator to tensor of tensors.

template<int rank_, int dim, typename Number>
Tensor<rank_-1,dim,Number>& Tensor< rank_, dim, Number >::operator[] ( const unsigned int  i)

Read-Write access operator.

template<int rank_, int dim, typename Number>
const Tensor<rank_-1,dim,Number>& Tensor< rank_, dim, Number >::operator[] ( const unsigned int  i) const

Read-only access operator.

template<int rank_, int dim, typename Number>
Number Tensor< rank_, dim, Number >::operator[] ( const TableIndices< rank_ > &  indices) const

Read access using TableIndices indices

template<int rank_, int dim, typename Number>
Number& Tensor< rank_, dim, Number >::operator[] ( const TableIndices< rank_ > &  indices)

Read and write access using TableIndices indices

template<int rank_, int dim, typename Number>
Tensor& Tensor< rank_, dim, Number >::operator= ( const Tensor< rank_, dim, Number > &  )

Assignment operator.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number>& Tensor< rank_, dim, Number >::operator= ( const Number  d)

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.

template<int rank_, int dim, typename Number>
bool Tensor< rank_, dim, Number >::operator== ( const Tensor< rank_, dim, Number > &  ) const

Test for equality of two tensors.

template<int rank_, int dim, typename Number>
bool Tensor< rank_, dim, Number >::operator!= ( const Tensor< rank_, dim, Number > &  ) const

Test for inequality of two tensors.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number>& Tensor< rank_, dim, Number >::operator+= ( const Tensor< rank_, dim, Number > &  )

Add another tensor.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number>& Tensor< rank_, dim, Number >::operator-= ( const Tensor< rank_, dim, Number > &  )

Subtract another tensor.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number>& Tensor< rank_, dim, Number >::operator*= ( const Number  factor)

Scale the tensor by factor, i.e. multiply all components by factor.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number>& Tensor< rank_, dim, Number >::operator/= ( const Number  factor)

Scale the vector by 1/factor.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number> Tensor< rank_, dim, Number >::operator+ ( const Tensor< rank_, dim, Number > &  ) const

Add two tensors. If possible, you should use operator += instead since this does not need the creation of a temporary.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number> Tensor< rank_, dim, Number >::operator- ( const Tensor< rank_, dim, Number > &  ) const

Subtract two tensors. If possible, you should use operator -= instead since this does not need the creation of a temporary.

template<int rank_, int dim, typename Number>
Tensor<rank_,dim,Number> Tensor< rank_, dim, Number >::operator- ( ) const

Unary minus operator. Negate all entries of a tensor.

template<int rank_, int dim, typename Number>
real_type Tensor< rank_, dim, Number >::norm ( ) const

Return the Frobenius-norm of a tensor, i.e. the square root of the sum of squares of all entries.

template<int rank_, int dim, typename Number>
real_type Tensor< rank_, dim, Number >::norm_square ( ) const

Return the square of the Frobenius-norm of a tensor, i.e. 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.

template<int rank_, int dim, typename Number>
template<typename Number2 >
void Tensor< rank_, dim, Number >::unroll ( Vector< Number2 > &  result) const

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.

template<int rank_, int dim, typename Number>
static unsigned int Tensor< rank_, dim, Number >::component_to_unrolled_index ( const TableIndices< rank_ > &  indices)
static

Returns an unrolled index in the range [0,dim^rank-1] for the element of the tensor indexed by the argument to the function.

template<int rank_, int dim, typename Number>
static TableIndices<rank_> Tensor< rank_, dim, Number >::unrolled_to_component_indices ( const unsigned int  i)
static

Opposite of component_to_unrolled_index: For an index in the range [0,dim^rank-1], return which set of indices it would correspond to.

template<int rank_, int dim, typename Number>
void Tensor< rank_, dim, Number >::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.

template<int rank_, int dim, typename Number>
static std::size_t Tensor< rank_, dim, Number >::memory_consumption ( )
static

Determine an estimate for the memory consumption (in bytes) of this object.

template<int rank_, int dim, typename Number>
Tensor< rank_, dim, Number >::DeclException1 ( ExcInvalidTensorIndex  ,
int  ,
<< "Invalid tensor index "<<  arg1 
)

Exception.

template<int rank_, int dim, typename Number>
template<class Archive >
void Tensor< rank_, dim, Number >::serialize ( Archive &  ar,
const unsigned int  version 
)

Read or write the data of this object to or from a stream for the purpose of serialization

template<int rank_, int dim, typename Number>
template<typename Number2 >
void Tensor< rank_, dim, Number >::unroll_recursion ( Vector< Number2 > &  result,
unsigned int start_index 
) const
private

Help function for unroll.

Friends And Related Function Documentation

template<int rank_, int dim, typename Number >
std::ostream & operator<< ( std::ostream &  out,
const Tensor< rank_, dim, Number > &  p 
)
related

Output operator for tensors. Print the elements consecutively, with a space in between, two spaces between rank 1 subtensors, three between rank 2 and so on.

Definition at line 724 of file tensor.h.

template<int dim, typename Number >
Number contract ( const Tensor< 1, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  src2 
)
related

Contract a tensor of rank 1 with a tensor of rank 1. The result is sum_j src1[j] src2[j].

Author
Guido Kanschat, 2000

Definition at line 759 of file tensor.h.

template<int dim, typename Number >
Number operator* ( const Tensor< 1, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  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.

Author
Wolfgang Bangerth, 2005

Definition at line 789 of file tensor.h.

template<int dim, typename Number >
Number double_contract ( const Tensor< 2, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  src2 
)
related

Double contract two tensors of rank 2, thus computing the Frobenius inner product sumi,j src1[i][j]*src2[i][j].

Author
Guido Kanschat, 2000

Definition at line 805 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 1, dim, Number > &  dest,
const Tensor< 2, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  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].

Author
Wolfgang Bangerth, 1998

Definition at line 825 of file tensor.h.

template<int dim, typename Number >
Tensor< 1, dim, Number > operator* ( const Tensor< 2, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  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.

Author
Wolfgang Bangerth, 2005

Definition at line 856 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 1, dim, Number > &  dest,
const Tensor< 1, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  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].

Author
Guido Kanschat, 2001

Definition at line 879 of file tensor.h.

template<int dim, typename Number >
Tensor< 1, dim, Number > operator* ( const Tensor< 1, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  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.

Author
Wolfgang Bangerth, 2005

Definition at line 911 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 2, dim, Number > &  dest,
const Tensor< 2, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  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].

Author
Wolfgang Bangerth, 1998

Definition at line 934 of file tensor.h.

template<int dim, typename Number >
Tensor< 2, dim, Number > operator* ( const Tensor< 2, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  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.

Author
Wolfgang Bangerth, 2005

Definition at line 968 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 2, dim, Number > &  dest,
const Tensor< 2, dim, Number > &  src1,
const unsigned int  index1,
const Tensor< 2, dim, Number > &  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.

Author
Wolfgang Bangerth, 1998

Definition at line 996 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 2, dim, Number > &  dest,
const Tensor< 3, dim, Number > &  src1,
const unsigned int  index1,
const Tensor< 1, dim, Number > &  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.

Author
Wolfgang Bangerth, 1998

Definition at line 1066 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 3, dim, Number > &  dest,
const Tensor< 3, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  src2 
)
related

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].

Author
Wolfgang Bangerth, 1998

Definition at line 1111 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 3, dim, Number > &  dest,
const Tensor< 3, dim, Number > &  src1,
const unsigned int  index1,
const Tensor< 2, dim, Number > &  src2,
const unsigned int  index2 
)
related

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.

Definition at line 1139 of file tensor.h.

template<int dim, typename Number >
Tensor< 3, dim, Number > operator* ( const Tensor< 3, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  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.

Author
Wolfgang Bangerth, 2005

Definition at line 1242 of file tensor.h.

template<int dim, typename Number >
void contract ( Tensor< 3, dim, Number > &  dest,
const Tensor< 2, dim, Number > &  src1,
const Tensor< 3, dim, Number > &  src2 
)
related

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].

Author
Wolfgang Bangerth, 1998

Definition at line 1264 of file tensor.h.

template<int dim, typename Number >
Tensor< 3, dim, Number > operator* ( const Tensor< 2, dim, Number > &  src1,
const Tensor< 3, dim, Number > &  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.

Author
Wolfgang Bangerth, 2005

Definition at line 1296 of file tensor.h.

template<int dim, typename Number >
Tensor< 4, dim, Number > operator* ( const Tensor< 3, dim, Number > &  src1,
const Tensor< 3, dim, Number > &  src2 
)
related

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].

Author
Wolfgang Bangerth, 1998

Definition at line 1319 of file tensor.h.

template<int dim, typename Number >
void double_contract ( Tensor< 2, dim, Number > &  dest,
const Tensor< 4, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  src2 
)
related

Contract the last two indices of src1 with the two indices src2, creating a rank-2 tensor. This is the matrix-vector product analog operation between tensors of rank 4 and rank 2.

Author
Wolfgang Bangerth, 2005

Definition at line 1343 of file tensor.h.

template<int dim, typename Number >
Number contract3 ( const Tensor< 1, dim, Number > &  u,
const Tensor< 2, dim, Number > &  A,
const Tensor< 1, dim, Number > &  v 
)
related

Contract three tensors, corresponding to the matrix vector product uT A v.

Author
Guido Kanschat, 2004

Definition at line 1365 of file tensor.h.

template<int dim, typename Number >
Number contract3 ( const Tensor< 1, dim, Number > &  t1,
const Tensor< 3, dim, Number > &  t2,
const Tensor< 2, dim, Number > &  t3 
)
related

Compute the contraction of three tensors $s=\sum_{i,j,k} a_{i}b_{ijk}c_{jk}$.

Author
Toby D. Young, 2011

Definition at line 1388 of file tensor.h.

template<int dim, typename Number >
Number contract3 ( const Tensor< 2, dim, Number > &  t1,
const Tensor< 3, dim, Number > &  t2,
const Tensor< 1, dim, Number > &  t3 
)
related

Compute the contraction of three tensors $s=\sum_{i,j,k} a_{ij}b_{ijk}c_{k}$.

Author
Toby D. Young, 2011

Definition at line 1411 of file tensor.h.

template<int dim, typename Number >
Number contract3 ( const Tensor< 2, dim, Number > &  t1,
const Tensor< 4, dim, Number > &  t2,
const Tensor< 2, dim, Number > &  t3 
)
related

Compute the contraction of three tensors $s=\sum_{i,j,k,l} a_{ij}b_{ijkl}c_{kl}$.

Author
Toby D. Young, 2011

Definition at line 1434 of file tensor.h.

template<int dim, typename Number >
void outer_product ( Tensor< 2, dim, Number > &  dst,
const Tensor< 1, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  src2 
)
related

Form the outer product of two tensors of rank 1 and 1, i.e. dst[i][j] = src1[i] * src2[j].

Author
Wolfgang Bangerth, 2000

Definition at line 1456 of file tensor.h.

template<int dim, typename Number >
void outer_product ( Tensor< 3, dim, Number > &  dst,
const Tensor< 1, dim, Number > &  src1,
const Tensor< 2, dim, Number > &  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].

Author
Wolfgang Bangerth, 2000

Definition at line 1474 of file tensor.h.

template<int dim, typename Number >
void outer_product ( Tensor< 3, dim, Number > &  dst,
const Tensor< 2, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  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].

Author
Wolfgang Bangerth, 2000

Definition at line 1493 of file tensor.h.

template<int dim, typename Number >
void outer_product ( Tensor< 1, dim, Number > &  dst,
const Number  src1,
const Tensor< 1, dim, Number > &  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).

Author
Wolfgang Bangerth, 2000

Definition at line 1516 of file tensor.h.

template<int dim, typename Number >
void outer_product ( Tensor< 1, dim, Number > &  dst,
const Tensor< 1, dim, Number >  src1,
const Number  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).

Author
Wolfgang Bangerth, 2000

Definition at line 1538 of file tensor.h.

template<int dim, typename Number >
void cross_product ( Tensor< 1, dim, Number > &  dst,
const Tensor< 1, dim, Number > &  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).

Author
Guido Kanschat, 2001

Definition at line 1562 of file tensor.h.

template<int dim, typename Number >
void cross_product ( Tensor< 1, dim, Number > &  dst,
const Tensor< 1, dim, Number > &  src1,
const Tensor< 1, dim, Number > &  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).

Author
Guido Kanschat, 2001

Definition at line 1585 of file tensor.h.

template<int dim, typename Number >
Number scalar_product ( const Tensor< 2, dim, Number > &  t1,
const Tensor< 2, dim, Number > &  t2 
)
related

Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two tensors $a,b$ 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 $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$.

Author
Wolfgang Bangerth, 2008

Definition at line 1610 of file tensor.h.

template<int rank, typename Number >
Number determinant ( const Tensor< rank, 1, Number > &  t)
related

Compute the determinant of a tensor of arbitrary rank and dimension one. Since this is a number, the return value is, of course, the number itself.

Author
Wolfgang Bangerth, 1998

Definition at line 1631 of file tensor.h.

template<typename Number >
Number determinant ( const Tensor< 1, 1, Number > &  t)
related

Compute the determinant of a tensor of rank one and dimension one. Since this is a number, the return value is, of course, the number itself.

Author
Wolfgang Bangerth, 1998

Definition at line 1648 of file tensor.h.

template<typename Number >
Number determinant ( const Tensor< 2, 1, Number > &  t)
related

Compute the determinant of a tensor of rank two and dimension one. Since this is a number, the return value is, of course, the number itself.

Author
Wolfgang Bangerth, 1998

Definition at line 1664 of file tensor.h.

template<typename Number >
Number determinant ( const Tensor< 2, 2, Number > &  t)
related

Compute the determinant of a tensor or rank 2, here for dim==2.

Author
Wolfgang Bangerth, 1998

Definition at line 1679 of file tensor.h.

template<typename Number >
Number determinant ( const Tensor< 2, 3, Number > &  t)
related

Compute the determinant of a tensor or rank 2, here for dim==3.

Author
Wolfgang Bangerth, 1998

Definition at line 1693 of file tensor.h.

template<int dim, typename Number >
Number determinant ( const Tensor< 2, dim, Number > &  t)
related

Compute the determinant of a tensor or rank 2, here for all dimensions for which no explicit specialization is available above.

Author
Wolfgang Bangerth, 2009

Definition at line 1721 of file tensor.h.

template<int dim, typename Number >
Number trace ( const Tensor< 2, dim, Number > &  d)
related

Compute and return the trace of a tensor of rank 2, i.e. the sum of its diagonal entries.

Author
Wolfgang Bangerth, 2001

Definition at line 1759 of file tensor.h.

template<int dim, typename Number >
Tensor< 2, dim, Number > invert ( const Tensor< 2, dim, Number > &  t)
related

Compute and return the inverse of the given tensor. Since the compiler can perform the return value optimization, and since the size of the return object is known, it is acceptable to return the result by value, rather than by reference as a parameter.

Author
Wolfgang Bangerth, 2000

Definition at line 1781 of file tensor.h.

template<int dim, typename Number >
Tensor< 2, dim, Number > transpose ( const Tensor< 2, dim, Number > &  t)
related

Return the transpose of the given tensor. Since the compiler can perform the return value optimization, and since the size of the return object is known, it is acceptable to return the result by value, rather than by reference as a parameter. Note that there are specializations of this function for dim==1,2,3.

Author
Wolfgang Bangerth, 2002

Definition at line 1851 of file tensor.h.

template<int dim, typename Number >
double l1_norm ( const Tensor< 2, dim, Number > &  t)
related

Return the $l_1$ norm of the given rank-2 tensor, where $||t||_1 = \max_j \sum_i |t_{ij}|$ (maximum of the sums over columns).

Author
Wolfgang Bangerth, 2012

Definition at line 1938 of file tensor.h.

template<int dim, typename Number >
double linfty_norm ( const Tensor< 2, dim, Number > &  t)
related

Return the $l_\infty$ norm of the given rank-2 tensor, where $||t||_\infty = \max_i \sum_j |t_{ij}|$ (maximum of the sums over rows).

Author
Wolfgang Bangerth, 2012

Definition at line 1967 of file tensor.h.

template<int rank, int dim, typename Number >
Tensor< rank, dim, Number > operator* ( const Tensor< rank, dim, Number > &  t,
const Number  factor 
)
related

Multiplication of a tensor of general rank with a scalar Number from the right.

Definition at line 1994 of file tensor.h.

template<int rank, int dim, typename Number >
Tensor< rank, dim, Number > operator* ( const Number  factor,
const Tensor< rank, dim, Number > &  t 
)
related

Multiplication of a tensor of general rank with a scalar Number from the left.

Definition at line 2013 of file tensor.h.

template<int rank, int dim, typename Number >
Tensor< rank, dim, Number > operator/ ( const Tensor< rank, dim, Number > &  t,
const Number  factor 
)
related

Division of a tensor of general rank by a scalar Number.

Definition at line 2031 of file tensor.h.

template<int rank, int dim>
Tensor< rank, dim > operator* ( const Tensor< rank, dim > &  t,
const double  factor 
)
related

Multiplication of a tensor of general rank with a scalar double from the right.

Definition at line 2051 of file tensor.h.

template<int rank, int dim>
Tensor< rank, dim > operator* ( const double  factor,
const Tensor< rank, dim > &  t 
)
related

Multiplication of a tensor of general rank with a scalar double from the left.

Definition at line 2070 of file tensor.h.

template<int rank, int dim>
Tensor< rank, dim > operator/ ( const Tensor< rank, dim > &  t,
const double  factor 
)
related

Division of a tensor of general rank by a scalar double.

Definition at line 2088 of file tensor.h.

template<int dim, typename Number >
std::ostream & operator<< ( std::ostream &  out,
const Tensor< 0, dim, Number > &  p 
)
related

Output operator for tensors of rank 0. Since such tensors are scalars, we simply print this one value.

<0,dim,Number>

Definition at line 1309 of file tensor_base.h.

template<int dim, typename Number >
std::ostream & operator<< ( std::ostream &  out,
const Tensor< 1, dim, Number > &  p 
)
related

Output operator for tensors of rank 1. Print the elements consecutively, with a space in between.

<1,dim,Number>

Definition at line 1325 of file tensor_base.h.

template<int rank_, int dim, typename Number>
std::ostream & operator<< ( std::ostream &  out,
const Tensor< 1, 1, double > &  p 
)
related

Output operator for tensors of rank 1 and dimension 1. This is implemented specialized from the general template in order to avoid a compiler warning that the loop is empty.

<1,dim,Number>

Definition at line 1344 of file tensor_base.h.

template<int dim, typename Number >
Tensor< 1, dim, Number > operator* ( const Tensor< 1, dim, Number > &  t,
const Number  factor 
)
related

Multiplication of a tensor of rank 1 with a scalar Number from the right.

<1,dim,Number>

Definition at line 1361 of file tensor_base.h.

template<int dim, typename Number >
Tensor< 1, dim, Number > operator* ( const Number  factor,
const Tensor< 1, dim, Number > &  t 
)
related

Multiplication of a tensor of rank 1 with a scalar Number from the left.

<1,dim,Number>

Definition at line 1380 of file tensor_base.h.

template<int dim, typename Number >
Tensor< 1, dim, Number > operator/ ( const Tensor< 1, dim, Number > &  t,
const Number  factor 
)
related

Division of a tensor of rank 1 by a scalar Number.

<1,dim,Number>

Definition at line 1399 of file tensor_base.h.

template<int 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,Number>

Definition at line 1418 of file tensor_base.h.

template<int 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,Number>

Definition at line 1437 of file tensor_base.h.

template<int 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,Number>

Definition at line 1456 of file tensor_base.h.

Member Data Documentation

template<int rank_, int dim, typename Number>
const unsigned int Tensor< rank_, dim, Number >::dimension = dim
static

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.

Definition at line 71 of file tensor.h.

template<int rank_, int dim, typename Number>
const unsigned int Tensor< rank_, dim, Number >::rank = rank_
static

Publish the rank of this tensor to the outside world.

Definition at line 77 of file tensor.h.

template<int rank_, int dim, typename Number>
const unsigned int Tensor< rank_, dim, Number >::n_independent_components = Tensor<rank_-1,dim>::n_independent_components *dim
static

Number of independent components of a tensor of current rank. This is dim times the number of independent components of each sub-tensor.

Definition at line 85 of file tensor.h.

template<int rank_, int dim, typename Number>
Tensor<rank_-1,dim,Number> Tensor< rank_, dim, Number >::subtensor[dim]
private

Array of tensors holding the subelements.

Definition at line 333 of file tensor.h.


The documentation for this singleton was generated from the following files: