Tensor< 1, dim > Class Template Reference
[Geometric and other primitives]

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

List of all members.

Classes

class  ExcDimTooSmall

Public Types

typedef double value_type
typedef double array_type [(dim!=0)?dim:100000000]

Public Member Functions

 Tensor (const bool initialize=true)
 Tensor (const array_type &initializer)
 Tensor (const Tensor< 1, dim > &)
double operator[] (const unsigned int index) const
doubleoperator[] (const unsigned int index)
Tensor< 1, dim > & operator= (const Tensor< 1, dim > &)
Tensor< 1, dim > & operator= (const double d)
bool operator== (const Tensor< 1, dim > &) const
bool operator!= (const Tensor< 1, dim > &) const
Tensor< 1, dim > & operator+= (const Tensor< 1, dim > &)
Tensor< 1, dim > & operator-= (const Tensor< 1, dim > &)
Tensor< 1, dim > & operator*= (const double factor)
Tensor< 1, dim > & operator/= (const double factor)
double operator* (const Tensor< 1, dim > &) const
Tensor< 1, dim > operator+ (const Tensor< 1, dim > &) const
Tensor< 1, dim > operator- (const Tensor< 1, dim > &) const
Tensor< 1, dim > operator- () const
double norm () const
double norm_square () const
void clear ()
void unroll (Vector< double > &result) const

Static Public Member Functions

static unsigned int memory_consumption ()

Static Public Attributes

static const unsigned int dimension = dim
static const unsigned int rank = 1

Private Member Functions

void unroll_recursion (Vector< double > &result, unsigned int &start_index) const

Private Attributes

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

Friends

class ::Tensor
class Point< dim >

Detailed Description

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

This class is a specialized version of the Tensor<rank,dim> 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> 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> class.

Author:
Wolfgang Bangerth, 1998-2005

Member Typedef Documentation

template<int dim>
typedef double Tensor< 1, dim >::value_type

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

template<int dim>
typedef double Tensor< 1, dim >::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.


Constructor & Destructor Documentation

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

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

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

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

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

Copy constructor.


Member Function Documentation

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

Assignment operator.

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

Test for equality of two tensors.

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

Test for inequality of two tensors.

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

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

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

Subtract another vector.

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

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

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

Scale the vector by 1/factor.

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

Returns the scalar product of two vectors.

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

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

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

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

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

Tensor with inverted entries.

Reimplemented in Point< dim >, Point< N >, Point< 2 >, and Point< spacedim >.

template<int dim>
double Tensor< 1, dim >::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>
double Tensor< 1, dim >::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>
void Tensor< 1, 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().

template<int dim>
void Tensor< 1, dim >::unroll ( Vector< double > &  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>
static unsigned int Tensor< 1, dim >::memory_consumption (  )  [static]

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

template<int dim>
void Tensor< 1, dim >::unroll_recursion ( Vector< double > &  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>
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.

template<int dim>
friend class Point< dim > [friend]

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


Member Data Documentation

template<int dim>
const unsigned int Tensor< 1, dim >::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.

template<int dim>
const unsigned int Tensor< 1, dim >::rank = 1 [static]

Publish the rank of this tensor to the outside world.

template<int dim>
double Tensor< 1, dim >::values[(dim!=0)?(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.


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

deal.II documentation generated on Mon Nov 23 22:58:13 2009 by doxygen 1.6.1