libMesh
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
libMesh::TypeTensor< T > Class Template Reference

This class defines a tensor in LIBMESH_DIM dimensional space of type T. More...

#include <type_tensor.h>

Inheritance diagram for libMesh::TypeTensor< T >:
[legend]

Public Types

typedef T value_type
 Helper typedef for C++98 generic programming.
 
typedef std::tuple< unsigned int, unsigned int > index_type
 Helper typedef for generic index programming.
 

Public Member Functions

 TypeTensor ()
 Empty constructor.
 
template<typename T2 >
 TypeTensor (const TypeTensor< T2 > &p)
 Copy-constructor.
 
 ~TypeTensor ()=default
 Destructor.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE void assign (const TypeTensor< T2 > &)
 Assign to this tensor without creating a temporary.
 
template<typename Scalar >
LIBMESH_DEVICE_INLINE std::enable_if< ScalarTraits< Scalar >::value, TypeTensor & >::type operator= (const Scalar &libmesh_dbg_var(p))
 Assignment-from-scalar operator.
 
const T & operator() (const unsigned int i, const unsigned int j) const
 
T & operator() (const unsigned int i, const unsigned int j)
 
LIBMESH_DEVICE_INLINE ConstTypeTensorColumn< T > slice (const unsigned int i) const
 
LIBMESH_DEVICE_INLINE TypeTensorColumn< T > slice (const unsigned int i)
 
TypeVector< T > row (const unsigned int r) const
 
LIBMESH_DEVICE_INLINE TypeVector< T > column (const unsigned int r) const
 
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > operator+ (const TypeTensor< T2 > &) const
 Add another tensor to this tensor.
 
template<typename T2 >
const TypeTensor< T > & operator+= (const TypeTensor< T2 > &)
 Add to this tensor.
 
template<typename T2 >
void add (const TypeTensor< T2 > &)
 Add to this tensor without creating a temporary.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE void add_scaled (const TypeTensor< T2 > &, const T &)
 Add a scaled tensor to this tensor without creating a temporary.
 
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > operator- (const TypeTensor< T2 > &) const
 Subtract a tensor from this tensor.
 
template<typename T2 >
const TypeTensor< T > & operator-= (const TypeTensor< T2 > &)
 Subtract from this tensor.
 
template<typename T2 >
void subtract (const TypeTensor< T2 > &)
 Subtract from this tensor without creating a temporary.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE void subtract_scaled (const TypeTensor< T2 > &, const T &)
 Subtract a scaled value from this tensor without creating a temporary.
 
TypeTensor< T > operator- () const
 
template<typename Scalar >
auto operator* (const Scalar &scalar) const -> typename std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< decltype(T() *scalar)> >::type
 Multiply this tensor by a scalar value.
 
template<typename Scalar , typename std::enable_if< ScalarTraits< Scalar >::value, int >::type = 0>
LIBMESH_DEVICE_INLINE const TypeTensor< T > & operator*= (const Scalar &factor)
 Multiply this tensor by a scalar value in place.
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< typenameCompareTypes< T, Scalar >::supertype > >::type operator/ (const Scalar &) const
 Divide each entry of this tensor by a scalar value.
 
const TypeTensor< T > & operator/= (const T &)
 Divide each entry of this tensor by a scalar value.
 
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > operator* (const TypeTensor< T2 > &) const
 Multiply 2 tensors together, i.e.
 
template<typename T2 >
const TypeTensor< T > & operator*= (const TypeTensor< T2 > &)
 Multiply this tensor by a tensor value in place.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE CompareTypes< T, T2 >::supertype contract (const TypeTensor< T2 > &) const
 Multiply 2 tensors together to return a scalar, i.e.
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > operator* (const TypeVector< T2 > &) const
 Right-multiply this tensor by a vector, i.e.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeVector< typename CompareTypes< T, T2 >::supertype > left_multiply (const TypeVector< T2 > &p) const
 Left-multiply this tensor by a vector, i.e.
 
TypeTensor< T > transpose () const
 
TypeTensor< T > inverse () const
 
LIBMESH_DEVICE_INLINE void solve (const TypeVector< T > &b, TypeVector< T > &x) const
 Solve the 2x2 or 3x3 system of equations A*x = b for x by directly inverting A and multiplying it by b.
 
auto norm () const
 
auto norm_sq () const
 
LIBMESH_DEVICE_INLINE bool is_zero () const
 
T det () const
 
T tr () const
 
LIBMESH_DEVICE_INLINE void zero ()
 Set all entries of the tensor to 0.
 
LIBMESH_DEVICE_INLINE bool operator== (const TypeTensor< T > &rhs) const
 
bool operator< (const TypeTensor< T > &rhs) const
 
bool operator> (const TypeTensor< T > &rhs) const
 
void print (std::ostream &os=libMesh::out) const
 Formatted print to a stream which defaults to libMesh::out.
 
void write_unformatted (std::ostream &out_stream, const bool newline=true) const
 Unformatted print to the stream out.
 
bool is_hpd (Real rel_tol=TOLERANCE *TOLERANCE) const
 Returns true if the TypeTensor is Hermitian (or symmetric, when T==Real) and positive-definite to within the provided relative tolerance, false otherwise.
 
template<typename Scalar >
LIBMESH_DEVICE_INLINE TypeTensor (const Scalar &xx, const Scalar &xy, const Scalar &xz, const Scalar &yx, const Scalar &yy, const Scalar &yz, const Scalar &zx, const Scalar &zy, typename std::enable_if< ScalarTraits< Scalar >::value, const Scalar >::type &zz)
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor (const TypeTensor< T2 > &p)
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > operator+ (const TypeTensor< T2 > &p) const
 
template<typename T2 >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & operator+= (const TypeTensor< T2 > &p)
 
template<typename T2 >
LIBMESH_DEVICE_INLINE void add (const TypeTensor< T2 > &p)
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > operator- (const TypeTensor< T2 > &p) const
 
template<typename T2 >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & operator-= (const TypeTensor< T2 > &p)
 
template<typename T2 >
LIBMESH_DEVICE_INLINE void subtract (const TypeTensor< T2 > &p)
 
template<typename Scalar >
LIBMESH_DEVICE_INLINE auto operator* (const Scalar &factor) const -> typename std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< decltype(T() *factor)> >::type
 
template<typename Scalar >
LIBMESH_DEVICE_INLINE std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< typenameCompareTypes< T, Scalar >::supertype > >::type operator/ (const Scalar &factor) const
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeVector< typename CompareTypes< T, T2 >::supertype > operator* (const TypeVector< T2 > &p) const
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > operator* (const TypeTensor< T2 > &p) const
 
template<typename T2 >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & operator*= (const TypeTensor< T2 > &p)
 
bool operator< (const TypeTensor< Real > &rhs) const
 
bool operator> (const TypeTensor< Real > &rhs) const
 
bool operator< (const TypeTensor< Complex > &rhs) const
 
bool operator> (const TypeTensor< Complex > &rhs) const
 

Protected Member Functions

 TypeTensor (const T &xx, const T &xy=0, const T &xz=0, const T &yx=0, const T &yy=0, const T &yz=0, const T &zx=0, const T &zy=0, const T &zz=0)
 Constructor-from-T.
 
template<typename Scalar >
 TypeTensor (const Scalar &xx, const Scalar &xy=0, const Scalar &xz=0, const Scalar &yx=0, const Scalar &yy=0, const Scalar &yz=0, const Scalar &zx=0, const Scalar &zy=0, typename std::enable_if< ScalarTraits< Scalar >::value, const Scalar >::type &zz=0)
 Constructor-from-Scalar.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor (const TypeVector< T2 > &vx)
 Constructor.
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor (const TypeVector< T2 > &vx, const TypeVector< T2 > &vy)
 
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor (const TypeVector< T2 > &vx, const TypeVector< T2 > &vy, const TypeVector< T2 > &vz)
 

Protected Attributes

T _coords [LIBMESH_DIM *LIBMESH_DIM]
 The coordinates of the TypeTensor.
 

Friends

template<typename T2 >
class TypeTensor
 
std::ostream & operator<< (std::ostream &os, const TypeTensor< T > &t)
 Formatted print as above but supports the syntax:
 

Detailed Description

template<typename T>
class libMesh::TypeTensor< T >

This class defines a tensor in LIBMESH_DIM dimensional space of type T.

T may either be Real or Complex.

Author
Roy Stogner
Date
2004

Definition at line 53 of file type_tensor.h.

Member Typedef Documentation

◆ index_type

template<typename T >
typedef std::tuple<unsigned int, unsigned int> libMesh::TypeTensor< T >::index_type

Helper typedef for generic index programming.

Definition at line 129 of file type_tensor.h.

◆ value_type

template<typename T >
typedef T libMesh::TypeTensor< T >::value_type

Helper typedef for C++98 generic programming.

Definition at line 124 of file type_tensor.h.

Constructor & Destructor Documentation

◆ TypeTensor() [1/9]

template<typename T >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( )

Empty constructor.

Gives the tensor 0 in LIBMESH_DIM dimensions.

Definition at line 535 of file type_tensor.h.

536{
537 _coords[0] = {};
538
539#if LIBMESH_DIM > 1
540 _coords[1] = {};
541 _coords[2] = {};
542 _coords[3] = {};
543#endif
544
545#if LIBMESH_DIM > 2
546 _coords[4] = {};
547 _coords[5] = {};
548 _coords[6] = {};
549 _coords[7] = {};
550 _coords[8] = {};
551#endif
552}
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.

◆ TypeTensor() [2/9]

template<typename T >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( const T &  xx,
const T &  xy = 0,
const T &  xz = 0,
const T &  yx = 0,
const T &  yy = 0,
const T &  yz = 0,
const T &  zx = 0,
const T &  zy = 0,
const T &  zz = 0 
)
explicitprotected

Constructor-from-T.

By default sets higher dimensional entries to 0. This is a poor constructor for 2D tensors - if the default arguments are to be overridden it requires that the "xz = 0." etc. arguments also be given explicitly.

Definition at line 558 of file type_tensor.h.

567{
568 _coords[0] = xx;
569
570#if LIBMESH_DIM == 2
571 _coords[1] = xy;
572 _coords[2] = yx;
573 _coords[3] = yy;
574#elif LIBMESH_DIM == 1
575 libmesh_assert_equal_to (xy, 0);
576 libmesh_assert_equal_to (yx, 0);
577 libmesh_assert_equal_to (yy, 0);
578 libmesh_ignore(xy, yx, yy);
579#endif
580
581#if LIBMESH_DIM == 3
582 _coords[1] = xy;
583 _coords[2] = xz;
584 _coords[3] = yx;
585 _coords[4] = yy;
586 _coords[5] = yz;
587 _coords[6] = zx;
588 _coords[7] = zy;
589 _coords[8] = zz;
590#else
591 libmesh_assert_equal_to (xz, 0);
592 libmesh_assert_equal_to (yz, 0);
593 libmesh_assert_equal_to (zx, 0);
594 libmesh_assert_equal_to (zy, 0);
595 libmesh_assert_equal_to (zz, 0);
596 libmesh_ignore(xz, yz, zx, zy, zz);
597#endif
598}
void libmesh_ignore(const Args &...)

References libMesh::libmesh_ignore().

◆ TypeTensor() [3/9]

template<typename T >
template<typename Scalar >
libMesh::TypeTensor< T >::TypeTensor ( const Scalar &  xx,
const Scalar &  xy = 0,
const Scalar &  xz = 0,
const Scalar &  yx = 0,
const Scalar &  yy = 0,
const Scalar &  yz = 0,
const Scalar &  zx = 0,
const Scalar &  zy = 0,
typename std::enable_if< ScalarTraits< Scalar >::value, const Scalar >::type &  zz = 0 
)
explicitprotected

Constructor-from-Scalar.

◆ TypeTensor() [4/9]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( const TypeVector< T2 > &  vx)
protected

Constructor.

Assigns each vector to a different row of the tensor. We're in LIBMESH_DIM space dimensions and so LIBMESH_DIM many vectors are needed.

Definition at line 664 of file type_tensor.h.

665{
666 libmesh_assert_equal_to (LIBMESH_DIM, 1);
667 _coords[0] = vx(0);
668}

◆ TypeTensor() [5/9]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( const TypeVector< T2 > &  vx,
const TypeVector< T2 > &  vy 
)
protected

Definition at line 673 of file type_tensor.h.

675{
676 libmesh_assert_equal_to (LIBMESH_DIM, 2);
677#if LIBMESH_DIM > 1
678 _coords[0] = vx(0);
679 _coords[1] = vx(1);
680 _coords[2] = vy(0);
681 _coords[3] = vy(1);
682#else
683 libmesh_ignore(vx, vy);
684#endif
685}

References libMesh::libmesh_ignore().

◆ TypeTensor() [6/9]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( const TypeVector< T2 > &  vx,
const TypeVector< T2 > &  vy,
const TypeVector< T2 > &  vz 
)
protected

Definition at line 690 of file type_tensor.h.

693{
694 libmesh_assert_equal_to (LIBMESH_DIM, 3);
695#if LIBMESH_DIM > 2
696 _coords[0] = vx(0);
697 _coords[1] = vx(1);
698 _coords[2] = vx(2);
699 _coords[3] = vy(0);
700 _coords[4] = vy(1);
701 _coords[5] = vy(2);
702 _coords[6] = vz(0);
703 _coords[7] = vz(1);
704 _coords[8] = vz(2);
705#else
706 libmesh_ignore(vx, vy, vz);
707#endif
708}

References libMesh::libmesh_ignore().

◆ TypeTensor() [7/9]

template<typename T >
template<typename T2 >
libMesh::TypeTensor< T >::TypeTensor ( const TypeTensor< T2 > &  p)

Copy-constructor.

◆ ~TypeTensor()

template<typename T >
libMesh::TypeTensor< T >::~TypeTensor ( )
default

Destructor.

◆ TypeTensor() [8/9]

template<typename T >
template<typename Scalar >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( const Scalar &  xx,
const Scalar &  xy,
const Scalar &  xz,
const Scalar &  yx,
const Scalar &  yy,
const Scalar &  yz,
const Scalar &  zx,
const Scalar &  zy,
typename std::enable_if< ScalarTraits< Scalar >::value, const Scalar >::type &  zz 
)

Definition at line 604 of file type_tensor.h.

615{
616 _coords[0] = xx;
617
618#if LIBMESH_DIM == 2
619 _coords[1] = xy;
620 _coords[2] = yx;
621 _coords[3] = yy;
622#elif LIBMESH_DIM == 1
623 libmesh_assert_equal_to (xy, 0);
624 libmesh_assert_equal_to (yx, 0);
625 libmesh_assert_equal_to (yy, 0);
626 libmesh_ignore(xy, yx, yy);
627#endif
628
629#if LIBMESH_DIM == 3
630 _coords[1] = xy;
631 _coords[2] = xz;
632 _coords[3] = yx;
633 _coords[4] = yy;
634 _coords[5] = yz;
635 _coords[6] = zx;
636 _coords[7] = zy;
637 _coords[8] = zz;
638#else
639 libmesh_assert_equal_to (xz, 0);
640 libmesh_assert_equal_to (yz, 0);
641 libmesh_assert_equal_to (zx, 0);
642 libmesh_assert_equal_to (zy, 0);
643 libmesh_assert_equal_to (zz, 0);
644 libmesh_ignore(xz, yz, zx, zy, zz);
645#endif
646}

References libMesh::libmesh_ignore().

◆ TypeTensor() [9/9]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE libMesh::TypeTensor< T >::TypeTensor ( const TypeTensor< T2 > &  p)

Definition at line 653 of file type_tensor.h.

654{
655 // copy the nodes from vector p to me
656 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
657 _coords[i] = p._coords[i];
658}

References libMesh::TypeTensor< T >::_coords.

Member Function Documentation

◆ add() [1/2]

template<typename T >
template<typename T2 >
void libMesh::TypeTensor< T >::add ( const TypeTensor< T2 > &  )

Add to this tensor without creating a temporary.

Referenced by NonlinearNeoHookeCurrentConfig::init_for_qp().

◆ add() [2/2]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::add ( const TypeTensor< T2 > &  p)

Definition at line 860 of file type_tensor.h.

861{
862 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
863 _coords[i] += p._coords[i];
864}

References libMesh::TypeTensor< T >::_coords.

◆ add_scaled()

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::add_scaled ( const TypeTensor< T2 > &  p,
const T &  factor 
)

◆ assign()

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::assign ( const TypeTensor< T2 > &  p)

Assign to this tensor without creating a temporary.

Definition at line 716 of file type_tensor.h.

717{
718 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
719 _coords[i] = p._coords[i];
720}

References libMesh::TypeTensor< T >::_coords.

◆ column()

template<typename T >
LIBMESH_DEVICE_INLINE TypeVector< T > libMesh::TypeTensor< T >::column ( const unsigned int  r) const
Returns
A copy of one column of the tensor as a TypeVector.

Definition at line 799 of file type_tensor.h.

800{
801 TypeVector<T> return_vector;
802
803 for (unsigned int i=0; i<LIBMESH_DIM; i++)
804 return_vector._coords[i] = _coords[i*LIBMESH_DIM + r];
805
806 return return_vector;
807}

References libMesh::TypeVector< T >::_coords.

Referenced by TypeTensorTest::testRowCol().

◆ contract()

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE CompareTypes< T, T2 >::supertype libMesh::TypeTensor< T >::contract ( const TypeTensor< T2 > &  t) const

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

Multiply 2 tensors together, 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.

sum Aij*Bij. The tensors may be of different types.

Definition at line 1288 of file type_tensor.h.

1289{
1290 typename CompareTypes<T,T2>::supertype sum = 0.;
1291 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1292 sum += _coords[i]*t._coords[i];
1293 return sum;
1294}

References libMesh::TypeTensor< T >::_coords.

Referenced by libMesh::HPCoarsenTest::add_projection(), libMesh::VariationalSmootherSystem::element_time_derivative(), libMesh::TensorTools::inner_product(), and libMesh::HPCoarsenTest::select_refinement().

◆ det()

template<typename T >
LIBMESH_DEVICE_INLINE T libMesh::TypeTensor< T >::det ( ) const
Returns
The determinant of the tensor.

Because these are 3x3 tensors at most, we don't do an LU decomposition like DenseMatrix does.

Definition at line 1319 of file type_tensor.h.

1320{
1321#if LIBMESH_DIM == 1
1322 return _coords[0];
1323#endif
1324
1325#if LIBMESH_DIM == 2
1326 return (_coords[0] * _coords[3]
1327 - _coords[1] * _coords[2]);
1328#endif
1329
1330#if LIBMESH_DIM == 3
1331 return (_coords[0] * _coords[4] * _coords[8]
1332 + _coords[1] * _coords[5] * _coords[6]
1333 + _coords[2] * _coords[3] * _coords[7]
1334 - _coords[0] * _coords[5] * _coords[7]
1335 - _coords[1] * _coords[3] * _coords[8]
1336 - _coords[2] * _coords[4] * _coords[6]);
1337#endif
1338}

Referenced by NonlinearNeoHookeCurrentConfig::calculate_stress(), NonlinearNeoHookeCurrentConfig::calculate_tangent(), libMesh::VariationalSmootherSystem::compute_mesh_quality_info(), LargeDeformationElasticity::compute_stresses(), libMesh::VariationalSmootherSystem::element_time_derivative(), NonlinearNeoHookeCurrentConfig::get_linearized_stiffness(), GradDivExactSolution::grad(), libMeshTest::KokkosTensorOracle::host_leading_determinant(), NonlinearNeoHookeCurrentConfig::init_for_qp(), GradDivExactSolution::operator()(), libMesh::Elem::quality(), libMesh::Hex::quality(), and libMesh::Sphere::Sphere().

◆ inverse()

template<typename T >
LIBMESH_DEVICE_INLINE TypeTensor< T > libMesh::TypeTensor< T >::inverse ( ) const
Returns
The inverse of this tensor as an independent object.

Definition at line 1100 of file type_tensor.h.

1101{
1102#if LIBMESH_DIM == 1
1103 if (_coords[0] == static_cast<T>(0.))
1104 libmesh_convergence_failure();
1105 return TypeTensor(1. / _coords[0]);
1106#endif
1107
1108#if LIBMESH_DIM == 2
1109 // Get convenient reference to this.
1110 const TypeTensor<T> & A = *this;
1111
1112 // Use temporary variables, avoid multiple accesses
1113 T a = A(0,0), b = A(0,1),
1114 c = A(1,0), d = A(1,1);
1115
1116 // Make sure det = ad - bc is not zero
1117 T my_det = a*d - b*c;
1118
1119 if (my_det == static_cast<T>(0.))
1120 libmesh_convergence_failure();
1121
1122 return TypeTensor(d/my_det, -b/my_det, -c/my_det, a/my_det);
1123#endif
1124
1125#if LIBMESH_DIM == 3
1126 // Get convenient reference to this.
1127 const TypeTensor<T> & A = *this;
1128
1129 T a11 = A(0,0), a12 = A(0,1), a13 = A(0,2),
1130 a21 = A(1,0), a22 = A(1,1), a23 = A(1,2),
1131 a31 = A(2,0), a32 = A(2,1), a33 = A(2,2);
1132
1133 T my_det = a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
1134
1135 if (my_det == static_cast<T>(0.))
1136 libmesh_convergence_failure();
1137
1138 // Inline comment characters are for lining up columns.
1139 return TypeTensor( (a33*a22-a32*a23)/my_det, -(a33*a12-a32*a13)/my_det, (a23*a12-a22*a13)/my_det,
1140 -(a33*a21-a31*a23)/my_det, (a33*a11-a31*a13)/my_det, -(a23*a11-a21*a13)/my_det,
1141 (a32*a21-a31*a22)/my_det, -(a32*a11-a31*a12)/my_det, (a22*a11-a21*a12)/my_det);
1142#endif
1143}
friend class TypeTensor
Definition type_tensor.h:56
static const Real b

References b.

Referenced by NonlinearNeoHookeCurrentConfig::calculate_stress(), libMesh::VariationalSmootherSystem::element_time_derivative(), libMesh::VariationalSmootherSystem::get_target_to_reference_jacobian(), libMeshTest::KokkosTensorOracle::host_leading_inverse(), NonlinearNeoHookeCurrentConfig::init_for_qp(), libMesh::Elem::quality(), and TypeTensorTest::testInverse().

◆ is_hpd()

template<typename T >
bool libMesh::TypeTensor< T >::is_hpd ( Real  rel_tol = TOLERANCE*TOLERANCE) const

Returns true if the TypeTensor is Hermitian (or symmetric, when T==Real) and positive-definite to within the provided relative tolerance, false otherwise.

Definition at line 67 of file type_tensor.C.

68{
69 // Convenient reference to this object, to be used for matrix
70 // operations.
71 const auto & A = *this;
72
73 // The norm of this matrix, needed for relative tolerance checks.
74 auto A_norm = A.norm();
75
76 // The zero matrix is only positive semi-definite
77 if (A_norm == 0)
78 return false;
79
80 // An absolute tolerance (based on the user's provided relative
81 // tolerance) to be used in the floating point comparisons below.
82 auto abs_tol = rel_tol * A_norm;
83
84 // Form the complex conjugate transpose of A
85 TypeTensor<T> A_conjugate_transpose;
86 for (unsigned int i=0; i<LIBMESH_DIM; i++)
87 for (unsigned int j=0; j<LIBMESH_DIM; j++)
88 A_conjugate_transpose(i,j) = libmesh_conj(A(j,i));
89
90 // Check if Hermitian
91 if ((A - A_conjugate_transpose).norm() > abs_tol)
92 return false;
93
94 // If we made it here, then we are Hermitian, so now we just need to
95 // check if we are positive-definite by checking that all principal
96 // minors are positive. Note: the determinant of a Hermitian matrix
97 // and all principal minors are real-valued. Since we already
98 // checked that the matrix is Hermitian above, we don't bother to
99 // check the complex parts are also zero now.
100
101 // For 3x3 and 2x2, check the 1x1 determinant
102#if LIBMESH_DIM > 1
103 if (std::real(A(0,0)) < -abs_tol)
104 return false;
105#endif
106
107 // For 3x3, check the upper 2x2 determinant
108#if LIBMESH_DIM > 2
109 if (std::real(A(0,0)*A(1,1) - A(0,1)*A(1,0)) < -abs_tol)
110 return false;
111#endif
112
113 // Finally, check the full determinant
114 if (std::real(A.det()) < -abs_tol)
115 return false;
116
117 // If we made it here, then the matrix is Hermitian
118 // positive-definite.
119 return true;
120}
LIBMESH_DEVICE_INLINE T libmesh_conj(T a)
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)

References libMesh::libmesh_conj(), and std::real().

Referenced by libMeshTest::KokkosTensorOracle::test_tensor_host_only_ops(), and TypeTensorTest::testIsHPD().

◆ is_zero()

template<typename T >
LIBMESH_DEVICE_INLINE bool libMesh::TypeTensor< T >::is_zero ( ) const
Returns
True if all values in the tensor are zero

Definition at line 1309 of file type_tensor.h.

1310{
1311 for (const auto & val : _coords)
1312 if (val != T(0))
1313 return false;
1314 return true;
1315}

Referenced by libMeshTest::KokkosTensorOracle::test_tensor_ops(), and TypeTensorTest::testIsZero().

◆ left_multiply()

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeVector< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::left_multiply ( const TypeVector< T2 > &  p) const

Left-multiply this tensor by a vector, i.e.

matrix-vector product. The tensor and vector may contain different numeric types.

Returns
A copy of the result vector, this tensor is unchanged.

Definition at line 1231 of file type_tensor.h.

1232{
1233 TypeVector<typename CompareTypes<T,T2>::supertype> returnval;
1234 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1235 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1236 returnval(i) += p(j)*(*this)(j,i);
1237
1238 return returnval;
1239}

Referenced by AzimuthalPeriodicBoundary::get_corresponding_pos().

◆ norm()

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

Definition at line 1300 of file type_tensor.h.

1301{
1302 using portable_math::sqrt;
1303 return sqrt(this->norm_sq());
1304}
auto norm_sq() const

◆ norm_sq()

template<typename T >
LIBMESH_DEVICE_INLINE auto libMesh::TypeTensor< T >::norm_sq ( ) const
Returns
The Frobenius norm of the tensor squared, i.e. sum of the element magnitudes squared.

Definition at line 1369 of file type_tensor.h.

1370{
1371 Real sum = 0.;
1372 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1373 sum += TensorTools::norm_sq(_coords[i]);
1374 return sum;
1375}
LIBMESH_DEVICE_INLINE auto norm_sq(const T &a)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::TensorTools::norm_sq(), and libMesh::Real.

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::ExactErrorEstimator::find_squared_element_error(), libMesh::TensorTools::norm_sq(), libMesh::TensorTools::norm_sq(), and libMesh::HPCoarsenTest::select_refinement().

◆ operator()() [1/2]

template<typename T >
LIBMESH_DEVICE_INLINE T & libMesh::TypeTensor< T >::operator() ( const unsigned int  i,
const unsigned int  j 
)
Returns
A writable reference to the (i,j) entry of the tensor.

Definition at line 745 of file type_tensor.h.

747{
748#if LIBMESH_DIM < 3
749
750 libmesh_error_msg_if(i >= LIBMESH_DIM || j >= LIBMESH_DIM,
751 "ERROR: You are assigning to a tensor component that is out of range for the compiled LIBMESH_DIM!");
752
753#endif
754
755 libmesh_assert_less (i, LIBMESH_DIM);
756 libmesh_assert_less (j, LIBMESH_DIM);
757
758 return _coords[i*LIBMESH_DIM+j];
759}

◆ operator()() [2/2]

template<typename T >
LIBMESH_DEVICE_INLINE const T & libMesh::TypeTensor< T >::operator() ( const unsigned int  i,
const unsigned int  j 
) const
Returns
A const reference to the (i,j) entry of the tensor.

Definition at line 726 of file type_tensor.h.

728{
729 libmesh_assert_less (i, 3);
730 libmesh_assert_less (j, 3);
731
732#if LIBMESH_DIM < 3
733 const static T my_zero = 0;
734 if (i >= LIBMESH_DIM || j >= LIBMESH_DIM)
735 return my_zero;
736#endif
737
738 return _coords[i*LIBMESH_DIM+j];
739}

◆ operator*() [1/6]

template<typename T >
template<typename Scalar >
LIBMESH_DEVICE_INLINE auto libMesh::TypeTensor< T >::operator* ( const Scalar &  factor) const -> typename std::enable_if< ScalarTraits<Scalar>::value, TypeTensor<decltype(T() * factor)>>::type

Definition at line 985 of file type_tensor.h.

988{
989 typedef decltype((*this)(0, 0) * factor) TS;
990
991
992#if LIBMESH_DIM == 1
993 return TypeTensor<TS>(_coords[0]*factor);
994#endif
995
996#if LIBMESH_DIM == 2
997 return TypeTensor<TS>(_coords[0]*factor,
998 _coords[1]*factor,
999 _coords[2]*factor,
1000 _coords[3]*factor);
1001#endif
1002
1003#if LIBMESH_DIM == 3
1004 return TypeTensor<TS>(_coords[0]*factor,
1005 _coords[1]*factor,
1006 _coords[2]*factor,
1007 _coords[3]*factor,
1008 _coords[4]*factor,
1009 _coords[5]*factor,
1010 _coords[6]*factor,
1011 _coords[7]*factor,
1012 _coords[8]*factor);
1013#endif
1014}

◆ operator*() [2/6]

template<typename T >
template<typename Scalar >
auto libMesh::TypeTensor< T >::operator* ( const Scalar &  scalar) const -> typename std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< decltype(T() *scalar)> >::type

Multiply this tensor by a scalar value.

Returns
A copy of the result, this tensor is unchanged.

◆ operator*() [3/6]

template<typename T >
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator* ( const TypeTensor< T2 > &  ) const

Multiply 2 tensors together, i.e.

matrix-matrix product. The tensors may contain different numeric types.

Returns
A copy of the result, this tensor is unchanged.

◆ operator*() [4/6]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator* ( const TypeTensor< T2 > &  p) const

Definition at line 1253 of file type_tensor.h.

1254{
1255 TypeTensor<typename CompareTypes<T, T2>::supertype> returnval;
1256 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1257 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1258 for (unsigned int k=0; k<LIBMESH_DIM; k++)
1259 returnval(i,j) += (*this)(i,k)*p(k,j);
1260
1261 return returnval;
1262}

◆ operator*() [5/6]

template<typename T >
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator* ( const TypeVector< T2 > &  ) const

Right-multiply this tensor by a vector, i.e.

matrix-vector product. The tensor and vector may contain different numeric types.

Returns
A copy of the result vector, this tensor is unchanged.

◆ operator*() [6/6]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeVector< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator* ( const TypeVector< T2 > &  p) const

Definition at line 1217 of file type_tensor.h.

1218{
1219 TypeVector<typename CompareTypes<T,T2>::supertype> returnval;
1220 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1221 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1222 returnval(i) += (*this)(i,j)*p(j);
1223
1224 return returnval;
1225}

◆ operator*=() [1/3]

template<typename T >
template<typename Scalar , typename std::enable_if< ScalarTraits< Scalar >::value, int >::type = 0>
LIBMESH_DEVICE_INLINE const TypeTensor< T > & libMesh::TypeTensor< T >::operator*= ( const Scalar &  factor)
inline

Multiply this tensor by a scalar value in place.

Returns
A reference to *this.

Definition at line 280 of file type_tensor.h.

281 {
282 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
283 _coords[i] *= factor;
284
285 return *this;
286 }

References libMesh::TypeTensor< T >::_coords.

◆ operator*=() [2/3]

template<typename T >
template<typename T2 >
const TypeTensor< T > & libMesh::TypeTensor< T >::operator*= ( const TypeTensor< T2 > &  )

Multiply this tensor by a tensor value in place.

Returns
A reference to *this

◆ operator*=() [3/3]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & libMesh::TypeTensor< T >::operator*= ( const TypeTensor< T2 > &  p)

Definition at line 1267 of file type_tensor.h.

1268{
1269 TypeTensor<T> temp;
1270 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1271 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1272 for (unsigned int k=0; k<LIBMESH_DIM; k++)
1273 temp(i,j) += (*this)(i,k)*p(k,j);
1274
1275 this->assign(temp);
1276 return *this;
1277}
LIBMESH_DEVICE_INLINE void assign(const TypeTensor< T2 > &)
Assign to this tensor without creating a temporary.

◆ operator+() [1/2]

template<typename T >
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator+ ( const TypeTensor< T2 > &  ) const

Add another tensor to this tensor.

Returns
A copy of the result, this tensor is unchanged.

◆ operator+() [2/2]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator+ ( const TypeTensor< T2 > &  p) const

Definition at line 814 of file type_tensor.h.

815{
816
817#if LIBMESH_DIM == 1
818 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0]);
819#endif
820
821#if LIBMESH_DIM == 2
822 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0],
823 _coords[1] + p._coords[1],
824 0.,
825 _coords[2] + p._coords[2],
826 _coords[3] + p._coords[3]);
827#endif
828
829#if LIBMESH_DIM == 3
830 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0],
831 _coords[1] + p._coords[1],
832 _coords[2] + p._coords[2],
833 _coords[3] + p._coords[3],
834 _coords[4] + p._coords[4],
835 _coords[5] + p._coords[5],
836 _coords[6] + p._coords[6],
837 _coords[7] + p._coords[7],
838 _coords[8] + p._coords[8]);
839#endif
840
841}

References libMesh::TypeTensor< T >::_coords.

◆ operator+=() [1/2]

template<typename T >
template<typename T2 >
const TypeTensor< T > & libMesh::TypeTensor< T >::operator+= ( const TypeTensor< T2 > &  )

Add to this tensor.

Returns
A reference to *this.

◆ operator+=() [2/2]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & libMesh::TypeTensor< T >::operator+= ( const TypeTensor< T2 > &  p)

Definition at line 848 of file type_tensor.h.

849{
850 this->add (p);
851
852 return *this;
853}
void add(const TypeTensor< T2 > &)
Add to this tensor without creating a temporary.

◆ operator-() [1/3]

template<typename T >
LIBMESH_DEVICE_INLINE TypeTensor< T > libMesh::TypeTensor< T >::operator- ( ) const
Returns
The negative of this tensor in a separate copy.

Definition at line 951 of file type_tensor.h.

952{
953
954#if LIBMESH_DIM == 1
955 return TypeTensor(-_coords[0]);
956#endif
957
958#if LIBMESH_DIM == 2
959 return TypeTensor(-_coords[0],
960 -_coords[1],
961 -_coords[2],
962 -_coords[3]);
963#endif
964
965#if LIBMESH_DIM == 3
966 return TypeTensor(-_coords[0],
967 -_coords[1],
968 -_coords[2],
969 -_coords[3],
970 -_coords[4],
971 -_coords[5],
972 -_coords[6],
973 -_coords[7],
974 -_coords[8]);
975#endif
976
977}

◆ operator-() [2/3]

template<typename T >
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator- ( const TypeTensor< T2 > &  ) const

Subtract a tensor from this tensor.

Returns
A copy of the result, this tensor is unchanged.

◆ operator-() [3/3]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE TypeTensor< typename CompareTypes< T, T2 >::supertype > libMesh::TypeTensor< T >::operator- ( const TypeTensor< T2 > &  p) const

Definition at line 884 of file type_tensor.h.

885{
886
887#if LIBMESH_DIM == 1
888 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0]);
889#endif
890
891#if LIBMESH_DIM == 2
892 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0],
893 _coords[1] - p._coords[1],
894 0.,
895 _coords[2] - p._coords[2],
896 _coords[3] - p._coords[3]);
897#endif
898
899#if LIBMESH_DIM == 3
900 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0],
901 _coords[1] - p._coords[1],
902 _coords[2] - p._coords[2],
903 _coords[3] - p._coords[3],
904 _coords[4] - p._coords[4],
905 _coords[5] - p._coords[5],
906 _coords[6] - p._coords[6],
907 _coords[7] - p._coords[7],
908 _coords[8] - p._coords[8]);
909#endif
910
911}

References libMesh::TypeTensor< T >::_coords.

◆ operator-=() [1/2]

template<typename T >
template<typename T2 >
const TypeTensor< T > & libMesh::TypeTensor< T >::operator-= ( const TypeTensor< T2 > &  )

Subtract from this tensor.

Returns
A reference to *this.

◆ operator-=() [2/2]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & libMesh::TypeTensor< T >::operator-= ( const TypeTensor< T2 > &  p)

Definition at line 918 of file type_tensor.h.

919{
920 this->subtract (p);
921
922 return *this;
923}
void subtract(const TypeTensor< T2 > &)
Subtract from this tensor without creating a temporary.

◆ operator/() [1/2]

template<typename T >
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< typenameCompareTypes< T, Scalar >::supertype > >::type libMesh::TypeTensor< T >::operator/ ( const Scalar &  ) const

Divide each entry of this tensor by a scalar value.

Returns
A copy of the result, this tensor is unchanged.

◆ operator/() [2/2]

template<typename T >
template<typename Scalar >
LIBMESH_DEVICE_INLINE std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< typenameCompareTypes< T, Scalar >::supertype > >::type libMesh::TypeTensor< T >::operator/ ( const Scalar &  factor) const

Definition at line 1035 of file type_tensor.h.

1036{
1037 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
1038
1039 typedef typename CompareTypes<T, Scalar>::supertype TS;
1040
1041#if LIBMESH_DIM == 1
1042 return TypeTensor<TS>(_coords[0]/factor);
1043#endif
1044
1045#if LIBMESH_DIM == 2
1046 return TypeTensor<TS>(_coords[0]/factor,
1047 _coords[1]/factor,
1048 _coords[2]/factor,
1049 _coords[3]/factor);
1050#endif
1051
1052#if LIBMESH_DIM == 3
1053 return TypeTensor<TS>(_coords[0]/factor,
1054 _coords[1]/factor,
1055 _coords[2]/factor,
1056 _coords[3]/factor,
1057 _coords[4]/factor,
1058 _coords[5]/factor,
1059 _coords[6]/factor,
1060 _coords[7]/factor,
1061 _coords[8]/factor);
1062#endif
1063
1064}

◆ operator/=()

template<typename T >
LIBMESH_DEVICE_INLINE const TypeTensor< T > & libMesh::TypeTensor< T >::operator/= ( const T &  factor)

Divide each entry of this tensor by a scalar value.

Returns
A reference to *this.

Definition at line 1200 of file type_tensor.h.

1201{
1202 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
1203
1204 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1205 _coords[i] /= factor;
1206
1207 return *this;
1208}

◆ operator<() [1/3]

bool libMesh::TypeTensor< Complex >::operator< ( const TypeTensor< Complex > &  rhs) const

Definition at line 157 of file type_tensor.C.

158{
159 for (unsigned int i=0; i<LIBMESH_DIM; i++)
160 for (unsigned int j=0; j<LIBMESH_DIM; j++)
161 {
162 if ((*this)(i,j).real() < rhs(i,j).real())
163 return true;
164 if ((*this)(i,j).real() > rhs(i,j).real())
165 return false;
166 if ((*this)(i,j).imag() < rhs(i,j).imag())
167 return true;
168 if ((*this)(i,j).imag() > rhs(i,j).imag())
169 return false;
170 }
171 return false;
172}
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

◆ operator<() [2/3]

bool libMesh::TypeTensor< Real >::operator< ( const TypeTensor< Real > &  rhs) const

Definition at line 124 of file type_tensor.C.

125{
126 for (unsigned int i=0; i<LIBMESH_DIM; i++)
127 for (unsigned int j=0; j<LIBMESH_DIM; j++)
128 {
129 if ((*this)(i,j) < rhs(i,j))
130 return true;
131 if ((*this)(i,j) > rhs(i,j))
132 return false;
133 }
134 return false;
135}

◆ operator<() [3/3]

template<typename T >
bool libMesh::TypeTensor< T >::operator< ( const TypeTensor< T > &  rhs) const
Returns
true if this tensor is "less" than another. Useful for sorting.

◆ operator=()

template<typename T >
template<typename Scalar >
LIBMESH_DEVICE_INLINE std::enable_if< ScalarTraits< Scalar >::value, TypeTensor & >::type libMesh::TypeTensor< T >::operator= ( const Scalar &  libmesh_dbg_varp)
inline

Assignment-from-scalar operator.

Used only to zero out vectors.

Returns
A reference to *this.

Definition at line 159 of file type_tensor.h.

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

References libMesh::TypeTensor< T >::zero().

◆ operator==()

template<typename T >
LIBMESH_DEVICE_INLINE bool libMesh::TypeTensor< T >::operator== ( const TypeTensor< T > &  rhs) const
Returns
true if two tensors are equal, false otherwise.

Definition at line 1381 of file type_tensor.h.

1382{
1383 using portable_math::abs;
1384
1385#if LIBMESH_DIM == 1
1386 return (abs(_coords[0] - rhs._coords[0])
1387 < TOLERANCE);
1388#endif
1389
1390#if LIBMESH_DIM == 2
1391 return ((abs(_coords[0] - rhs._coords[0]) +
1392 abs(_coords[1] - rhs._coords[1]) +
1393 abs(_coords[2] - rhs._coords[2]) +
1394 abs(_coords[3] - rhs._coords[3]))
1395 < 4.*TOLERANCE);
1396#endif
1397
1398#if LIBMESH_DIM == 3
1399 return ((abs(_coords[0] - rhs._coords[0]) +
1400 abs(_coords[1] - rhs._coords[1]) +
1401 abs(_coords[2] - rhs._coords[2]) +
1402 abs(_coords[3] - rhs._coords[3]) +
1403 abs(_coords[4] - rhs._coords[4]) +
1404 abs(_coords[5] - rhs._coords[5]) +
1405 abs(_coords[6] - rhs._coords[6]) +
1406 abs(_coords[7] - rhs._coords[7]) +
1407 abs(_coords[8] - rhs._coords[8]))
1408 < 9.*TOLERANCE);
1409#endif
1410
1411}
static constexpr Real TOLERANCE

References libMesh::TypeTensor< T >::_coords, and libMesh::TOLERANCE.

◆ operator>() [1/3]

bool libMesh::TypeTensor< Complex >::operator> ( const TypeTensor< Complex > &  rhs) const

Definition at line 177 of file type_tensor.C.

178{
179 for (unsigned int i=0; i<LIBMESH_DIM; i++)
180 for (unsigned int j=0; j<LIBMESH_DIM; j++)
181 {
182 if ((*this)(i,j).real() > rhs(i,j).real())
183 return true;
184 if ((*this)(i,j).real() < rhs(i,j).real())
185 return false;
186 if ((*this)(i,j).imag() > rhs(i,j).imag())
187 return true;
188 if ((*this)(i,j).imag() < rhs(i,j).imag())
189 return false;
190 }
191 return false;
192}

◆ operator>() [2/3]

bool libMesh::TypeTensor< Real >::operator> ( const TypeTensor< Real > &  rhs) const

Definition at line 140 of file type_tensor.C.

141{
142 for (unsigned int i=0; i<LIBMESH_DIM; i++)
143 for (unsigned int j=0; j<LIBMESH_DIM; j++)
144 {
145 if ((*this)(i,j) > rhs(i,j))
146 return true;
147 if ((*this)(i,j) < rhs(i,j))
148 return false;
149 }
150 return false;
151}

◆ operator>() [3/3]

template<typename T >
bool libMesh::TypeTensor< T >::operator> ( const TypeTensor< T > &  rhs) const
Returns
true if this tensor is "greater" than another.

◆ print()

template<typename T >
void libMesh::TypeTensor< T >::print ( std::ostream &  os = libMesh::out) const

Formatted print to a stream which defaults to libMesh::out.

Definition at line 1414 of file type_tensor.h.

1415{
1416#if LIBMESH_DIM == 1
1417
1418 os << "x=" << (*this)(0,0) << std::endl;
1419
1420#endif
1421#if LIBMESH_DIM == 2
1422
1423 os << "(xx,xy)=("
1424 << std::setw(8) << (*this)(0,0) << ", "
1425 << std::setw(8) << (*this)(0,1) << ")"
1426 << std::endl;
1427 os << "(yx,yy)=("
1428 << std::setw(8) << (*this)(1,0) << ", "
1429 << std::setw(8) << (*this)(1,1) << ")"
1430 << std::endl;
1431
1432#endif
1433#if LIBMESH_DIM == 3
1434
1435 os << "(xx,xy,xz)=("
1436 << std::setw(8) << (*this)(0,0) << ", "
1437 << std::setw(8) << (*this)(0,1) << ", "
1438 << std::setw(8) << (*this)(0,2) << ")"
1439 << std::endl;
1440 os << "(yx,yy,yz)=("
1441 << std::setw(8) << (*this)(1,0) << ", "
1442 << std::setw(8) << (*this)(1,1) << ", "
1443 << std::setw(8) << (*this)(1,2) << ")"
1444 << std::endl;
1445 os << "(zx,zy,zz)=("
1446 << std::setw(8) << (*this)(2,0) << ", "
1447 << std::setw(8) << (*this)(2,1) << ", "
1448 << std::setw(8) << (*this)(2,2) << ")"
1449 << std::endl;
1450#endif
1451}

◆ row()

template<typename T >
LIBMESH_DEVICE_INLINE TypeVector< T > libMesh::TypeTensor< T >::row ( const unsigned int  r) const
Returns
A copy of one row of the tensor as a TypeVector.

Definition at line 785 of file type_tensor.h.

786{
787 TypeVector<T> return_vector;
788
789 for (unsigned int j=0; j<LIBMESH_DIM; j++)
790 return_vector._coords[j] = _coords[r*LIBMESH_DIM + j];
791
792 return return_vector;
793}

References libMesh::TypeVector< T >::_coords.

Referenced by SolutionGradient< dim >::component(), SolutionGradient< dim >::operator()(), and TypeTensorTest::testRowCol().

◆ slice() [1/2]

template<typename T >
LIBMESH_DEVICE_INLINE TypeTensorColumn< T > libMesh::TypeTensor< T >::slice ( const unsigned int  i)
Returns
A writable proxy for the \( i^{th} \) column of the tensor.

Definition at line 775 of file type_tensor.h.

776{
777 libmesh_assert_less (i, LIBMESH_DIM);
778 return TypeTensorColumn<T>(*this, i);
779}

◆ slice() [2/2]

template<typename T >
LIBMESH_DEVICE_INLINE ConstTypeTensorColumn< T > libMesh::TypeTensor< T >::slice ( const unsigned int  i) const
Returns
A proxy for the \( i^{th} \) column of the tensor.

Definition at line 765 of file type_tensor.h.

766{
767 libmesh_assert_less (i, LIBMESH_DIM);
768 return ConstTypeTensorColumn<T>(*this, i);
769}

◆ solve()

template<typename T >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::solve ( const TypeVector< T > &  b,
TypeVector< T > &  x 
) const

Solve the 2x2 or 3x3 system of equations A*x = b for x by directly inverting A and multiplying it by b.

Returns
The solution in the x vector.

Definition at line 1149 of file type_tensor.h.

1150{
1151#if LIBMESH_DIM == 1
1152 if (_coords[0] == static_cast<T>(0.))
1153 libmesh_convergence_failure();
1154 x(0) = b(0) / _coords[0];
1155#endif
1156
1157#if LIBMESH_DIM == 2
1158 T my_det = _coords[0]*_coords[3] - _coords[1]*_coords[2];
1159
1160 if (my_det == static_cast<T>(0.))
1161 libmesh_convergence_failure();
1162
1163 T my_det_inv = 1./my_det;
1164
1165 x(0) = my_det_inv*( _coords[3]*b(0) - _coords[1]*b(1));
1166 x(1) = my_det_inv*(-_coords[2]*b(0) + _coords[0]*b(1));
1167#endif
1168
1169#if LIBMESH_DIM == 3
1170 T my_det =
1171 // a11*(a33 *a22 - a32 *a23)
1172 _coords[0]*(_coords[8]*_coords[4] - _coords[7]*_coords[5])
1173 // -a21*(a33 *a12 - a32 *a13)
1174 -_coords[3]*(_coords[8]*_coords[1] - _coords[7]*_coords[2]) +
1175 // +a31*(a23 *a12 - a22 *a13)
1176 +_coords[6]*(_coords[5]*_coords[1] - _coords[4]*_coords[2]);
1177
1178 if (my_det == static_cast<T>(0.))
1179 libmesh_convergence_failure();
1180
1181 T my_det_inv = 1./my_det;
1182 x(0) = my_det_inv*((_coords[8]*_coords[4] - _coords[7]*_coords[5])*b(0) -
1183 (_coords[8]*_coords[1] - _coords[7]*_coords[2])*b(1) +
1184 (_coords[5]*_coords[1] - _coords[4]*_coords[2])*b(2));
1185
1186 x(1) = my_det_inv*((_coords[6]*_coords[5] - _coords[8]*_coords[3])*b(0) +
1187 (_coords[8]*_coords[0] - _coords[6]*_coords[2])*b(1) -
1188 (_coords[5]*_coords[0] - _coords[3]*_coords[2])*b(2));
1189
1190 x(2) = my_det_inv*((_coords[7]*_coords[3] - _coords[6]*_coords[4])*b(0) -
1191 (_coords[7]*_coords[0] - _coords[6]*_coords[1])*b(1) +
1192 (_coords[4]*_coords[0] - _coords[3]*_coords[1])*b(2));
1193#endif
1194}

References b.

Referenced by InfFERadialTest::base_point(), and libMesh::InfFEMap::inverse_map().

◆ subtract() [1/2]

template<typename T >
template<typename T2 >
void libMesh::TypeTensor< T >::subtract ( const TypeTensor< T2 > &  )

Subtract from this tensor without creating a temporary.

◆ subtract() [2/2]

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::subtract ( const TypeTensor< T2 > &  p)

Definition at line 930 of file type_tensor.h.

931{
932 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
933 _coords[i] -= p._coords[i];
934}

References libMesh::TypeTensor< T >::_coords.

◆ subtract_scaled()

template<typename T >
template<typename T2 >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::subtract_scaled ( const TypeTensor< T2 > &  p,
const T &  factor 
)

Subtract a scaled value from this tensor without creating a temporary.

Definition at line 941 of file type_tensor.h.

942{
943 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
944 _coords[i] -= factor*p._coords[i];
945}

References libMesh::TypeTensor< T >::_coords.

Referenced by libMesh::HPCoarsenTest::select_refinement().

◆ tr()

template<typename T >
LIBMESH_DEVICE_INLINE T libMesh::TypeTensor< T >::tr ( ) const
Returns
The trace of the tensor.

Definition at line 1342 of file type_tensor.h.

1343{
1344#if LIBMESH_DIM == 1
1345 return _coords[0];
1346#endif
1347
1348#if LIBMESH_DIM == 2
1349 return _coords[0] + _coords[3];
1350#endif
1351
1352#if LIBMESH_DIM == 3
1353 return _coords[0] + _coords[4] + _coords[8];
1354#endif
1355}

◆ transpose()

template<typename T >
LIBMESH_DEVICE_INLINE TypeTensor< T > libMesh::TypeTensor< T >::transpose ( ) const

◆ write_unformatted()

template<typename T >
void libMesh::TypeTensor< T >::write_unformatted ( std::ostream &  out_stream,
const bool  newline = true 
) const

Unformatted print to the stream out.

Simply prints the elements of the tensor separated by spaces and newlines.

Definition at line 39 of file type_tensor.C.

41{
42 libmesh_assert (out_stream);
43
44 out_stream << std::setiosflags(std::ios::showpoint)
45 << (*this)(0,0) << " "
46 << (*this)(0,1) << " "
47 << (*this)(0,2) << " ";
48 if (newline)
49 out_stream << '\n';
50
51 out_stream << std::setiosflags(std::ios::showpoint)
52 << (*this)(1,0) << " "
53 << (*this)(1,1) << " "
54 << (*this)(1,2) << " ";
55 if (newline)
56 out_stream << '\n';
57
58 out_stream << std::setiosflags(std::ios::showpoint)
59 << (*this)(2,0) << " "
60 << (*this)(2,1) << " "
61 << (*this)(2,2) << " ";
62 if (newline)
63 out_stream << '\n';
64}
libmesh_assert(ctx)

References libMesh::libmesh_assert().

◆ zero()

template<typename T >
LIBMESH_DEVICE_INLINE void libMesh::TypeTensor< T >::zero ( )

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  os,
const TypeTensor< T > &  t 
)
friend

Formatted print as above but supports the syntax:

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

Definition at line 444 of file type_tensor.h.

445 {
446 t.print(os);
447 return os;
448 }

◆ TypeTensor

template<typename T >
template<typename T2 >
friend class TypeTensor
friend

Definition at line 56 of file type_tensor.h.

Member Data Documentation

◆ _coords

template<typename T >
T libMesh::TypeTensor< T >::_coords[LIBMESH_DIM *LIBMESH_DIM]
protected

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