www.mooseframework.org
Public Types | Public Member Functions | Static Public Member Functions | Static Private Attributes | Friends | List of all members
RankTwoTensorTempl< T > Class Template Reference

RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material. More...

#include <MooseTypes.h>

Inheritance diagram for RankTwoTensorTempl< T >:
[legend]

Public Types

enum  InitMethod { initNone, initIdentity }
 
enum  FillMethod {
  autodetect = 0, isotropic1 = 1, diagonal3 = 3, symmetric6 = 6,
  general = 9
}
 To fill up the 9 entries in the 2nd-order tensor, fillFromInputVector is called with one of the following fill_methods. More...
 

Public Member Functions

 RankTwoTensorTempl ()
 Default constructor; fills to zero. More...
 
 RankTwoTensorTempl (const InitMethod)
 Select specific initialization pattern. More...
 
 RankTwoTensorTempl (const TypeVector< T > &row1, const TypeVector< T > &row2, const TypeVector< T > &row3)
 Constructor that takes in 3 vectors and uses them to create rows _coords[0][i] = row1(i), _coords[1][i] = row2(i), _coords[2][i] = row3(i) More...
 
 RankTwoTensorTempl (const std::vector< T > &input)
 Constructor that proxies the fillFromInputVector method. More...
 
 RankTwoTensorTempl (T S11, T S22, T S33, T S23, T S13, T S12)
 Initialization list replacement constructors, 6 arguments. More...
 
 RankTwoTensorTempl (T S11, T S21, T S31, T S12, T S22, T S32, T S13, T S23, T S33)
 Initialization list replacement constructors, 9 arguments. More...
 
 RankTwoTensorTempl (const RankTwoTensorTempl< T > &a)=default
 Copy assignment operator must be defined if used. More...
 
 RankTwoTensorTempl (const TensorValue< T > &a)
 Copy constructor from TensorValue<T> More...
 
 RankTwoTensorTempl (const TypeTensor< T > &a)
 Copy constructor from TypeTensor<T> More...
 
template<typename T2 >
 RankTwoTensorTempl (const RankTwoTensorTempl< T2 > &a)
 Construct from other template. More...
 
void fillFromInputVector (const std::vector< T > &input, FillMethod fill_method=autodetect)
 fillFromInputVector takes 6 or 9 inputs to fill in the Rank-2 tensor. More...
 
void fillFromScalarVariable (const VariableValue &scalar_variable)
 fillFromScalarVariable takes FIRST/THIRD/SIXTH order scalar variable to fill in the Rank-2 tensor. More...
 
TypeVector< T > column (const unsigned int c) const
 returns _coords[i][c], ie, column c, with c = 0, 1, 2 More...
 
RankTwoTensorTempl< T > rotated (const RankTwoTensorTempl< T > &R) const
 Returns a rotated version of the tensor data given a rank two tensor rotation tensor _coords[i][j] = R_ij * R_jl * _coords[k][l]. More...
 
void rotate (const RankTwoTensorTempl< T > &R)
 rotates the tensor data given a rank two tensor rotation tensor _coords[i][j] = R_ij * R_jl * _coords[k][l] More...
 
RankTwoTensorTempl< T > rotateXyPlane (T a)
 rotates the tensor data anticlockwise around the z-axis More...
 
RankTwoTensorTempl< T > transpose () const
 Returns a matrix that is the transpose of the matrix this was called on. More...
 
RankTwoTensorTempl< T > & operator= (const RankTwoTensorTempl< T > &a)
 sets _coords to a, and returns _coords More...
 
template<typename Scalar >
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, RankTwoTensorTempl & >::type operator= (const Scalar &libmesh_dbg_var(p))
 Assignment-from-scalar operator. More...
 
RankTwoTensorTempl< T > & operator+= (const RankTwoTensorTempl< T > &a)
 adds a to _coords More...
 
template<typename T2 >
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > operator+ (const TypeTensor< T2 > &a) const
 returns _coords + a More...
 
RankTwoTensorTempl< T > & operator-= (const RankTwoTensorTempl< T > &a)
 sets _coords -= a and returns vals More...
 
template<typename T2 >
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > operator- (const TypeTensor< T2 > &a) const
 returns _coords - a More...
 
RankTwoTensorTempl< T > operator- () const
 returns -_coords More...
 
RankTwoTensorTempl< T > & operator*= (const T &a)
 performs _coords *= a More...
 
template<typename T2 , typename std::enable_if< ScalarTraits< T2 >::value, int >::type = 0>
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > operator* (const T2 &a) const
 returns _coords*a More...
 
RankTwoTensorTempl< T > & operator/= (const T &a)
 performs _coords /= a More...
 
template<typename T2 , typename std::enable_if< ScalarTraits< T2 >::value, int >::type = 0>
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > operator/ (const T2 &a) const
 returns _coords/a More...
 
template<typename T2 >
TypeVector< typename CompareTypes< T, T2 >::supertype > operator* (const TypeVector< T2 > &a) const
 Defines multiplication with a vector to get a vector. More...
 
template<typename T2 >
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > operator* (const TypeTensor< T2 > &a) const
 Defines multiplication with a TypeTensor<T> More...
 
RankTwoTensorTempl< T > & operator*= (const TypeTensor< T > &a)
 Defines multiplication with a TypeTensor<T> More...
 
bool operator== (const RankTwoTensorTempl< T > &a) const
 Defines logical equality with another RankTwoTensorTempl<T> More...
 
RankTwoTensorTempl< T > & operator= (const ColumnMajorMatrixTempl< T > &a)
 Sets _coords to the values in a ColumnMajorMatrix (must be 3x3) More...
 
doubleContraction (const RankTwoTensorTempl< T > &a) const
 returns _coords_ij * a_ij (sum on i, j) More...
 
RankFourTensorTempl< T > outerProduct (const RankTwoTensorTempl< T > &a) const
 returns C_ijkl = a_ij * b_kl More...
 
RankFourTensorTempl< T > mixedProductIkJl (const RankTwoTensorTempl< T > &a) const
 returns C_ijkl = a_ik * b_jl More...
 
RankFourTensorTempl< T > mixedProductJkIl (const RankTwoTensorTempl< T > &a) const
 returns C_ijkl = a_jk * b_il More...
 
RankFourTensorTempl< T > mixedProductIlJk (const RankTwoTensorTempl< T > &a) const
 returns C_ijkl = a_il * b_jk More...
 
RankFourTensorTempl< T > positiveProjectionEigenDecomposition (std::vector< T > &eigval, RankTwoTensorTempl< T > &eigvec) const
 return positive projection tensor of eigen-decomposition More...
 
RankTwoTensorTempl< T > deviatoric () const
 returns A_ij - de_ij*tr(A)/3, where A are the _coords More...
 
trace () const
 returns the trace of the tensor, ie _coords[i][i] (sum i = 0, 1, 2) More...
 
RankTwoTensorTempl< T > inverse () const
 retuns the inverse of the tensor More...
 
RankTwoTensorTempl< T > dtrace () const
 Denote the _coords[i][j] by A_ij, then this returns d(trace)/dA_ij. More...
 
generalSecondInvariant () const
 Denote the _coords[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns (S_ij + S_ji)*(S_ij + S_ji)/8 Note the explicit symmeterisation. More...
 
secondInvariant () const
 Calculates the second invariant (I2) of a tensor. More...
 
RankTwoTensorTempl< T > dsecondInvariant () const
 Denote the _coords[i][j] by A_ij, then this returns d(secondInvariant)/dA_ij. More...
 
RankFourTensorTempl< T > d2secondInvariant () const
 Denote the _coords[i][j] by A_ij, then this returns d^2(secondInvariant)/dA_ij/dA_kl. More...
 
sin3Lode (const T &r0, const T &r0_value) const
 Sin(3*Lode_angle) If secondInvariant() <= r0 then return r0_value This is to gaurd against precision-loss errors. More...
 
RankTwoTensorTempl< T > dsin3Lode (const T &r0) const
 d(sin3Lode)/dA_ij If secondInvariant() <= r0 then return zero This is to gaurd against precision-loss errors. More...
 
RankFourTensorTempl< T > d2sin3Lode (const T &r0) const
 d^2(sin3Lode)/dA_ij/dA_kl If secondInvariant() <= r0 then return zero This is to gaurd against precision-loss errors. More...
 
thirdInvariant () const
 Denote the _coords[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns det(S + S.transpose())/2 Note the explicit symmeterisation. More...
 
RankTwoTensorTempl< T > dthirdInvariant () const
 Denote the _coords[i][j] by A_ij, then this returns d(thirdInvariant()/dA_ij. More...
 
RankFourTensorTempl< T > d2thirdInvariant () const
 Denote the _coords[i][j] by A_ij, then this returns d^2(thirdInvariant)/dA_ij/dA_kl. More...
 
RankTwoTensorTempl< T > ddet () const
 Denote the _coords[i][j] by A_ij, then this returns d(det)/dA_ij. More...
 
void print (std::ostream &stm=Moose::out) const
 Print the rank two tensor. More...
 
void printReal (std::ostream &stm=Moose::out) const
 Print the Real part of the DualReal rank two tensor. More...
 
void printDualReal (unsigned int nDual, std::ostream &stm=Moose::out) const
 Print the Real part of the DualReal rank two tensor along with its first nDual dual numbers. More...
 
void addIa (const T &a)
 Add identity times a to _coords. More...
 
L2norm () const
 Sqrt(_coords[i][j]*_coords[i][j]) More...
 
void surfaceFillFromInputVector (const std::vector< T > &input)
 sets _coords[0][0], _coords[0][1], _coords[1][0], _coords[1][1] to input, and the remainder to zero More...
 
void symmetricEigenvalues (std::vector< T > &eigvals) const
 computes eigenvalues, assuming tens is symmetric, and places them in ascending order in eigvals More...
 
RankTwoTensorTempl< T > permutationTensor (const std::array< unsigned int, LIBMESH_DIM > &old_elements, const std::array< unsigned int, LIBMESH_DIM > &new_elements) const
 computes and returns the permutation matrix P More...
 
RankTwoTensorTempl< T > givensRotation (unsigned int row1, unsigned int row2, unsigned int col) const
 computes and returns the Givens rotation matrix R More...
 
void hessenberg (RankTwoTensorTempl< T > &H, RankTwoTensorTempl< T > &U) const
 computes the Hessenberg form of this matrix A and its unitary transformation U such that A = U * H * U^T More...
 
void QR (RankTwoTensorTempl< T > &Q, RankTwoTensorTempl< T > &R, unsigned int dim=RankTwoTensorTempl< T >::N) const
 computes the QR factorization such that A = Q * R, where Q is the unitary matrix and R an upper triangular matrix More...
 
void symmetricEigenvaluesEigenvectors (std::vector< T > &eigvals, RankTwoTensorTempl< T > &eigvecs) const
 computes eigenvalues and eigenvectors, assuming tens is symmetric, and places them in ascending order in eigvals. More...
 
void dsymmetricEigenvalues (std::vector< T > &eigvals, std::vector< RankTwoTensorTempl< T >> &deigvals) const
 computes eigenvalues, and their symmetric derivatives wrt vals, assuming tens is symmetric More...
 
void d2symmetricEigenvalues (std::vector< RankFourTensorTempl< T >> &deriv) const
 Computes second derivatives of Eigenvalues of a rank two tensor. More...
 
void syev (const char *calculation_type, std::vector< T > &eigvals, std::vector< T > &a) const
 Uses the petscblaslapack.h LAPACKsyev_ routine to find, for symmetric _coords: (1) the eigenvalues (if calculation_type == "N") (2) the eigenvalues and eigenvectors (if calculation_type == "V") More...
 
void getRUDecompositionRotation (RankTwoTensorTempl< T > &rot) const
 Uses the petscblaslapack.h LAPACKsyev_ routine to perform RU decomposition and obtain the rotation tensor. More...
 
void vectorOuterProduct (const TypeVector< T > &, const TypeVector< T > &)
 RankTwoTensorTempl<T> from outer product of vectors. More...
 
void fillRealTensor (TensorValue< T > &)
 Return real tensor of a rank two tensor. More...
 
void fillRow (unsigned int, const TypeVector< T > &)
 Assigns value to the columns of a specified row. More...
 
void fillColumn (unsigned int, const TypeVector< T > &)
 Assigns value to the rows of a specified column. More...
 
RankTwoTensorTempl< T > initialContraction (const RankFourTensorTempl< T > &b) const
 returns this_ij * b_ijkl More...
 
void setToIdentity ()
 set the tensor to the identity matrix More...
 
template<>
void printReal (std::ostream &stm) const
 
template<>
void printDualReal (unsigned int nDual, std::ostream &stm) const
 
template<>
void QR (RankTwoTensorTempl< DualReal > &Q, RankTwoTensorTempl< DualReal > &R, unsigned int dim) const
 
template<>
void symmetricEigenvaluesEigenvectors (std::vector< DualReal > &eigvals, RankTwoTensorTempl< DualReal > &eigvecs) const
 
template<>
void syev (const char *, std::vector< DualReal > &, std::vector< DualReal > &) const
 
template<>
void getRUDecompositionRotation (RankTwoTensorTempl< DualReal > &) const
 

Static Public Member Functions

static RankTwoTensorTempl initializeFromRows (const TypeVector< T > &row0, const TypeVector< T > &row1, const TypeVector< T > &row2)
 named constructor for initializing from row vectors More...
 
static RankTwoTensorTempl initializeFromColumns (const TypeVector< T > &col0, const TypeVector< T > &col1, const TypeVector< T > &col2)
 named constructor for initializing from column vectors More...
 
static RankTwoTensorTempl Identity ()
 
static MooseEnum fillMethodEnum ()
 Static method for use in validParams for getting the "fill_method". More...
 
static void initRandom (unsigned int)
 This function initializes random seed based on a user-defined number. More...
 
static RankTwoTensorTempl< T > genRandomTensor (T, T)
 This function generates a random unsymmetric rank two tensor. More...
 
static RankTwoTensorTempl< T > genRandomSymmTensor (T, T)
 This function generates a random symmetric rank two tensor. More...
 

Static Private Attributes

static constexpr unsigned int N = LIBMESH_DIM
 
static constexpr unsigned int N2 = N * N
 
static constexpr Real identityCoords [N2] = {1, 0, 0, 0, 1, 0, 0, 0, 1}
 

Friends

template<class T2 >
class RankFourTensorTempl
 
template<class T2 >
class RankThreeTensorTempl
 
template<class T2 >
void dataStore (std::ostream &, RankTwoTensorTempl< T2 > &, void *)
 
template<class T2 >
void dataLoad (std::istream &, RankTwoTensorTempl< T2 > &, void *)
 

Detailed Description

template<typename T>
class RankTwoTensorTempl< T >

RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material.

It is designed to allow for maximum clarity of the mathematics and ease of use. Original class authors: A. M. Jokisaari, O. Heinonen, M. R. Tonks

RankTwoTensorTempl holds the 9 separate Sigma_ij or Epsilon_ij entries. The entries are accessed by index, with i, j equal to 1, 2, or 3, or internally i, j = 0, 1, 2.

Definition at line 114 of file MooseTypes.h.

Member Enumeration Documentation

◆ FillMethod

template<typename T>
enum RankTwoTensorTempl::FillMethod

To fill up the 9 entries in the 2nd-order tensor, fillFromInputVector is called with one of the following fill_methods.

See the fill*FromInputVector functions for more details

Enumerator
autodetect 
isotropic1 
diagonal3 
symmetric6 
general 

Definition at line 94 of file RankTwoTensor.h.

95  {
96  autodetect = 0,
97  isotropic1 = 1,
98  diagonal3 = 3,
99  symmetric6 = 6,
100  general = 9
101  };

◆ InitMethod

template<typename T>
enum RankTwoTensorTempl::InitMethod
Enumerator
initNone 
initIdentity 

Definition at line 77 of file RankTwoTensor.h.

78  {
79  initNone,
81  };

Constructor & Destructor Documentation

◆ RankTwoTensorTempl() [1/10]

template<typename T >
RankTwoTensorTempl< T >::RankTwoTensorTempl ( )

Default constructor; fills to zero.

Definition at line 65 of file RankTwoTensor.C.

66 {
67  mooseAssert(N == 3, "RankTwoTensorTempl is currently only tested for 3 dimensions.");
68 
69  for (unsigned int i = 0; i < N2; i++)
70  this->_coords[i] = 0.0;
71 }

Referenced by RankTwoTensorTempl< Real >::Identity().

◆ RankTwoTensorTempl() [2/10]

template<typename T >
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const InitMethod  init)

Select specific initialization pattern.

Definition at line 74 of file RankTwoTensor.C.

75 {
76  switch (init)
77  {
78  case initNone:
79  break;
80 
81  case initIdentity:
82  this->zero();
83  for (unsigned int i = 0; i < N; ++i)
84  (*this)(i, i) = 1.0;
85  break;
86 
87  default:
88  mooseError("Unknown RankTwoTensorTempl initialization pattern.");
89  }
90 }

◆ RankTwoTensorTempl() [3/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const TypeVector< T > &  row1,
const TypeVector< T > &  row2,
const TypeVector< T > &  row3 
)

Constructor that takes in 3 vectors and uses them to create rows _coords[0][i] = row1(i), _coords[1][i] = row2(i), _coords[2][i] = row3(i)

TODO: deprecate this method in favor of initializeFromRows.

Definition at line 94 of file RankTwoTensor.C.

97 {
98  // Initialize the Tensor matrix from the passed in vectors
99  for (unsigned int i = 0; i < N; i++)
100  this->_coords[i] = row1(i);
101 
102  for (unsigned int i = 0; i < N; i++)
103  this->_coords[N + i] = row2(i);
104 
105  const unsigned int two_n = N * 2;
106  for (unsigned int i = 0; i < N; i++)
107  this->_coords[two_n + i] = row3(i);
108 }

◆ RankTwoTensorTempl() [4/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const std::vector< T > &  input)
inline

Constructor that proxies the fillFromInputVector method.

Definition at line 122 of file RankTwoTensor.h.

122 { this->fillFromInputVector(input); };

◆ RankTwoTensorTempl() [5/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( S11,
S22,
S33,
S23,
S13,
S12 
)

Initialization list replacement constructors, 6 arguments.

Definition at line 131 of file RankTwoTensor.C.

132 {
133  (*this)(0, 0) = S11;
134  (*this)(1, 1) = S22;
135  (*this)(2, 2) = S33;
136  (*this)(1, 2) = (*this)(2, 1) = S23;
137  (*this)(0, 2) = (*this)(2, 0) = S13;
138  (*this)(0, 1) = (*this)(1, 0) = S12;
139 }

◆ RankTwoTensorTempl() [6/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( S11,
S21,
S31,
S12,
S22,
S32,
S13,
S23,
S33 
)

Initialization list replacement constructors, 9 arguments.

Definition at line 142 of file RankTwoTensor.C.

144 {
145  (*this)(0, 0) = S11;
146  (*this)(1, 0) = S21;
147  (*this)(2, 0) = S31;
148  (*this)(0, 1) = S12;
149  (*this)(1, 1) = S22;
150  (*this)(2, 1) = S32;
151  (*this)(0, 2) = S13;
152  (*this)(1, 2) = S23;
153  (*this)(2, 2) = S33;
154 }

◆ RankTwoTensorTempl() [7/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const RankTwoTensorTempl< T > &  a)
default

Copy assignment operator must be defined if used.

◆ RankTwoTensorTempl() [8/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const TensorValue< T > &  a)
inline

Copy constructor from TensorValue<T>

Definition at line 134 of file RankTwoTensor.h.

134 : TensorValue<T>(a) {}

◆ RankTwoTensorTempl() [9/10]

template<typename T>
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const TypeTensor< T > &  a)
inline

Copy constructor from TypeTensor<T>

Definition at line 137 of file RankTwoTensor.h.

137 : TensorValue<T>(a) {}

◆ RankTwoTensorTempl() [10/10]

template<typename T>
template<typename T2 >
RankTwoTensorTempl< T >::RankTwoTensorTempl ( const RankTwoTensorTempl< T2 > &  a)
inline

Construct from other template.

Definition at line 141 of file RankTwoTensor.h.

141  : TensorValue<T>(a)
142  {
143  }

Member Function Documentation

◆ addIa()

template<typename T>
void RankTwoTensorTempl< T >::addIa ( const T &  a)

Add identity times a to _coords.

Definition at line 874 of file RankTwoTensor.C.

875 {
876  for (unsigned int i = 0; i < N; ++i)
877  (*this)(i, i) += a;
878 }

Referenced by RankTwoTensorTempl< Real >::deviatoric(), RankTwoTensorTempl< Real >::hessenberg(), RankTwoTensorTempl< Real >::QR(), and RankTwoTensorTempl< Real >::symmetricEigenvaluesEigenvectors().

◆ column()

template<typename T >
TypeVector< T > RankTwoTensorTempl< T >::column ( const unsigned int  c) const

returns _coords[i][c], ie, column c, with c = 0, 1, 2

Definition at line 241 of file RankTwoTensor.C.

242 {
243  VectorValue<T> result;
244 
245  for (unsigned int i = 0; i < N; ++i)
246  result(i) = (*this)(i, c);
247 
248  return result;
249 }

Referenced by RankTwoTensorTempl< Real >::positiveProjectionEigenDecomposition().

◆ d2secondInvariant()

template<typename T >
RankFourTensorTempl< T > RankTwoTensorTempl< T >::d2secondInvariant ( ) const

Denote the _coords[i][j] by A_ij, then this returns d^2(secondInvariant)/dA_ij/dA_kl.

Definition at line 581 of file RankTwoTensor.C.

582 {
583  RankFourTensorTempl<T> result;
584 
585  unsigned int index = 0;
586  for (unsigned int i = 0; i < N; ++i)
587  for (unsigned int j = 0; j < N; ++j)
588  for (unsigned int k = 0; k < N; ++k)
589  for (unsigned int l = 0; l < N; ++l)
590  result._vals[index++] = 0.5 * (i == k) * (j == l) + 0.5 * (i == l) * (j == k) -
591  (1.0 / 3.0) * (i == j) * (k == l);
592 
593  return result;
594 }

◆ d2sin3Lode()

template<typename T>
RankFourTensorTempl< T > RankTwoTensorTempl< T >::d2sin3Lode ( const T &  r0) const

d^2(sin3Lode)/dA_ij/dA_kl If secondInvariant() <= r0 then return zero This is to gaurd against precision-loss errors.

Note that sin(3*Lode_angle) is not defined for secondInvariant() = 0

Definition at line 778 of file RankTwoTensor.C.

779 {
780  T bar = secondInvariant();
781  if (bar <= r0)
782  return RankFourTensorTempl<T>();
783 
784  T J3 = thirdInvariant();
787  RankFourTensorTempl<T> deriv =
788  d2thirdInvariant() / std::pow(bar, 1.5) - 1.5 * d2secondInvariant() * J3 / std::pow(bar, 2.5);
789 
790  for (unsigned i = 0; i < N; ++i)
791  for (unsigned j = 0; j < N; ++j)
792  for (unsigned k = 0; k < N; ++k)
793  for (unsigned l = 0; l < N; ++l)
794  deriv(i, j, k, l) +=
795  (-1.5 * dII(i, j) * dIII(k, l) - 1.5 * dIII(i, j) * dII(k, l)) / std::pow(bar, 2.5) +
796  1.5 * 2.5 * dII(i, j) * dII(k, l) * J3 / std::pow(bar, 3.5);
797 
798  deriv *= -1.5 * std::sqrt(3.0);
799  return deriv;
800 }

◆ d2symmetricEigenvalues()

template<typename T>
void RankTwoTensorTempl< T >::d2symmetricEigenvalues ( std::vector< RankFourTensorTempl< T >> &  deriv) const

Computes second derivatives of Eigenvalues of a rank two tensor.

Parameters
derivstore second derivative of the current tensor in here

Definition at line 1149 of file RankTwoTensor.C.

1150 {
1151  std::vector<T> eigvec;
1152  std::vector<T> eigvals;
1153  T ev[N][N];
1154 
1155  // reset rank four tensor
1156  deriv.assign(N, RankFourTensorTempl<T>());
1157 
1158  // get eigen values and eigen vectors
1159  syev("V", eigvals, eigvec);
1160 
1161  for (unsigned int i = 0; i < N; ++i)
1162  for (unsigned int j = 0; j < N; ++j)
1163  ev[i][j] = eigvec[i * N + j];
1164 
1165  for (unsigned int alpha = 0; alpha < N; ++alpha)
1166  for (unsigned int beta = 0; beta < N; ++beta)
1167  {
1168  if (eigvals[alpha] == eigvals[beta])
1169  continue;
1170 
1171  for (unsigned int i = 0; i < N; ++i)
1172  for (unsigned int j = 0; j < N; ++j)
1173  for (unsigned int k = 0; k < N; ++k)
1174  for (unsigned int l = 0; l < N; ++l)
1175  {
1176  deriv[alpha](i, j, k, l) +=
1177  0.5 * (ev[beta][i] * ev[alpha][j] + ev[alpha][i] * ev[beta][j]) *
1178  (ev[beta][k] * ev[alpha][l] + ev[beta][l] * ev[alpha][k]) /
1179  (eigvals[alpha] - eigvals[beta]);
1180  }
1181  }
1182 }

◆ d2thirdInvariant()

template<typename T >
RankFourTensorTempl< T > RankTwoTensorTempl< T >::d2thirdInvariant ( ) const

Denote the _coords[i][j] by A_ij, then this returns d^2(thirdInvariant)/dA_ij/dA_kl.

Definition at line 659 of file RankTwoTensor.C.

660 {
661  RankTwoTensorTempl<T> s = 0.5 * deviatoric();
662  s += s.transpose();
663 
665  unsigned int index = 0;
666  for (unsigned int i = 0; i < N; ++i)
667  for (unsigned int j = 0; j < N; ++j)
668  for (unsigned int k = 0; k < N; ++k)
669  for (unsigned int l = 0; l < N; ++l)
670  {
671  d2._vals[index++] = (i == j) * s(k, l) / 3.0 + (k == l) * s(i, j) / 3.0;
672  // for (unsigned int a = 0; a < N; ++a)
673  // for (unsigned int b = 0; b < N; ++b)
674  // d2(i, j, k, l) += 0.5*(PermutationTensor::eps(i, k, a)*PermutationTensor::eps(j, l,
675  // b) + PermutationTensor::eps(i, l, a)*PermutationTensor::eps(j, k, b))*s(a, b);
676  }
677 
678  // I'm not sure which is more readable: the above
679  // PermutationTensor stuff, or the stuff below.
680  // Anyway, they yield the same result, and so i leave
681  // both of them here to enlighten you!
682 
683  d2(0, 0, 1, 1) += s(2, 2);
684  d2(0, 0, 1, 2) -= s(2, 1);
685  d2(0, 0, 2, 1) -= s(1, 2);
686  d2(0, 0, 2, 2) += s(1, 1);
687 
688  d2(0, 1, 0, 1) -= s(2, 2) / 2.0;
689  d2(0, 1, 1, 0) -= s(2, 2) / 2.0;
690  d2(0, 1, 0, 2) += s(1, 2) / 2.0;
691  d2(0, 1, 2, 0) += s(1, 2) / 2.0;
692  d2(0, 1, 1, 2) += s(2, 0) / 2.0;
693  d2(0, 1, 2, 1) += s(2, 0) / 2.0;
694  d2(0, 1, 2, 2) -= s(1, 0);
695 
696  d2(0, 2, 0, 1) += s(2, 1) / 2.0;
697  d2(0, 2, 1, 0) += s(2, 1) / 2.0;
698  d2(0, 2, 0, 2) -= s(1, 1) / 2.0;
699  d2(0, 2, 2, 0) -= s(1, 1) / 2.0;
700  d2(0, 2, 1, 1) -= s(2, 0);
701  d2(0, 2, 1, 2) += s(1, 0) / 2.0;
702  d2(0, 2, 2, 1) += s(1, 0) / 2.0;
703 
704  d2(1, 0, 0, 1) -= s(2, 2) / 2.0;
705  d2(1, 0, 1, 0) -= s(2, 2) / 2.0;
706  d2(1, 0, 0, 2) += s(1, 2) / 2.0;
707  d2(1, 0, 2, 0) += s(1, 2) / 2.0;
708  d2(1, 0, 1, 2) += s(2, 0) / 2.0;
709  d2(1, 0, 2, 1) += s(2, 0) / 2.0;
710  d2(1, 0, 2, 2) -= s(1, 0);
711 
712  d2(1, 1, 0, 0) += s(2, 2);
713  d2(1, 1, 0, 2) -= s(2, 0);
714  d2(1, 1, 2, 0) -= s(2, 0);
715  d2(1, 1, 2, 2) += s(0, 0);
716 
717  d2(1, 2, 0, 0) -= s(2, 1);
718  d2(1, 2, 0, 1) += s(2, 0) / 2.0;
719  d2(1, 2, 1, 0) += s(2, 0) / 2.0;
720  d2(1, 2, 0, 2) += s(0, 1) / 2.0;
721  d2(1, 2, 2, 0) += s(0, 1) / 2.0;
722  d2(1, 2, 1, 2) -= s(0, 0) / 2.0;
723  d2(1, 2, 2, 1) -= s(0, 0) / 2.0;
724 
725  d2(2, 0, 0, 1) += s(2, 1) / 2.0;
726  d2(2, 0, 1, 0) += s(2, 1) / 2.0;
727  d2(2, 0, 0, 2) -= s(1, 1) / 2.0;
728  d2(2, 0, 2, 0) -= s(1, 1) / 2.0;
729  d2(2, 0, 1, 1) -= s(2, 0);
730  d2(2, 0, 1, 2) += s(1, 0) / 2.0;
731  d2(2, 0, 2, 1) += s(1, 0) / 2.0;
732 
733  d2(2, 1, 0, 0) -= s(2, 1);
734  d2(2, 1, 0, 1) += s(2, 0) / 2.0;
735  d2(2, 1, 1, 0) += s(2, 0) / 2.0;
736  d2(2, 1, 0, 2) += s(0, 1) / 2.0;
737  d2(2, 1, 2, 0) += s(0, 1) / 2.0;
738  d2(2, 1, 1, 2) -= s(0, 0) / 2.0;
739  d2(2, 1, 2, 1) -= s(0, 0) / 2.0;
740 
741  d2(2, 2, 0, 0) += s(1, 1);
742  d2(2, 2, 0, 1) -= s(1, 0);
743  d2(2, 2, 1, 0) -= s(1, 0);
744  d2(2, 2, 1, 1) += s(0, 0);
745 
746  return d2;
747 }

◆ ddet()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::ddet ( ) const

Denote the _coords[i][j] by A_ij, then this returns d(det)/dA_ij.

Definition at line 804 of file RankTwoTensor.C.

805 {
807 
808  d(0, 0) = (*this)(1, 1) * (*this)(2, 2) - (*this)(2, 1) * (*this)(1, 2);
809  d(0, 1) = (*this)(2, 0) * (*this)(1, 2) - (*this)(1, 0) * (*this)(2, 2);
810  d(0, 2) = (*this)(1, 0) * (*this)(2, 1) - (*this)(2, 0) * (*this)(1, 1);
811  d(1, 0) = (*this)(2, 1) * (*this)(0, 2) - (*this)(0, 1) * (*this)(2, 2);
812  d(1, 1) = (*this)(0, 0) * (*this)(2, 2) - (*this)(2, 0) * (*this)(0, 2);
813  d(1, 2) = (*this)(2, 0) * (*this)(0, 1) - (*this)(0, 0) * (*this)(2, 1);
814  d(2, 0) = (*this)(0, 1) * (*this)(1, 2) - (*this)(1, 1) * (*this)(0, 2);
815  d(2, 1) = (*this)(1, 0) * (*this)(0, 2) - (*this)(0, 0) * (*this)(1, 2);
816  d(2, 2) = (*this)(0, 0) * (*this)(1, 1) - (*this)(1, 0) * (*this)(0, 1);
817 
818  return d;
819 }

◆ deviatoric()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::deviatoric ( ) const

returns A_ij - de_ij*tr(A)/3, where A are the _coords

Definition at line 531 of file RankTwoTensor.C.

532 {
534  deviatoric.addIa(-1.0 / 3.0 * this->tr()); // actually construct deviatoric part
535  return deviatoric;
536 }

◆ doubleContraction()

template<typename T>
T RankTwoTensorTempl< T >::doubleContraction ( const RankTwoTensorTempl< T > &  a) const

returns _coords_ij * a_ij (sum on i, j)

Definition at line 402 of file RankTwoTensor.C.

403 {
404  // deprecate this!
405  return TensorValue<T>::contract(b);
406 }

◆ dsecondInvariant()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::dsecondInvariant ( ) const

Denote the _coords[i][j] by A_ij, then this returns d(secondInvariant)/dA_ij.

Definition at line 574 of file RankTwoTensor.C.

575 {
576  return 0.5 * (deviatoric() + deviatoric().transpose());
577 }

◆ dsin3Lode()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::dsin3Lode ( const T &  r0) const

d(sin3Lode)/dA_ij If secondInvariant() <= r0 then return zero This is to gaurd against precision-loss errors.

Note that sin(3*Lode_angle) is not defined for secondInvariant() = 0

Definition at line 765 of file RankTwoTensor.C.

766 {
767  T bar = secondInvariant();
768  if (bar <= r0)
769  return RankTwoTensorTempl<T>();
770  else
771  return -1.5 * std::sqrt(3.0) *
772  (dthirdInvariant() / std::pow(bar, 1.5) -
773  1.5 * dsecondInvariant() * thirdInvariant() / std::pow(bar, 2.5));
774 }

◆ dsymmetricEigenvalues()

template<typename T>
void RankTwoTensorTempl< T >::dsymmetricEigenvalues ( std::vector< T > &  eigvals,
std::vector< RankTwoTensorTempl< T >> &  deigvals 
) const

computes eigenvalues, and their symmetric derivatives wrt vals, assuming tens is symmetric

Parameters
eigvalsare the eigenvalues of the matrix, in ascending order
deigvalsHere digvals[i](j,k) = (1/2)*(d(eigvals[i])/dA_jk + d(eigvals[i]/dA_kj)) Note the explicit symmeterisation here. For equal eigenvalues, these derivatives are not gauranteed to be the ones you expect, since the derivatives in this case are often defined by continuation from the un-equal case, and that is too sophisticated for this routine.

Definition at line 1110 of file RankTwoTensor.C.

1112 {
1113  deigvals.resize(N);
1114 
1115  std::vector<T> a;
1116  syev("V", eigvals, a);
1117 
1118  // now a contains the eigenvetors
1119  // extract these and place appropriately in deigvals
1120  std::vector<T> eig_vec;
1121  eig_vec.resize(N);
1122 
1123  for (unsigned int i = 0; i < N; ++i)
1124  {
1125  for (unsigned int j = 0; j < N; ++j)
1126  eig_vec[j] = a[i * N + j];
1127  for (unsigned int j = 0; j < N; ++j)
1128  for (unsigned int k = 0; k < N; ++k)
1129  deigvals[i](j, k) = eig_vec[j] * eig_vec[k];
1130  }
1131 
1132  // There are discontinuities in the derivative
1133  // for equal eigenvalues. The following is
1134  // an attempt to make a sensible choice for
1135  // the derivative. This agrees with a central-difference
1136  // approximation to the derivative.
1137  if (eigvals[0] == eigvals[1] && eigvals[0] == eigvals[2])
1138  deigvals[0] = deigvals[1] = deigvals[2] = (deigvals[0] + deigvals[1] + deigvals[2]) / 3.0;
1139  else if (eigvals[0] == eigvals[1])
1140  deigvals[0] = deigvals[1] = (deigvals[0] + deigvals[1]) / 2.0;
1141  else if (eigvals[0] == eigvals[2])
1142  deigvals[0] = deigvals[2] = (deigvals[0] + deigvals[2]) / 2.0;
1143  else if (eigvals[1] == eigvals[2])
1144  deigvals[1] = deigvals[2] = (deigvals[1] + deigvals[2]) / 2.0;
1145 }

◆ dthirdInvariant()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::dthirdInvariant ( ) const

Denote the _coords[i][j] by A_ij, then this returns d(thirdInvariant()/dA_ij.

Definition at line 636 of file RankTwoTensor.C.

637 {
638  RankTwoTensorTempl<T> s = 0.5 * deviatoric();
639  s += s.transpose();
640 
642  T sec_over_three = secondInvariant() / 3.0;
643 
644  d(0, 0) = s(1, 1) * s(2, 2) - s(2, 1) * s(1, 2) + sec_over_three;
645  d(0, 1) = s(2, 0) * s(1, 2) - s(1, 0) * s(2, 2);
646  d(0, 2) = s(1, 0) * s(2, 1) - s(2, 0) * s(1, 1);
647  d(1, 0) = s(2, 1) * s(0, 2) - s(0, 1) * s(2, 2);
648  d(1, 1) = s(0, 0) * s(2, 2) - s(2, 0) * s(0, 2) + sec_over_three;
649  d(1, 2) = s(2, 0) * s(0, 1) - s(0, 0) * s(2, 1);
650  d(2, 0) = s(0, 1) * s(1, 2) - s(1, 1) * s(0, 2);
651  d(2, 1) = s(1, 0) * s(0, 2) - s(0, 0) * s(1, 2);
652  d(2, 2) = s(0, 0) * s(1, 1) - s(1, 0) * s(0, 1) + sec_over_three;
653 
654  return d;
655 }

◆ dtrace()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::dtrace ( ) const

Denote the _coords[i][j] by A_ij, then this returns d(trace)/dA_ij.

Definition at line 613 of file RankTwoTensor.C.

614 {
615  return RankTwoTensorTempl<T>(1, 0, 0, 0, 1, 0, 0, 0, 1);
616 }

◆ fillColumn()

template<typename T>
void RankTwoTensorTempl< T >::fillColumn ( unsigned int  c,
const TypeVector< T > &  v 
)

Assigns value to the rows of a specified column.

Definition at line 1331 of file RankTwoTensor.C.

1332 {
1333  for (unsigned int i = 0; i < N; ++i)
1334  (*this)(i, c) = v(i);
1335 }

◆ fillFromInputVector()

template<typename T>
void RankTwoTensorTempl< T >::fillFromInputVector ( const std::vector< T > &  input,
FillMethod  fill_method = autodetect 
)

fillFromInputVector takes 6 or 9 inputs to fill in the Rank-2 tensor.

If 6 inputs, then symmetry is assumed S_ij = S_ji, and _coords[0][0] = input[0] _coords[1][1] = input[1] _coords[2][2] = input[2] _coords[1][2] = input[3] _coords[0][2] = input[4] _coords[0][1] = input[5] If 9 inputs then input order is [0][0], [1][0], [2][0], [0][1], [1][1], ..., [2][2]

Definition at line 158 of file RankTwoTensor.C.

159 {
160  if (fill_method != autodetect && fill_method != input.size())
161  mooseError("Expected an input vector size of ", fill_method, " to fill the RankTwoTensorTempl");
162 
163  switch (input.size())
164  {
165  case 1:
166  this->zero();
167  (*this)(0, 0) = input[0]; // S11
168  (*this)(1, 1) = input[0]; // S22
169  (*this)(2, 2) = input[0]; // S33
170  break;
171 
172  case 3:
173  this->zero();
174  (*this)(0, 0) = input[0]; // S11
175  (*this)(1, 1) = input[1]; // S22
176  (*this)(2, 2) = input[2]; // S33
177  break;
178 
179  case 6:
180  (*this)(0, 0) = input[0]; // S11
181  (*this)(1, 1) = input[1]; // S22
182  (*this)(2, 2) = input[2]; // S33
183  (*this)(1, 2) = (*this)(2, 1) = input[3]; // S23
184  (*this)(0, 2) = (*this)(2, 0) = input[4]; // S13
185  (*this)(0, 1) = (*this)(1, 0) = input[5]; // S12
186  break;
187 
188  case 9:
189  (*this)(0, 0) = input[0]; // S11
190  (*this)(1, 0) = input[1]; // S21
191  (*this)(2, 0) = input[2]; // S31
192  (*this)(0, 1) = input[3]; // S12
193  (*this)(1, 1) = input[4]; // S22
194  (*this)(2, 1) = input[5]; // S32
195  (*this)(0, 2) = input[6]; // S13
196  (*this)(1, 2) = input[7]; // S23
197  (*this)(2, 2) = input[8]; // S33
198  break;
199 
200  default:
201  mooseError("Please check the number of entries in the input vector for building "
202  "a RankTwoTensorTempl. It must be 1, 3, 6, or 9");
203  }
204 }

Referenced by GenericConstantRankTwoTensor::GenericConstantRankTwoTensor(), and RankTwoTensorTempl< Real >::RankTwoTensorTempl().

◆ fillFromScalarVariable()

template<typename T >
void RankTwoTensorTempl< T >::fillFromScalarVariable ( const VariableValue scalar_variable)

fillFromScalarVariable takes FIRST/THIRD/SIXTH order scalar variable to fill in the Rank-2 tensor.

Definition at line 208 of file RankTwoTensor.C.

209 {
210  switch (scalar_variable.size())
211  {
212  case 1:
213  this->zero();
214  (*this)(0, 0) = scalar_variable[0]; // S11
215  break;
216 
217  case 3:
218  this->zero();
219  (*this)(0, 0) = scalar_variable[0]; // S11
220  (*this)(1, 1) = scalar_variable[1]; // S22
221  (*this)(0, 1) = (*this)(1, 0) = scalar_variable[2]; // S12
222  break;
223 
224  case 6:
225  (*this)(0, 0) = scalar_variable[0]; // S11
226  (*this)(1, 1) = scalar_variable[1]; // S22
227  (*this)(2, 2) = scalar_variable[2]; // S33
228  (*this)(1, 2) = (*this)(2, 1) = scalar_variable[3]; // S23
229  (*this)(0, 2) = (*this)(2, 0) = scalar_variable[4]; // S13
230  (*this)(0, 1) = (*this)(1, 0) = scalar_variable[5]; // S12
231  break;
232 
233  default:
234  mooseError("Only FIRST, THIRD, or SIXTH order scalar variable can be used to build "
235  "a RankTwoTensorTempl.");
236  }
237 }

◆ fillMethodEnum()

template<typename T >
MooseEnum RankTwoTensorTempl< T >::fillMethodEnum ( )
static

Static method for use in validParams for getting the "fill_method".

Definition at line 59 of file RankTwoTensor.C.

60 {
61  return MooseEnum("autodetect=0 isotropic1=1 diagonal3=3 symmetric6=6 general=9", "autodetect");
62 }

◆ fillRealTensor()

template<typename T>
void RankTwoTensorTempl< T >::fillRealTensor ( TensorValue< T > &  tensor)

Return real tensor of a rank two tensor.

Definition at line 1314 of file RankTwoTensor.C.

1315 {
1316  for (unsigned int i = 0; i < N; ++i)
1317  for (unsigned int j = 0; j < N; ++j)
1318  tensor(i, j) = (*this)(i, j);
1319 }

◆ fillRow()

template<typename T>
void RankTwoTensorTempl< T >::fillRow ( unsigned int  r,
const TypeVector< T > &  v 
)

Assigns value to the columns of a specified row.

Definition at line 1323 of file RankTwoTensor.C.

1324 {
1325  for (unsigned int i = 0; i < N; ++i)
1326  (*this)(r, i) = v(i);
1327 }

◆ generalSecondInvariant()

template<typename T >
T RankTwoTensorTempl< T >::generalSecondInvariant ( ) const

Denote the _coords[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns (S_ij + S_ji)*(S_ij + S_ji)/8 Note the explicit symmeterisation.

Definition at line 540 of file RankTwoTensor.C.

541 {
542  // clang-format off
543  T result = (*this)(0, 0) * (*this)(1, 1) +
544  (*this)(0, 0) * (*this)(2, 2) +
545  (*this)(1, 1) * (*this)(2, 2) -
546  (*this)(0, 1) * (*this)(1, 0) -
547  (*this)(0, 2) * (*this)(2, 0) -
548  (*this)(1, 2) * (*this)(2, 1);
549  // clang-format on
550  return result;
551 }

◆ genRandomSymmTensor()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::genRandomSymmTensor ( scale,
offset 
)
static

This function generates a random symmetric rank two tensor.

The first real scales the random number. The second real offsets the uniform random number

Definition at line 1292 of file RankTwoTensor.C.

1293 {
1294  RankTwoTensorTempl<T> tensor;
1295 
1296  for (unsigned int i = 0; i < N; i++)
1297  for (unsigned int j = i; j < N; j++)
1298  tensor(i, j) = tensor(j, i) = (MooseRandom::rand() + offset) * scale;
1299 
1300  return tensor;
1301 }

◆ genRandomTensor()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::genRandomTensor ( scale,
offset 
)
static

This function generates a random unsymmetric rank two tensor.

The first real scales the random number. The second real offsets the uniform random number

Definition at line 1279 of file RankTwoTensor.C.

1280 {
1281  RankTwoTensorTempl<T> tensor;
1282 
1283  for (unsigned int i = 0; i < N; i++)
1284  for (unsigned int j = 0; j < N; j++)
1285  tensor(i, j) = (MooseRandom::rand() + offset) * scale;
1286 
1287  return tensor;
1288 }

◆ getRUDecompositionRotation() [1/2]

template<>
void RankTwoTensorTempl< DualReal >::getRUDecompositionRotation ( RankTwoTensorTempl< DualReal > &  ) const

Definition at line 1265 of file RankTwoTensor.C.

1266 {
1267  mooseError("DualRankTwoTensor does not support getRUDecompositionRotation");
1268 }

◆ getRUDecompositionRotation() [2/2]

template<typename T>
void RankTwoTensorTempl< T >::getRUDecompositionRotation ( RankTwoTensorTempl< T > &  rot) const

Uses the petscblaslapack.h LAPACKsyev_ routine to perform RU decomposition and obtain the rotation tensor.

Definition at line 1228 of file RankTwoTensor.C.

1229 {
1230  const RankTwoTensorTempl<T> & a = *this;
1231  RankTwoTensorTempl<T> c, diag, evec;
1232  PetscScalar cmat[N][N], work[10];
1233  PetscReal w[N];
1234 
1235  // prepare data for the LAPACKsyev_ routine (which comes from petscblaslapack.h)
1236  PetscBLASInt nd = N, lwork = 10, info;
1237 
1238  c = a.transpose() * a;
1239 
1240  for (unsigned int i = 0; i < N; ++i)
1241  for (unsigned int j = 0; j < N; ++j)
1242  cmat[i][j] = c(i, j);
1243 
1244  LAPACKsyev_("V", "U", &nd, &cmat[0][0], &nd, w, work, &lwork, &info);
1245 
1246  if (info != 0)
1247  mooseError("In computing the eigenvalues and eigenvectors of a symmetric rank-2 tensor, the "
1248  "PETSC LAPACK syev routine returned error code ",
1249  info);
1250 
1251  diag.zero();
1252 
1253  for (unsigned int i = 0; i < N; ++i)
1254  diag(i, i) = std::sqrt(w[i]);
1255 
1256  for (unsigned int i = 0; i < N; ++i)
1257  for (unsigned int j = 0; j < N; ++j)
1258  evec(i, j) = cmat[i][j];
1259 
1260  rot = a * ((evec.transpose() * diag * evec).inverse());
1261 }

◆ givensRotation()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::givensRotation ( unsigned int  row1,
unsigned int  row2,
unsigned int  col 
) const

computes and returns the Givens rotation matrix R

Parameters
row1is the row number of the first component to rotate
row2is the row number of the second component to rotate
colis the column number of the components to rotate consider a RankTwoTensor A = [ a11 a12 a13 a21 a22 a23 a31 a32 a33] and we want to rotate a21 and a31. Then row1 = 1, row2 = 2, col = 0. It retunrs the Givens rotation matrix R of this tensor A such that R * A rotates the second component to zero, i.e. R * A = [ a11 a12 a13 r a22 a23 0 a32 a33] A DualReal instantiation is available to rotate dual numbers as well.

Definition at line 948 of file RankTwoTensor.C.

949 {
950  T c, s;
951  T a = (*this)(row1, col);
952  T b = (*this)(row2, col);
953 
955  {
956  c = a >= 0.0 ? 1.0 : -1.0;
957  s = 0.0;
958  }
959  else if (std::abs(a) > std::abs(b))
960  {
961  T t = b / a;
962  Real sgn = a >= 0.0 ? 1.0 : -1.0;
963  T u = sgn * std::sqrt(1.0 + t * t);
964  c = 1.0 / u;
965  s = c * t;
966  }
967  else
968  {
969  T t = a / b;
970  Real sgn = b >= 0.0 ? 1.0 : -1.0;
971  T u = sgn * std::sqrt(1.0 + t * t);
972  s = 1.0 / u;
973  c = s * t;
974  }
975 
977  R(row1, row1) = c;
978  R(row1, row2) = s;
979  R(row2, row1) = -s;
980  R(row2, row2) = c;
981 
982  return R;
983 }

Referenced by RankTwoTensorTempl< Real >::QR().

◆ hessenberg()

template<typename T>
void RankTwoTensorTempl< T >::hessenberg ( RankTwoTensorTempl< T > &  H,
RankTwoTensorTempl< T > &  U 
) const

computes the Hessenberg form of this matrix A and its unitary transformation U such that A = U * H * U^T

Definition at line 987 of file RankTwoTensor.C.

988 {
989  H = *this;
990  U.zero();
991  U.addIa(1.0);
992 
993  if (N < 3)
994  return;
995 
996  RankTwoTensorTempl<T> R = this->givensRotation(N - 2, N - 1, 0);
997  H = R * H * R.transpose();
998  U = U * R.transpose();
999 }

◆ Identity()

template<typename T>
static RankTwoTensorTempl RankTwoTensorTempl< T >::Identity ( )
inlinestatic

Definition at line 146 of file RankTwoTensor.h.

146 { return RankTwoTensorTempl(initIdentity); }

◆ initialContraction()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::initialContraction ( const RankFourTensorTempl< T > &  b) const

returns this_ij * b_ijkl

Definition at line 1339 of file RankTwoTensor.C.

1340 {
1341  RankTwoTensorTempl<T> result;
1342 
1343  unsigned int index = 0;
1344  for (unsigned int i = 0; i < N; ++i)
1345  for (unsigned int j = 0; j < N; ++j)
1346  {
1347  const T & a = (*this)(i, j);
1348  for (unsigned int k = 0; k < N; ++k)
1349  for (unsigned int l = 0; l < N; ++l)
1350  result(k, l) += a * b._vals[index++];
1351  }
1352 
1353  return result;
1354 }

◆ initializeFromColumns()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::initializeFromColumns ( const TypeVector< T > &  col0,
const TypeVector< T > &  col1,
const TypeVector< T > &  col2 
)
static

named constructor for initializing from column vectors

Definition at line 122 of file RankTwoTensor.C.

125 {
126  return RankTwoTensorTempl<T>(
127  col0(0), col0(1), col0(2), col1(0), col1(1), col1(2), col2(0), col2(1), col2(2));
128 }

◆ initializeFromRows()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::initializeFromRows ( const TypeVector< T > &  row0,
const TypeVector< T > &  row1,
const TypeVector< T > &  row2 
)
static

named constructor for initializing from row vectors

Definition at line 112 of file RankTwoTensor.C.

115 {
116  return RankTwoTensorTempl<T>(
117  row0(0), row1(0), row2(0), row0(1), row1(1), row2(1), row0(2), row1(2), row2(2));
118 }

◆ initRandom()

template<typename T >
void RankTwoTensorTempl< T >::initRandom ( unsigned int  rand_seed)
static

This function initializes random seed based on a user-defined number.

Definition at line 1272 of file RankTwoTensor.C.

1273 {
1274  MooseRandom::seed(rand_seed);
1275 }

◆ inverse()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::inverse ( ) const

retuns the inverse of the tensor

Definition at line 606 of file RankTwoTensor.C.

607 {
608  return TensorValue<T>::inverse();
609 }

◆ L2norm()

template<typename T >
T RankTwoTensorTempl< T >::L2norm ( ) const

Sqrt(_coords[i][j]*_coords[i][j])

Definition at line 882 of file RankTwoTensor.C.

883 {
884  T norm = 0.0;
885  for (unsigned int i = 0; i < N2; ++i)
886  {
887  T v = this->_coords[i];
888  norm += v * v;
889  }
890  return norm == 0.0 ? 0.0 : std::sqrt(norm);
891 }

◆ mixedProductIkJl()

template<typename T>
RankFourTensorTempl< T > RankTwoTensorTempl< T >::mixedProductIkJl ( const RankTwoTensorTempl< T > &  a) const

returns C_ijkl = a_ik * b_jl

Definition at line 427 of file RankTwoTensor.C.

428 {
429  RankFourTensorTempl<T> result;
430 
431  unsigned int index = 0;
432  for (unsigned int i = 0; i < N; ++i)
433  for (unsigned int j = 0; j < N; ++j)
434  for (unsigned int k = 0; k < N; ++k)
435  {
436  const T & a = (*this)(i, k);
437  for (unsigned int l = 0; l < N; ++l)
438  result._vals[index++] = a * b(j, l);
439  }
440 
441  return result;
442 }

Referenced by RankTwoTensorTempl< Real >::positiveProjectionEigenDecomposition().

◆ mixedProductIlJk()

template<typename T>
RankFourTensorTempl< T > RankTwoTensorTempl< T >::mixedProductIlJk ( const RankTwoTensorTempl< T > &  a) const

returns C_ijkl = a_il * b_jk

Definition at line 446 of file RankTwoTensor.C.

447 {
448  RankFourTensorTempl<T> result;
449 
450  for (unsigned int i = 0; i < N; ++i)
451  for (unsigned int j = 0; j < N; ++j)
452  for (unsigned int k = 0; k < N; ++k)
453  for (unsigned int l = 0; l < N; ++l)
454  result(i, j, k, l) = (*this)(i, l) * b(j, k);
455 
456  return result;
457 }

Referenced by RankTwoTensorTempl< Real >::positiveProjectionEigenDecomposition().

◆ mixedProductJkIl()

template<typename T>
RankFourTensorTempl< T > RankTwoTensorTempl< T >::mixedProductJkIl ( const RankTwoTensorTempl< T > &  a) const

returns C_ijkl = a_jk * b_il

Definition at line 461 of file RankTwoTensor.C.

462 {
463  RankFourTensorTempl<T> result;
464 
465  unsigned int index = 0;
466  for (unsigned int i = 0; i < N; ++i)
467  for (unsigned int j = 0; j < N; ++j)
468  for (unsigned int k = 0; k < N; ++k)
469  {
470  const T & a = (*this)(j, k);
471  for (unsigned int l = 0; l < N; ++l)
472  result._vals[index++] = a * b(i, l);
473  }
474 
475  return result;
476 }

◆ operator*() [1/3]

template<typename T >
template<typename T2 , typename std::enable_if< ScalarTraits< T2 >::value, int >::type >
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > RankTwoTensorTempl< T >::operator* ( const T2 &  a) const

returns _coords*a

Definition at line 559 of file RankTwoTensor.h.

560 {
561  return TensorValue<T>::operator*(b);
562 }

◆ operator*() [2/3]

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

Defines multiplication with a TypeTensor<T>

Definition at line 575 of file RankTwoTensor.h.

576 {
577  return TensorValue<T>::operator*(b);
578 }

◆ operator*() [3/3]

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

Defines multiplication with a vector to get a vector.

Definition at line 567 of file RankTwoTensor.h.

568 {
569  return TensorValue<T>::operator*(b);
570 }

◆ operator*=() [1/2]

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator*= ( const T &  a)

performs _coords *= a

Definition at line 351 of file RankTwoTensor.C.

352 {
353  TensorValue<T>::operator*=(a);
354  return *this;
355 }

◆ operator*=() [2/2]

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator*= ( const TypeTensor< T > &  a)

Defines multiplication with a TypeTensor<T>

Definition at line 367 of file RankTwoTensor.C.

368 {
369  *this = *this * a;
370  return *this;
371 }

◆ operator+()

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

returns _coords + a

Definition at line 543 of file RankTwoTensor.h.

544 {
545  return TensorValue<T>::operator+(b);
546 }

◆ operator+=()

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator+= ( const RankTwoTensorTempl< T > &  a)

adds a to _coords

Definition at line 328 of file RankTwoTensor.C.

329 {
330  TensorValue<T>::operator+=(a);
331  return *this;
332 }

◆ operator-() [1/2]

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::operator- ( ) const

returns -_coords

Definition at line 344 of file RankTwoTensor.C.

345 {
346  return TensorValue<T>::operator-();
347 }

◆ operator-() [2/2]

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

returns _coords - a

Definition at line 551 of file RankTwoTensor.h.

552 {
553  return TensorValue<T>::operator-(b);
554 }

◆ operator-=()

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator-= ( const RankTwoTensorTempl< T > &  a)

sets _coords -= a and returns vals

Definition at line 336 of file RankTwoTensor.C.

337 {
338  TensorValue<T>::operator-=(a);
339  return *this;
340 }

◆ operator/()

template<typename T >
template<typename T2 , typename std::enable_if< ScalarTraits< T2 >::value, int >::type >
RankTwoTensorTempl< typename CompareTypes< T, T2 >::supertype > RankTwoTensorTempl< T >::operator/ ( const T2 &  a) const

returns _coords/a

Definition at line 583 of file RankTwoTensor.h.

584 {
585  return TensorValue<T>::operator/(b);
586 }

◆ operator/=()

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator/= ( const T &  a)

performs _coords /= a

Definition at line 359 of file RankTwoTensor.C.

360 {
361  TensorValue<T>::operator/=(a);
362  return *this;
363 }

◆ operator=() [1/3]

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator= ( const ColumnMajorMatrixTempl< T > &  a)

Sets _coords to the values in a ColumnMajorMatrix (must be 3x3)

Definition at line 387 of file RankTwoTensor.C.

388 {
389  if (a.n() != N || a.m() != N)
390  mooseError("Dimensions of ColumnMajorMatrixTempl<T> are incompatible with RankTwoTensorTempl");
391 
392  const T * cmm_rawdata = a.rawData();
393  for (unsigned int i = 0; i < N; ++i)
394  for (unsigned int j = 0; j < N; ++j)
395  this->_coords[i * N + j] = cmm_rawdata[i + j * N];
396 
397  return *this;
398 }

◆ operator=() [2/3]

template<typename T>
RankTwoTensorTempl< T > & RankTwoTensorTempl< T >::operator= ( const RankTwoTensorTempl< T > &  a)

sets _coords to a, and returns _coords

Definition at line 320 of file RankTwoTensor.C.

321 {
322  TensorValue<T>::operator=(a);
323  return *this;
324 }

◆ operator=() [3/3]

template<typename T>
template<typename Scalar >
boostcopy::enable_if_c<ScalarTraits<Scalar>::value, RankTwoTensorTempl &>::type RankTwoTensorTempl< T >::operator= ( const Scalar &  libmesh_dbg_varp)
inline

Assignment-from-scalar operator.

Used only to zero out vectors.

Definition at line 208 of file RankTwoTensor.h.

209  {
210  libmesh_assert_equal_to(p, Scalar(0));
211  this->zero();
212  return *this;
213  }

◆ operator==()

template<typename T>
bool RankTwoTensorTempl< T >::operator== ( const RankTwoTensorTempl< T > &  a) const

Defines logical equality with another RankTwoTensorTempl<T>

Definition at line 375 of file RankTwoTensor.C.

376 {
377  for (unsigned int i = 0; i < N; ++i)
378  for (unsigned int j = 0; j < N; ++j)
379  if (!MooseUtils::absoluteFuzzyEqual((*this)(i, j), a(i, j)))
380  return false;
381 
382  return true;
383 }

◆ outerProduct()

template<typename T>
RankFourTensorTempl< T > RankTwoTensorTempl< T >::outerProduct ( const RankTwoTensorTempl< T > &  a) const

returns C_ijkl = a_ij * b_kl

Definition at line 410 of file RankTwoTensor.C.

411 {
412  RankFourTensorTempl<T> result;
413 
414  unsigned int index = 0;
415  for (unsigned int ij = 0; ij < N2; ++ij)
416  {
417  const T & a = this->_coords[ij];
418  for (unsigned int kl = 0; kl < N2; ++kl)
419  result._vals[index++] = a * b._coords[kl];
420  }
421 
422  return result;
423 }

Referenced by RankTwoTensorTempl< Real >::positiveProjectionEigenDecomposition().

◆ permutationTensor()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::permutationTensor ( const std::array< unsigned int, LIBMESH_DIM > &  old_elements,
const std::array< unsigned int, LIBMESH_DIM > &  new_elements 
) const

computes and returns the permutation matrix P

Parameters
old_elementsis the original row/column numbering
new_elementsis the permuted row/column numbering Dual numbers are permuted as well P * A permutes rows and A * P^T permutes columns

Definition at line 934 of file RankTwoTensor.C.

937 {
939 
940  for (unsigned int i = 0; i < N; ++i)
941  P(old_elements[i], new_elements[i]) = 1.0;
942 
943  return P;
944 }

◆ positiveProjectionEigenDecomposition()

template<typename T>
RankFourTensorTempl< T > RankTwoTensorTempl< T >::positiveProjectionEigenDecomposition ( std::vector< T > &  eigval,
RankTwoTensorTempl< T > &  eigvec 
) const

return positive projection tensor of eigen-decomposition

Definition at line 480 of file RankTwoTensor.C.

482 {
483  // The calculate of projection tensor follows
484  // C. Miehe and M. Lambrecht, Commun. Numer. Meth. Engng 2001; 17:337~353
485 
486  // Compute eigenvectors and eigenvalues of this tensor
487  this->symmetricEigenvaluesEigenvectors(eigval, eigvec);
488 
489  // Separate out positive and negative eigen values
490  std::array<T, N> epos;
491  std::array<T, N> d;
492  for (unsigned int i = 0; i < N; ++i)
493  {
494  epos[i] = (std::abs(eigval[i]) + eigval[i]) / 2.0;
495  d[i] = eigval[i] > 0 ? 1.0 : 0.0;
496  }
497 
498  // projection tensor
499  RankFourTensorTempl<T> proj_pos;
500  RankFourTensorTempl<T> Gab, Gba;
501  RankTwoTensorTempl<T> Ma, Mb;
502 
503  for (unsigned int a = 0; a < N; ++a)
504  {
505  Ma.vectorOuterProduct(eigvec.column(a), eigvec.column(a));
506  proj_pos += d[a] * Ma.outerProduct(Ma);
507  }
508 
509  for (unsigned int a = 0; a < N; ++a)
510  for (unsigned int b = 0; b < a; ++b)
511  {
512  Ma.vectorOuterProduct(eigvec.column(a), eigvec.column(a));
513  Mb.vectorOuterProduct(eigvec.column(b), eigvec.column(b));
514 
515  Gab = Ma.mixedProductIkJl(Mb) + Ma.mixedProductIlJk(Mb);
516  Gba = Mb.mixedProductIkJl(Ma) + Mb.mixedProductIlJk(Ma);
517 
518  T theta_ab;
519  if (!MooseUtils::absoluteFuzzyEqual(eigval[a], eigval[b]))
520  theta_ab = 0.5 * (epos[a] - epos[b]) / (eigval[a] - eigval[b]);
521  else
522  theta_ab = 0.25 * (d[a] + d[b]);
523 
524  proj_pos += theta_ab * (Gab + Gba);
525  }
526  return proj_pos;
527 }

◆ print()

template<typename T >
void RankTwoTensorTempl< T >::print ( std::ostream &  stm = Moose::out) const

Print the rank two tensor.

Definition at line 823 of file RankTwoTensor.C.

824 {
825  const RankTwoTensorTempl<T> & a = *this;
826  for (unsigned int i = 0; i < N; ++i)
827  {
828  for (unsigned int j = 0; j < N; ++j)
829  stm << std::setw(15) << a(i, j) << ' ';
830  stm << std::endl;
831  }
832 }

◆ printDualReal() [1/2]

template<>
void RankTwoTensorTempl< DualReal >::printDualReal ( unsigned int  nDual,
std::ostream &  stm 
) const

Definition at line 856 of file RankTwoTensor.C.

857 {
858  const RankTwoTensorTempl<DualReal> & a = *this;
859  for (unsigned int i = 0; i < N; ++i)
860  {
861  for (unsigned int j = 0; j < N; ++j)
862  {
863  stm << std::setw(15) << a(i, j).value() << " {";
864  for (unsigned int k = 0; k < nDual; ++k)
865  stm << std::setw(5) << a(i, j).derivatives()[k] << ' ';
866  stm << " }";
867  }
868  stm << std::endl;
869  }
870 }

◆ printDualReal() [2/2]

template<typename T>
void RankTwoTensorTempl< T >::printDualReal ( unsigned int  nDual,
std::ostream &  stm = Moose::out 
) const

Print the Real part of the DualReal rank two tensor along with its first nDual dual numbers.

◆ printReal() [1/2]

template<>
void RankTwoTensorTempl< DualReal >::printReal ( std::ostream &  stm) const

Definition at line 843 of file RankTwoTensor.C.

844 {
845  const RankTwoTensorTempl<DualReal> & a = *this;
846  for (unsigned int i = 0; i < N; ++i)
847  {
848  for (unsigned int j = 0; j < N; ++j)
849  stm << std::setw(15) << a(i, j).value() << ' ';
850  stm << std::endl;
851  }
852 }

◆ printReal() [2/2]

template<typename T>
void RankTwoTensorTempl< T >::printReal ( std::ostream &  stm = Moose::out) const

Print the Real part of the DualReal rank two tensor.

◆ QR() [1/2]

template<>
void RankTwoTensorTempl< DualReal >::QR ( RankTwoTensorTempl< DualReal > &  Q,
RankTwoTensorTempl< DualReal > &  R,
unsigned int  dim 
) const

Definition at line 1023 of file RankTwoTensor.C.

1026 {
1027  R = *this;
1028  Q.zero();
1029  Q.addIa(1.0);
1030 
1031  for (unsigned int i = 0; i < dim - 1; i++)
1032  for (unsigned int b = dim - 1; b > i; b--)
1033  {
1034  unsigned int a = b - 1;
1035 
1036  // special case when both entries to rotate are zero
1037  // in which case the dual numbers cannot be rotated
1038  // therefore we need to find another nonzero entry to permute
1040  if (MooseUtils::absoluteFuzzyEqual(R(a, i).value(), 0.0) &&
1041  MooseUtils::absoluteFuzzyEqual(R(b, i).value(), 0.0))
1042  {
1043  unsigned int c = 3 - a - b;
1044  if (!MooseUtils::absoluteFuzzyEqual(R(c, i).value(), 0.0))
1045  P = this->permutationTensor({{a, b, c}}, {{c, b, a}});
1046  }
1047 
1048  Q = Q * P.transpose();
1049  R = P * R;
1051  R = P.transpose() * CS * R;
1052  Q = Q * CS.transpose() * P;
1053  }
1054 }

◆ QR() [2/2]

template<typename T>
void RankTwoTensorTempl< T >::QR ( RankTwoTensorTempl< T > &  Q,
RankTwoTensorTempl< T > &  R,
unsigned int  dim = RankTwoTensorTempl<T>::N 
) const

computes the QR factorization such that A = Q * R, where Q is the unitary matrix and R an upper triangular matrix

Definition at line 1003 of file RankTwoTensor.C.

1006 {
1007  R = *this;
1008  Q.zero();
1009  Q.addIa(1.0);
1010 
1011  for (unsigned int i = 0; i < dim - 1; i++)
1012  for (unsigned int b = dim - 1; b > i; b--)
1013  {
1014  unsigned int a = b - 1;
1015  RankTwoTensorTempl<T> CS = R.givensRotation(a, b, i);
1016  R = CS * R;
1017  Q = Q * CS.transpose();
1018  }
1019 }

Referenced by RankTwoTensorTempl< Real >::symmetricEigenvaluesEigenvectors().

◆ rotate()

template<typename T>
void RankTwoTensorTempl< T >::rotate ( const RankTwoTensorTempl< T > &  R)

rotates the tensor data given a rank two tensor rotation tensor _coords[i][j] = R_ij * R_jl * _coords[k][l]

Parameters
Rrotation matrix as a RankTwoTensorTempl

Definition at line 262 of file RankTwoTensor.C.

263 {
265  unsigned int i1 = 0;
266  for (unsigned int i = 0; i < N; i++)
267  {
268  unsigned int j1 = 0;
269  for (unsigned int j = 0; j < N; j++)
270  {
271  // tmp += R(i,k)*R(j,l)*(*this)(k,l);
272  // clang-format off
273  T tmp = R._coords[i1 + 0] * R._coords[j1 + 0] * (*this)(0, 0) +
274  R._coords[i1 + 0] * R._coords[j1 + 1] * (*this)(0, 1) +
275  R._coords[i1 + 0] * R._coords[j1 + 2] * (*this)(0, 2) +
276  R._coords[i1 + 1] * R._coords[j1 + 0] * (*this)(1, 0) +
277  R._coords[i1 + 1] * R._coords[j1 + 1] * (*this)(1, 1) +
278  R._coords[i1 + 1] * R._coords[j1 + 2] * (*this)(1, 2) +
279  R._coords[i1 + 2] * R._coords[j1 + 0] * (*this)(2, 0) +
280  R._coords[i1 + 2] * R._coords[j1 + 1] * (*this)(2, 1) +
281  R._coords[i1 + 2] * R._coords[j1 + 2] * (*this)(2, 2);
282  // clang-format on
283  temp._coords[i1 + j] = tmp;
284  j1 += N;
285  }
286  i1 += N;
287  }
288  for (unsigned int i = 0; i < N2; i++)
289  this->_coords[i] = temp._coords[i];
290 }

Referenced by RankTwoTensorTempl< Real >::rotated().

◆ rotated()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::rotated ( const RankTwoTensorTempl< T > &  R) const

Returns a rotated version of the tensor data given a rank two tensor rotation tensor _coords[i][j] = R_ij * R_jl * _coords[k][l].

Parameters
Rrotation matrix as another RankTwoTensorTempl

Definition at line 253 of file RankTwoTensor.C.

254 {
255  RankTwoTensorTempl<T> result(*this);
256  result.rotate(R);
257  return result;
258 }

◆ rotateXyPlane()

template<typename T>
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::rotateXyPlane ( a)

rotates the tensor data anticlockwise around the z-axis

Parameters
aangle in radians

Definition at line 294 of file RankTwoTensor.C.

295 {
296  T c = std::cos(a);
297  T s = std::sin(a);
298  T x = (*this)(0, 0) * c * c + (*this)(1, 1) * s * s + 2.0 * (*this)(0, 1) * c * s;
299  T y = (*this)(0, 0) * s * s + (*this)(1, 1) * c * c - 2.0 * (*this)(0, 1) * c * s;
300  T xy = ((*this)(1, 1) - (*this)(0, 0)) * c * s + (*this)(0, 1) * (c * c - s * s);
301 
302  RankTwoTensorTempl<T> b(*this);
303 
304  b(0, 0) = x;
305  b(1, 1) = y;
306  b(1, 0) = b(0, 1) = xy;
307 
308  return b;
309 }

◆ secondInvariant()

template<typename T >
T RankTwoTensorTempl< T >::secondInvariant ( ) const

Calculates the second invariant (I2) of a tensor.

Definition at line 555 of file RankTwoTensor.C.

556 {
557  T result = 0.0;
558 
559  // RankTwoTensorTempl<T> deviatoric(*this);
560  // deviatoric.addIa(-1.0/3.0 * this->tr()); // actually construct deviatoric part
561  // result = 0.5*(deviatoric + deviatoric.transpose()).doubleContraction(deviatoric +
562  // deviatoric.transpose());
563  result = Utility::pow<2>((*this)(0, 0) - (*this)(1, 1)) / 6.0;
564  result += Utility::pow<2>((*this)(0, 0) - (*this)(2, 2)) / 6.0;
565  result += Utility::pow<2>((*this)(1, 1) - (*this)(2, 2)) / 6.0;
566  result += Utility::pow<2>((*this)(0, 1) + (*this)(1, 0)) / 4.0;
567  result += Utility::pow<2>((*this)(0, 2) + (*this)(2, 0)) / 4.0;
568  result += Utility::pow<2>((*this)(1, 2) + (*this)(2, 1)) / 4.0;
569  return result;
570 }

◆ setToIdentity()

template<typename T >
void RankTwoTensorTempl< T >::setToIdentity ( )

set the tensor to the identity matrix

Definition at line 1358 of file RankTwoTensor.C.

1359 {
1360  mooseAssert(N2 == 9, "RankTwoTensorTempl is currently only tested for 3 dimensions.");
1361  for (unsigned int i = 0; i < N2; ++i)
1362  this->_coords[i] = identityCoords[i];
1363 }

◆ sin3Lode()

template<typename T>
T RankTwoTensorTempl< T >::sin3Lode ( const T &  r0,
const T &  r0_value 
) const

Sin(3*Lode_angle) If secondInvariant() <= r0 then return r0_value This is to gaurd against precision-loss errors.

Note that sin(3*Lode_angle) is not defined for secondInvariant() = 0

Definition at line 751 of file RankTwoTensor.C.

752 {
753  T bar = secondInvariant();
754  if (bar <= r0)
755  // in this case the Lode angle is not defined
756  return r0_value;
757  else
758  // the min and max here gaurd against precision-loss when bar is tiny but nonzero.
759  return std::max(std::min(-1.5 * std::sqrt(3.0) * thirdInvariant() / std::pow(bar, 1.5), 1.0),
760  -1.0);
761 }

◆ surfaceFillFromInputVector()

template<typename T>
void RankTwoTensorTempl< T >::surfaceFillFromInputVector ( const std::vector< T > &  input)

sets _coords[0][0], _coords[0][1], _coords[1][0], _coords[1][1] to input, and the remainder to zero

Definition at line 895 of file RankTwoTensor.C.

896 {
897  if (input.size() == 4)
898  {
899  // initialize with zeros
900  this->zero();
901  (*this)(0, 0) = input[0];
902  (*this)(0, 1) = input[1];
903  (*this)(1, 0) = input[2];
904  (*this)(1, 1) = input[3];
905  }
906  else
907  mooseError("please provide correct number of values for surface RankTwoTensorTempl<T> "
908  "initialization.");
909 }

◆ syev() [1/2]

template<>
void RankTwoTensorTempl< DualReal >::syev ( const char *  ,
std::vector< DualReal > &  ,
std::vector< DualReal > &   
) const

Definition at line 1219 of file RankTwoTensor.C.

1222 {
1223  mooseError("DualRankTwoTensor does not sypport the syev method");
1224 }

◆ syev() [2/2]

template<typename T>
void RankTwoTensorTempl< T >::syev ( const char *  calculation_type,
std::vector< T > &  eigvals,
std::vector< T > &  a 
) const

Uses the petscblaslapack.h LAPACKsyev_ routine to find, for symmetric _coords: (1) the eigenvalues (if calculation_type == "N") (2) the eigenvalues and eigenvectors (if calculation_type == "V")

Parameters
calculation_typeIf "N" then calculation eigenvalues only
eigvalsEigenvalues are placed in this array, in ascending order
aEigenvectors are placed in this array if calculation_type == "V". See code in dsymmetricEigenvalues for extracting eigenvectors from the a output.

Definition at line 1186 of file RankTwoTensor.C.

1189 {
1190  eigvals.resize(N);
1191  a.resize(N * N);
1192 
1193  // prepare data for the LAPACKsyev_ routine (which comes from petscblaslapack.h)
1194  int nd = N;
1195  int lwork = 66 * nd;
1196  int info;
1197  std::vector<PetscScalar> work(lwork);
1198 
1199  for (unsigned int i = 0; i < N; ++i)
1200  for (unsigned int j = 0; j < N; ++j)
1201  // a is destroyed by dsyev, and if calculation_type == "V" then eigenvectors are placed
1202  // there Note the explicit symmeterisation
1203  a[i * N + j] = 0.5 * (this->operator()(i, j) + this->operator()(j, i));
1204 
1205  // compute the eigenvalues only (if calculation_type == "N"),
1206  // or both the eigenvalues and eigenvectors (if calculation_type == "V")
1207  // assume upper triangle of a is stored (second "U")
1208  LAPACKsyev_(calculation_type, "U", &nd, &a[0], &nd, &eigvals[0], &work[0], &lwork, &info);
1209 
1210  if (info != 0)
1211  mooseError("In computing the eigenvalues and eigenvectors for the symmetric rank-2 tensor (",
1212  Moose::stringify(a),
1213  "), the PETSC LAPACK syev routine returned error code ",
1214  info);
1215 }

◆ symmetricEigenvalues()

template<typename T>
void RankTwoTensorTempl< T >::symmetricEigenvalues ( std::vector< T > &  eigvals) const

computes eigenvalues, assuming tens is symmetric, and places them in ascending order in eigvals

Definition at line 913 of file RankTwoTensor.C.

914 {
915  std::vector<T> a;
916  syev("N", eigvals, a);
917 }

◆ symmetricEigenvaluesEigenvectors() [1/2]

template<>
void RankTwoTensorTempl< DualReal >::symmetricEigenvaluesEigenvectors ( std::vector< DualReal > &  eigvals,
RankTwoTensorTempl< DualReal > &  eigvecs 
) const

Definition at line 1058 of file RankTwoTensor.C.

1060 {
1061  const Real eps = libMesh::TOLERANCE * libMesh::TOLERANCE;
1062 
1063  eigvals.resize(N);
1065  this->hessenberg(D, eigvecs);
1066 
1067  unsigned int iter = 0;
1068  for (unsigned m = N - 1; m > 0; m--)
1069  do
1070  {
1071  iter++;
1072  DualReal shift = D(m, m);
1073  D.addIa(-shift);
1074  D.QR(Q, R, m + 1);
1075  D = R * Q;
1076  D.addIa(shift);
1077  eigvecs = eigvecs * Q;
1078  } while (std::abs(D(m, m - 1)) > eps);
1079 
1080  for (unsigned int i = 0; i < N; i++)
1081  eigvals[i] = D(i, i);
1082 
1083  // Sort eigenvalues and corresponding vectors.
1084  for (unsigned int i = 0; i < N - 1; i++)
1085  {
1086  unsigned int k = i;
1087  DualReal p = eigvals[i];
1088  for (unsigned int j = i + 1; j < N; j++)
1089  if (eigvals[j] < p)
1090  {
1091  k = j;
1092  p = eigvals[j];
1093  }
1094  if (k != i)
1095  {
1096  eigvals[k] = eigvals[i];
1097  eigvals[i] = p;
1098  for (unsigned int j = 0; j < N; j++)
1099  {
1100  p = eigvecs(j, i);
1101  eigvecs(j, i) = eigvecs(j, k);
1102  eigvecs(j, k) = p;
1103  }
1104  }
1105  }
1106 }

◆ symmetricEigenvaluesEigenvectors() [2/2]

template<typename T>
void RankTwoTensorTempl< T >::symmetricEigenvaluesEigenvectors ( std::vector< T > &  eigvals,
RankTwoTensorTempl< T > &  eigvecs 
) const

computes eigenvalues and eigenvectors, assuming tens is symmetric, and places them in ascending order in eigvals.

eigvecs is a matrix with the first column being the first eigenvector, the second column being the second, etc.

Definition at line 921 of file RankTwoTensor.C.

923 {
924  std::vector<T> a;
925  syev("V", eigvals, a);
926 
927  for (unsigned int i = 0; i < N; ++i)
928  for (unsigned int j = 0; j < N; ++j)
929  eigvecs(j, i) = a[i * N + j];
930 }

◆ thirdInvariant()

template<typename T >
T RankTwoTensorTempl< T >::thirdInvariant ( ) const

Denote the _coords[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns det(S + S.transpose())/2 Note the explicit symmeterisation.

Definition at line 620 of file RankTwoTensor.C.

621 {
622  RankTwoTensorTempl<T> s = 0.5 * deviatoric();
623  s += s.transpose();
624 
625  T result = 0.0;
626 
627  result = s(0, 0) * (s(1, 1) * s(2, 2) - s(2, 1) * s(1, 2));
628  result -= s(1, 0) * (s(0, 1) * s(2, 2) - s(2, 1) * s(0, 2));
629  result += s(2, 0) * (s(0, 1) * s(1, 2) - s(1, 1) * s(0, 2));
630 
631  return result;
632 }

◆ trace()

template<typename T >
T RankTwoTensorTempl< T >::trace ( ) const

returns the trace of the tensor, ie _coords[i][i] (sum i = 0, 1, 2)

Definition at line 598 of file RankTwoTensor.C.

599 {
600  // deprecate this!
601  return this->tr();
602 }

◆ transpose()

template<typename T >
RankTwoTensorTempl< T > RankTwoTensorTempl< T >::transpose ( ) const

Returns a matrix that is the transpose of the matrix this was called on.

Definition at line 313 of file RankTwoTensor.C.

314 {
315  return TensorValue<T>::transpose();
316 }

Referenced by RankTwoTensorTempl< Real >::d2thirdInvariant(), RankTwoTensorTempl< Real >::dthirdInvariant(), RankTwoTensorTempl< Real >::getRUDecompositionRotation(), RankTwoTensorTempl< Real >::hessenberg(), RankTwoTensorTempl< Real >::QR(), and RankTwoTensorTempl< Real >::thirdInvariant().

◆ vectorOuterProduct()

template<typename T>
void RankTwoTensorTempl< T >::vectorOuterProduct ( const TypeVector< T > &  v1,
const TypeVector< T > &  v2 
)

RankTwoTensorTempl<T> from outer product of vectors.

Definition at line 1305 of file RankTwoTensor.C.

1306 {
1307  for (unsigned int i = 0; i < N; ++i)
1308  for (unsigned int j = 0; j < N; ++j)
1309  (*this)(i, j) = v1(i) * v2(j);
1310 }

Referenced by RankTwoTensorTempl< Real >::positiveProjectionEigenDecomposition().

Friends And Related Function Documentation

◆ dataLoad

template<typename T>
template<class T2 >
void dataLoad ( std::istream &  ,
RankTwoTensorTempl< T2 > &  ,
void *   
)
friend

◆ dataStore

template<typename T>
template<class T2 >
void dataStore ( std::ostream &  ,
RankTwoTensorTempl< T2 > &  ,
void *   
)
friend

◆ RankFourTensorTempl

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

Definition at line 532 of file RankTwoTensor.h.

◆ RankThreeTensorTempl

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

Definition at line 534 of file RankTwoTensor.h.

Member Data Documentation

◆ identityCoords

template<typename T>
constexpr Real RankTwoTensorTempl< T >::identityCoords = {1, 0, 0, 0, 1, 0, 0, 0, 1}
staticconstexprprivate

Definition at line 524 of file RankTwoTensor.h.

◆ N

template<typename T>
constexpr unsigned int RankTwoTensorTempl< T >::N = LIBMESH_DIM
staticconstexprprivate

Definition at line 522 of file RankTwoTensor.h.

◆ N2

template<typename T>
constexpr unsigned int RankTwoTensorTempl< T >::N2 = N * N
staticconstexprprivate

Definition at line 523 of file RankTwoTensor.h.


The documentation for this class was generated from the following files:
RankTwoTensorTempl::initIdentity
Definition: RankTwoTensor.h:80
RankTwoTensorTempl::addIa
void addIa(const T &a)
Add identity times a to _coords.
Definition: RankTwoTensor.C:874
RankTwoTensorTempl::thirdInvariant
T thirdInvariant() const
Denote the _coords[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns det(S + S....
Definition: RankTwoTensor.C:620
RankTwoTensorTempl::QR
void QR(RankTwoTensorTempl< T > &Q, RankTwoTensorTempl< T > &R, unsigned int dim=RankTwoTensorTempl< T >::N) const
computes the QR factorization such that A = Q * R, where Q is the unitary matrix and R an upper trian...
Definition: RankTwoTensor.C:1003
ColumnMajorMatrixTempl::rawData
T * rawData()
Returns a reference to the raw data pointer.
Definition: ColumnMajorMatrix.h:557
RankTwoTensorTempl::outerProduct
RankFourTensorTempl< T > outerProduct(const RankTwoTensorTempl< T > &a) const
returns C_ijkl = a_ij * b_kl
Definition: RankTwoTensor.C:410
ColumnMajorMatrixTempl::n
unsigned int n() const
Returns the number of rows.
Definition: ColumnMajorMatrix.h:543
RankTwoTensorTempl::hessenberg
void hessenberg(RankTwoTensorTempl< T > &H, RankTwoTensorTempl< T > &U) const
computes the Hessenberg form of this matrix A and its unitary transformation U such that A = U * H * ...
Definition: RankTwoTensor.C:987
PermutationTensor::eps
int eps(unsigned int i, unsigned int j)
2D version
Definition: PermutationTensor.C:13
RankTwoTensorTempl::secondInvariant
T secondInvariant() const
Calculates the second invariant (I2) of a tensor.
Definition: RankTwoTensor.C:555
RankTwoTensorTempl::transpose
RankTwoTensorTempl< T > transpose() const
Returns a matrix that is the transpose of the matrix this was called on.
Definition: RankTwoTensor.C:313
std::abs
MetaPhysicL::DualNumber< T, D > abs(const MetaPhysicL::DualNumber< T, D > &in)
RankTwoTensorTempl::syev
void syev(const char *calculation_type, std::vector< T > &eigvals, std::vector< T > &a) const
Uses the petscblaslapack.h LAPACKsyev_ routine to find, for symmetric _coords: (1) the eigenvalues (i...
Definition: RankTwoTensor.C:1186
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
MatrixTools::inverse
void inverse(const std::vector< std::vector< Real >> &m, std::vector< std::vector< Real >> &m_inv)
Inverse the dense square matrix m using LAPACK routines.
Definition: MatrixTools.C:27
RankTwoTensorTempl::N
static constexpr unsigned int N
Definition: RankTwoTensor.h:522
RankTwoTensorTempl::N2
static constexpr unsigned int N2
Definition: RankTwoTensor.h:523
RankTwoTensorTempl::symmetric6
Definition: RankTwoTensor.h:99
RankTwoTensorTempl::identityCoords
static constexpr Real identityCoords[N2]
Definition: RankTwoTensor.h:524
RankTwoTensorTempl::deviatoric
RankTwoTensorTempl< T > deviatoric() const
returns A_ij - de_ij*tr(A)/3, where A are the _coords
Definition: RankTwoTensor.C:531
RankTwoTensorTempl::diagonal3
Definition: RankTwoTensor.h:98
DualReal
DualNumber< Real, DNDerivativeType > DualReal
Definition: DualReal.h:52
RankTwoTensorTempl::d2thirdInvariant
RankFourTensorTempl< T > d2thirdInvariant() const
Denote the _coords[i][j] by A_ij, then this returns d^2(thirdInvariant)/dA_ij/dA_kl.
Definition: RankTwoTensor.C:659
RankTwoTensorTempl::fillFromInputVector
void fillFromInputVector(const std::vector< T > &input, FillMethod fill_method=autodetect)
fillFromInputVector takes 6 or 9 inputs to fill in the Rank-2 tensor.
Definition: RankTwoTensor.C:158
MooseRandom::rand
static double rand()
This method returns the next random number (double format) from the generator.
Definition: MooseRandom.h:49
RankTwoTensorTempl::isotropic1
Definition: RankTwoTensor.h:97
RankTwoTensorTempl::initNone
Definition: RankTwoTensor.h:79
Moose::stringify
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:61
mooseError
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition: MooseError.h:210
RankTwoTensorTempl::permutationTensor
RankTwoTensorTempl< T > permutationTensor(const std::array< unsigned int, LIBMESH_DIM > &old_elements, const std::array< unsigned int, LIBMESH_DIM > &new_elements) const
computes and returns the permutation matrix P
Definition: RankTwoTensor.C:934
RankTwoTensorTempl::mixedProductIkJl
RankFourTensorTempl< T > mixedProductIkJl(const RankTwoTensorTempl< T > &a) const
returns C_ijkl = a_ik * b_jl
Definition: RankTwoTensor.C:427
x
static PetscErrorCode Vec x
Definition: PetscDMMoose.C:1263
RankTwoTensorTempl::column
TypeVector< T > column(const unsigned int c) const
returns _coords[i][c], ie, column c, with c = 0, 1, 2
Definition: RankTwoTensor.C:241
RankTwoTensorTempl::inverse
RankTwoTensorTempl< T > inverse() const
retuns the inverse of the tensor
Definition: RankTwoTensor.C:606
MooseRandom::seed
static void seed(unsigned int seed)
The method seeds the random number generator.
Definition: MooseRandom.h:43
RankTwoTensorTempl::symmetricEigenvaluesEigenvectors
void symmetricEigenvaluesEigenvectors(std::vector< T > &eigvals, RankTwoTensorTempl< T > &eigvecs) const
computes eigenvalues and eigenvectors, assuming tens is symmetric, and places them in ascending order...
Definition: RankTwoTensor.C:921
RankTwoTensorTempl::d2secondInvariant
RankFourTensorTempl< T > d2secondInvariant() const
Denote the _coords[i][j] by A_ij, then this returns d^2(secondInvariant)/dA_ij/dA_kl.
Definition: RankTwoTensor.C:581
operator*
auto operator*(const T1 &a, const RankFourTensorTempl< T2 > &b) -> typename std::enable_if< ScalarTraits< T1 >::value, RankFourTensorTempl< decltype(T1() *T2())>>::type
Definition: RankFourTensor.h:426
RankTwoTensorTempl::dthirdInvariant
RankTwoTensorTempl< T > dthirdInvariant() const
Denote the _coords[i][j] by A_ij, then this returns d(thirdInvariant()/dA_ij.
Definition: RankTwoTensor.C:636
RankTwoTensorTempl::RankTwoTensorTempl
RankTwoTensorTempl()
Default constructor; fills to zero.
Definition: RankTwoTensor.C:65
RankTwoTensorTempl::dsecondInvariant
RankTwoTensorTempl< T > dsecondInvariant() const
Denote the _coords[i][j] by A_ij, then this returns d(secondInvariant)/dA_ij.
Definition: RankTwoTensor.C:574
MooseUtils::absoluteFuzzyEqual
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:234
RankTwoTensorTempl::givensRotation
RankTwoTensorTempl< T > givensRotation(unsigned int row1, unsigned int row2, unsigned int col) const
computes and returns the Givens rotation matrix R
Definition: RankTwoTensor.C:948
MathUtils::pow
T pow(T x, int e)
Definition: MathUtils.h:44
RankTwoTensorTempl::autodetect
Definition: RankTwoTensor.h:96
RankTwoTensorTempl::mixedProductIlJk
RankFourTensorTempl< T > mixedProductIlJk(const RankTwoTensorTempl< T > &a) const
returns C_ijkl = a_il * b_jk
Definition: RankTwoTensor.C:446
RankFourTensorTempl::_vals
T _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...
Definition: RankFourTensor.h:313
RankFourTensorTempl
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
Definition: MooseTypes.h:118
ColumnMajorMatrixTempl::m
unsigned int m() const
Returns the number of columns.
Definition: ColumnMajorMatrix.h:550
m
PetscInt m
Definition: PetscDMMoose.C:1504
RankTwoTensorTempl
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: MooseTypes.h:114
RankTwoTensorTempl::general
Definition: RankTwoTensor.h:100
RankTwoTensorTempl::vectorOuterProduct
void vectorOuterProduct(const TypeVector< T > &, const TypeVector< T > &)
RankTwoTensorTempl<T> from outer product of vectors.
Definition: RankTwoTensor.C:1305