libMesh
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
libMesh::TensorValue< T > Class Template Reference

This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space. More...

#include <exact_solution.h>

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

Classes

struct  rebind
 

Public Types

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

Public Member Functions

 TensorValue ()
 Empty constructor. More...
 
 TensorValue (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 >
 TensorValue (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-scalars. More...
 
template<typename T2 >
 TensorValue (const TypeVector< T2 > &vx)
 Constructor. More...
 
template<typename T2 >
 TensorValue (const TypeVector< T2 > &vx, const TypeVector< T2 > &vy)
 Constructor. More...
 
template<typename T2 >
 TensorValue (const TypeVector< T2 > &vx, const TypeVector< T2 > &vy, const TypeVector< T2 > &vz)
 Constructor. More...
 
template<typename T2 >
 TensorValue (const TensorValue< T2 > &p)
 Copy-constructor. More...
 
template<typename T2 >
 TensorValue (const TypeTensor< T2 > &p)
 Copy-constructor. More...
 
 TensorValue (const TypeTensor< Real > &p_re, const TypeTensor< Real > &p_im)
 Constructor that takes two TypeTensor<Real> representing the real and imaginary part as arguments. More...
 
template<typename Scalar >
std::enable_if< ScalarTraits< Scalar >::value, TensorValue & >::type operator= (const Scalar &libmesh_dbg_var(p))
 Assignment-from-scalar operator. More...
 
template<typename T2 >
void assign (const TypeTensor< T2 > &)
 Assign to this tensor without creating a temporary. 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...
 
TypeTensor< T > operator- () const
 
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...
 
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 T2 >
TypeTensor< typename CompareTypes< T, T2 >::supertype > operator* (const TypeTensor< T2 > &) const
 Multiply 2 tensors together, 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 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 T2 >
const TypeTensor< T > & operator*= (const TypeTensor< T2 > &)
 Multiply this tensor by a tensor 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 >
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 > 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
 
template<>
bool operator< (const TypeTensor< Real > &rhs) const
 
template<>
bool operator< (const TypeTensor< Complex > &rhs) const
 
bool operator> (const TypeTensor< T > &rhs) const
 
template<>
bool operator> (const TypeTensor< Real > &rhs) const
 
template<>
bool operator> (const TypeTensor< Complex > &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...
 

Static Public Member Functions

static TensorValue< Realintrinsic_rotation_matrix (Real phi, Real theta, Real psi)
 Generate the intrinsic rotation matrix associated with the provided Euler angles. More...
 
static TensorValue< Realinverse_intrinsic_rotation_matrix (Real phi, Real theta, Real psi)
 Invert the rotation that would occur if the same angles were provided to intrinsic_rotation_matrix, e.g. More...
 
static TensorValue< Realextrinsic_rotation_matrix (Real angle1_deg, Real angle2_deg, Real angle3_deg)
 Generate the extrinsic rotation matrix associated with the provided Euler angles. More...
 
static TensorValue< Realinverse_extrinsic_rotation_matrix (Real angle1_deg, Real angle2_deg, Real angle3_deg)
 Invert the rotation that would occur if the same angles were provided to extrinsic_rotation_matrix, e.g. More...
 

Protected Attributes

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

Detailed Description

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

This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.

The typedef RealTensorValue always defines a real-valued tensor, and NumberTensorValue defines a real or complex-valued tensor depending on how the library was configured.

Author
Roy H. Stogner
Date
2004

Definition at line 46 of file exact_solution.h.

Member Typedef Documentation

◆ index_type

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

Helper typedef for generic index programming.

Definition at line 125 of file type_tensor.h.

◆ value_type

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

Definition at line 47 of file tensor_value.h.

Constructor & Destructor Documentation

◆ TensorValue() [1/9]

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

Empty constructor.

Gives the tensor 0 in LIBMESH_DIM dimensional T space.

Definition at line 215 of file tensor_value.h.

215  :
216  TypeTensor<T> ()
217 {
218 }

◆ TensorValue() [2/9]

template<typename T >
libMesh::TensorValue< T >::TensorValue ( 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 
)
inlineexplicit

Constructor-from-T.

By default sets higher dimensional entries to 0.

Definition at line 224 of file tensor_value.h.

232  :
233  TypeTensor<T> (xx,xy,xz,yx,yy,yz,zx,zy,zz)
234 {
235 }

◆ TensorValue() [3/9]

template<typename T >
template<typename Scalar >
libMesh::TensorValue< T >::TensorValue ( 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 
)
inlineexplicit

Constructor-from-scalars.

By default sets higher dimensional entries to 0.

Definition at line 241 of file tensor_value.h.

251  :
252  TypeTensor<T> (xx,xy,xz,yx,yy,yz,zx,zy,zz)
253 {
254 }

◆ TensorValue() [4/9]

template<typename T >
template<typename T2 >
libMesh::TensorValue< T >::TensorValue ( const TypeVector< T2 > &  vx)
inline

Constructor.

Takes 1 row vector for LIBMESH_DIM=1

Definition at line 271 of file tensor_value.h.

271  :
272  TypeTensor<T> (vx)
273 {
274 }

◆ TensorValue() [5/9]

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

Constructor.

Takes 2 row vectors for LIBMESH_DIM=2

Definition at line 281 of file tensor_value.h.

282  :
283  TypeTensor<T> (vx, vy)
284 {
285 }

◆ TensorValue() [6/9]

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

Constructor.

Takes 3 row vectors for LIBMESH_DIM=3

Definition at line 292 of file tensor_value.h.

294  :
295  TypeTensor<T> (vx, vy, vz)
296 {
297 }

◆ TensorValue() [7/9]

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

Copy-constructor.

Definition at line 261 of file tensor_value.h.

261  :
262  TypeTensor<T> (p)
263 {
264 }

◆ TensorValue() [8/9]

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

Copy-constructor.

Definition at line 304 of file tensor_value.h.

304  :
305  TypeTensor<T> (p)
306 {
307 }

◆ TensorValue() [9/9]

template<typename T >
libMesh::TensorValue< T >::TensorValue ( const TypeTensor< Real > &  p_re,
const TypeTensor< Real > &  p_im 
)
inline

Constructor that takes two TypeTensor<Real> representing the real and imaginary part as arguments.

Definition at line 313 of file tensor_value.h.

314  :
315  TypeTensor<T> (Complex (p_re(0,0), p_im(0,0)),
316  Complex (p_re(0,1), p_im(0,1)),
317  Complex (p_re(0,2), p_im(0,2)),
318  Complex (p_re(1,0), p_im(1,0)),
319  Complex (p_re(1,1), p_im(1,1)),
320  Complex (p_re(1,2), p_im(1,2)),
321  Complex (p_re(2,0), p_im(2,0)),
322  Complex (p_re(2,1), p_im(2,1)),
323  Complex (p_re(2,2), p_im(2,2)))
324 {
325 }
std::complex< Real > Complex

Member Function Documentation

◆ add()

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

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

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

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
inlineinherited
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
inlineinherited

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
inlineinherited
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

◆ extrinsic_rotation_matrix()

template<typename T >
TensorValue< Real > libMesh::TensorValue< T >::extrinsic_rotation_matrix ( Real  angle1_deg,
Real  angle2_deg,
Real  angle3_deg 
)
static

Generate the extrinsic rotation matrix associated with the provided Euler angles.

An extrinsic rotation rotates the bodies in the domain and leaves the coordinate axes fixed. We follow the convention described at https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix and we use the matrix described by the 'Proper Euler Angles' column and Z1 X2 Z3 row, which indicates that the rotations are performed sequentially about the z, x, and z axes, in that order. A positive angle yields a counter-clockwise rotation about the axis in question. Note that angles should be provided in degrees

Parameters
angle1_degrotation angle around z-axis
angle2_degrotation angle around x-axis (post angle1)
angle3_degrotation angle around z-axis (post angle1 and angle2)
Returns
The associated rotation matrix

Definition at line 372 of file tensor_value.h.

References libMesh::libmesh_ignore(), and libMesh::pi.

Referenced by libMesh::TensorValue< T >::inverse_extrinsic_rotation_matrix(), and TypeTensorTest::testRotation().

375 {
376 #if LIBMESH_DIM == 3
377  const auto angle1 = angle1_deg / 180. * pi;
378  const auto angle2 = angle2_deg / 180. * pi;
379  const auto angle3 = angle3_deg / 180. * pi;
380  const auto s1 = std::sin(angle1), c1 = std::cos(angle1);
381  const auto s2 = std::sin(angle2), c2 = std::cos(angle2);
382  const auto s3 = std::sin(angle3), c3 = std::cos(angle3);
383 
384  return TensorValue<Real>(c1 * c3 - c2 * s1 * s3,
385  -c1 * s3 - c2 * c3 * s1,
386  s1 * s2,
387  c3 * s1 + c1 * c2 * s3,
388  c1 * c2 * c3 - s1 * s3,
389  -c1 * s2,
390  s2 * s3,
391  c3 * s2,
392  c2);
393 #else
394  libmesh_ignore(angle1_deg, angle2_deg, angle3_deg);
395  libmesh_error_msg("TensorValue<T>::extrinsic_rotation_matrix() requires libMesh to be compiled "
396  "with LIBMESH_DIM==3");
397  // We'll never get here
398  return TensorValue<Real>();
399 #endif
400 }
void libmesh_ignore(const Args &...)
const Real pi
.
Definition: libmesh.h:292

◆ intrinsic_rotation_matrix()

template<typename T >
TensorValue< Real > libMesh::TensorValue< T >::intrinsic_rotation_matrix ( Real  phi,
Real  theta,
Real  psi 
)
static

Generate the intrinsic rotation matrix associated with the provided Euler angles.

An intrinsic rotation leaves bodies in the domain fixed while rotating the coordinate axes. We follow the convention described at http://mathworld.wolfram.com/EulerAngles.html (equations 6-14 give the entries of the composite transformation matrix). The rotations are performed sequentially about the z, x', and z'' axes, in that order. A positive angle for a given step in the rotation sequences gives the appearance of rotating an entity in the domain counter-clockwise around the rotation axis, although in fact it is the coordinate axes themselves that are rotating. In order to give the appearance of a body rotating counter-clockwise, we actually rotate the coordinate axes by the negative of the angle passed into the method. All angles should be provided in degrees

Parameters
phiThe negative of the angle we will rotate the coordinate axes around the original z-axis
thetaThe negative of the angle we will rotate the coordinate axes around the "current" x-axis (post phi), e.g. x'
psiThe negative of the angle we will rotate the coordinate axes around the "current" z-axis (post phi and theta), e.g. z''
Returns
The associated rotation matrix

Definition at line 330 of file tensor_value.h.

References libMesh::libmesh_ignore(), libMesh::pi, and libMesh::Real.

Referenced by libMesh::TensorValue< T >::inverse_intrinsic_rotation_matrix(), and libMesh::MeshTools::Modification::rotate().

331 {
332 #if LIBMESH_DIM == 3
333  // We apply a negative sign here or else we don't get the appearance of
334  // counter-clockwise/right-hand-rule rotation of the bodies with respect to the coordinate axes
335  // (but as explained in the method doxygen we are *actually* rotating the coordinate axes while
336  // leaving the bodies fixed)
337  const Real p = -phi / 180. * pi;
338  const Real t = -theta / 180. * pi;
339  const Real s = -psi / 180. * pi;
340  const Real sp = std::sin(p), cp = std::cos(p);
341  const Real st = std::sin(t), ct = std::cos(t);
342  const Real ss = std::sin(s), cs = std::cos(s);
343 
344  return TensorValue<Real>(cp * cs - sp * ct * ss,
345  sp * cs + cp * ct * ss,
346  st * ss,
347  -cp * ss - sp * ct * cs,
348  -sp * ss + cp * ct * cs,
349  st * cs,
350  sp * st,
351  -cp * st,
352  ct);
353 #else
354  libmesh_ignore(phi, theta, psi);
355  libmesh_error_msg("TensorValue<T>::intrinsic_rotation_matrix() requires libMesh to be compiled "
356  "with LIBMESH_DIM==3");
357  // We'll never get here
358  return TensorValue<Real>();
359 #endif
360 }
void libmesh_ignore(const Args &...)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real pi
.
Definition: libmesh.h:292

◆ inverse()

template<typename T >
TypeTensor< T > libMesh::TypeTensor< T >::inverse ( ) const
inlineinherited
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

◆ inverse_extrinsic_rotation_matrix()

template<typename T >
TensorValue< Real > libMesh::TensorValue< T >::inverse_extrinsic_rotation_matrix ( Real  angle1_deg,
Real  angle2_deg,
Real  angle3_deg 
)
static

Invert the rotation that would occur if the same angles were provided to extrinsic_rotation_matrix, e.g.

return to the original starting point

Definition at line 404 of file tensor_value.h.

References libMesh::TensorValue< T >::extrinsic_rotation_matrix().

Referenced by TypeTensorTest::testRotation().

407 {
408  // The inverse of a rotation matrix is just the transpose
409  return TensorValue<T>::extrinsic_rotation_matrix(angle1_deg, angle2_deg, angle3_deg).transpose();
410 }
static TensorValue< Real > extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg)
Generate the extrinsic rotation matrix associated with the provided Euler angles. ...
Definition: tensor_value.h:372

◆ inverse_intrinsic_rotation_matrix()

template<typename T >
TensorValue< Real > libMesh::TensorValue< T >::inverse_intrinsic_rotation_matrix ( Real  phi,
Real  theta,
Real  psi 
)
static

Invert the rotation that would occur if the same angles were provided to intrinsic_rotation_matrix, e.g.

return to the original starting point. All angles should be provided in degrees

Definition at line 364 of file tensor_value.h.

References libMesh::TensorValue< T >::intrinsic_rotation_matrix().

365 {
366  // The inverse of a rotation matrix is just the transpose
367  return TensorValue<T>::intrinsic_rotation_matrix(phi, theta, psi).transpose();
368 }
static TensorValue< Real > intrinsic_rotation_matrix(Real phi, Real theta, Real psi)
Generate the intrinsic rotation matrix associated with the provided Euler angles. ...
Definition: tensor_value.h:330

◆ is_hpd()

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

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
inlineinherited
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
inlineinherited

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

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
inlineinherited

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
inlineinherited

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

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

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
inlineinherited

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

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
inlineinherited

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

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
inlineinherited

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

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
inherited

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
inherited

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
inherited
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, TensorValue &>::type libMesh::TensorValue< T >::operator= ( const Scalar &  libmesh_dbg_varp)
inline

Assignment-from-scalar operator.

Used only to zero out tensors.

Definition at line 145 of file tensor_value.h.

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

146  { 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
inlineinherited
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
inherited

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
inherited

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
inherited
Returns
true if this tensor is "greater" than another.

◆ print()

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

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

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

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

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
inlineinherited
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
inlineinherited
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
inherited

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

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

Member Data Documentation

◆ _coords

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

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