https://mooseframework.inl.gov
RankThreeTensor.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 namespace libMesh
23 {
24 template <typename>
25 class TensorValue;
26 template <typename>
27 class TypeTensor;
28 template <typename>
29 class VectorValue;
30 }
31 
32 // Forward declarations
33 class MooseEnum;
34 
35 namespace MathUtils
36 {
37 template <typename T>
38 void mooseSetToZero(T & v);
39 
44 template <>
45 void mooseSetToZero<RankThreeTensorTempl<Real>>(RankThreeTensorTempl<Real> & v);
46 template <>
47 void mooseSetToZero<RankThreeTensorTempl<ADReal>>(RankThreeTensorTempl<ADReal> & v);
48 }
49 
54 template <typename T>
56 {
57 public:
59  static constexpr unsigned int N = Moose::dim;
60  static constexpr unsigned int N2 = N * N;
61  static constexpr unsigned int N3 = N * N * N;
63 
66  {
68  };
69 
76  {
80  };
81 
84 
86  RankThreeTensorTempl(const RankThreeTensorTempl<T> & a) = default;
87 
91  template <typename T2>
93 
96 
98  RankThreeTensorTempl(const std::vector<T> &, FillMethod method = automatic);
99 
101  inline T & operator()(unsigned int i, unsigned int j, unsigned int k)
102  {
103  return _vals[((i * N + j) * N + k)];
104  }
105 
107  inline T operator()(unsigned int i, unsigned int j, unsigned int k) const
108  {
109  return _vals[((i * N + j) * N + k)];
110  }
111 
113  RankThreeTensorTempl<T> & operator=(const T & value);
114 
116  void zero();
117 
119  void print(std::ostream & stm = Moose::out) const;
120 
121  friend std::ostream & operator<<(std::ostream & os, const RankThreeTensorTempl<T> & t)
122  {
123  t.print(os);
124  return os;
125  }
126 
129 
130  template <typename T2>
132 
135 
138 
140  RankThreeTensorTempl<T> operator*(const T a) const;
141 
143  RankThreeTensorTempl<T> & operator*=(const T a);
144 
146  RankThreeTensorTempl<T> operator/(const T a) const;
147 
149  RankThreeTensorTempl<T> & operator/=(const T a);
150 
153 
156 
159 
162 
165 
167  T L2norm() const;
168 
173  template <class T2>
174  void rotate(const T2 & R);
175 
180  void rotate(const libMesh::TensorValue<T> & R);
181 
183  static MooseEnum fillMethodEnum();
184 
193  void fillFromInputVector(const std::vector<T> & input, FillMethod fill_method = automatic);
194 
200  void fillFromPlaneNormal(const libMesh::VectorValue<T> & input);
201 
207 
214 
215 protected:
217  T _vals[N3];
218 
219  void fillGeneralFromInputVector(const std::vector<T> & input);
220 
221  template <class T2>
222  friend void dataStore(std::ostream &, RankThreeTensorTempl<T2> &, void *);
223 
224  template <class T2>
225  friend void dataLoad(std::istream &, RankThreeTensorTempl<T2> &, void *);
226 
227  template <class T2>
228  friend class RankTwoTensorTempl;
229 
230  template <class T2>
231  friend class RankThreeTensorTempl;
232 
233  template <class T2>
234  friend class RankFourTensorTempl;
235 };
236 
237 namespace MetaPhysicL
238 {
239 template <typename T>
240 struct RawType<RankThreeTensorTempl<T>>
241 {
243 
245  {
246  value_type ret;
247  for (const auto i : libMesh::make_range(RankThreeTensorTempl<T>::N))
248  for (const auto j : libMesh::make_range(RankThreeTensorTempl<T>::N))
249  for (const auto k : libMesh::make_range(RankThreeTensorTempl<T>::N))
250  ret(i, j, k) = raw_value(in(i, j, k));
251 
252  return ret;
253  }
254 };
255 }
256 
257 template <typename T>
258 template <typename T2>
260 {
261  for (const auto i : libMesh::make_range(N3))
262  _vals[i] = copy._vals[i];
263 }
264 
265 template <typename T>
266 template <class T2>
267 void
269 {
270  unsigned int index = 0;
271  for (const auto i : libMesh::make_range(N))
272  for (const auto j : libMesh::make_range(N))
273  for (const auto k : libMesh::make_range(N))
274  {
275  unsigned int index2 = 0;
276  T sum = 0.0;
277  for (const auto m : libMesh::make_range(N))
278  {
279  T a = R(i, m);
280  for (const auto n : libMesh::make_range(N))
281  {
282  T ab = a * R(j, n);
283  for (const auto o : libMesh::make_range(N))
284  sum += ab * R(k, o) * _vals[index2++];
285  }
286  }
287  _vals[index++] = sum;
288  }
289 }
290 
291 template <typename T>
294 {
295  return b * a;
296 }
297 
299 template <typename T>
302 {
304  "RankTwoTensor and RankThreeTensor have to have the same dimension N.");
305  RankTwoTensorTempl<T> result;
306 
307  for (const auto i : libMesh::make_range(RankThreeTensorTempl<T>::N))
308  for (const auto j : libMesh::make_range(RankThreeTensorTempl<T>::N))
309  for (const auto k : libMesh::make_range(RankThreeTensorTempl<T>::N))
310  result(i, j) += p(k) * b(k, i, j);
311 
312  return result;
313 }
314 
315 template <typename T>
316 template <typename T2>
319 {
320  for (const auto i : libMesh::make_range(N))
321  for (const auto j : libMesh::make_range(N))
322  for (const auto k : libMesh::make_range(N))
323  (*this)(i, j, k) = a(i, j, k);
324 
325  return *this;
326 }
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:372
static constexpr unsigned int N2
void fillFromPlaneNormal(const libMesh::VectorValue< T > &input)
Fills RankThreeTensor from plane normal vectors ref.
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: EigenADReal.h:73
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:153
libMesh::VectorValue< T > doubleContraction(const RankTwoTensorTempl< T > &b) const
Creates a vector from the double contraction of a rank three and rank two tensor. ...
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
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:33
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.
libMesh::VectorValue< T > operator*(const RankTwoTensorTempl< T > &a) const
b_i = r_ijk * a_jk
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:33
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 *)
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
Definition: RankTwoTensor.h:87
friend void dataStore(std::ostream &, RankThreeTensorTempl< T2 > &, void *)
IntRange< T > make_range(T beg, T end)
void zero()
Zeros out the 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)