www.mooseframework.org
RankThreeTensor.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 RANKTHREETENSOR_H
8 #define RANKTHREETENSOR_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 RankThreeTensor;
21 class RankFourTensor;
22 
23 template <typename T>
24 void mooseSetToZero(T & v);
25 
30 template <>
32 
38 {
39 public:
42  {
44  };
45 
52  {
54  };
55 
58 
61 
63  RankThreeTensor(const std::vector<Real> &, FillMethod);
64 
66  inline Real & operator()(unsigned int i, unsigned int j, unsigned int k)
67  {
68  return _vals[((i * N + j) * N + k)];
69  }
70 
72  inline Real operator()(unsigned int i, unsigned int j, unsigned int k) const
73  {
74  return _vals[((i * N + j) * N + k)];
75  }
76 
78  void zero();
79 
81  void print(std::ostream & stm = Moose::out) const;
82 
85 
87  // RankTwoTensor operator*(const RankTwoTensor & a) const;
88 
90  RealVectorValue operator*(const RankTwoTensor & a) const;
91 
93  // RealTensorValue operator*(const RealTensorValue & a) const;
94 
96  RankThreeTensor operator*(const Real a) const;
97 
99  RankThreeTensor & operator*=(const Real a);
100 
102  RankThreeTensor operator/(const Real a) const;
103 
105  RankThreeTensor & operator/=(const Real a);
106 
109 
111  RankThreeTensor operator+(const RankThreeTensor & a) const;
112 
115 
117  RankThreeTensor operator-(const RankThreeTensor & a) const;
118 
120  RankThreeTensor operator-() const;
121 
123  Real L2norm() const;
124 
129  template <class T>
130  void rotate(const T & R);
131 
136  void rotate(const RealTensorValue & R);
137 
142  void rotate(const RankTwoTensor & R);
143 
145  static MooseEnum fillMethodEnum();
146 
155  void fillFromInputVector(const std::vector<Real> & input, FillMethod fill_method);
156 
162  void fillFromPlaneNormal(const RealVectorValue & input);
163 
169 
174 
175 protected:
177  static constexpr unsigned int N = LIBMESH_DIM;
178  static constexpr unsigned int N2 = N * N;
179  static constexpr unsigned int N3 = N * N * N;
180 
182  Real _vals[N3];
183 
184  void fillGeneralFromInputVector(const std::vector<Real> & input);
185 
186  template <class T>
187  friend void dataStore(std::ostream &, T &, void *);
188 
189  template <class T>
190  friend void dataLoad(std::istream &, T &, void *);
191 };
192 
193 template <>
194 void dataStore(std::ostream &, RankThreeTensor &, void *);
195 
196 template <>
197 void dataLoad(std::istream &, RankThreeTensor &, void *);
198 
199 inline RankThreeTensor operator*(Real a, const RankThreeTensor & b) { return b * a; }
200 
203 
204 template <class T>
205 void
207 {
208  unsigned int index = 0;
209  for (unsigned int i = 0; i < N; ++i)
210  for (unsigned int j = 0; j < N; ++j)
211  for (unsigned int k = 0; k < N; ++k)
212  {
213  unsigned int index2 = 0;
214  Real sum = 0.0;
215  for (unsigned int m = 0; m < N; ++m)
216  {
217  Real a = R(i, m);
218  for (unsigned int n = 0; n < N; ++n)
219  {
220  Real ab = a * R(j, n);
221  for (unsigned int o = 0; o < N; ++o)
222  sum += ab * R(k, o) * _vals[index2++];
223  }
224  }
225  _vals[index++] = sum;
226  }
227 }
228 
229 #endif // RANKTHREETENSOR_H
RankThreeTensor & operator+=(const RankThreeTensor &a)
r_ijk += a_ijk for all i, j, k
InitMethod
Initialization method.
RankFourTensor mixedProductRankFour(const RankTwoTensor &a) const
Creates fourth order tensor D=A*b*A where A is rank 3 and b is rank 2.
VectorValue< Real > RealVectorValue
Definition: Assembly.h:40
RankThreeTensor & operator=(const RankThreeTensor &a)
copies values from a into this tensor
void fillFromPlaneNormal(const RealVectorValue &input)
Fills RankThreeTensor from plane normal vectors ref.
Real L2norm() const
(r_ijk*r_ijk)
void print(std::ostream &stm=Moose::out) const
Print the rank three tensor.
static constexpr unsigned int N2
static MooseEnum fillMethodEnum()
Static method for use in validParams for getting the "fill_method".
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
FillMethod
To fill up the 27 entries in the 3rd-order tensor, fillFromInputVector is called with one of the foll...
Real & operator()(unsigned int i, unsigned int j, unsigned int k)
Gets the value for the index specified. Takes index = 0,1,2.
static constexpr unsigned int N
Dimensionality of rank-three tensor.
void fillFromInputVector(const std::vector< Real > &input, FillMethod fill_method)
fillFromInputVector takes some number of inputs to fill the Rank-3 tensor.
RankThreeTensor operator+(const RankThreeTensor &a) const
r_ijkl + a_ijk
PetscInt m
RankThreeTensor operator/(const Real a) const
r_ijk/a
Real operator()(unsigned int i, unsigned int j, unsigned int k) const
Gets the value for the index specified. Takes index = 0,1,2. Used for const.
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
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
void fillGeneralFromInputVector(const std::vector< Real > &input)
void zero()
Zeros out the tensor.
RealVectorValue operator*(const RankTwoTensor &a) const
r_ijk*a_kl
PetscInt n
RealVectorValue doubleContraction(const RankTwoTensor &b) const
Creates a vector from the double contraction of a rank three and rank two tensor. ...
RankThreeTensor & operator/=(const Real a)
r_ijk /= a for all i, j, k
RankThreeTensor()
Default constructor; fills to zero.
void rotate(const T &R)
Rotate the tensor using r_ijk = R_im R_in R_ko r_mno.
static constexpr unsigned int N3
RankThreeTensor operator-() const
-r_ijk
friend void dataLoad(std::istream &, T &, void *)
Definition: DataIO.h:351
friend void dataStore(std::ostream &, T &, void *)
Definition: DataIO.h:155
TensorValue< Real > RealTensorValue
Definition: Assembly.h:45
RankThreeTensor & operator-=(const RankThreeTensor &a)
r_ijk -= a_ijk
RankFourTensor is designed to handle any N-dimensional fourth order tensor, C.
RankThreeTensor & operator*=(const Real a)
r_ijk *= a
void mooseSetToZero< RankThreeTensor >(RankThreeTensor &v)
Helper function template specialization to set an object to zero.