www.mooseframework.org
RankThreeTensor.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "Moose.h"
13 #include "ADRankTwoTensorForward.h"
16 
17 #include "libmesh/libmesh.h"
18 #include "libmesh/int_range.h"
19 
20 #include "metaphysicl/raw_type.h"
21 
22 using libMesh::Real;
23 namespace libMesh
24 {
25 template <typename>
26 class TensorValue;
27 template <typename>
28 class TypeTensor;
29 template <typename>
30 class VectorValue;
31 }
32 
33 // Forward declarations
34 class MooseEnum;
35 
36 namespace MathUtils
37 {
38 template <typename T>
39 void mooseSetToZero(T & v);
40 
45 template <>
46 void mooseSetToZero<RankThreeTensorTempl<Real>>(RankThreeTensorTempl<Real> & v);
47 template <>
48 void mooseSetToZero<RankThreeTensorTempl<DualReal>>(RankThreeTensorTempl<DualReal> & v);
49 }
50 
55 template <typename T>
57 {
58 public:
60  static constexpr unsigned int N = Moose::dim;
61  static constexpr unsigned int N2 = N * N;
62  static constexpr unsigned int N3 = N * N * N;
64 
67  {
69  };
70 
77  {
81  };
82 
85 
87  RankThreeTensorTempl(const RankThreeTensorTempl<T> & a) = default;
88 
92  template <typename T2>
94 
97 
99  RankThreeTensorTempl(const std::vector<T> &, FillMethod method = automatic);
100 
102  inline T & operator()(unsigned int i, unsigned int j, unsigned int k)
103  {
104  return _vals[((i * N + j) * N + k)];
105  }
106 
108  inline T operator()(unsigned int i, unsigned int j, unsigned int k) const
109  {
110  return _vals[((i * N + j) * N + k)];
111  }
112 
114  RankThreeTensorTempl<T> & operator=(const T & value);
115 
117  void zero();
118 
120  void print(std::ostream & stm = Moose::out) const;
121 
124 
125  template <typename T2>
127 
129  VectorValue<T> operator*(const RankTwoTensorTempl<T> & a) const;
130 
132  RankThreeTensorTempl<T> operator*(const T a) const;
133 
135  RankThreeTensorTempl<T> & operator*=(const T a);
136 
138  RankThreeTensorTempl<T> operator/(const T a) const;
139 
141  RankThreeTensorTempl<T> & operator/=(const T a);
142 
145 
148 
151 
154 
157 
159  T L2norm() const;
160 
165  template <class T2>
166  void rotate(const T2 & R);
167 
172  void rotate(const TensorValue<T> & R);
173 
175  static MooseEnum fillMethodEnum();
176 
185  void fillFromInputVector(const std::vector<T> & input, FillMethod fill_method = automatic);
186 
192  void fillFromPlaneNormal(const VectorValue<T> & input);
193 
199 
205  VectorValue<T> doubleContraction(const RankTwoTensorTempl<T> & b) const;
206 
207 protected:
209  T _vals[N3];
210 
211  void fillGeneralFromInputVector(const std::vector<T> & input);
212 
213  template <class T2>
214  friend void dataStore(std::ostream &, RankThreeTensorTempl<T2> &, void *);
215 
216  template <class T2>
217  friend void dataLoad(std::istream &, RankThreeTensorTempl<T2> &, void *);
218 
219  template <class T2>
220  friend class RankTwoTensorTempl;
221 
222  template <class T2>
223  friend class RankThreeTensorTempl;
224 
225  template <class T2>
226  friend class RankFourTensorTempl;
227 };
228 
229 namespace MetaPhysicL
230 {
231 template <typename T>
232 struct RawType<RankThreeTensorTempl<T>>
233 {
235 
237  {
238  value_type ret;
239  for (const auto i : make_range(RankThreeTensorTempl<T>::N))
240  for (const auto j : make_range(RankThreeTensorTempl<T>::N))
241  for (const auto k : make_range(RankThreeTensorTempl<T>::N))
242  ret(i, j, k) = raw_value(in(i, j, k));
243 
244  return ret;
245  }
246 };
247 }
248 
249 template <typename T>
250 template <typename T2>
252 {
253  for (const auto i : make_range(N3))
254  _vals[i] = copy._vals[i];
255 }
256 
257 template <typename T>
258 template <class T2>
259 void
261 {
262  unsigned int index = 0;
263  for (const auto i : make_range(N))
264  for (const auto j : make_range(N))
265  for (const auto k : make_range(N))
266  {
267  unsigned int index2 = 0;
268  T sum = 0.0;
269  for (const auto m : make_range(N))
270  {
271  T a = R(i, m);
272  for (const auto n : make_range(N))
273  {
274  T ab = a * R(j, n);
275  for (const auto o : make_range(N))
276  sum += ab * R(k, o) * _vals[index2++];
277  }
278  }
279  _vals[index++] = sum;
280  }
281 }
282 
283 template <typename T>
286 {
287  return b * a;
288 }
289 
291 template <typename T>
293 operator*(const VectorValue<T> & p, const RankThreeTensorTempl<T> & b)
294 {
296  "RankTwoTensor and RankThreeTensor have to have the same dimension N.");
297  RankTwoTensorTempl<T> result;
298 
299  for (const auto i : make_range(RankThreeTensorTempl<T>::N))
300  for (const auto j : make_range(RankThreeTensorTempl<T>::N))
301  for (const auto k : make_range(RankThreeTensorTempl<T>::N))
302  result(i, j) += p(k) * b(k, i, j);
303 
304  return result;
305 }
306 
307 template <typename T>
308 template <typename T2>
311 {
312  for (const auto i : make_range(N))
313  for (const auto j : make_range(N))
314  for (const auto k : make_range(N))
315  (*this)(i, j, k) = a(i, j, k);
316 
317  return *this;
318 }
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
RankThreeTensorTempl< T > operator*(T a, const RankThreeTensorTempl< T > &b)
RankFourTensorTempl< T > mixedProductRankFour(const RankTwoTensorTempl< T > &a) const
Creates fourth order tensor D_{ijkl}=A_{mij}*b_{mn}*A_{nkl} where A is rank 3 and b is rank 2...
T 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.
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
Definition: MathUtils.h:368
void fillFromPlaneNormal(const VectorValue< T > &input)
Fills RankThreeTensor from plane normal vectors ref.
static constexpr unsigned int N2
RankThreeTensorTempl< typename RawType< T >::value_type > value_type
RankThreeTensorTempl< T > & operator/=(const T a)
r_ijk /= a for all i, j, k
auto raw_value(const Eigen::Map< T > &in)
Definition: ADReal.h:73
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:148
We need to instantiate the following CompareTypes to tell the compiler that ADReal is a subtype of Ch...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
RankThreeTensorTempl< T > & operator-=(const RankThreeTensorTempl< T > &a)
r_ijk -= a_ijk
void fillFromInputVector(const std::vector< T > &input, FillMethod fill_method=automatic)
fillFromInputVector takes some number of inputs to fill the Rank-3 tensor.
RankThreeTensorTempl< T > operator/(const T a) const
r_ijk/a
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
RankThreeTensorTempl< T > operator-() const
-r_ijk
FillMethod
To fill up the 27 entries in the 3rd-order tensor, fillFromInputVector is called with one of the foll...
RankThreeTensorTempl< T > & operator+=(const RankThreeTensorTempl< T > &a)
r_ijk += a_ijk for all i, j, k
static MooseEnum fillMethodEnum()
Static method for use in validParams for getting the "fill_method".
RankThreeTensorTempl< T > & operator*=(const T a)
r_ijk *= a
void rotate(const T2 &R)
Rotate the tensor using r_ijk = R_im R_in R_ko r_mno.
RankThreeTensorTempl< T > & operator=(const T &value)
Assignment-from-scalar operator.
T & operator()(unsigned int i, unsigned int j, unsigned int k)
Gets the value for the index specified. Takes index = 0,1,2.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
T _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
InitMethod
Initialization method.
static constexpr unsigned int N3
RankThreeTensorTempl()
Default constructor; fills to zero.
RankThreeTensorTempl< T > operator+(const RankThreeTensorTempl< T > &a) const
r_ijkl + a_ijk
T L2norm() const
(r_ijk*r_ijk)
friend void dataLoad(std::istream &, RankThreeTensorTempl< T2 > &, void *)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: RankTwoTensor.h:79
friend void dataStore(std::ostream &, RankThreeTensorTempl< T2 > &, void *)
IntRange< T > make_range(T beg, T end)
VectorValue< T > operator*(const RankTwoTensorTempl< T > &a) const
b_i = r_ijk * a_jk
void zero()
Zeros out the tensor.
VectorValue< T > doubleContraction(const RankTwoTensorTempl< T > &b) const
Creates a vector from the double contraction of a rank three and rank two tensor. ...
void fillGeneralFromInputVector(const std::vector< T > &input)
void print(std::ostream &stm=Moose::out) const
Print the rank three tensor.
static constexpr unsigned int N
tensor dimension and powers of the dimension
static value_type value(const RankThreeTensorTempl< T > &in)