libMesh
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 <tensor_tools.h>

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

Public Types

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

Public Member Functions

 TypeTensor ()
 Empty constructor. More...
 
template<typename T2 >
 TypeTensor (const TypeTensor< T2 > &p)
 Copy-constructor. More...
 
 ~TypeTensor ()
 Destructor. More...
 
template<typename T2 >
void assign (const TypeTensor< T2 > &)
 Assign to this tensor without creating a temporary. More...
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeTensor & >::type operator= (const Scalar &libmesh_dbg_var(p))
 Assignment-from-scalar operator. More...
 
const T & operator() (const unsigned int i, const unsigned int j) const
 
T & operator() (const unsigned int i, const unsigned int j)
 
ConstTypeTensorColumn< T > slice (const unsigned int i) const
 
TypeTensorColumn< T > slice (const unsigned int i)
 
TypeVector< T > row (const unsigned int r) const
 
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. More...
 
template<typename T2 >
const TypeTensor< T > & operator+= (const TypeTensor< T2 > &)
 Add to this tensor. More...
 
template<typename T2 >
void add (const TypeTensor< T2 > &)
 Add to this tensor without creating a temporary. More...
 
template<typename T2 >
void add_scaled (const TypeTensor< T2 > &, const T &)
 Add a scaled tensor to this tensor without creating a temporary. More...
 
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > operator- (const TypeTensor< T2 > &) const
 Subtract a tensor from this tensor. More...
 
template<typename T2 >
const TypeTensor< T > & operator-= (const TypeTensor< T2 > &)
 Subtract from this tensor. More...
 
template<typename T2 >
void subtract (const TypeTensor< T2 > &)
 Subtract from this tensor without creating a temporary. More...
 
template<typename T2 >
void subtract_scaled (const TypeTensor< T2 > &, const T &)
 Subtract a scaled value from this tensor without creating a temporary. More...
 
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. More...
 
template<typename Scalar , typename std::enable_if< ScalarTraits< Scalar >::value, int >::type = 0>
const TypeTensor< T > & operator*= (const Scalar &factor)
 Multiply this tensor by a scalar value in place. More...
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TypeTensor< typename CompareTypes< T, Scalar >::supertype > >::type operator/ (const Scalar &) const
 Divide each entry of this tensor by a scalar value. More...
 
const TypeTensor< T > & operator/= (const T &)
 Divide each entry of this tensor by a scalar value. More...
 
template<typename T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > operator* (const TypeTensor< T2 > &) const
 Multiply 2 tensors together, i.e. More...
 
template<typename T2 >
const TypeTensor< T > & operator*= (const TypeTensor< T2 > &)
 Multiply this tensor by a tensor value in place. More...
 
template<typename T2 >
CompareTypes< T, T2 >::supertype contract (const TypeTensor< T2 > &) const
 Multiply 2 tensors together to return a scalar, i.e. More...
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > operator* (const TypeVector< T2 > &) const
 Right-multiply this tensor by a vector, i.e. More...
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > left_multiply (const TypeVector< T2 > &p) const
 Left-multiply this tensor by a vector, i.e. More...
 
TypeTensor< T > transpose () const
 
TypeTensor< T > inverse () const
 
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. More...
 
auto norm () const
 
auto norm_sq () const
 
bool is_zero () const
 
det () const
 
tr () const
 
void zero ()
 Set all entries of the tensor to 0. More...
 
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. More...
 
void write_unformatted (std::ostream &out_stream, const bool newline=true) const
 Unformatted print to the stream out. More...
 
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. More...
 
template<>
bool operator< (const TypeTensor< Real > &rhs) const
 
template<>
bool operator> (const TypeTensor< Real > &rhs) const
 
template<>
bool operator< (const TypeTensor< Complex > &rhs) const
 
template<>
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. More...
 
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. More...
 
template<typename T2 >
 TypeTensor (const TypeVector< T2 > &vx)
 Constructor. More...
 
template<typename T2 >
 TypeTensor (const TypeVector< T2 > &vx, const TypeVector< T2 > &vy)
 
template<typename T2 >
 TypeTensor (const TypeVector< T2 > &vx, const TypeVector< T2 > &vy, const TypeVector< T2 > &vz)
 

Protected Attributes

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

Friends

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

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 36 of file tensor_tools.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 125 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 120 of file type_tensor.h.

Constructor & Destructor Documentation

◆ TypeTensor() [1/7]

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

Empty constructor.

Gives the tensor 0 in LIBMESH_DIM dimensions.

Definition at line 517 of file type_tensor.h.

518 {
519  _coords[0] = {};
520 
521 #if LIBMESH_DIM > 1
522  _coords[1] = {};
523  _coords[2] = {};
524  _coords[3] = {};
525 #endif
526 
527 #if LIBMESH_DIM > 2
528  _coords[4] = {};
529  _coords[5] = {};
530  _coords[6] = {};
531  _coords[7] = {};
532  _coords[8] = {};
533 #endif
534 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ TypeTensor() [2/7]

template<typename T >
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 
)
inlineexplicitprotected

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

References libMesh::libmesh_ignore().

549 {
550  _coords[0] = xx;
551 
552 #if LIBMESH_DIM == 2
553  _coords[1] = xy;
554  _coords[2] = yx;
555  _coords[3] = yy;
556 #elif LIBMESH_DIM == 1
557  libmesh_assert_equal_to (xy, 0);
558  libmesh_assert_equal_to (yx, 0);
559  libmesh_assert_equal_to (yy, 0);
560  libmesh_ignore(xy, yx, yy);
561 #endif
562 
563 #if LIBMESH_DIM == 3
564  _coords[1] = xy;
565  _coords[2] = xz;
566  _coords[3] = yx;
567  _coords[4] = yy;
568  _coords[5] = yz;
569  _coords[6] = zx;
570  _coords[7] = zy;
571  _coords[8] = zz;
572 #else
573  libmesh_assert_equal_to (xz, 0);
574  libmesh_assert_equal_to (yz, 0);
575  libmesh_assert_equal_to (zx, 0);
576  libmesh_assert_equal_to (zy, 0);
577  libmesh_assert_equal_to (zz, 0);
578  libmesh_ignore(xz, yz, zx, zy, zz);
579 #endif
580 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
void libmesh_ignore(const Args &...)

◆ TypeTensor() [3/7]

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

Constructor-from-Scalar.

Definition at line 586 of file type_tensor.h.

References libMesh::libmesh_ignore().

597 {
598  _coords[0] = xx;
599 
600 #if LIBMESH_DIM == 2
601  _coords[1] = xy;
602  _coords[2] = yx;
603  _coords[3] = yy;
604 #elif LIBMESH_DIM == 1
605  libmesh_assert_equal_to (xy, 0);
606  libmesh_assert_equal_to (yx, 0);
607  libmesh_assert_equal_to (yy, 0);
608  libmesh_ignore(xy, yx, yy);
609 #endif
610 
611 #if LIBMESH_DIM == 3
612  _coords[1] = xy;
613  _coords[2] = xz;
614  _coords[3] = yx;
615  _coords[4] = yy;
616  _coords[5] = yz;
617  _coords[6] = zx;
618  _coords[7] = zy;
619  _coords[8] = zz;
620 #else
621  libmesh_assert_equal_to (xz, 0);
622  libmesh_assert_equal_to (yz, 0);
623  libmesh_assert_equal_to (zx, 0);
624  libmesh_assert_equal_to (zy, 0);
625  libmesh_assert_equal_to (zz, 0);
626  libmesh_ignore(xz, yz, zx, zy, zz);
627 #endif
628 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
void libmesh_ignore(const Args &...)

◆ TypeTensor() [4/7]

template<typename T >
template<typename T2 >
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 645 of file type_tensor.h.

646 {
647  libmesh_assert_equal_to (LIBMESH_DIM, 1);
648  _coords[0] = vx(0);
649 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ TypeTensor() [5/7]

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

Definition at line 653 of file type_tensor.h.

References libMesh::libmesh_ignore().

655 {
656  libmesh_assert_equal_to (LIBMESH_DIM, 2);
657 #if LIBMESH_DIM > 1
658  _coords[0] = vx(0);
659  _coords[1] = vx(1);
660  _coords[2] = vy(0);
661  _coords[3] = vy(1);
662 #else
663  libmesh_ignore(vx, vy);
664 #endif
665 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
void libmesh_ignore(const Args &...)

◆ TypeTensor() [6/7]

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

Definition at line 669 of file type_tensor.h.

References libMesh::libmesh_ignore().

672 {
673  libmesh_assert_equal_to (LIBMESH_DIM, 3);
674 #if LIBMESH_DIM > 2
675  _coords[0] = vx(0);
676  _coords[1] = vx(1);
677  _coords[2] = vx(2);
678  _coords[3] = vy(0);
679  _coords[4] = vy(1);
680  _coords[5] = vy(2);
681  _coords[6] = vz(0);
682  _coords[7] = vz(1);
683  _coords[8] = vz(2);
684 #else
685  libmesh_ignore(vx, vy, vz);
686 #endif
687 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
void libmesh_ignore(const Args &...)

◆ TypeTensor() [7/7]

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

Copy-constructor.

Definition at line 635 of file type_tensor.h.

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

636 {
637  // copy the nodes from vector p to me
638  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
639  _coords[i] = p._coords[i];
640 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ ~TypeTensor()

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

Destructor.

Definition at line 694 of file type_tensor.h.

695 {
696 }

Member Function Documentation

◆ add()

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

Add to this tensor without creating a temporary.

Definition at line 847 of file type_tensor.h.

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

848 {
849  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
850  _coords[i] += p._coords[i];
851 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ add_scaled()

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

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

Definition at line 858 of file type_tensor.h.

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

Referenced by libMesh::HPCoarsenTest::add_projection(), LinearElasticityWithContact::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::MeshFunction::hessian(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::System::point_hessian(), and libMesh::HPCoarsenTest::select_refinement().

859 {
860  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
861  _coords[i] += factor*p._coords[i];
862 
863 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ assign()

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

Assign to this tensor without creating a temporary.

Definition at line 703 of file type_tensor.h.

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

704 {
705  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
706  _coords[i] = p._coords[i];
707 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ column()

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

Definition at line 786 of file type_tensor.h.

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

Referenced by TypeTensorTest::testRowCol().

787 {
788  TypeVector<T> return_vector;
789 
790  for (unsigned int i=0; i<LIBMESH_DIM; i++)
791  return_vector._coords[i] = _coords[i*LIBMESH_DIM + r];
792 
793  return return_vector;
794 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ contract()

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

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

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().

1276 {
1277  typename CompareTypes<T,T2>::supertype sum = 0.;
1278  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1279  sum += _coords[i]*t._coords[i];
1280  return sum;
1281 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ det()

template<typename T >
T libMesh::TypeTensor< T >::det ( ) const
inline
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 1306 of file type_tensor.h.

Referenced by libMesh::VariationalSmootherSystem::compute_mesh_quality_info(), LargeDeformationElasticity::compute_stresses(), libMesh::VariationalSmootherSystem::element_time_derivative(), libMesh::Hex::quality(), and libMesh::Sphere::Sphere().

1307 {
1308 #if LIBMESH_DIM == 1
1309  return _coords[0];
1310 #endif
1311 
1312 #if LIBMESH_DIM == 2
1313  return (_coords[0] * _coords[3]
1314  - _coords[1] * _coords[2]);
1315 #endif
1316 
1317 #if LIBMESH_DIM == 3
1318  return (_coords[0] * _coords[4] * _coords[8]
1319  + _coords[1] * _coords[5] * _coords[6]
1320  + _coords[2] * _coords[3] * _coords[7]
1321  - _coords[0] * _coords[5] * _coords[7]
1322  - _coords[1] * _coords[3] * _coords[8]
1323  - _coords[2] * _coords[4] * _coords[6]);
1324 #endif
1325 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ inverse()

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

Definition at line 1087 of file type_tensor.h.

References b.

Referenced by NonlinearNeoHookeCurrentConfig::calculate_stress(), libMesh::VariationalSmootherSystem::element_time_derivative(), libMesh::VariationalSmootherSystem::get_target_to_reference_jacobian(), and TypeTensorTest::testInverse().

1088 {
1089 #if LIBMESH_DIM == 1
1090  if (_coords[0] == static_cast<T>(0.))
1091  libmesh_convergence_failure();
1092  return TypeTensor(1. / _coords[0]);
1093 #endif
1094 
1095 #if LIBMESH_DIM == 2
1096  // Get convenient reference to this.
1097  const TypeTensor<T> & A = *this;
1098 
1099  // Use temporary variables, avoid multiple accesses
1100  T a = A(0,0), b = A(0,1),
1101  c = A(1,0), d = A(1,1);
1102 
1103  // Make sure det = ad - bc is not zero
1104  T my_det = a*d - b*c;
1105 
1106  if (my_det == static_cast<T>(0.))
1107  libmesh_convergence_failure();
1108 
1109  return TypeTensor(d/my_det, -b/my_det, -c/my_det, a/my_det);
1110 #endif
1111 
1112 #if LIBMESH_DIM == 3
1113  // Get convenient reference to this.
1114  const TypeTensor<T> & A = *this;
1115 
1116  T a11 = A(0,0), a12 = A(0,1), a13 = A(0,2),
1117  a21 = A(1,0), a22 = A(1,1), a23 = A(1,2),
1118  a31 = A(2,0), a32 = A(2,1), a33 = A(2,2);
1119 
1120  T my_det = a11*(a33*a22-a32*a23) - a21*(a33*a12-a32*a13) + a31*(a23*a12-a22*a13);
1121 
1122  if (my_det == static_cast<T>(0.))
1123  libmesh_convergence_failure();
1124 
1125  // Inline comment characters are for lining up columns.
1126  return TypeTensor( (a33*a22-a32*a23)/my_det, -(a33*a12-a32*a13)/my_det, (a23*a12-a22*a13)/my_det,
1127  -(a33*a21-a31*a23)/my_det, (a33*a11-a31*a13)/my_det, -(a23*a11-a21*a13)/my_det,
1128  (a32*a21-a31*a22)/my_det, -(a32*a11-a31*a12)/my_det, (a22*a11-a21*a12)/my_det);
1129 #endif
1130 }
TypeTensor()
Empty constructor.
Definition: type_tensor.h:517
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
static const Real b

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

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

Referenced by TypeTensorTest::testIsHPD().

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 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
T libmesh_conj(T a)
auto norm() const
Definition: type_tensor.h:1287

◆ is_zero()

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

Definition at line 1296 of file type_tensor.h.

Referenced by TypeTensorTest::testIsZero().

1297 {
1298  for (const auto & val : _coords)
1299  if (val != T(0))
1300  return false;
1301  return true;
1302 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ left_multiply()

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

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

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

◆ norm()

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

Definition at line 1287 of file type_tensor.h.

References libMesh::TensorTools::norm_sq().

1288 {
1289  using std::sqrt;
1290  return sqrt(this->norm_sq());
1291 }
auto norm_sq() const
Definition: type_tensor.h:1356

◆ norm_sq()

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

Definition at line 1356 of file type_tensor.h.

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

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

1357 {
1358  Real sum = 0.;
1359  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1360  sum += TensorTools::norm_sq(_coords[i]);
1361  return sum;
1362 }
auto norm_sq(const T &a)
Definition: tensor_tools.h:104
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

◆ operator()() [1/2]

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

Definition at line 713 of file type_tensor.h.

715 {
716  libmesh_assert_less (i, 3);
717  libmesh_assert_less (j, 3);
718 
719 #if LIBMESH_DIM < 3
720  const static T my_zero = 0;
721  if (i >= LIBMESH_DIM || j >= LIBMESH_DIM)
722  return my_zero;
723 #endif
724 
725  return _coords[i*LIBMESH_DIM+j];
726 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator()() [2/2]

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

Definition at line 732 of file type_tensor.h.

734 {
735 #if LIBMESH_DIM < 3
736 
737  libmesh_error_msg_if(i >= LIBMESH_DIM || j >= LIBMESH_DIM,
738  "ERROR: You are assigning to a tensor component that is out of range for the compiled LIBMESH_DIM!");
739 
740 #endif
741 
742  libmesh_assert_less (i, LIBMESH_DIM);
743  libmesh_assert_less (j, LIBMESH_DIM);
744 
745  return _coords[i*LIBMESH_DIM+j];
746 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator*() [1/3]

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
inline

Multiply this tensor by a scalar value.

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

Definition at line 972 of file type_tensor.h.

975 {
976  typedef decltype((*this)(0, 0) * factor) TS;
977 
978 
979 #if LIBMESH_DIM == 1
980  return TypeTensor<TS>(_coords[0]*factor);
981 #endif
982 
983 #if LIBMESH_DIM == 2
984  return TypeTensor<TS>(_coords[0]*factor,
985  _coords[1]*factor,
986  _coords[2]*factor,
987  _coords[3]*factor);
988 #endif
989 
990 #if LIBMESH_DIM == 3
991  return TypeTensor<TS>(_coords[0]*factor,
992  _coords[1]*factor,
993  _coords[2]*factor,
994  _coords[3]*factor,
995  _coords[4]*factor,
996  _coords[5]*factor,
997  _coords[6]*factor,
998  _coords[7]*factor,
999  _coords[8]*factor);
1000 #endif
1001 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator*() [2/3]

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

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.

Definition at line 1240 of file type_tensor.h.

1241 {
1242  TypeTensor<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  for (unsigned int k=0; k<LIBMESH_DIM; k++)
1246  returnval(i,j) += (*this)(i,k)*p(k,j);
1247 
1248  return returnval;
1249 }

◆ operator*() [3/3]

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

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.

Definition at line 1204 of file type_tensor.h.

1205 {
1206  TypeVector<typename CompareTypes<T,T2>::supertype> returnval;
1207  for (unsigned int i=0; i<LIBMESH_DIM; i++)
1208  for (unsigned int j=0; j<LIBMESH_DIM; j++)
1209  returnval(i) += (*this)(i,j)*p(j);
1210 
1211  return returnval;
1212 }

◆ operator*=() [1/2]

template<typename T>
template<typename Scalar , typename std::enable_if< ScalarTraits< Scalar >::value, int >::type = 0>
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 268 of file type_tensor.h.

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

269  {
270  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
271  _coords[i] *= factor;
272 
273  return *this;
274  }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator*=() [2/2]

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

Multiply this tensor by a tensor value in place.

Returns
A reference to *this

Definition at line 1254 of file type_tensor.h.

1255 {
1256  TypeTensor<T> temp;
1257  for (unsigned int i=0; i<LIBMESH_DIM; i++)
1258  for (unsigned int j=0; j<LIBMESH_DIM; j++)
1259  for (unsigned int k=0; k<LIBMESH_DIM; k++)
1260  temp(i,j) += (*this)(i,k)*p(k,j);
1261 
1262  this->assign(temp);
1263  return *this;
1264 }
void assign(const TypeTensor< T2 > &)
Assign to this tensor without creating a temporary.
Definition: type_tensor.h:703

◆ operator+()

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

Add another tensor to this tensor.

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

Definition at line 801 of file type_tensor.h.

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

802 {
803 
804 #if LIBMESH_DIM == 1
805  return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0]);
806 #endif
807 
808 #if LIBMESH_DIM == 2
809  return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0],
810  _coords[1] + p._coords[1],
811  0.,
812  _coords[2] + p._coords[2],
813  _coords[3] + p._coords[3]);
814 #endif
815 
816 #if LIBMESH_DIM == 3
817  return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] + p._coords[0],
818  _coords[1] + p._coords[1],
819  _coords[2] + p._coords[2],
820  _coords[3] + p._coords[3],
821  _coords[4] + p._coords[4],
822  _coords[5] + p._coords[5],
823  _coords[6] + p._coords[6],
824  _coords[7] + p._coords[7],
825  _coords[8] + p._coords[8]);
826 #endif
827 
828 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator+=()

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

Add to this tensor.

Returns
A reference to *this.

Definition at line 835 of file type_tensor.h.

836 {
837  this->add (p);
838 
839  return *this;
840 }
void add(const TypeTensor< T2 > &)
Add to this tensor without creating a temporary.
Definition: type_tensor.h:847

◆ operator-() [1/2]

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

Subtract a tensor from this tensor.

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

Definition at line 871 of file type_tensor.h.

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

872 {
873 
874 #if LIBMESH_DIM == 1
875  return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0]);
876 #endif
877 
878 #if LIBMESH_DIM == 2
879  return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0],
880  _coords[1] - p._coords[1],
881  0.,
882  _coords[2] - p._coords[2],
883  _coords[3] - p._coords[3]);
884 #endif
885 
886 #if LIBMESH_DIM == 3
887  return TypeTensor<typename CompareTypes<T, T2>::supertype>(_coords[0] - p._coords[0],
888  _coords[1] - p._coords[1],
889  _coords[2] - p._coords[2],
890  _coords[3] - p._coords[3],
891  _coords[4] - p._coords[4],
892  _coords[5] - p._coords[5],
893  _coords[6] - p._coords[6],
894  _coords[7] - p._coords[7],
895  _coords[8] - p._coords[8]);
896 #endif
897 
898 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator-() [2/2]

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

Definition at line 938 of file type_tensor.h.

939 {
940 
941 #if LIBMESH_DIM == 1
942  return TypeTensor(-_coords[0]);
943 #endif
944 
945 #if LIBMESH_DIM == 2
946  return TypeTensor(-_coords[0],
947  -_coords[1],
948  -_coords[2],
949  -_coords[3]);
950 #endif
951 
952 #if LIBMESH_DIM == 3
953  return TypeTensor(-_coords[0],
954  -_coords[1],
955  -_coords[2],
956  -_coords[3],
957  -_coords[4],
958  -_coords[5],
959  -_coords[6],
960  -_coords[7],
961  -_coords[8]);
962 #endif
963 
964 }
TypeTensor()
Empty constructor.
Definition: type_tensor.h:517
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator-=()

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

Subtract from this tensor.

Returns
A reference to *this.

Definition at line 905 of file type_tensor.h.

906 {
907  this->subtract (p);
908 
909  return *this;
910 }
void subtract(const TypeTensor< T2 > &)
Subtract from this tensor without creating a temporary.
Definition: type_tensor.h:917

◆ operator/()

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

Divide each entry of this tensor by a scalar value.

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

Definition at line 1022 of file type_tensor.h.

1023 {
1024  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
1025 
1026  typedef typename CompareTypes<T, Scalar>::supertype TS;
1027 
1028 #if LIBMESH_DIM == 1
1029  return TypeTensor<TS>(_coords[0]/factor);
1030 #endif
1031 
1032 #if LIBMESH_DIM == 2
1033  return TypeTensor<TS>(_coords[0]/factor,
1034  _coords[1]/factor,
1035  _coords[2]/factor,
1036  _coords[3]/factor);
1037 #endif
1038 
1039 #if LIBMESH_DIM == 3
1040  return TypeTensor<TS>(_coords[0]/factor,
1041  _coords[1]/factor,
1042  _coords[2]/factor,
1043  _coords[3]/factor,
1044  _coords[4]/factor,
1045  _coords[5]/factor,
1046  _coords[6]/factor,
1047  _coords[7]/factor,
1048  _coords[8]/factor);
1049 #endif
1050 
1051 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator/=()

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

Divide each entry of this tensor by a scalar value.

Returns
A reference to *this.

Definition at line 1187 of file type_tensor.h.

1188 {
1189  libmesh_assert_not_equal_to (factor, static_cast<T>(0.));
1190 
1191  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1192  _coords[i] /= factor;
1193 
1194  return *this;
1195 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator<() [1/3]

template<>
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<() [2/3]

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

Definition at line 157 of file type_tensor.C.

References std::imag(), and std::real().

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 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

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

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

154  { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
void zero()
Set all entries of the tensor to 0.
Definition: type_tensor.h:1346

◆ operator==()

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

Definition at line 1368 of file type_tensor.h.

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

1369 {
1370 #if LIBMESH_DIM == 1
1371  return (std::abs(_coords[0] - rhs._coords[0])
1372  < TOLERANCE);
1373 #endif
1374 
1375 #if LIBMESH_DIM == 2
1376  return ((std::abs(_coords[0] - rhs._coords[0]) +
1377  std::abs(_coords[1] - rhs._coords[1]) +
1378  std::abs(_coords[2] - rhs._coords[2]) +
1379  std::abs(_coords[3] - rhs._coords[3]))
1380  < 4.*TOLERANCE);
1381 #endif
1382 
1383 #if LIBMESH_DIM == 3
1384  return ((std::abs(_coords[0] - rhs._coords[0]) +
1385  std::abs(_coords[1] - rhs._coords[1]) +
1386  std::abs(_coords[2] - rhs._coords[2]) +
1387  std::abs(_coords[3] - rhs._coords[3]) +
1388  std::abs(_coords[4] - rhs._coords[4]) +
1389  std::abs(_coords[5] - rhs._coords[5]) +
1390  std::abs(_coords[6] - rhs._coords[6]) +
1391  std::abs(_coords[7] - rhs._coords[7]) +
1392  std::abs(_coords[8] - rhs._coords[8]))
1393  < 9.*TOLERANCE);
1394 #endif
1395 
1396 }
static constexpr Real TOLERANCE
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ operator>() [1/3]

template<>
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>() [2/3]

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

Definition at line 177 of file type_tensor.C.

References std::imag(), and std::real().

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 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)

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

1400 {
1401 #if LIBMESH_DIM == 1
1402 
1403  os << "x=" << (*this)(0,0) << std::endl;
1404 
1405 #endif
1406 #if LIBMESH_DIM == 2
1407 
1408  os << "(xx,xy)=("
1409  << std::setw(8) << (*this)(0,0) << ", "
1410  << std::setw(8) << (*this)(0,1) << ")"
1411  << std::endl;
1412  os << "(yx,yy)=("
1413  << std::setw(8) << (*this)(1,0) << ", "
1414  << std::setw(8) << (*this)(1,1) << ")"
1415  << std::endl;
1416 
1417 #endif
1418 #if LIBMESH_DIM == 3
1419 
1420  os << "(xx,xy,xz)=("
1421  << std::setw(8) << (*this)(0,0) << ", "
1422  << std::setw(8) << (*this)(0,1) << ", "
1423  << std::setw(8) << (*this)(0,2) << ")"
1424  << std::endl;
1425  os << "(yx,yy,yz)=("
1426  << std::setw(8) << (*this)(1,0) << ", "
1427  << std::setw(8) << (*this)(1,1) << ", "
1428  << std::setw(8) << (*this)(1,2) << ")"
1429  << std::endl;
1430  os << "(zx,zy,zz)=("
1431  << std::setw(8) << (*this)(2,0) << ", "
1432  << std::setw(8) << (*this)(2,1) << ", "
1433  << std::setw(8) << (*this)(2,2) << ")"
1434  << std::endl;
1435 #endif
1436 }

◆ row()

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

Definition at line 772 of file type_tensor.h.

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

Referenced by TypeTensorTest::testRowCol().

773 {
774  TypeVector<T> return_vector;
775 
776  for (unsigned int j=0; j<LIBMESH_DIM; j++)
777  return_vector._coords[j] = _coords[r*LIBMESH_DIM + j];
778 
779  return return_vector;
780 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ slice() [1/2]

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

Definition at line 752 of file type_tensor.h.

753 {
754  libmesh_assert_less (i, LIBMESH_DIM);
755  return ConstTypeTensorColumn<T>(*this, i);
756 }

◆ slice() [2/2]

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

Definition at line 762 of file type_tensor.h.

763 {
764  libmesh_assert_less (i, LIBMESH_DIM);
765  return TypeTensorColumn<T>(*this, i);
766 }

◆ solve()

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

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

References b.

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

1137 {
1138 #if LIBMESH_DIM == 1
1139  if (_coords[0] == static_cast<T>(0.))
1140  libmesh_convergence_failure();
1141  x(0) = b(0) / _coords[0];
1142 #endif
1143 
1144 #if LIBMESH_DIM == 2
1145  T my_det = _coords[0]*_coords[3] - _coords[1]*_coords[2];
1146 
1147  if (my_det == static_cast<T>(0.))
1148  libmesh_convergence_failure();
1149 
1150  T my_det_inv = 1./my_det;
1151 
1152  x(0) = my_det_inv*( _coords[3]*b(0) - _coords[1]*b(1));
1153  x(1) = my_det_inv*(-_coords[2]*b(0) + _coords[0]*b(1));
1154 #endif
1155 
1156 #if LIBMESH_DIM == 3
1157  T my_det =
1158  // a11*(a33 *a22 - a32 *a23)
1159  _coords[0]*(_coords[8]*_coords[4] - _coords[7]*_coords[5])
1160  // -a21*(a33 *a12 - a32 *a13)
1161  -_coords[3]*(_coords[8]*_coords[1] - _coords[7]*_coords[2]) +
1162  // +a31*(a23 *a12 - a22 *a13)
1163  +_coords[6]*(_coords[5]*_coords[1] - _coords[4]*_coords[2]);
1164 
1165  if (my_det == static_cast<T>(0.))
1166  libmesh_convergence_failure();
1167 
1168  T my_det_inv = 1./my_det;
1169  x(0) = my_det_inv*((_coords[8]*_coords[4] - _coords[7]*_coords[5])*b(0) -
1170  (_coords[8]*_coords[1] - _coords[7]*_coords[2])*b(1) +
1171  (_coords[5]*_coords[1] - _coords[4]*_coords[2])*b(2));
1172 
1173  x(1) = my_det_inv*((_coords[6]*_coords[5] - _coords[8]*_coords[3])*b(0) +
1174  (_coords[8]*_coords[0] - _coords[6]*_coords[2])*b(1) -
1175  (_coords[5]*_coords[0] - _coords[3]*_coords[2])*b(2));
1176 
1177  x(2) = my_det_inv*((_coords[7]*_coords[3] - _coords[6]*_coords[4])*b(0) -
1178  (_coords[7]*_coords[0] - _coords[6]*_coords[1])*b(1) +
1179  (_coords[4]*_coords[0] - _coords[3]*_coords[1])*b(2));
1180 #endif
1181 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451
static const Real b

◆ subtract()

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

Subtract from this tensor without creating a temporary.

Definition at line 917 of file type_tensor.h.

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

918 {
919  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
920  _coords[i] -= p._coords[i];
921 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ subtract_scaled()

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

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

Definition at line 928 of file type_tensor.h.

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

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

929 {
930  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
931  _coords[i] -= factor*p._coords[i];
932 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ tr()

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

Definition at line 1329 of file type_tensor.h.

1330 {
1331 #if LIBMESH_DIM == 1
1332  return _coords[0];
1333 #endif
1334 
1335 #if LIBMESH_DIM == 2
1336  return _coords[0] + _coords[3];
1337 #endif
1338 
1339 #if LIBMESH_DIM == 3
1340  return _coords[0] + _coords[4] + _coords[8];
1341 #endif
1342 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

◆ transpose()

template<typename T >
TypeTensor< T > libMesh::TypeTensor< T >::transpose ( ) const
inline
Returns
The transpose of this tensor (with complex numbers not conjugated).

Definition at line 1057 of file type_tensor.h.

Referenced by assemble_shell(), libMesh::VariationalSmootherSystem::compute_mesh_quality_info(), LargeDeformationElasticity::compute_stresses(), libMesh::VariationalSmootherSystem::element_time_derivative(), libMesh::get_jacobian_at_qp(), CurlCurlExactSolution::grad(), GradDivExactSolution::grad(), and TypeTensorTest::testIsHPD().

1058 {
1059 #if LIBMESH_DIM == 1
1060  return TypeTensor(_coords[0]);
1061 #endif
1062 
1063 #if LIBMESH_DIM == 2
1064  return TypeTensor(_coords[0],
1065  _coords[2],
1066  _coords[1],
1067  _coords[3]);
1068 #endif
1069 
1070 #if LIBMESH_DIM == 3
1071  return TypeTensor(_coords[0],
1072  _coords[3],
1073  _coords[6],
1074  _coords[1],
1075  _coords[4],
1076  _coords[7],
1077  _coords[2],
1078  _coords[5],
1079  _coords[8]);
1080 #endif
1081 }
TypeTensor()
Empty constructor.
Definition: type_tensor.h:517
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

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

References libMesh::libmesh_assert().

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)

◆ zero()

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

Set all entries of the tensor to 0.

Definition at line 1346 of file type_tensor.h.

Referenced by LinearElasticityWithContact::compute_stresses(), LargeDeformationElasticity::compute_stresses(), NonlinearNeoHookeCurrentConfig::init_for_qp(), libMesh::TensorValue< T >::operator=(), and libMesh::TypeTensor< T >::operator=().

1347 {
1348  for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1349  _coords[i] = 0.;
1350 }
T _coords[LIBMESH_DIM *LIBMESH_DIM]
The coordinates of the TypeTensor.
Definition: type_tensor.h:451

Friends And Related Function 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 426 of file type_tensor.h.

427  {
428  t.print(os);
429  return os;
430  }

◆ TypeTensor

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

Definition at line 55 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: