libMesh
Public Types | Public Member Functions | Public Attributes | Static Private Member Functions | Friends | List of all members
libMesh::TypeNTensor< N, T > Class Template Reference

This class will eventually define a rank-N tensor in LIBMESH_DIM dimensional space of type T. More...

#include <tensor_tools.h>

Public Types

typedef tuple_of< N, unsigned int > index_type
 Helper typedef for generic index programming. More...
 

Public Member Functions

 TypeNTensor ()
 
 TypeNTensor (const T &)
 
 TypeNTensor (const TypeVector< T > &)
 
 TypeNTensor (const TypeTensor< T > &)
 
 operator TypeVector< T > () const
 
 operator VectorValue< T > () const
 
 operator TypeTensor< T > () const
 
 operator TensorValue< T > () const
 
 ~TypeNTensor ()
 Destructor. More...
 
const TypeNTensor< N-1, T > slice (const unsigned int) const
 
TypeNTensor< N-1, T > slice (const unsigned int)
 
template<typename T2 >
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator+ (const TypeNTensor< N, T2 > &) const
 Add two tensors. More...
 
template<typename T2 >
const TypeNTensor< N, T > & operator+= (const TypeNTensor< N, T2 > &)
 Add to this tensor. More...
 
template<typename T2 >
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator- (const TypeNTensor< N, T2 > &) const
 Subtract two tensors. More...
 
template<typename T2 >
const TypeNTensor< N, T > & operator-= (const TypeNTensor< N, T2 > &)
 Subtract from this tensor. More...
 
TypeNTensor< N, T > operator- () const
 
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator* (const Scalar) const
 Multiply every entry of a tensor by a number. More...
 
template<typename Scalar >
const TypeNTensor< N, T > & operator*= (const Scalar)
 Multiply every entry of this tensor by a number. More...
 
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator/ (const Scalar) const
 Divide every entry of a tensor by a number. More...
 
const TypeNTensor< N, T > & operator/= (const T)
 Divide every entry of this tensor by a number. More...
 
template<typename T2 >
CompareTypes< T, T2 >::supertype contract (const TypeNTensor< N, T2 > &) const
 Multiply 2 tensors together to return a scalar, i.e. More...
 
Real size_sq () const
 
Real norm_sq () const
 
bool operator== (const TypeNTensor< N, T > &) const
 
bool operator< (const TypeNTensor< N, T > &) const
 
bool operator> (const TypeNTensor< N, T > &) const
 
void print (std::ostream &) const
 Do a formatted print of this tensor to a stream which defaults to libMesh::out. More...
 
template<typename T2 >
void add_scaled (const TypeNTensor< N, T2 > &, const T &)
 Add a scaled type N tensor to this type N tensor without creating a temporary. More...
 

Public Attributes

std::vector< T > _coords
 The coordinates of the TypeNTensor. More...
 

Static Private Member Functions

static constexpr int int_pow (int b, int e)
 

Friends

std::ostream & operator<< (std::ostream &os, const TypeNTensor< N, T > &t)
 Does a formatted print (as above) but supports the syntax: More...
 

Detailed Description

template<unsigned int N, typename T>
class libMesh::TypeNTensor< N, T >

This class will eventually define a rank-N tensor in LIBMESH_DIM dimensional space of type T.

Right now it defines a shim to allow for rank-independent code to compile (but not give correct results) in the case of vector-valued elements and second derivatives.

Author
Roy Stogner
Date
2012

Definition at line 34 of file tensor_tools.h.

Member Typedef Documentation

◆ index_type

template<unsigned int N, typename T>
typedef tuple_of<N, unsigned int> libMesh::TypeNTensor< N, T >::index_type

Helper typedef for generic index programming.

Definition at line 54 of file type_n_tensor.h.

Constructor & Destructor Documentation

◆ TypeNTensor() [1/4]

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::TypeNTensor ( )

Definition at line 56 of file type_n_tensor.h.

56 : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
static constexpr int int_pow(int b, int e)
std::vector< T > _coords
The coordinates of the TypeNTensor.

◆ TypeNTensor() [2/4]

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::TypeNTensor ( const T &  )

Definition at line 58 of file type_n_tensor.h.

58 : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
static constexpr int int_pow(int b, int e)
std::vector< T > _coords
The coordinates of the TypeNTensor.

◆ TypeNTensor() [3/4]

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::TypeNTensor ( const TypeVector< T > &  )

Definition at line 60 of file type_n_tensor.h.

60 : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
static constexpr int int_pow(int b, int e)
std::vector< T > _coords
The coordinates of the TypeNTensor.

◆ TypeNTensor() [4/4]

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::TypeNTensor ( const TypeTensor< T > &  )

Definition at line 62 of file type_n_tensor.h.

62 : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
static constexpr int int_pow(int b, int e)
std::vector< T > _coords
The coordinates of the TypeNTensor.

◆ ~TypeNTensor()

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::~TypeNTensor ( )

Destructor.

Definition at line 73 of file type_n_tensor.h.

73 {}

Member Function Documentation

◆ add_scaled()

template<unsigned int N, typename T >
template<typename T2 >
void libMesh::TypeNTensor< N, T >::add_scaled ( const TypeNTensor< N, T2 > &  p,
const T &  factor 
)

Add a scaled type N tensor to this type N tensor without creating a temporary.

Definition at line 243 of file type_n_tensor.h.

244 {
245  unsigned int size = int_pow(LIBMESH_DIM, N);
246  for (unsigned int i = 0; i < size ; i++)
247  _coords[i] += factor*p._coords[i];
248 }
static constexpr int int_pow(int b, int e)
std::vector< T > _coords
The coordinates of the TypeNTensor.

◆ contract()

template<unsigned int N, typename T>
template<typename T2 >
CompareTypes<T,T2>::supertype libMesh::TypeNTensor< N, T >::contract ( const TypeNTensor< N, T2 > &  ) const

Multiply 2 tensors together to return a scalar, i.e.

$ \sum_{ij} A_{ij} B_{ij} $ The tensors may contain different numeric types. Also known as the "double inner product" or "double dot product" of tensors.

Returns
The scalar-valued result, this tensor is unchanged.

Definition at line 164 of file type_n_tensor.h.

Referenced by libMesh::TensorTools::inner_product().

164 { return 0; }

◆ int_pow()

template<unsigned int N, typename T>
static constexpr int libMesh::TypeNTensor< N, T >::int_pow ( int  b,
int  e 
)
staticprivate

Definition at line 233 of file type_n_tensor.h.

234  {
235  return (e == 0) ? 1 : b * int_pow(b, e - 1);
236  }
static constexpr int int_pow(int b, int e)

◆ norm_sq()

template<unsigned int N, typename T>
Real libMesh::TypeNTensor< N, T >::norm_sq ( ) const
Returns
The Frobenius norm of the tensor squared, i.e. the sum of the entry magnitudes squared.

Definition at line 180 of file type_n_tensor.h.

180 { return 0.;}

◆ operator TensorValue< T >()

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::operator TensorValue< T > ( ) const

Definition at line 68 of file type_n_tensor.h.

68 { libmesh_not_implemented(); return 0; }

◆ operator TypeTensor< T >()

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::operator TypeTensor< T > ( ) const

Definition at line 67 of file type_n_tensor.h.

67 { libmesh_not_implemented(); return 0; }

◆ operator TypeVector< T >()

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::operator TypeVector< T > ( ) const

Definition at line 64 of file type_n_tensor.h.

64 { libmesh_not_implemented(); return 0; }

◆ operator VectorValue< T >()

template<unsigned int N, typename T>
libMesh::TypeNTensor< N, T >::operator VectorValue< T > ( ) const

Definition at line 65 of file type_n_tensor.h.

65 { libmesh_not_implemented(); return 0; }

◆ operator*()

template<unsigned int N, typename T>
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits<Scalar>::value, TypeNTensor<N,typename CompareTypes<T, Scalar>::supertype> >::type libMesh::TypeNTensor< N, T >::operator* ( const Scalar  ) const

Multiply every entry of a tensor by a number.

Definition at line 130 of file type_n_tensor.h.

131  { return TypeNTensor<N,typename CompareTypes<T, Scalar>::supertype>(); }

◆ operator*=()

template<unsigned int N, typename T>
template<typename Scalar >
const TypeNTensor<N,T>& libMesh::TypeNTensor< N, T >::operator*= ( const Scalar  )

Multiply every entry of this tensor by a number.

Definition at line 137 of file type_n_tensor.h.

137 { return *this; }

◆ operator+()

template<unsigned int N, typename T>
template<typename T2 >
TypeNTensor<N,typename CompareTypes<T, T2>::supertype> libMesh::TypeNTensor< N, T >::operator+ ( const TypeNTensor< N, T2 > &  ) const

Add two tensors.

Definition at line 92 of file type_n_tensor.h.

93  { return TypeNTensor<N,typename CompareTypes<T,T2>::supertype>(); }

◆ operator+=()

template<unsigned int N, typename T>
template<typename T2 >
const TypeNTensor<N,T>& libMesh::TypeNTensor< N, T >::operator+= ( const TypeNTensor< N, T2 > &  )

Add to this tensor.

Definition at line 99 of file type_n_tensor.h.

100  { return *this; }

◆ operator-() [1/2]

template<unsigned int N, typename T>
template<typename T2 >
TypeNTensor<N,typename CompareTypes<T, T2>::supertype> libMesh::TypeNTensor< N, T >::operator- ( const TypeNTensor< N, T2 > &  ) const

Subtract two tensors.

Definition at line 107 of file type_n_tensor.h.

108  { return TypeNTensor<N,typename CompareTypes<T,T2>::supertype>(); }

◆ operator-() [2/2]

template<unsigned int N, typename T>
TypeNTensor<N,T> libMesh::TypeNTensor< N, T >::operator- ( ) const
Returns
The negative of a tensor.

Definition at line 120 of file type_n_tensor.h.

121  { return *this; }

◆ operator-=()

template<unsigned int N, typename T>
template<typename T2 >
const TypeNTensor<N,T>& libMesh::TypeNTensor< N, T >::operator-= ( const TypeNTensor< N, T2 > &  )

Subtract from this tensor.

Definition at line 114 of file type_n_tensor.h.

115  { return *this; }

◆ operator/()

template<unsigned int N, typename T>
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits<Scalar>::value, TypeNTensor<N,typename CompareTypes<T, Scalar>::supertype> >::type libMesh::TypeNTensor< N, T >::operator/ ( const Scalar  ) const

Divide every entry of a tensor by a number.

Definition at line 146 of file type_n_tensor.h.

146 { return *this; }

◆ operator/=()

template<unsigned int N, typename T>
const TypeNTensor<N,T>& libMesh::TypeNTensor< N, T >::operator/= ( const T  )

Divide every entry of this tensor by a number.

Definition at line 151 of file type_n_tensor.h.

151 { return *this; }

◆ operator<()

template<unsigned int N, typename T>
bool libMesh::TypeNTensor< N, T >::operator< ( const TypeNTensor< N, T > &  ) const
Returns
true if this tensor is "less" than another.

Useful for sorting.

Definition at line 193 of file type_n_tensor.h.

194  { return false; }

◆ operator==()

template<unsigned int N, typename T>
bool libMesh::TypeNTensor< N, T >::operator== ( const TypeNTensor< N, T > &  ) const
Returns
true if two tensors are equal, false otherwise.

Definition at line 185 of file type_n_tensor.h.

186  { return true; }

◆ operator>()

template<unsigned int N, typename T>
bool libMesh::TypeNTensor< N, T >::operator> ( const TypeNTensor< N, T > &  ) const
Returns
true if this tensor is "greater" than another.

Definition at line 199 of file type_n_tensor.h.

200  { return false; }

◆ print()

template<unsigned int N, typename T>
void libMesh::TypeNTensor< N, T >::print ( std::ostream &  ) const

Do a formatted print of this tensor to a stream which defaults to libMesh::out.

Definition at line 206 of file type_n_tensor.h.

206 {}

◆ size_sq()

template<unsigned int N, typename T>
Real libMesh::TypeNTensor< N, T >::size_sq ( ) const
Returns
The Frobenius norm of the tensor squared, i.e. the sum of the entry magnitudes squared.
Deprecated:
Use the norm_sq() function instead.

Definition at line 173 of file type_n_tensor.h.

173 { libmesh_deprecated(); return 0.;}

◆ slice() [1/2]

template<unsigned int N, typename T>
const TypeNTensor<N-1,T> libMesh::TypeNTensor< N, T >::slice ( const unsigned  int) const
Returns
A proxy for the $ i^{th} $ slice of the tensor.

Definition at line 78 of file type_n_tensor.h.

79  { return TypeNTensor<N-1,T>(); }

◆ slice() [2/2]

template<unsigned int N, typename T>
TypeNTensor<N-1,T> libMesh::TypeNTensor< N, T >::slice ( const unsigned  int)
Returns
A writable proxy for the $ i^{th} $ slice of the tensor.

Definition at line 84 of file type_n_tensor.h.

85  { return TypeNTensor<N-1,T>(); }

Friends And Related Function Documentation

◆ operator<<

template<unsigned int N, typename T>
std::ostream& operator<< ( std::ostream &  os,
const TypeNTensor< N, T > &  t 
)
friend

Does a formatted print (as above) but supports the syntax:

std::cout << t << std::endl;

Definition at line 214 of file type_n_tensor.h.

216  {
217  t.print(os);
218  return os;
219  }

Member Data Documentation

◆ _coords

template<unsigned int N, typename T>
std::vector<T> libMesh::TypeNTensor< N, T >::_coords

The coordinates of the TypeNTensor.

Definition at line 230 of file type_n_tensor.h.


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