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

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

Classes

struct  rebind
 

Public Types

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

Public Member Functions

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

Static Public Member Functions

static TensorValue< Real > intrinsic_rotation_matrix (Real phi, Real theta, Real psi)
 Generate the intrinsic rotation matrix associated with the provided Euler angles.
 
static TensorValue< Real > inverse_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.
 
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.
 
static TensorValue< Real > inverse_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.
 

Protected Attributes

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

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 45 of file tensor_value.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 129 of file type_tensor.h.

◆ value_type

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

Definition at line 48 of file tensor_value.h.

Constructor & Destructor Documentation

◆ TensorValue() [1/12]

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

Empty constructor.

Gives the tensor 0 in LIBMESH_DIM dimensional T space.

Definition at line 219 of file tensor_value.h.

219 :
220 TypeTensor<T> ()
221{
222}

◆ TensorValue() [2/12]

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

Constructor-from-T.

By default sets higher dimensional entries to 0.

Definition at line 228 of file tensor_value.h.

236 :
237 TypeTensor<T> (xx,xy,xz,yx,yy,yz,zx,zy,zz)
238{
239}

◆ TensorValue() [3/12]

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

Constructor-from-scalars.

By default sets higher dimensional entries to 0.

◆ TensorValue() [4/12]

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

Constructor.

Takes 1 row vector for LIBMESH_DIM=1

Definition at line 275 of file tensor_value.h.

275 :
276 TypeTensor<T> (vx)
277{
278}

◆ TensorValue() [5/12]

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

Constructor.

Takes 2 row vectors for LIBMESH_DIM=2

Definition at line 285 of file tensor_value.h.

286 :
287 TypeTensor<T> (vx, vy)
288{
289}

◆ TensorValue() [6/12]

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

Constructor.

Takes 3 row vectors for LIBMESH_DIM=3

Definition at line 296 of file tensor_value.h.

298 :
299 TypeTensor<T> (vx, vy, vz)
300{
301}

◆ TensorValue() [7/12]

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

Copy-constructor.

◆ TensorValue() [8/12]

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

Copy-constructor.

◆ TensorValue() [9/12]

template<typename T >
LIBMESH_DEVICE_INLINE libMesh::TensorValue< T >::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.

Definition at line 317 of file tensor_value.h.

318 :
319 TypeTensor<T> (Complex (p_re(0,0), p_im(0,0)),
320 Complex (p_re(0,1), p_im(0,1)),
321 Complex (p_re(0,2), p_im(0,2)),
322 Complex (p_re(1,0), p_im(1,0)),
323 Complex (p_re(1,1), p_im(1,1)),
324 Complex (p_re(1,2), p_im(1,2)),
325 Complex (p_re(2,0), p_im(2,0)),
326 Complex (p_re(2,1), p_im(2,1)),
327 Complex (p_re(2,2), p_im(2,2)))
328{
329}
std::complex< Real > Complex

◆ TensorValue() [10/12]

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

Definition at line 245 of file tensor_value.h.

255 :
256 TypeTensor<T> (xx,xy,xz,yx,yy,yz,zx,zy,zz)
257{
258}

◆ TensorValue() [11/12]

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

Definition at line 265 of file tensor_value.h.

265 :
266 TypeTensor<T> (p)
267{
268}

◆ TensorValue() [12/12]

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

Definition at line 308 of file tensor_value.h.

308 :
309 TypeTensor<T> (p)
310{
311}

Member Function Documentation

◆ add() [1/2]

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

Add to this tensor without creating a temporary.

Referenced by NonlinearNeoHookeCurrentConfig::init_for_qp().

◆ add() [2/2]

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

Definition at line 869 of file type_tensor.h.

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

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

◆ add_scaled()

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

◆ assign()

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

Assign to this tensor without creating a temporary.

Definition at line 725 of file type_tensor.h.

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

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

◆ column()

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

Definition at line 808 of file type_tensor.h.

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

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

Referenced by TypeTensorTest::testRowCol().

◆ contract()

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

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

Multiply 2 tensors together, i.e.

\( \sum_{ij} A_{ij} B_{ij} \) The tensors may contain different numeric types. Also known as the "double inner product" or "double dot product" of tensors.

Returns
The scalar-valued result, this tensor is unchanged.

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

Definition at line 1297 of file type_tensor.h.

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

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

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

◆ det()

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

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

Definition at line 1328 of file type_tensor.h.

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

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

◆ 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 376 of file tensor_value.h.

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

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

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

◆ 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 \emph negative of the angle passed into the method. All angles should be provided in degrees

Parameters
phiThe \emph negative of the angle we will rotate the coordinate axes around the original z-axis
thetaThe \emph negative of the angle we will rotate the coordinate axes around the "current" x-axis (post phi), e.g. x'
psiThe \emph 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 334 of file tensor_value.h.

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

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

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

◆ inverse()

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

Definition at line 1109 of file type_tensor.h.

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

References b.

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

◆ 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 408 of file tensor_value.h.

411{
412 // The inverse of a rotation matrix is just the transpose
413 return TensorValue<T>::extrinsic_rotation_matrix(angle1_deg, angle2_deg, angle3_deg).transpose();
414}
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.

References libMesh::TensorValue< T >::extrinsic_rotation_matrix(), and libMesh::TypeTensor< T >::transpose().

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

◆ 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 368 of file tensor_value.h.

369{
370 // The inverse of a rotation matrix is just the transpose
371 return TensorValue<T>::intrinsic_rotation_matrix(phi, theta, psi).transpose();
372}
static TensorValue< Real > intrinsic_rotation_matrix(Real phi, Real theta, Real psi)
Generate the intrinsic rotation matrix associated with the provided Euler angles.

References libMesh::TensorValue< T >::intrinsic_rotation_matrix(), and libMesh::TypeTensor< T >::transpose().

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

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

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

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

◆ is_zero()

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

Definition at line 1318 of file type_tensor.h.

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

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

◆ left_multiply()

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

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

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

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

Definition at line 1240 of file type_tensor.h.

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

Referenced by AzimuthalPeriodicBoundary::get_corresponding_pos().

◆ norm()

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

Definition at line 1309 of file type_tensor.h.

1310{
1311 using std::sqrt;
1312 return sqrt(this->norm_sq());
1313}
auto norm_sq() const

◆ norm_sq()

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

Definition at line 1378 of file type_tensor.h.

1379{
1380 Real sum = 0.;
1381 for (unsigned int i=0; i<LIBMESH_DIM*LIBMESH_DIM; i++)
1382 sum += TensorTools::norm_sq(_coords[i]);
1383 return sum;
1384}
LIBMESH_DEVICE_INLINE auto norm_sq(const T &a)

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

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

◆ operator()() [1/2]

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

Definition at line 754 of file type_tensor.h.

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

◆ operator()() [2/2]

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

Definition at line 735 of file type_tensor.h.

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

◆ operator*() [1/6]

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

Definition at line 994 of file type_tensor.h.

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

◆ operator*() [2/6]

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

Multiply this tensor by a scalar value.

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

◆ operator*() [3/6]

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

Multiply 2 tensors together, i.e.

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

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

◆ operator*() [4/6]

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

Definition at line 1262 of file type_tensor.h.

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

◆ operator*() [5/6]

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

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

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

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

◆ operator*() [6/6]

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

Definition at line 1226 of file type_tensor.h.

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

◆ operator*=() [1/3]

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

Multiply this tensor by a scalar value in place.

Returns
A reference to *this.

Definition at line 281 of file type_tensor.h.

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

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

◆ operator*=() [2/3]

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

Multiply this tensor by a tensor value in place.

Returns
A reference to *this

◆ operator*=() [3/3]

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

Definition at line 1276 of file type_tensor.h.

1277{
1278 TypeTensor<T> temp;
1279 for (unsigned int i=0; i<LIBMESH_DIM; i++)
1280 for (unsigned int j=0; j<LIBMESH_DIM; j++)
1281 for (unsigned int k=0; k<LIBMESH_DIM; k++)
1282 temp(i,j) += (*this)(i,k)*p(k,j);
1283
1284 this->assign(temp);
1285 return *this;
1286}
LIBMESH_DEVICE_INLINE void assign(const TypeTensor< T2 > &)
Assign to this tensor without creating a temporary.

◆ operator+() [1/2]

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

Add another tensor to this tensor.

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

◆ operator+() [2/2]

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

Definition at line 823 of file type_tensor.h.

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

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

◆ operator+=() [1/2]

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

Add to this tensor.

Returns
A reference to *this.

◆ operator+=() [2/2]

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

Definition at line 857 of file type_tensor.h.

858{
859 this->add (p);
860
861 return *this;
862}
void add(const TypeTensor< T2 > &)
Add to this tensor without creating a temporary.

◆ operator-() [1/3]

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

Definition at line 960 of file type_tensor.h.

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

◆ operator-() [2/3]

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

Subtract a tensor from this tensor.

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

◆ operator-() [3/3]

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

Definition at line 893 of file type_tensor.h.

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

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

◆ operator-=() [1/2]

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

Subtract from this tensor.

Returns
A reference to *this.

◆ operator-=() [2/2]

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

Definition at line 927 of file type_tensor.h.

928{
929 this->subtract (p);
930
931 return *this;
932}
void subtract(const TypeTensor< T2 > &)
Subtract from this tensor without creating a temporary.

◆ operator/() [1/2]

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

Divide each entry of this tensor by a scalar value.

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

◆ operator/() [2/2]

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

Definition at line 1044 of file type_tensor.h.

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

◆ operator/=()

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

Divide each entry of this tensor by a scalar value.

Returns
A reference to *this.

Definition at line 1209 of file type_tensor.h.

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

◆ operator<() [1/3]

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

Definition at line 157 of file type_tensor.C.

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

◆ operator<() [2/3]

bool libMesh::TypeTensor< Real >::operator< ( const TypeTensor< Real > &  rhs) const
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<() [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 >
LIBMESH_DEVICE_INLINE 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 149 of file tensor_value.h.

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

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

◆ operator==()

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

Definition at line 1390 of file type_tensor.h.

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

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

◆ operator>() [1/3]

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

Definition at line 177 of file type_tensor.C.

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

◆ operator>() [2/3]

bool libMesh::TypeTensor< Real >::operator> ( const TypeTensor< Real > &  rhs) const
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>() [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 1421 of file type_tensor.h.

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

◆ row()

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

Definition at line 794 of file type_tensor.h.

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

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

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

◆ slice() [1/2]

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

Definition at line 784 of file type_tensor.h.

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

◆ slice() [2/2]

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

Definition at line 774 of file type_tensor.h.

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

◆ solve()

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

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

Returns
The solution in the x vector.

Definition at line 1158 of file type_tensor.h.

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

References b.

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

◆ subtract() [1/2]

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

Subtract from this tensor without creating a temporary.

◆ subtract() [2/2]

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

Definition at line 939 of file type_tensor.h.

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

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

◆ subtract_scaled()

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

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

Definition at line 950 of file type_tensor.h.

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

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

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

◆ tr()

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

Definition at line 1351 of file type_tensor.h.

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

◆ transpose()

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

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

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

References libMesh::libmesh_assert().

◆ zero()

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

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: