www.mooseframework.org
RankFourTensor.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 RANKFOURTENSOR_H
8 #define RANKFOURTENSOR_H
9 
10 // MOOSE includes
11 #include "DataIO.h"
12 
13 #include "libmesh/tensor_value.h"
14 #include "libmesh/libmesh.h"
15 #include "libmesh/vector_value.h"
16 
17 // Forward declarations
18 class MooseEnum;
19 class RankTwoTensor;
20 class RankFourTensor;
21 
22 template <typename T>
23 void mooseSetToZero(T & v);
24 
29 template <>
31 
43 {
44 public:
47  {
52  };
53 
60  {
71  };
72 
75 
78 
80  RankFourTensor(const std::vector<Real> &, FillMethod);
81 
82  // Named constructors
85 
87  inline Real & operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
88  {
89  return _vals[((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBMESH_DIM + l];
90  }
91 
96  inline Real operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l) const
97  {
98  return _vals[((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBMESH_DIM + l];
99  }
100 
102  void zero();
103 
105  void print(std::ostream & stm = Moose::out) const;
106 
109 
111  RankTwoTensor operator*(const RankTwoTensor & a) const;
112 
114  RealTensorValue operator*(const RealTensorValue & a) const;
115 
117  RankFourTensor operator*(const Real a) const;
118 
120  RankFourTensor & operator*=(const Real a);
121 
123  RankFourTensor operator/(const Real a) const;
124 
126  RankFourTensor & operator/=(const Real a);
127 
130 
132  RankFourTensor operator+(const RankFourTensor & a) const;
133 
136 
138  RankFourTensor operator-(const RankFourTensor & a) const;
139 
141  RankFourTensor operator-() const;
142 
144  RankFourTensor operator*(const RankFourTensor & a) const;
145 
147  Real L2norm() const;
148 
153  RankFourTensor invSymm() const;
154 
159  template <class T>
160  void rotate(const T & R);
161 
166  void rotate(const RealTensorValue & R);
167 
172  void rotate(const RankTwoTensor & R);
173 
179 
192  void surfaceFillFromInputVector(const std::vector<Real> & input);
193 
195  static MooseEnum fillMethodEnum();
196 
212  void fillFromInputVector(const std::vector<Real> & input, FillMethod fill_method);
213 
215  void fillGeneralIsotropic(Real i0, Real i1, Real i2);
216  void fillAntisymmetricIsotropic(Real i0);
217  void fillSymmetricIsotropic(Real i0, Real i1);
218  void fillSymmetricIsotropicEandNu(Real E, Real nu);
220 
223 
225  Real sum3x3() const;
226 
228  RealGradient sum3x1() const;
229 
231  bool isSymmetric() const;
232 
234  bool isIsotropic() const;
235 
236 protected:
238  static constexpr unsigned int N = LIBMESH_DIM;
239  static constexpr unsigned int N2 = N * N;
240  static constexpr unsigned int N3 = N * N * N;
241  static constexpr unsigned int N4 = N * N * N * N;
242 
245  Real _vals[N4];
246 
261  void fillSymmetricFromInputVector(const std::vector<Real> & input, bool all);
262 
269  void fillAntisymmetricFromInputVector(const std::vector<Real> & input);
270 
279  void fillGeneralIsotropicFromInputVector(const std::vector<Real> & input);
280 
287  void fillAntisymmetricIsotropicFromInputVector(const std::vector<Real> & input);
288 
296  void fillSymmetricIsotropicFromInputVector(const std::vector<Real> & input);
297 
307  void fillSymmetricIsotropicEandNuFromInputVector(const std::vector<Real> & input);
308 
316  void fillAxisymmetricRZFromInputVector(const std::vector<Real> & input);
317 
323  void fillGeneralFromInputVector(const std::vector<Real> & input);
324 
339  void fillPrincipalFromInputVector(const std::vector<Real> & input);
340  template <class T>
341  friend void dataStore(std::ostream &, T &, void *);
342 
343  template <class T>
344  friend void dataLoad(std::istream &, T &, void *);
345 
346  friend class RankTwoTensor;
347  friend class RankThreeTensor;
348 };
349 
350 template <>
351 void dataStore(std::ostream &, RankFourTensor &, void *);
352 
353 template <>
354 void dataLoad(std::istream &, RankFourTensor &, void *);
355 
356 inline RankFourTensor operator*(Real a, const RankFourTensor & b) { return b * a; }
357 
358 template <class T>
359 void
361 {
362  RankFourTensor old = *this;
363 
364  int index = 0;
365  for (unsigned int i = 0; i < N; ++i)
366  for (unsigned int j = 0; j < N; ++j)
367  for (unsigned int k = 0; k < N; ++k)
368  for (unsigned int l = 0; l < N; ++l)
369  {
370  Real sum = 0.0;
371  int index2 = 0;
372  for (unsigned int m = 0; m < N; ++m)
373  {
374  Real a = R(i, m);
375  for (unsigned int n = 0; n < N; ++n)
376  {
377  Real ab = a * R(j, n);
378  for (unsigned int o = 0; o < N; ++o)
379  {
380  Real abc = ab * R(k, o);
381  for (unsigned int p = 0; p < N; ++p)
382  sum += abc * R(l, p) * old._vals[index2++];
383  }
384  }
385  }
386  _vals[index++] = sum;
387  }
388 }
389 
390 #endif // RANKFOURTENSOR_H
RankFourTensor operator/(const Real a) const
C_ijkl/a.
void fillAntisymmetricIsotropicFromInputVector(const std::vector< Real > &input)
fillAntisymmetricIsotropicFromInputVector takes 1 input to fill the the antisymmetric Rank-4 tensor w...
RealVectorValue RealGradient
Definition: Assembly.h:43
RankFourTensor operator-() const
-C_ijkl
void fillGeneralFromInputVector(const std::vector< Real > &input)
fillGeneralFromInputVector takes 81 inputs to fill the Rank-4 tensor No symmetries are explicitly mai...
FillMethod
To fill up the 81 entries in the 4th-order tensor, fillFromInputVector is called with one of the foll...
void fillSymmetricIsotropicEandNu(Real E, Real nu)
RankTwoTensor innerProductTranspose(const RankTwoTensor &) const
Inner product of the major transposed tensor with a rank two tensor.
void zero()
Zeros out the tensor.
void fillGeneralIsotropic(Real i0, Real i1, Real i2)
Vector-less fill API functions. See docs of the corresponding ...FromInputVector methods.
void rotate(const T &R)
Rotate the tensor using C_ijkl = R_im R_in R_ko R_lp C_mnop.
RankFourTensor & operator=(const RankFourTensor &a)
copies values from a into this tensor
void surfaceFillFromInputVector(const std::vector< Real > &input)
Fills the tensor entries ignoring the last dimension (ie, C_ijkl=0 if any of i, j, k, or l = 3).
bool isIsotropic() const
checks if the tensor is isotropic
void fillSymmetricIsotropicEandNuFromInputVector(const std::vector< Real > &input)
fillSymmetricIsotropicEandNuFromInputVector is a variation of the fillSymmetricIsotropicFromInputVect...
RankFourTensor()
Default constructor; fills to zero.
Real operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l) const
Gets the value for the index specified.
RankFourTensor invSymm() const
This returns A_ijkl such that C_ijkl*A_klmn = 0.5*(de_im de_jn + de_in de_jm) This routine assumes th...
Real L2norm() const
sqrt(C_ijkl*C_ijkl)
friend void dataLoad(std::istream &, T &, void *)
Definition: DataIO.h:351
void fillFromInputVector(const std::vector< Real > &input, FillMethod fill_method)
fillFromInputVector takes some number of inputs to fill the Rank-4 tensor.
InitMethod
Initialization method.
Real & operator()(unsigned int i, unsigned int j, unsigned int k, unsigned int l)
Gets the value for the index specified. Takes index = 0,1,2.
RankTwoTensor operator*(const RankTwoTensor &a) const
C_ijkl*a_kl.
bool isSymmetric() const
checks if the tensor is symmetric
RealGradient sum3x1() const
Calculates the vector a[i] = sum over j Ciijj for i and j varying from 0 to 2.
RankFourTensor transposeMajor() const
Transpose the tensor by swapping the first pair with the second pair of indices.
static constexpr unsigned int N2
PetscInt m
RankFourTensor & operator*=(const Real a)
C_ijkl *= a.
void fillAntisymmetricFromInputVector(const std::vector< Real > &input)
fillAntisymmetricFromInputVector takes 6 inputs to fill the the antisymmetric Rank-4 tensor with the ...
void fillAntisymmetricIsotropic(Real i0)
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
static constexpr unsigned int N4
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
Real _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...
RankFourTensor & operator+=(const RankFourTensor &a)
C_ijkl += a_ijkl for all i, j, k, l.
void mooseSetToZero< RankFourTensor >(RankFourTensor &v)
Helper function template specialization to set an object to zero.
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
RankFourTensor & operator-=(const RankFourTensor &a)
C_ijkl -= a_ijkl.
void fillSymmetricIsotropicFromInputVector(const std::vector< Real > &input)
fillSymmetricIsotropicFromInputVector takes 2 inputs to fill the the symmetric Rank-4 tensor with the...
void fillSymmetricFromInputVector(const std::vector< Real > &input, bool all)
fillSymmetricFromInputVector takes either 21 (all=true) or 9 (all=false) inputs to fill in the Rank-4...
void fillGeneralIsotropicFromInputVector(const std::vector< Real > &input)
fillGeneralIsotropicFromInputVector takes 3 inputs to fill the Rank-4 tensor with symmetries C_ijkl =...
void fillSymmetricIsotropic(Real i0, Real i1)
Real sum3x3() const
Calculates the sum of Ciijj for i and j varying from 0 to 2.
PetscInt n
static RankFourTensor IdentityFour()
RankFourTensor operator+(const RankFourTensor &a) const
C_ijkl + a_ijkl.
friend void dataStore(std::ostream &, T &, void *)
Definition: DataIO.h:155
void fillPrincipalFromInputVector(const std::vector< Real > &input)
fillPrincipalFromInputVector takes 9 inputs to fill a Rank-4 tensor C1111 = input0 C1122 = input1 C11...
static RankFourTensor Identity()
static MooseEnum fillMethodEnum()
Static method for use in validParams for getting the "fill_method".
RankFourTensor & operator/=(const Real a)
C_ijkl /= a for all i, j, k, l.
static constexpr unsigned int N3
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45
void print(std::ostream &stm=Moose::out) const
Print the rank four tensor.
void fillAxisymmetricRZFromInputVector(const std::vector< Real > &input)
fillAxisymmetricRZFromInputVector takes 5 inputs to fill the axisymmetric Rank-4 tensor with the appr...
static constexpr unsigned int N
Dimensionality of rank-four tensor.
RankFourTensor is designed to handle any N-dimensional fourth order tensor, C.