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.
 
LIBMESH_DEVICE_INLINE ~TypeTensor ()
 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 536 of file type_tensor.h.

537{
538 _coords[0] = {};
539
540#if LIBMESH_DIM > 1
541 _coords[1] = {};
542 _coords[2] = {};
543 _coords[3] = {};
544#endif
545
546#if LIBMESH_DIM > 2
547 _coords[4] = {};
548 _coords[5] = {};
549 _coords[6] = {};
550 _coords[7] = {};
551 _coords[8] = {};
552#endif
553}
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 559 of file type_tensor.h.

568{
569 _coords[0] = xx;
570
571#if LIBMESH_DIM == 2
572 _coords[1] = xy;
573 _coords[2] = yx;
574 _coords[3] = yy;
575#elif LIBMESH_DIM == 1
576 libmesh_assert_equal_to (xy, 0);
577 libmesh_assert_equal_to (yx, 0);
578 libmesh_assert_equal_to (yy, 0);
579 libmesh_ignore(xy, yx, yy);
580#endif
581
582#if LIBMESH_DIM == 3
583 _coords[1] = xy;
584 _coords[2] = xz;
585 _coords[3] = yx;
586 _coords[4] = yy;
587 _coords[5] = yz;
588 _coords[6] = zx;
589 _coords[7] = zy;
590 _coords[8] = zz;
591#else
592 libmesh_assert_equal_to (xz, 0);
593 libmesh_assert_equal_to (yz, 0);
594 libmesh_assert_equal_to (zx, 0);
595 libmesh_assert_equal_to (zy, 0);
596 libmesh_assert_equal_to (zz, 0);
597 libmesh_ignore(xz, yz, zx, zy, zz);
598#endif
599}
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 665 of file type_tensor.h.

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

◆ 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 674 of file type_tensor.h.

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

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 691 of file type_tensor.h.

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

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_DEVICE_INLINE libMesh::TypeTensor< T >::~TypeTensor ( )

Destructor.

Definition at line 716 of file type_tensor.h.

717{
718}

◆ 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 605 of file type_tensor.h.

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

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 654 of file type_tensor.h.

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

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 869 of file type_tensor.h.

870{
871 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
872 _coords[i] += p._coords[i];
873}

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 725 of file type_tensor.h.

726{
727 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
728 _coords[i] = p._coords[i];
729}

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 808 of file type_tensor.h.

809{
810 TypeVector<T> return_vector;
811
812 for (unsigned int i=0; i<LIBMESH_DIM; i++)
813 return_vector._coords[i] = _coords[i*LIBMESH_DIM + r];
814
815 return return_vector;
816}

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 1297 of file type_tensor.h.

1298{
1299 typename CompareTypes<T,T2>::supertype sum = 0.;
1300 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1301 sum += _coords[i]*t._coords[i];
1302 return sum;
1303}

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 1328 of file type_tensor.h.

1329{
1330#if LIBMESH_DIM == 1
1331 return _coords[0];
1332#endif
1333
1334#if LIBMESH_DIM == 2
1335 return (_coords[0] * _coords[3]
1336 - _coords[1] * _coords[2]);
1337#endif
1338
1339#if LIBMESH_DIM == 3
1340 return (_coords[0] * _coords[4] * _coords[8]
1341 + _coords[1] * _coords[5] * _coords[6]
1342 + _coords[2] * _coords[3] * _coords[7]
1343 - _coords[0] * _coords[5] * _coords[7]
1344 - _coords[1] * _coords[3] * _coords[8]
1345 - _coords[2] * _coords[4] * _coords[6]);
1346#endif
1347}

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 1109 of file type_tensor.h.

1110{
1111#if LIBMESH_DIM == 1
1112 if (_coords[0] == static_cast<T>(0.))
1113 libmesh_convergence_failure();
1114 return TypeTensor(1. / _coords[0]);
1115#endif
1116
1117#if LIBMESH_DIM == 2
1118 // Get convenient reference to this.
1119 const TypeTensor<T> & A = *this;
1120
1121 // Use temporary variables, avoid multiple accesses
1122 T a = A(0,0), b = A(0,1),
1123 c = A(1,0), d = A(1,1);
1124
1125 // Make sure det = ad - bc is not zero
1126 T my_det = a*d - b*c;
1127
1128 if (my_det == static_cast<T>(0.))
1129 libmesh_convergence_failure();
1130
1131 return TypeTensor(d/my_det, -b/my_det, -c/my_det, a/my_det);
1132#endif
1133
1134#if LIBMESH_DIM == 3
1135 // Get convenient reference to this.
1136 const TypeTensor<T> & A = *this;
1137
1138 T a11 = A(0,0), a12 = A(0,1), a13 = A(0,2),
1139 a21 = A(1,0), a22 = A(1,1), a23 = A(1,2),
1140 a31 = A(2,0), a32 = A(2,1), a33 = A(2,2);
1141
1142 T my_det = a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
1143
1144 if (my_det == static_cast<T>(0.))
1145 libmesh_convergence_failure();
1146
1147 // Inline comment characters are for lining up columns.
1148 return TypeTensor( (a33*a22-a32*a23)/my_det, -(a33*a12-a32*a13)/my_det, (a23*a12-a22*a13)/my_det,
1149 -(a33*a21-a31*a23)/my_det, (a33*a11-a31*a13)/my_det, -(a23*a11-a21*a13)/my_det,
1150 (a32*a21-a31*a22)/my_det, -(a32*a11-a31*a12)/my_det, (a22*a11-a21*a12)/my_det);
1151#endif
1152}
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 1318 of file type_tensor.h.

1319{
1320 for (const auto & val : _coords)
1321 if (val != T(0))
1322 return false;
1323 return true;
1324}

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 1240 of file type_tensor.h.

1241{
1242 TypeVector<typename CompareTypes<T,T2>::supertype> returnval;
1243 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1244 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1245 returnval(i) += p(j)*(*this)(j,i);
1246
1247 return returnval;
1248}

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 1309 of file type_tensor.h.

1310{
1311 using std::sqrt;
1312 return sqrt(this->norm_sq());
1313}
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 1378 of file type_tensor.h.

1379{
1380 Real sum = 0.;
1381 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1382 sum += TensorTools::norm_sq(_coords[i]);
1383 return sum;
1384}
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 754 of file type_tensor.h.

756{
757#if LIBMESH_DIM < 3
758
759 libmesh_error_msg_if(i >= LIBMESH_DIM || j >= LIBMESH_DIM,
760 "ERROR: You are assigning to a tensor component that is out of range for the compiled LIBMESH_DIM!");
761
762#endif
763
764 libmesh_assert_less (i, LIBMESH_DIM);
765 libmesh_assert_less (j, LIBMESH_DIM);
766
767 return _coords[i*LIBMESH_DIM+j];
768}

◆ 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 735 of file type_tensor.h.

737{
738 libmesh_assert_less (i, 3);
739 libmesh_assert_less (j, 3);
740
741#if LIBMESH_DIM < 3
742 const static T my_zero = 0;
743 if (i >= LIBMESH_DIM || j >= LIBMESH_DIM)
744 return my_zero;
745#endif
746
747 return _coords[i*LIBMESH_DIM+j];
748}

◆ 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 994 of file type_tensor.h.

997{
998 typedef decltype((*this)(0, 0) * factor) TS;
999
1000
1001#if LIBMESH_DIM == 1
1002 return TypeTensor<TS>(_coords[0]*factor);
1003#endif
1004
1005#if LIBMESH_DIM == 2
1006 return TypeTensor<TS>(_coords[0]*factor,
1007 _coords[1]*factor,
1008 _coords[2]*factor,
1009 _coords[3]*factor);
1010#endif
1011
1012#if LIBMESH_DIM == 3
1013 return TypeTensor<TS>(_coords[0]*factor,
1014 _coords[1]*factor,
1015 _coords[2]*factor,
1016 _coords[3]*factor,
1017 _coords[4]*factor,
1018 _coords[5]*factor,
1019 _coords[6]*factor,
1020 _coords[7]*factor,
1021 _coords[8]*factor);
1022#endif
1023}

◆ 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 1262 of file type_tensor.h.

1263{
1264 TypeTensor<typename CompareTypes<T, T2>::supertype> returnval;
1265 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1266 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1267 for (unsigned int k=0; k<LIBMESH_DIM; k++)
1268 returnval(i,j) += (*this)(i,k)*p(k,j);
1269
1270 return returnval;
1271}

◆ 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 1226 of file type_tensor.h.

1227{
1228 TypeVector<typename CompareTypes<T,T2>::supertype> returnval;
1229 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1230 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1231 returnval(i) += (*this)(i,j)*p(j);
1232
1233 return returnval;
1234}

◆ 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 281 of file type_tensor.h.

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

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 1276 of file type_tensor.h.

1277{
1278 TypeTensor<T> temp;
1279 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1280 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1281 for (unsigned int k=0; k<LIBMESH_DIM; k++)
1282 temp(i,j) += (*this)(i,k)*p(k,j);
1283
1284 this->assign(temp);
1285 return *this;
1286}
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 823 of file type_tensor.h.

824{
825
826#if LIBMESH_DIM == 1
827 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0]);
828#endif
829
830#if LIBMESH_DIM == 2
831 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0],
832 _coords[1] + p._coords[1],
833 0.,
834 _coords[2] + p._coords[2],
835 _coords[3] + p._coords[3]);
836#endif
837
838#if LIBMESH_DIM == 3
839 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0],
840 _coords[1] + p._coords[1],
841 _coords[2] + p._coords[2],
842 _coords[3] + p._coords[3],
843 _coords[4] + p._coords[4],
844 _coords[5] + p._coords[5],
845 _coords[6] + p._coords[6],
846 _coords[7] + p._coords[7],
847 _coords[8] + p._coords[8]);
848#endif
849
850}

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 857 of file type_tensor.h.

858{
859 this->add (p);
860
861 return *this;
862}
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 960 of file type_tensor.h.

961{
962
963#if LIBMESH_DIM == 1
964 return TypeTensor(-_coords[0]);
965#endif
966
967#if LIBMESH_DIM == 2
968 return TypeTensor(-_coords[0],
969 -_coords[1],
970 -_coords[2],
971 -_coords[3]);
972#endif
973
974#if LIBMESH_DIM == 3
975 return TypeTensor(-_coords[0],
976 -_coords[1],
977 -_coords[2],
978 -_coords[3],
979 -_coords[4],
980 -_coords[5],
981 -_coords[6],
982 -_coords[7],
983 -_coords[8]);
984#endif
985
986}

◆ 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 893 of file type_tensor.h.

894{
895
896#if LIBMESH_DIM == 1
897 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0]);
898#endif
899
900#if LIBMESH_DIM == 2
901 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0],
902 _coords[1] - p._coords[1],
903 0.,
904 _coords[2] - p._coords[2],
905 _coords[3] - p._coords[3]);
906#endif
907
908#if LIBMESH_DIM == 3
909 return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0],
910 _coords[1] - p._coords[1],
911 _coords[2] - p._coords[2],
912 _coords[3] - p._coords[3],
913 _coords[4] - p._coords[4],
914 _coords[5] - p._coords[5],
915 _coords[6] - p._coords[6],
916 _coords[7] - p._coords[7],
917 _coords[8] - p._coords[8]);
918#endif
919
920}

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 927 of file type_tensor.h.

928{
929 this->subtract (p);
930
931 return *this;
932}
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 1044 of file type_tensor.h.

1045{
1046 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
1047
1048 typedef typename CompareTypes<T, Scalar>::supertype TS;
1049
1050#if LIBMESH_DIM == 1
1051 return TypeTensor<TS>(_coords[0]/factor);
1052#endif
1053
1054#if LIBMESH_DIM == 2
1055 return TypeTensor<TS>(_coords[0]/factor,
1056 _coords[1]/factor,
1057 _coords[2]/factor,
1058 _coords[3]/factor);
1059#endif
1060
1061#if LIBMESH_DIM == 3
1062 return TypeTensor<TS>(_coords[0]/factor,
1063 _coords[1]/factor,
1064 _coords[2]/factor,
1065 _coords[3]/factor,
1066 _coords[4]/factor,
1067 _coords[5]/factor,
1068 _coords[6]/factor,
1069 _coords[7]/factor,
1070 _coords[8]/factor);
1071#endif
1072
1073}

◆ 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 1209 of file type_tensor.h.

1210{
1211 libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
1212
1213 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1214 _coords[i] /= factor;
1215
1216 return *this;
1217}

◆ 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 160 of file type_tensor.h.

161 { 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 1390 of file type_tensor.h.

1391{
1392#if LIBMESH_DIM == 1
1393 return (std::abs(_coords[0] - rhs._coords[0])
1394 < TOLERANCE);
1395#endif
1396
1397#if LIBMESH_DIM == 2
1398 return ((std::abs(_coords[0] - rhs._coords[0]) +
1399 std::abs(_coords[1] - rhs._coords[1]) +
1400 std::abs(_coords[2] - rhs._coords[2]) +
1401 std::abs(_coords[3] - rhs._coords[3]))
1402 < 4.*TOLERANCE);
1403#endif
1404
1405#if LIBMESH_DIM == 3
1406 return ((std::abs(_coords[0] - rhs._coords[0]) +
1407 std::abs(_coords[1] - rhs._coords[1]) +
1408 std::abs(_coords[2] - rhs._coords[2]) +
1409 std::abs(_coords[3] - rhs._coords[3]) +
1410 std::abs(_coords[4] - rhs._coords[4]) +
1411 std::abs(_coords[5] - rhs._coords[5]) +
1412 std::abs(_coords[6] - rhs._coords[6]) +
1413 std::abs(_coords[7] - rhs._coords[7]) +
1414 std::abs(_coords[8] - rhs._coords[8]))
1415 < 9.*TOLERANCE);
1416#endif
1417
1418}
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 1421 of file type_tensor.h.

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

◆ 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 794 of file type_tensor.h.

795{
796 TypeVector<T> return_vector;
797
798 for (unsigned int j=0; j<LIBMESH_DIM; j++)
799 return_vector._coords[j] = _coords[r*LIBMESH_DIM + j];
800
801 return return_vector;
802}

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 784 of file type_tensor.h.

785{
786 libmesh_assert_less (i, LIBMESH_DIM);
787 return TypeTensorColumn<T>(*this, i);
788}

◆ 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 774 of file type_tensor.h.

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

◆ 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 1158 of file type_tensor.h.

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

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 939 of file type_tensor.h.

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

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 950 of file type_tensor.h.

951{
952 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
953 _coords[i] -= factor*p._coords[i];
954}

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 1351 of file type_tensor.h.

1352{
1353#if LIBMESH_DIM == 1
1354 return _coords[0];
1355#endif
1356
1357#if LIBMESH_DIM == 2
1358 return _coords[0] + _coords[3];
1359#endif
1360
1361#if LIBMESH_DIM == 3
1362 return _coords[0] + _coords[4] + _coords[8];
1363#endif
1364}

◆ 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 445 of file type_tensor.h.

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

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