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

#include <tensor_base.h>

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

Public Types

typedef Number value_type
 
typedef numbers::NumberTraits
< Number >::real_type 
real_type
 
typedef Number array_type [(dim!=0)?dim:100000000]
 

Public Member Functions

 Tensor (const bool initialize=true)
 
 Tensor (const array_type &initializer)
 
 Tensor (const Tensor< 1, dim, Number > &)
 
Number operator[] (const unsigned int index) const
 
Number & operator[] (const unsigned int index)
 
Number operator[] (const TableIndices< 1 > &indices) const
 
Number & operator[] (const TableIndices< 1 > &indices)
 
Tensor< 1, dim, Number > & operator= (const Tensor< 1, dim, Number > &)
 
Tensor< 1, dim, Number > & operator= (const Number d)
 
bool operator== (const Tensor< 1, dim, Number > &) const
 
bool operator!= (const Tensor< 1, dim, Number > &) const
 
Tensor< 1, dim, Number > & operator+= (const Tensor< 1, dim, Number > &)
 
Tensor< 1, dim, Number > & operator-= (const Tensor< 1, dim, Number > &)
 
Tensor< 1, dim, Number > & operator*= (const Number factor)
 
Tensor< 1, dim, Number > & operator/= (const Number factor)
 
Number operator* (const Tensor< 1, dim, Number > &) const
 
Tensor< 1, dim, Number > operator+ (const Tensor< 1, dim, Number > &) const
 
Tensor< 1, dim, Number > operator- (const Tensor< 1, dim, Number > &) const
 
Tensor< 1, dim, Number > operator- () const
 
real_type norm () const
 
real_type norm_square () const
 
void clear ()
 
template<typename Number2 >
void unroll (Vector< Number2 > &result) const
 
 DeclException1 (ExcDimTooSmall, int,<< "dim must be positive, but was "<< 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< 1 > &indices)
 
static TableIndices< 1 > 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 = 1
 
static const unsigned int n_independent_components = dim
 

Private Member Functions

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

Private Attributes

Number values [(dim!=0)?(dim):(dim+1)]
 

Friends

template<int otherrank, int otherdim, typename OtherNumber >
class ::Tensor
 
class Point< dim, Number >
 

Detailed Description

template<int dim, typename Number>
class Tensor< 1, dim, Number >

This class is a specialized version of the Tensor<rank,dim,Number> class. It handles tensors with one index, i.e. vectors, of fixed dimension and provides the basis for the functionality needed for tensors of higher rank.

Within deal.II, the distinction between this class and its derived class Point is that we use the Point class mainly to denote the points that make up geometric objects. As such, they have a small number of additional operations over general tensors of rank 1 for which we use the Tensor<1,dim,Number> class. In particular, there is a distance() function to compute the Euclidian distance between two points in space.

However, the Point class is really only used where the coordinates of an object can be thought to possess the dimension of a length. For all other uses, such as the gradient of a scalar function (which is a tensor of rank 1, or vector, with as many elements as a point object, but with different physical units), we use the Tensor<1,dim,Number> class.

Author
Wolfgang Bangerth, 1998-2005

Definition at line 329 of file tensor_base.h.

Member Typedef Documentation

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

Type of stored objects. This is a Number for a rank 1 tensor.

Definition at line 369 of file tensor_base.h.

template<int dim, typename Number >
typedef numbers::NumberTraits<Number>::real_type Tensor< 1, 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 385 of file tensor_base.h.

template<int dim, typename Number >
typedef Number Tensor< 1, dim, Number >::array_type[(dim!=0)?dim:100000000]

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

Avoid warning about zero-sized array for dim==0 by choosing lunatic value that is likely to overflow memory limits.

Definition at line 398 of file tensor_base.h.

Constructor & Destructor Documentation

template<int dim, typename Number >
Tensor< 1, dim, Number >::Tensor ( const bool  initialize = true)
explicit

Constructor. Initialize all entries to zero if initialize==true; this is the default behaviour.

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

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

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

Copy constructor.

Member Function Documentation

template<int dim, typename Number >
Number Tensor< 1, dim, Number >::operator[] ( const unsigned int  index) const

Read access to the indexth coordinate.

Note that the derived Point class also provides access through the () operator for backcompatibility.

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

Read and write access to the indexth coordinate.

Note that the derived Point class also provides access through the () operator for backcompatibility.

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

Read access using TableIndices indices

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

Read and write access using TableIndices indices

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

Assignment operator.

template<int dim, typename Number >
Tensor<1,dim,Number>& Tensor< 1, 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 dim, typename Number >
bool Tensor< 1, dim, Number >::operator== ( const Tensor< 1, dim, Number > &  ) const

Test for equality of two tensors.

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

Test for inequality of two tensors.

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

Add another vector, i.e. move this point by the given offset.

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

Subtract another vector.

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

Scale the vector by factor, i.e. multiply all coordinates by factor.

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

Scale the vector by 1/factor.

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

Returns the scalar product of two vectors.

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

Add two tensors. If possible, use operator += instead since this does not need to copy a point at least once.

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

Subtract two tensors. If possible, use operator += instead since this does not need to copy a point at least once.

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

Tensor with inverted entries.

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

Return the Frobenius-norm of a tensor, i.e. the square root of the sum of squares of all entries. For the present case of rank-1 tensors, this equals the usual l2 norm of the vector.

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

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.

template<int dim, typename Number >
void Tensor< 1, 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 dim, typename Number >
template<typename Number2 >
void Tensor< 1, 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 marches fastest.

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

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

Given that this is a rank-1 object, the returned value is simply the value of the only index stored by the argument.

template<int dim, typename Number >
static TableIndices<1> Tensor< 1, 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-1], return which set of indices it would correspond to.

Given that this is a rank-1 object, the returned set of indices consists of only a single element with value equal to the argument to this function.

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

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

template<int dim, typename Number >
template<class Archive >
void Tensor< 1, 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 dim, typename Number >
template<typename Number2 >
void Tensor< 1, dim, Number >::unroll_recursion ( Vector< Number2 > &  result,
unsigned int start_index 
) const
private

Help function for unroll. If we have detected an access control bug in the compiler, this function is declared public, otherwise private. Do not attempt to use this function from outside in any case, even if it should be public for your compiler.

Friends And Related Function Documentation

template<int dim, typename Number >
template<int otherrank, int otherdim, typename OtherNumber >
friend class ::Tensor
friend

Make the following classes friends to this class. In principle, it would suffice if otherrank==2, but that is not possible in C++ at present.

Also, it would be sufficient to make the function unroll_loops a friend, but that seems to be impossible as well.

Definition at line 689 of file tensor_base.h.

template<int dim, typename Number >
friend class Point< dim, Number >
friend

Point is allowed access to the coordinates. This is supposed to improve speed.

Definition at line 696 of file tensor_base.h.

Member Data Documentation

template<int dim, typename Number >
const unsigned int Tensor< 1, 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 349 of file tensor_base.h.

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

Publish the rank of this tensor to the outside world.

Definition at line 355 of file tensor_base.h.

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

Number of independent components of a tensor of rank 1.

Definition at line 362 of file tensor_base.h.

template<int dim, typename Number >
Number Tensor< 1, dim, Number >::values[(dim!=0)?(dim):(dim+1)]
private

Store the values in a simple array. For dim==0 store one element, because otherways the compiler would choke. We catch this case in the constructor to disallow the creation of such an object.

Definition at line 658 of file tensor_base.h.


The documentation for this class was generated from the following file: