19#include "libmesh/libmesh.h"
20#include "libmesh/tensor_value.h"
22#include "metaphysicl/raw_type.h"
85 static constexpr unsigned int full_index[6][2] = {{0, 0}, {1, 1}, {2, 2}, {1, 2}, {0, 2}, {0, 1}};
88 static constexpr unsigned int reverse_index[3][3] = {{0, 5, 4}, {5, 1, 3}, {4, 3, 2}};
124 const T & S11,
const T & S22,
const T & S33,
const T & S23,
const T & S13,
const T & S12);
143 const T & S11,
const T & S22,
const T & S33,
const T & S23,
const T & S13,
const T & S12);
153 template <
typename T2>
156 for (
const auto i : make_range(
N))
168 initializeSymmetric(
const TypeVector<T> & v0,
const TypeVector<T> & v1,
const TypeVector<T> & v2);
235 void rotate(
const TypeTensor<T> & R);
244 template <
typename T2>
250 template <
typename Scalar>
254 libmesh_assert_equal_to(p, Scalar(0));
263 template <
typename T2>
271 template <
typename T2>
282 template <
typename T2>
284 typename std::enable_if<libMesh::ScalarTraits<T2>::value,
291 template <
typename T2>
293 typename std::enable_if<libMesh::ScalarTraits<T2>::value,
297 template <
typename T2>
298 TypeVector<typename libMesh::CompareTypes<T, T2>::supertype>
302 template <
typename T2>
309 template <
typename T2>
371 T
sin3Lode(
const T & r0,
const T & r0_value)
const;
411 void print(std::ostream & stm = Moose::out)
const;
414 void printReal(std::ostream & stm = Moose::out)
const;
417 void printADReal(
unsigned int nDual, std::ostream & stm = Moose::out)
const;
426 void addIa(
const T & a);
483 void syev(
const char * calculation_type, std::vector<T> & eigvals, std::vector<T> & a)
const;
510 for (
unsigned int i = 0; i < SymmetricRankTwoTensorTempl<T>::N; ++i)
519template <
typename T2>
522 typename std::enable_if<libMesh::ScalarTraits<T2>::value,
526 for (
const auto i : make_range(N))
527 result.
_vals[i] = _vals[i] * a;
532template <
typename T2>
535 typename std::enable_if<libMesh::ScalarTraits<T2>::value,
539 for (
const auto i : make_range(N))
540 result.
_vals[i] = _vals[i] / a;
546template <
typename T2>
547TypeVector<typename libMesh::CompareTypes<T, T2>::supertype>
550 TypeVector<typename libMesh::CompareTypes<T, T2>::supertype> ret;
551 ret(0) = a(0) * _vals[0] + a(1) * _vals[5] + a(2) * _vals[4];
552 ret(1) = a(0) * _vals[5] + a(1) * _vals[1] + a(2) * _vals[3];
553 ret(2) = a(0) * _vals[4] + a(1) * _vals[3] + a(2) * _vals[2];
557template <
typename T2>
561 for (std::size_t i = 0; i < N; ++i)
562 if (_vals[i] != a.
_vals[i])
568template <
typename T2>
572 for (std::size_t i = 0; i < N; ++i)
573 if (_vals[i] != a.
_vals[i])
589 if (MooseUtils::IsLikeReal<T>::value)
591 this->symmetricEigenvaluesEigenvectors(eigval, eigvec);
594 std::array<T, N> epos;
596 for (
unsigned int i = 0; i < Ndim; ++i)
598 epos[i] = (abs(eigval[i]) + eigval[i]) / 2.0;
599 d[i] = 0 < eigval[i] ? 1.0 : 0.0;
605 for (
unsigned int a = 0; a < Ndim; ++a)
608 proj_pos += d[a] * Ma.outerProduct(Ma);
611 for (
const auto a : make_range(Ndim))
612 for (
const auto b : make_range(a))
618 for (
const auto aa : make_range(N))
619 for (
const auto bb : make_range(N))
626 Gabba(aa, bb) = (Ma(i, k) * Mb(j, l) + Ma(i, l) * Mb(j, k) + Ma(j, l) * Mb(i, k) +
627 Ma(j, k) * Mb(i, l)) *
632 if (!MooseUtils::relativeFuzzyEqual(eigval[a], eigval[b]))
633 theta_ab = 0.5 * (epos[a] - epos[b]) / (eigval[a] - eigval[b]);
635 theta_ab = 0.25 * (d[a] + d[b]);
637 proj_pos += theta_ab * Gabba;
642 mooseError(
"positiveProjectionEigenDecomposition is only available for ordered tensor "
650 using std::max, std::min, std::sqrt,
std::pow;
651 if (MooseUtils::IsLikeReal<T>::value)
653 T bar = secondInvariant();
659 return max(min(thirdInvariant() * -1.5 * sqrt(3.0) / pow(bar, 1.5), 1.0), -1.0);
662 mooseError(
"sin3Lode is only available for ordered tensor component types");
670 if (MooseUtils::IsLikeReal<T>::value)
672 T bar = secondInvariant();
676 return -1.5 * sqrt(3.0) *
677 (dthirdInvariant() / pow(bar, 1.5) -
678 1.5 * dsecondInvariant() * thirdInvariant() / pow(bar, 2.5));
681 mooseError(
"dsin3Lode is only available for ordered tensor component types");
685template <
typename T2>
689 for (
const auto i : make_range(N))
696template <
typename T,
typename Scalar>
697inline typename std::enable_if_t<
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
OutputTools< Real >::VariableValue VariableValue
MooseArray< Real > VariableValue
std::enable_if_t< libMesh::ScalarTraits< Scalar >::value, SymmetricRankTwoTensorTempl< typename libMesh::CompareTypes< T, Scalar >::supertype > > operator*(const Scalar &factor, const SymmetricRankTwoTensorTempl< T > &t)
This class defines a Tensor that can change its shape.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
libMesh::VectorValue< T > column(const unsigned int i) const
Get the i-th column of the second order tensor.
SymmetricRankFourTensorTempl is designed to handle an N-dimensional fourth order tensor with minor sy...
FillMethod
To fill up the 6 entries in the 2nd-order tensor, fillFromInputVector is called with one of the follo...
static SymmetricRankTwoTensorTempl identity()
static constexpr unsigned int reverse_index[3][3]
libMesh::VectorValue< T > column(const unsigned int n) const
get the specified column of the tensor
T generalSecondInvariant() const
Calculates the second invariant (I2) of a tensor.
static constexpr std::array< Real, N > identityCoords
void printADReal(unsigned int nDual, std::ostream &stm=Moose::out) const
Print the Real part of the ADReal rank two tensor along with its first nDual dual numbers.
T operator()(unsigned int i, unsigned int j) const
Gets the value for the index specified.
libMesh::VectorValue< T > row(const unsigned int n) const
get the specified row of the tensor
SymmetricRankTwoTensorTempl(const std::vector< T > &input)
Constructor that proxies the fillFromInputVector method.
void rotate(const TypeTensor< T > &R)
rotates the tensor data given a rank two tensor rotation tensor _vals[i][j] = R_ij * R_jl * _vals[k][...
static constexpr Real mandelFactor(unsigned int i)
returns the 1 or sqrt(2) prefactor in the Mandel notation for the index i ranging from 0-5.
SymmetricRankTwoTensorTempl< T > deviatoric() const
returns A_ij - de_ij*tr(A)/3, where A are the _vals
SymmetricRankTwoTensorTempl< T > dsecondInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d(secondInvariant)/dA_ij.
bool isSymmetric() const
Test for symmetry. Surprisingly this is always true.
T tr() const
Returns the trace.
friend void dataLoad(std::istream &, SymmetricRankTwoTensorTempl< T2 > &, void *)
friend std::ostream & operator<<(std::ostream &os, const SymmetricRankTwoTensorTempl< T > &t)
bool operator==(const SymmetricRankTwoTensorTempl< T2 > &a) const
Defines logical equality with another SymmetricRankTwoTensorTempl<T2>
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 _vals: (1) the eigenvalues (if ...
SymmetricRankTwoTensorTempl< T > dsin3Lode(const T &r0) const
d(sin3Lode)/dA_ij If secondInvariant() <= r0 then return zero This is to gaurd against precision-loss...
void symmetricEigenvaluesEigenvectors(std::vector< T > &eigvals, RankTwoTensorTempl< T > &eigvecs) const
computes eigenvalues and eigenvectors, assuming tens is symmetric, and places them in ascending order...
SymmetricRankTwoTensorTempl< T > & operator=(const SymmetricRankTwoTensorTempl< T2 > &a)
sets _vals to a, and returns _vals
SymmetricRankFourTensorTempl< T > d2secondInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d^2(secondInvariant)/dA_ij/dA_kl.
T L2norm() const
Sqrt(_vals[i][j]*_vals[i][j])
SymmetricRankTwoTensorTempl(const SymmetricRankTwoTensorTempl< T2 > &a)
Construct from other template.
void fillFromScalarVariable(const VariableValue &scalar_variable)
fillFromScalarVariable takes FIRST/THIRD/SIXTH order scalar variable to fill in the Rank-2 tensor.
SymmetricRankTwoTensorTempl< T > initialContraction(const SymmetricRankFourTensorTempl< T > &b) const
returns this_ij * b_ijkl
SymmetricRankTwoTensorTempl< T > transpose() const
Returns a matrix that is the transpose of the matrix this was called on.
T value_type
For generic programming.
SymmetricRankFourTensorTempl< T > d2thirdInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d^2(thirdInvariant)/dA_ij/dA_kl.
TypeVector< typename libMesh::CompareTypes< T, T2 >::supertype > operator*(const TypeVector< T2 > &a) const
Defines multiplication with a vector to get a vector.
SymmetricRankTwoTensorTempl< T > operator-() const
returns -_vals
std::enable_if< libMesh::ScalarTraits< Scalar >::value, SymmetricRankTwoTensorTempl & >::type operator=(const Scalar &libmesh_dbg_var(p))
Assignment-from-scalar operator.
SymmetricRankTwoTensorTempl< T > dthirdInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d(thirdInvariant()/dA_ij.
static void initRandom(unsigned int)
This function initializes random seed based on a user-defined number.
static SymmetricRankTwoTensorTempl< T > selfOuterProduct(const TypeVector< T > &)
SymmetricRankTwoTensorTempl<T> from outer product of a vector with itself.
SymmetricRankTwoTensorTempl< T > & operator/=(const T &a)
performs _vals /= a
SymmetricRankTwoTensorTempl< T > & operator*=(const T &a)
performs _vals *= a
static SymmetricRankTwoTensorTempl< T > timesTranspose(const RankTwoTensorTempl< T > &)
return the matrix multiplied with its transpose A*A^T (guaranteed symmetric)
SymmetricRankTwoTensorTempl< typename libMesh::CompareTypes< T, T2 >::supertype > operator+(const SymmetricRankTwoTensorTempl< T2 > &a) const
returns _vals + a
T doubleContraction(const SymmetricRankTwoTensorTempl< T > &a) const
returns _vals_ij * a_ij (sum on i, j)
SymmetricRankTwoTensorTempl< T > inverse() const
retuns the inverse of the tensor
static constexpr unsigned int Ndim
tensor dimension and Mandel vector length
void addIa(const T &a)
Add identity times a to _vals.
T & operator()(unsigned int i)
Gets the raw value for the index specified. Takes index = 0,1,2,3,4,5.
static SymmetricRankTwoTensorTempl< T > genRandomSymmTensor(T, T)
This function generates a random symmetric rank two tensor.
SymmetricRankFourTensorTempl< T > outerProduct(const SymmetricRankTwoTensorTempl< T > &a) const
returns C_ijkl = a_ij * b_kl
SymmetricRankTwoTensorTempl< T > & operator=(const ColumnMajorMatrixTempl< T > &a)
Sets _vals to the values in a ColumnMajorMatrix (must be 3x3)
T operator()(unsigned int i) const
Gets the raw value for the index specified.
SymmetricRankTwoTensorTempl< T > dtrace() const
Denote the _vals[i][j] by A_ij, then this returns d(trace)/dA_ij.
void print(std::ostream &stm=Moose::out) const
Print the rank two tensor.
static MooseEnum fillMethodEnum()
Static method for use in validParams for getting the "fill_method".
void fillFromInputVector(const std::vector< T > &input, FillMethod fill_method=autodetect)
fillFromInputVector takes 1, 3, or 6 inputs to fill in the symmmetric Rank-2 tensor.
static constexpr unsigned int full_index[6][2]
auto operator/(const T2 &a) const -> typename std::enable_if< libMesh::ScalarTraits< T2 >::value, SymmetricRankTwoTensorTempl< decltype(T()/T2())> >::type
returns _vals/a
void surfaceFillFromInputVector(const std::vector< T > &input)
sets _vals[0][0], _vals[0][1], _vals[1][0], _vals[1][1] to input, and the remainder to zero
bool operator!=(const SymmetricRankTwoTensorTempl< T2 > &a) const
Defines logical inequality with another SymmetricRankTwoTensorTempl<T2>
SymmetricRankTwoTensorTempl< T > square() const
Returns the matrix squared.
SymmetricRankTwoTensorTempl< T > ddet() const
Denote the _vals[i][j] by A_ij, then this returns d(det)/dA_ij.
SymmetricRankTwoTensorTempl< T > & operator+=(const SymmetricRankTwoTensorTempl< T > &a)
adds a to _vals
void zero()
Set all components to zero.
T thirdInvariant() const
Denote the _vals[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns det(S + S....
friend void dataStore(std::ostream &, SymmetricRankTwoTensorTempl< T2 > &, void *)
void printReal(std::ostream &stm=Moose::out) const
Print the Real part of the ADReal rank two tensor.
static SymmetricRankTwoTensorTempl< T > plusTranspose(const RankTwoTensorTempl< T > &)
return the matrix plus its transpose A-A^T (guaranteed symmetric)
T secondInvariant() const
Denote the _vals[i][j] by A_ij, then S_ij = A_ij - de_ij*tr(A)/3 Then this returns (S_ij + S_ji)*(S_i...
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-...
SymmetricRankFourTensorTempl< T > positiveProjectionEigenDecomposition(std::vector< T > &, RankTwoTensorTempl< T > &) const
return positive projection tensor of eigen-decomposition
SymmetricRankTwoTensorTempl< T > & operator-=(const SymmetricRankTwoTensorTempl< T > &a)
sets _vals -= a and returns vals
T trace() const
returns the trace of the tensor, ie _vals[i][i] (sum i = 0, 1, 2)
static SymmetricRankTwoTensorTempl fromRawComponents(const T &S11, const T &S22, const T &S33, const T &S23, const T &S13, const T &S12)
static constexpr unsigned int N
static SymmetricRankTwoTensorTempl< T > transposeTimes(const RankTwoTensorTempl< T > &)
return the matrix multiplied with its transpose A^T*A (guaranteed symmetric)
void setToIdentity()
set the tensor to the identity matrix
SymmetricRankTwoTensorTempl()
Default constructor; fills to zero.
void symmetricEigenvalues(std::vector< T > &eigvals) const
computes eigenvalues, assuming tens is symmetric, and places them in ascending order in eigvals
auto operator*(const T2 &a) const -> typename std::enable_if< libMesh::ScalarTraits< T2 >::value, SymmetricRankTwoTensorTempl< decltype(T() *T2())> >::type
returns _vals*a
static SymmetricRankTwoTensorTempl initializeSymmetric(const TypeVector< T > &v0, const TypeVector< T > &v1, const TypeVector< T > &v2)
named constructor for initializing symmetrically
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
void mooseSetToZero< SymmetricRankTwoTensor >(SymmetricRankTwoTensor &v)
Helper function template specialization to set an object to zero.
void mooseSetToZero< ADSymmetricRankTwoTensor >(ADSymmetricRankTwoTensor &v)
Helper function template specialization to set an object to zero.
static constexpr Real sqrt2
std::sqrt is not constexpr, so we add sqrt(2) as a constant (used in Mandel notation)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
MooseUnits pow(const MooseUnits &, int)