www.mooseframework.org
RankTwoTensor.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 #ifndef RANKTWOTENSOR_H
8 #define RANKTWOTENSOR_H
9 
10 #include "Moose.h"
11 
12 #include "RankFourTensor.h"
13 
14 // Any requisite includes here
15 #include "libmesh/libmesh.h"
16 #include "libmesh/vector_value.h"
17 #include "libmesh/tensor_value.h"
18 
19 #include <vector>
20 #include "MooseRandom.h"
21 
22 // Forward declarations
23 class RankTwoTensor;
24 class RankFourTensor;
25 
26 template <typename T>
27 void mooseSetToZero(T & v);
28 
33 template <>
35 
46 {
47 public:
48  // Select initialization
50  {
53  };
54 
56  RankTwoTensor();
57 
60 
67  {
70  diagonal3 = 3,
72  general = 9
73  };
74 
79  RankTwoTensor(const TypeVector<Real> & row1,
80  const TypeVector<Real> & row2,
81  const TypeVector<Real> & row3);
82 
84  static RankTwoTensor initializeFromRows(const TypeVector<Real> & row0,
85  const TypeVector<Real> & row1,
86  const TypeVector<Real> & row2);
87 
89  static RankTwoTensor initializeFromColumns(const TypeVector<Real> & col0,
90  const TypeVector<Real> & col1,
91  const TypeVector<Real> & col2);
92 
94  RankTwoTensor(const std::vector<Real> & input) { this->fillFromInputVector(input); };
95 
97  RankTwoTensor(Real S11, Real S22, Real S33, Real S23, Real S13, Real S12);
98 
101  Real S11, Real S21, Real S31, Real S12, Real S22, Real S32, Real S13, Real S23, Real S33);
102 
104  RankTwoTensor(const TypeTensor<Real> & a);
105 
106  // Named constructors
108 
110  inline Real & operator()(unsigned int i, unsigned int j) { return _vals[i * N + j]; }
111 
113  inline Real operator()(unsigned int i, unsigned int j) const { return _vals[i * N + j]; }
114 
116  void zero();
117 
119  static MooseEnum fillMethodEnum();
120 
132  void fillFromInputVector(const std::vector<Real> & input, FillMethod fill_method = autodetect);
133 
134 public:
136  TypeVector<Real> row(const unsigned int r) const;
137 
139  TypeVector<Real> column(const unsigned int c) const;
140 
146  RankTwoTensor rotated(const RealTensorValue & R) const;
147 
153  void rotate(const RealTensorValue & R);
154 
160  void rotate(const RankTwoTensor & R);
161 
167 
172  RankTwoTensor transpose() const;
173 
176 
179 
181  RankTwoTensor operator+(const RankTwoTensor & a) const;
182 
185 
187  RankTwoTensor operator-(const RankTwoTensor & a) const;
188 
190  RankTwoTensor operator-() const;
191 
193  RankTwoTensor & operator*=(const Real a);
194 
196  RankTwoTensor operator*(const Real a) const;
197 
199  RankTwoTensor & operator/=(const Real a);
200 
202  RankTwoTensor operator/(const Real a) const;
203 
205  TypeVector<Real> operator*(const TypeVector<Real> & a) const;
206 
209 
211  RankTwoTensor operator*(const RankTwoTensor & a) const;
212 
214  RankTwoTensor operator*(const TypeTensor<Real> & a) const;
215 
217  bool operator==(const RankTwoTensor & a) const;
218 
221 
223  Real doubleContraction(const RankTwoTensor & a) const;
224 
226  RankFourTensor outerProduct(const RankTwoTensor & a) const;
227 
230 
233 
235  RankTwoTensor deviatoric() const;
236 
238  Real trace() const;
239 
244  RankTwoTensor dtrace() const;
245 
252  Real generalSecondInvariant() const;
253 
257  Real secondInvariant() const;
258 
264 
270 
277  Real sin3Lode(const Real r0, const Real r0_value) const;
278 
285  RankTwoTensor dsin3Lode(const Real r0) const;
286 
293  RankFourTensor d2sin3Lode(const Real r0) const;
294 
301  Real thirdInvariant() const;
302 
308 
314 
316  Real det() const;
317 
322  RankTwoTensor ddet() const;
323 
325  RankTwoTensor inverse() const;
326 
328  void print(std::ostream & stm = Moose::out) const;
329 
331  void addIa(const Real a);
332 
334  Real L2norm() const;
335 
340  void surfaceFillFromInputVector(const std::vector<Real> & input);
341 
346  void symmetricEigenvalues(std::vector<Real> & eigvals) const;
347 
353  void symmetricEigenvaluesEigenvectors(std::vector<Real> & eigvals, RankTwoTensor & eigvecs) const;
354 
366  void dsymmetricEigenvalues(std::vector<Real> & eigvals,
367  std::vector<RankTwoTensor> & deigvals) const;
368 
373  void d2symmetricEigenvalues(std::vector<RankFourTensor> & deriv) const;
374 
384  void syev(const char * calculation_type,
385  std::vector<PetscScalar> & eigvals,
386  std::vector<PetscScalar> & a) const;
387 
392  void getRUDecompositionRotation(RankTwoTensor & rot) const;
393 
397  static void initRandom(unsigned int);
398 
404  static RankTwoTensor genRandomTensor(Real, Real);
405 
411  static RankTwoTensor genRandomSymmTensor(Real, Real);
412 
414  void vectorOuterProduct(const TypeVector<Real> &, const TypeVector<Real> &);
415 
418 
420  void fillRow(unsigned int, const TypeVector<Real> &);
421 
423  void fillColumn(unsigned int, const TypeVector<Real> &);
424 
427 
428 private:
429  static constexpr unsigned int N = LIBMESH_DIM;
430  static constexpr unsigned int N2 = N * N;
431 
433  Real _vals[N2];
434 
435  template <class T>
436  friend void dataStore(std::ostream &, T &, void *);
437 
438  template <class T>
439  friend void dataLoad(std::istream &, T &, void *);
440  friend class RankFourTensor;
441  friend class RankThreeTensor;
442 };
443 
444 inline RankTwoTensor operator*(Real a, const RankTwoTensor & b) { return b * a; }
445 
446 template <>
447 void dataStore(std::ostream & stream, RankTwoTensor &, void *);
448 
449 template <>
450 void dataLoad(std::istream & stream, RankTwoTensor &, void *);
451 
452 #endif // RANKTWOTENSOR_H
void fillFromInputVector(const std::vector< Real > &input, FillMethod fill_method=autodetect)
fillFromInputVector takes 6 or 9 inputs to fill in the Rank-2 tensor.
Real sin3Lode(const Real r0, const Real r0_value) const
Sin(3*Lode_angle) If secondInvariant() <= r0 then return r0_value This is to gaurd against precision-...
RankTwoTensor dthirdInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d(thirdInvariant()/dA_ij.
void zero()
zeroes all _vals components
RankTwoTensor transpose() const
Returns a matrix that is the transpose of the matrix this was called on.
RankTwoTensor dsin3Lode(const Real r0) const
d(sin3Lode)/dA_ij If secondInvariant() <= r0 then return zero This is to gaurd against precision-loss...
RankTwoTensor operator*(const Real a) const
returns _vals*a
RankFourTensor d2sin3Lode(const Real r0) const
d^2(sin3Lode)/dA_ij/dA_kl If secondInvariant() <= r0 then return zero This is to gaurd against precis...
void d2symmetricEigenvalues(std::vector< RankFourTensor > &deriv) const
Computes second derivatives of Eigenvalues of a rank two tensor.
RankTwoTensor operator/(const Real a) const
returns _vals/a
Real _vals[N2]
The values of the rank-two tensor stored by index=(i * LIBMESH_DIM + j)
void vectorOuterProduct(const TypeVector< Real > &, const TypeVector< Real > &)
RankTwoTensor from outer product of vectors.
RankTwoTensor & operator=(const RankTwoTensor &a)
sets _vals to a, and returns _vals
void fillColumn(unsigned int, const TypeVector< Real > &)
Assigns value to the rows of a specified column.
friend void dataLoad(std::istream &, T &, void *)
Definition: DataIO.h:351
static RankTwoTensor genRandomSymmTensor(Real, Real)
This function generates a random symmetric rank two tensor.
RankFourTensor mixedProductJkIl(const RankTwoTensor &a) const
returns C_ijkl = a_jk * b_il
static RankTwoTensor initializeFromColumns(const TypeVector< Real > &col0, const TypeVector< Real > &col1, const TypeVector< Real > &col2)
named constructor for initializing from column vectors
RankTwoTensor initialContraction(const RankFourTensor &b) const
returns this_ij * b_ijkl
This class defines a Tensor that can change its shape.
Real L2norm() const
Sqrt(_vals[i][j]*_vals[i][j])
FillMethod
To fill up the 9 entries in the 2nd-order tensor, fillFromInputVector is called with one of the follo...
Definition: RankTwoTensor.h:66
RankTwoTensor()
Default constructor; fills to zero.
Definition: RankTwoTensor.C:54
RankTwoTensor deviatoric() const
returns A_ij - de_ij*tr(A)/3, where A are the _vals
RankTwoTensor inverse() const
Calculate the inverse of the tensor.
static MooseEnum fillMethodEnum()
Static method for use in validParams for getting the "fill_method".
Definition: RankTwoTensor.C:49
Real & operator()(unsigned int i, unsigned int j)
Gets the value for the index specified. Takes index = 0,1,2.
void symmetricEigenvaluesEigenvectors(std::vector< Real > &eigvals, RankTwoTensor &eigvecs) const
computes eigenvalues and eigenvectors, assuming tens is symmetric, and places them in ascending order...
void addIa(const Real a)
Add identity times a to _vals.
RankTwoTensor operator-() const
returns -_vals
RankTwoTensor & operator*=(const Real a)
performs _vals *= a
bool operator==(const RankTwoTensor &a) const
Defines logical equality with another RankTwoTensor.
static void initRandom(unsigned int)
This function initializes random seed based on a user-defined number.
RankTwoTensor & operator/=(const Real a)
performs _vals /= a
Real doubleContraction(const RankTwoTensor &a) const
returns _vals_ij * a_ij (sum on i, j)
RankFourTensor outerProduct(const RankTwoTensor &a) const
returns C_ijkl = a_ij * b_kl
void symmetricEigenvalues(std::vector< Real > &eigvals) const
computes eigenvalues, assuming tens is symmetric, and places them in ascending order in eigvals ...
Real operator()(unsigned int i, unsigned int j) const
Gets the value for the index specified. Takes index = 0,1,2, used for const.
RankFourTensor mixedProductIkJl(const RankTwoTensor &a) const
returns C_ijkl = a_ik * b_jl
void dsymmetricEigenvalues(std::vector< Real > &eigvals, std::vector< RankTwoTensor > &deigvals) const
computes eigenvalues, and their symmetric derivatives wrt vals, assuming tens is symmetric ...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
RankTwoTensor is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: RankTwoTensor.h:45
TypeVector< Real > column(const unsigned int c) const
returns _vals[i][c], ie, column c, with c = 0, 1, 2
void getRUDecompositionRotation(RankTwoTensor &rot) const
Uses the petscblaslapack.h LAPACKsyev_ routine to perform RU decomposition and obtain the rotation te...
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
RankFourTensor d2secondInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d^2(secondInvariant)/dA_ij/dA_kl.
TypeVector< Real > row(const unsigned int r) const
returns _vals[r][i], ie, row r, with r = 0, 1, 2
RankTwoTensor rotateXyPlane(Real a)
rotates the tensor data anticlockwise around the z-axis
RankTwoTensor rotated(const RealTensorValue &R) const
Returns a rotated version of the tensor data given a rank two tensor rotation tensor _vals[i][j] = R_...
void rotate(const RealTensorValue &R)
rotates the tensor data given a rank two tensor rotation tensor _vals[i][j] = R_ij * R_jl * _vals[k][...
static RankTwoTensor genRandomTensor(Real, Real)
This function generates a random unsymmetric rank two tensor.
RankFourTensor d2thirdInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d^2(thirdInvariant)/dA_ij/dA_kl.
RankTwoTensor operator+(const RankTwoTensor &a) const
returns _vals + a
Real secondInvariant() const
Calculates the second invariant (I2) of a tensor.
Real 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...
static constexpr unsigned int N
void mooseSetToZero< RankTwoTensor >(RankTwoTensor &v)
Helper function template specialization to set an object to zero.
Definition: RankTwoTensor.C:29
void print(std::ostream &stm=Moose::out) const
Print the rank two tensor.
RankTwoTensor & operator+=(const RankTwoTensor &a)
adds a to _vals
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
Real trace() const
returns the trace of the tensor, ie _vals[i][i] (sum i = 0, 1, 2)
void syev(const char *calculation_type, std::vector< PetscScalar > &eigvals, std::vector< PetscScalar > &a) const
Uses the petscblaslapack.h LAPACKsyev_ routine to find, for symmetric _vals: (1) the eigenvalues (if ...
RankTwoTensor ddet() const
Denote the _vals[i][j] by A_ij, then this returns d(det)/dA_ij.
static constexpr unsigned int N2
RankTwoTensor dtrace() const
Denote the _vals[i][j] by A_ij, then this returns d(trace)/dA_ij.
void fillRow(unsigned int, const TypeVector< Real > &)
Assigns value to the columns of a specified row.
RankTwoTensor dsecondInvariant() const
Denote the _vals[i][j] by A_ij, then this returns d(secondInvariant)/dA_ij.
friend void dataStore(std::ostream &, T &, void *)
Definition: DataIO.h:155
static RankTwoTensor Identity()
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45
void surfaceFillFromInputVector(const std::vector< Real > &input)
sets _vals[0][0], _vals[0][1], _vals[1][0], _vals[1][1] to input, and the remainder to zero ...
Real generalSecondInvariant() 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...
void fillRealTensor(RealTensorValue &)
Return real tensor of a rank two tensor.
static RankTwoTensor initializeFromRows(const TypeVector< Real > &row0, const TypeVector< Real > &row1, const TypeVector< Real > &row2)
named constructor for initializing from row vectors
Definition: RankTwoTensor.C:98
Real det() const
Calculate the determinant of the tensor.
RankTwoTensor & operator-=(const RankTwoTensor &a)
sets _vals -= a and returns vals
RankTwoTensor(const std::vector< Real > &input)
Constructor that proxies the fillFromInputVector method.
Definition: RankTwoTensor.h:94
RankFourTensor is designed to handle any N-dimensional fourth order tensor, C.