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 Attributes | Private Attributes | List of all members
Tensor< 0, dim, Number > Class Template Reference

#include <tensor_base.h>

Public Types

typedef Number value_type
 
typedef numbers::NumberTraits
< Number >::real_type 
real_type
 

Public Member Functions

 Tensor ()
 
 Tensor (const value_type &initializer)
 
 Tensor (const Tensor< 0, dim, Number > &)
 
 operator Number () const
 
 operator Number & ()
 
Tensor< 0, dim, Number > & operator= (const Tensor< 0, dim, Number > &)
 
Tensor< 0, dim, Number > & operator= (const Number d)
 
bool operator== (const Tensor< 0, dim, Number > &) const
 
bool operator!= (const Tensor< 0, dim, Number > &) const
 
Tensor< 0, dim, Number > & operator+= (const Tensor< 0, dim, Number > &)
 
Tensor< 0, dim, Number > & operator-= (const Tensor< 0, dim, Number > &)
 
Tensor< 0, dim, Number > & operator*= (const Number factor)
 
Tensor< 0, dim, Number > & operator/= (const Number factor)
 
Number operator* (const Tensor< 0, dim, Number > &) const
 
Tensor< 0, dim, Number > operator+ (const Tensor< 0, dim, Number > &) const
 
Tensor< 0, dim, Number > operator- (const Tensor< 0, dim, Number > &) const
 
Tensor< 0, dim, Number > operator- () const
 
real_type norm () const
 
real_type norm_square () const
 
void clear ()
 
 DeclException1 (ExcDimTooSmall, int,<< "dim must be positive, but was "<< arg1)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Static Public Attributes

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

Private Attributes

Number value
 

Detailed Description

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

This class is a specialized version of the Tensor<rank,dim,Number> class. It handles tensors of rank zero, i.e. scalars. The second template argument is ignored.

This class exists because in some cases we want to construct objects of type Tensor<spacedim-dim,dim,Number>, which should expand to scalars, vectors, matrices, etc, depending on the values of the template arguments dim and spacedim. We therefore need a class that acts as a scalar (i.e. Number) for all purposes but is part of the Tensor template family.

Author
Wolfgang Bangerth, 2009

Definition at line 70 of file tensor_base.h.

Member Typedef Documentation

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

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

Definition at line 103 of file tensor_base.h.

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

Constructor & Destructor Documentation

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

Constructor. Set to zero.

template<int dim, typename Number >
Tensor< 0, dim, Number >::Tensor ( const value_type initializer)

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

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

Copy constructor.

Member Function Documentation

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

Conversion to Number. Since rank-0 tensors are scalars, this is a natural operation.

template<int dim, typename Number >
Tensor< 0, dim, Number >::operator Number & ( )

Conversion to Number. Since rank-0 tensors are scalars, this is a natural operation.

This is the non-const conversion operator that returns a writable reference.

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

Assignment operator.

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

Assignment operator.

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

Test for equality of two tensors.

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

Test for inequality of two tensors.

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

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

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

Subtract another vector.

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

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

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

Scale the vector by 1/factor.

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

Returns the scalar product of two vectors.

template<int dim, typename Number >
Tensor<0,dim,Number> Tensor< 0, dim, Number >::operator+ ( const Tensor< 0, 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<0,dim,Number> Tensor< 0, dim, Number >::operator- ( const Tensor< 0, 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<0,dim,Number> Tensor< 0, dim, Number >::operator- ( ) const

Tensor with inverted entries.

template<int dim, typename Number >
real_type Tensor< 0, 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< 0, 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< 0, 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<class Archive >
void Tensor< 0, 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

Member Data Documentation

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

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

Publish the rank of this tensor to the outside world.

Definition at line 96 of file tensor_base.h.

template<int dim, typename Number >
Number Tensor< 0, dim, Number >::value
private

The value of this scalar object.

Definition at line 301 of file tensor_base.h.


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