https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
16
17#include "libmesh/libmesh.h"
18#include "libmesh/int_range.h"
19
20#include "metaphysicl/raw_type.h"
21
22namespace libMesh
23{
24template <typename>
25class TensorValue;
26template <typename>
27class TypeTensor;
28template <typename>
29class VectorValue;
30}
31
32// Forward declarations
33class MooseEnum;
34
35namespace MathUtils
36{
37template <typename T>
38void mooseSetToZero(T & v);
39
44template <>
45void mooseSetToZero<RankThreeTensorTempl<Real>>(RankThreeTensorTempl<Real> & v);
46template <>
47void mooseSetToZero<RankThreeTensorTempl<ADReal>>(RankThreeTensorTempl<ADReal> & v);
48}
49
54template <typename T>
56{
57public:
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
81
84
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
144
146 RankThreeTensorTempl<T> operator/(const T a) const;
147
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
201
207
214
215protected:
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>
232
233 template <class T2>
235};
236
237namespace MetaPhysicL
238{
239template <typename T>
240struct RawType<RankThreeTensorTempl<T>>
241{
243
245 {
246 value_type ret;
250 ret(i, j, k) = raw_value(in(i, j, k));
251
252 return ret;
253 }
254};
255}
256
257template <typename T>
258template <typename T2>
260{
261 for (const auto i : libMesh::make_range(N3))
262 _vals[i] = copy._vals[i];
263}
264
265template <typename T>
266template <class T2>
267void
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
291template <typename T>
294{
295 return b * a;
296}
297
299template <typename T>
302{
304 "RankTwoTensor and RankThreeTensor have to have the same dimension N.");
306
310 result(i, j) += p(k) * b(k, i, j);
311
312 return result;
313}
314
315template <typename T>
316template <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}
RankThreeTensorTempl< T > operator*(T a, const RankThreeTensorTempl< T > &b)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
FillMethod
To fill up the 27 entries in the 3rd-order tensor, fillFromInputVector is called with one of the foll...
void print(std::ostream &stm=Moose::out) const
Print the rank three tensor.
libMesh::VectorValue< T > operator*(const RankTwoTensorTempl< T > &a) const
b_i = r_ijk * a_jk
RankThreeTensorTempl< T > operator-() const
-r_ijk
T _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k)
static constexpr unsigned int N
tensor dimension and powers of the dimension
InitMethod
Initialization method.
RankThreeTensorTempl< T > & operator-=(const RankThreeTensorTempl< T > &a)
r_ijk -= a_ijk
RankThreeTensorTempl< T > & operator/=(const T a)
r_ijk /= a for all i, j, k
RankThreeTensorTempl< T > & operator*=(const T a)
r_ijk *= a
friend void dataStore(std::ostream &, RankThreeTensorTempl< T2 > &, void *)
RankThreeTensorTempl< T > & operator=(const T &value)
Assignment-from-scalar operator.
void fillFromInputVector(const std::vector< T > &input, FillMethod fill_method=automatic)
fillFromInputVector takes some number of inputs to fill the Rank-3 tensor.
friend std::ostream & operator<<(std::ostream &os, const RankThreeTensorTempl< T > &t)
static constexpr unsigned int N3
RankThreeTensorTempl< T > operator/(const T a) const
r_ijk/a
void zero()
Zeros out the tensor.
static constexpr unsigned int N2
libMesh::VectorValue< T > doubleContraction(const RankTwoTensorTempl< T > &b) const
Creates a vector from the double contraction of a rank three and rank two tensor.
friend void dataLoad(std::istream &, RankThreeTensorTempl< T2 > &, void *)
void rotate(const T2 &R)
Rotate the tensor using r_ijk = R_im R_in R_ko r_mno.
T & operator()(unsigned int i, unsigned int j, unsigned int k)
Gets the value for the index specified. Takes index = 0,1,2.
T L2norm() const
\sqrt(r_ijk*r_ijk)
RankThreeTensorTempl< T > & operator+=(const RankThreeTensorTempl< T > &a)
r_ijk += a_ijk for all i, j, k
void fillFromPlaneNormal(const libMesh::VectorValue< T > &input)
Fills RankThreeTensor from plane normal vectors ref.
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.
static MooseEnum fillMethodEnum()
Static method for use in validParams for getting the "fill_method".
RankThreeTensorTempl(const RankThreeTensorTempl< T > &a)=default
Copy assignment operator must be defined if used.
RankThreeTensorTempl< T > operator+(const RankThreeTensorTempl< T > &a) const
r_ijkl + a_ijk
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.
friend class RankThreeTensorTempl
void fillGeneralFromInputVector(const std::vector< T > &input)
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
void mooseSetToZero(T &v)
Helper function templates to set a variable to zero.
Definition MathUtils.h:373
We need to instantiate the following CompareTypes to tell the compiler that ADReal is a subtype of Ch...
auto raw_value(const Eigen::Map< T > &in)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
IntRange< T > make_range(T beg, T end)
RankThreeTensorTempl< typename RawType< T >::value_type > value_type
static value_type value(const RankThreeTensorTempl< T > &in)