libMesh
Loading...
Searching...
No Matches
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 <type_n_tensor.h>

Public Types

typedef tuple_of< N, unsigned intindex_type
 Helper typedef for generic index programming.
 

Public Member Functions

 TypeNTensor ()
 
 TypeNTensor (const T &)
 
 TypeNTensor (const TypeVector< T > &)
 
 TypeNTensor (const TypeTensor< T > &)
 
 TypeNTensor (const TypeNTensor< N, T > &)
 
TypeNTensoroperator= (const TypeNTensor< N, T > &)
 
 operator TypeVector< T > () const
 
 operator VectorValue< T > () const
 
 operator TypeTensor< T > () const
 
 operator TensorValue< T > () const
 
 ~TypeNTensor ()=default
 Destructor.
 
const TypeNTensor< N-1, T > slice (const unsigned int) const
 
TypeNTensor< N-1, T > slice (const unsigned int)
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor & >::type operator= (const Scalar &libmesh_dbg_var(p))
 
template<typename T2 >
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator+ (const TypeNTensor< N, T2 > &) const
 Add two tensors.
 
template<typename T2 >
const TypeNTensor< N, T > & operator+= (const TypeNTensor< N, T2 > &)
 Add to this tensor.
 
template<typename T2 >
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator- (const TypeNTensor< N, T2 > &) const
 Subtract two tensors.
 
template<typename T2 >
const TypeNTensor< N, T > & operator-= (const TypeNTensor< N, T2 > &)
 Subtract from this tensor.
 
TypeNTensor< N, T > operator- () const
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor< N, typenameCompareTypes< T, Scalar >::supertype > >::type operator* (const Scalar) const
 Multiply every entry of a tensor by a number.
 
template<typename Scalar >
const TypeNTensor< N, T > & operator*= (const Scalar)
 Multiply every entry of this tensor by a number.
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor< N, typenameCompareTypes< T, Scalar >::supertype > >::type operator/ (const Scalar) const
 Divide every entry of a tensor by a number.
 
const TypeNTensor< N, T > & operator/= (const T)
 Divide every entry of this tensor by a number.
 
template<typename T2 >
CompareTypes< T, T2 >::supertype contract (const TypeNTensor< N, T2 > &) const
 Multiply 2 tensors together to return a scalar, i.e.
 
auto norm () const
 
auto norm_sq () const
 
void zero ()
 Set all entries of the tensor to 0.
 
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.
 
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.
 

Public Attributes

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

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:
 

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 48 of file type_n_tensor.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/5]

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

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/5]

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

Definition at line 58 of file type_n_tensor.h.

58: _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}

◆ TypeNTensor() [3/5]

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

Definition at line 60 of file type_n_tensor.h.

60: _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}

◆ TypeNTensor() [4/5]

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

Definition at line 62 of file type_n_tensor.h.

62: _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}

◆ TypeNTensor() [5/5]

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

Definition at line 64 of file type_n_tensor.h.

64: _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}

◆ ~TypeNTensor()

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

Destructor.

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 
)
inline

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

Definition at line 312 of file type_n_tensor.h.

313{
314 unsigned int size = int_pow(LIBMESH_DIM, N);
315 for (unsigned int i = 0; i < size ; i++)
316 _coords[i] += factor*p._coords[i];
317}

References libMesh::TypeNTensor< N, T >::_coords.

◆ contract()

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

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 211 of file type_n_tensor.h.

212 {
213 libmesh_not_implemented();
214 return 0;
215 }

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

◆ int_pow()

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

Definition at line 302 of file type_n_tensor.h.

303 {
304 return (e == 0) ? 1 : b * int_pow(b, e - 1);
305 }
static const Real b

References b, and libMesh::TypeNTensor< N, T >::int_pow().

Referenced by libMesh::TypeNTensor< N, T >::int_pow().

◆ norm()

template<unsigned int N, typename T >
auto libMesh::TypeNTensor< N, T >::norm ( ) const
inline
Returns
The Frobenius norm of the tensor, i.e. the square-root of the sum of the elements squared.

Definition at line 221 of file type_n_tensor.h.

222 {
223 libmesh_not_implemented();
224 return 0.;
225 }

◆ norm_sq()

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

Definition at line 231 of file type_n_tensor.h.

232 {
233 libmesh_not_implemented();
234 return 0.;
235 }

◆ operator TensorValue< T >()

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

Definition at line 72 of file type_n_tensor.h.

72{ libmesh_not_implemented(); return 0; }

◆ operator TypeTensor< T >()

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

Definition at line 71 of file type_n_tensor.h.

71{ libmesh_not_implemented(); return 0; }

◆ operator TypeVector< T >()

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

Definition at line 68 of file type_n_tensor.h.

68{ libmesh_not_implemented(); return 0; }

◆ operator VectorValue< T >()

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

Definition at line 69 of file type_n_tensor.h.

69{ libmesh_not_implemented(); return 0; }

◆ operator*()

template<unsigned int N, typename T >
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor< N, typenameCompareTypes< T, Scalar >::supertype > >::type libMesh::TypeNTensor< N, T >::operator* ( const Scalar  ) const
inline

Multiply every entry of a tensor by a number.

Definition at line 162 of file type_n_tensor.h.

163 {
164 libmesh_not_implemented();
165 return TypeNTensor<N,typename CompareTypes<T, Scalar>::supertype>();
166 }

◆ operator*=()

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

Multiply every entry of this tensor by a number.

Definition at line 172 of file type_n_tensor.h.

173 {
174 libmesh_not_implemented();
175 return *this;
176 }

◆ 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
inline

Add two tensors.

Definition at line 109 of file type_n_tensor.h.

110 {
111 libmesh_not_implemented();
112 return TypeNTensor<N,typename CompareTypes<T,T2>::supertype>();
113 }

◆ operator+=()

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

Add to this tensor.

Definition at line 119 of file type_n_tensor.h.

120 {
121 libmesh_not_implemented();
122 return *this;
123 }

◆ operator-() [1/2]

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

Definition at line 149 of file type_n_tensor.h.

150 {
151 libmesh_not_implemented();
152 return *this;
153 }

◆ operator-() [2/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
inline

Subtract two tensors.

Definition at line 130 of file type_n_tensor.h.

131 {
132 libmesh_not_implemented();
133 return TypeNTensor<N,typename CompareTypes<T,T2>::supertype>();
134 }

◆ operator-=()

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

Subtract from this tensor.

Definition at line 140 of file type_n_tensor.h.

141 {
142 libmesh_not_implemented();
143 return *this;
144 }

◆ operator/()

template<unsigned int N, typename T >
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor< N, typenameCompareTypes< T, Scalar >::supertype > >::type libMesh::TypeNTensor< N, T >::operator/ ( const Scalar  ) const
inline

Divide every entry of a tensor by a number.

Definition at line 185 of file type_n_tensor.h.

186 {
187 libmesh_not_implemented();
188 return *this;
189 }

◆ operator/=()

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

Divide every entry of this tensor by a number.

Definition at line 194 of file type_n_tensor.h.

195 {
196 libmesh_not_implemented();
197 return *this;
198 }

◆ operator<()

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

Useful for sorting.

Definition at line 256 of file type_n_tensor.h.

257 {
258 libmesh_not_implemented();
259 return false;
260 }

◆ operator=() [1/2]

template<unsigned int N, typename T >
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeNTensor & >::type libMesh::TypeNTensor< N, T >::operator= ( const Scalar &  libmesh_dbg_varp)
inline

Definition at line 101 of file type_n_tensor.h.

102 { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
void zero()
Set all entries of the tensor to 0.

References libMesh::TypeNTensor< N, T >::zero().

◆ operator=() [2/2]

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

Definition at line 66 of file type_n_tensor.h.

66{ libmesh_not_implemented(); return *this; }

◆ operator==()

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

Definition at line 245 of file type_n_tensor.h.

246 {
247 libmesh_not_implemented();
248 return true;
249 }

◆ operator>()

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

Definition at line 265 of file type_n_tensor.h.

266 {
267 libmesh_not_implemented();
268 return false;
269 }

◆ print()

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

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

Definition at line 275 of file type_n_tensor.h.

275{}

◆ slice() [1/2]

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

Definition at line 91 of file type_n_tensor.h.

92 {
93 libmesh_not_implemented();
94 return TypeNTensor<N-1,T>();
95 }

◆ slice() [2/2]

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

Definition at line 82 of file type_n_tensor.h.

83 {
84 libmesh_not_implemented();
85 return TypeNTensor<N-1,T>();
86 }

◆ zero()

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

Set all entries of the tensor to 0.

Definition at line 240 of file type_n_tensor.h.

240{ libmesh_not_implemented(); }

Referenced by libMesh::TypeNTensor< N, T >::operator=().

Friends And Related Symbol 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 283 of file type_n_tensor.h.

285 {
286 t.print(os);
287 return os;
288 }

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 299 of file type_n_tensor.h.

Referenced by libMesh::TypeNTensor< N, T >::add_scaled().


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