www.mooseframework.org
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
RankThreeTensor Class Reference

RankThreeTensor is designed to handle any N-dimensional third order tensor, r. More...

#include <RankThreeTensor.h>

Public Types

enum  InitMethod { initNone }
 Initialization method. More...
 
enum  FillMethod { general }
 To fill up the 27 entries in the 3rd-order tensor, fillFromInputVector is called with one of the following fill_methods. More...
 

Public Member Functions

 RankThreeTensor ()
 Default constructor; fills to zero. More...
 
 RankThreeTensor (const InitMethod)
 Select specific initialization pattern. More...
 
 RankThreeTensor (const std::vector< Real > &, FillMethod)
 Fill from vector. More...
 
Real & operator() (unsigned int i, unsigned int j, unsigned int k)
 Gets the value for the index specified. Takes index = 0,1,2. More...
 
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. More...
 
void zero ()
 Zeros out the tensor. More...
 
void print (std::ostream &stm=Moose::out) const
 Print the rank three tensor. More...
 
RankThreeTensoroperator= (const RankThreeTensor &a)
 copies values from a into this tensor More...
 
RealVectorValue operator* (const RankTwoTensor &a) const
 r_ijk*a_kl More...
 
RankThreeTensor operator* (const Real a) const
 r_ijk*a More...
 
RankThreeTensoroperator*= (const Real a)
 r_ijk *= a More...
 
RankThreeTensor operator/ (const Real a) const
 r_ijk/a More...
 
RankThreeTensoroperator/= (const Real a)
 r_ijk /= a for all i, j, k More...
 
RankThreeTensoroperator+= (const RankThreeTensor &a)
 r_ijk += a_ijk for all i, j, k More...
 
RankThreeTensor operator+ (const RankThreeTensor &a) const
 r_ijkl + a_ijk More...
 
RankThreeTensoroperator-= (const RankThreeTensor &a)
 r_ijk -= a_ijk More...
 
RankThreeTensor operator- (const RankThreeTensor &a) const
 r_ijk - a_ijk More...
 
RankThreeTensor operator- () const
 -r_ijk More...
 
Real L2norm () const
 (r_ijk*r_ijk) More...
 
template<class T >
void rotate (const T &R)
 Rotate the tensor using r_ijk = R_im R_in R_ko r_mno. More...
 
void rotate (const RealTensorValue &R)
 Rotate the tensor using r_ijk = R_im R_in R_ko r_mno. More...
 
void fillFromInputVector (const std::vector< Real > &input, FillMethod fill_method)
 fillFromInputVector takes some number of inputs to fill the Rank-3 tensor. More...
 
void fillFromPlaneNormal (const RealVectorValue &input)
 Fills RankThreeTensor from plane normal vectors ref. More...
 
RankFourTensor mixedProductRankFour (const RankTwoTensor &a) const
 Creates fourth order tensor D=A*b*A where A is rank 3 and b is rank 2. More...
 
RealVectorValue doubleContraction (const RankTwoTensor &b) const
 Creates a vector from the double contraction of a rank three and rank two tensor. More...
 

Static Public Member Functions

static MooseEnum fillMethodEnum ()
 Static method for use in validParams for getting the "fill_method". More...
 

Protected Member Functions

void fillGeneralFromInputVector (const std::vector< Real > &input)
 

Protected Attributes

Real _vals [N3]
 The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) More...
 

Static Protected Attributes

static constexpr unsigned int N = LIBMESH_DIM
 Dimensionality of rank-three tensor. More...
 
static constexpr unsigned int N2 = N * N
 
static constexpr unsigned int N3 = N * N * N
 

Friends

template<class T >
void dataStore (std::ostream &, T &, void *)
 
template<class T >
void dataLoad (std::istream &, T &, void *)
 

Detailed Description

RankThreeTensor is designed to handle any N-dimensional third order tensor, r.

Definition at line 44 of file RankThreeTensor.h.

Member Enumeration Documentation

◆ FillMethod

To fill up the 27 entries in the 3rd-order tensor, fillFromInputVector is called with one of the following fill_methods.

See the fill*FromInputVector functions for more details

Enumerator
general 

Definition at line 58 of file RankThreeTensor.h.

59  {
60  general
61  };

◆ InitMethod

Initialization method.

Enumerator
initNone 

Definition at line 48 of file RankThreeTensor.h.

Constructor & Destructor Documentation

◆ RankThreeTensor() [1/3]

RankThreeTensor::RankThreeTensor ( )

Default constructor; fills to zero.

Definition at line 54 of file RankThreeTensor.C.

55 {
56  mooseAssert(N == 3, "RankThreeTensor is currently only tested for 3 dimensions.");
57 
58  for (unsigned int i = 0; i < N3; ++i)
59  _vals[i] = 0;
60 }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ RankThreeTensor() [2/3]

RankThreeTensor::RankThreeTensor ( const InitMethod  init)

Select specific initialization pattern.

Definition at line 62 of file RankThreeTensor.C.

63 {
64  switch (init)
65  {
66  case initNone:
67  break;
68 
69  default:
70  mooseError("Unknown RankThreeTensor initialization pattern.");
71  }
72 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208

◆ RankThreeTensor() [3/3]

RankThreeTensor::RankThreeTensor ( const std::vector< Real > &  input,
FillMethod  fill_method 
)

Fill from vector.

Definition at line 74 of file RankThreeTensor.C.

75 {
76  fillFromInputVector(input, fill_method);
77 }
void fillFromInputVector(const std::vector< Real > &input, FillMethod fill_method)
fillFromInputVector takes some number of inputs to fill the Rank-3 tensor.

Member Function Documentation

◆ doubleContraction()

RealVectorValue RankThreeTensor::doubleContraction ( const RankTwoTensor b) const

Creates a vector from the double contraction of a rank three and rank two tensor.

Definition at line 323 of file RankThreeTensor.C.

324 {
325  RealVectorValue result;
326 
327  for (unsigned int i = 0; i < N; ++i)
328  for (unsigned int j = 0; j < N2; ++j)
329  result(i) += _vals[i * N2 + j] * b._coords[j];
330 
331  return result;
332 }
static constexpr unsigned int N2
VectorValue< Real > RealVectorValue
Definition: Assembly.h:32
static constexpr unsigned int N
Dimensionality of rank-three tensor.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...

◆ fillFromInputVector()

void RankThreeTensor::fillFromInputVector ( const std::vector< Real > &  input,
FillMethod  fill_method 
)

fillFromInputVector takes some number of inputs to fill the Rank-3 tensor.

Parameters
inputthe numbers that will be placed in the tensor
fill_methodthis can be: general (use fillGeneralFromInputVector) more fill_methods to be implemented soon!

Definition at line 214 of file RankThreeTensor.C.

Referenced by RankThreeTensor().

215 {
216  zero();
217 
218  switch (fill_method)
219  {
220  case general:
222  break;
223  default:
224  mooseError("fillFromInputVector called with unknown fill_method of ", fill_method);
225  }
226 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
void fillGeneralFromInputVector(const std::vector< Real > &input)
void zero()
Zeros out the tensor.

◆ fillFromPlaneNormal()

void RankThreeTensor::fillFromPlaneNormal ( const RealVectorValue &  input)

Fills RankThreeTensor from plane normal vectors ref.

Kuhl et. al. Int. J. Solids Struct. 38(2001) 2933-2952

Parameters
inputplane normal vector

Definition at line 229 of file RankThreeTensor.C.

230 {
231  unsigned int index = 0;
232  for (unsigned int i = 0; i < N; ++i)
233  {
234  const Real a = input(i);
235  for (unsigned int j = 0; j < N; ++j)
236  {
237  const Real b = input(j);
238  for (unsigned int k = 0; k < N; ++k)
239  {
240  const Real c = input(k);
241  Real sum = 0;
242  sum = -2 * a * b * c;
243  if (i == j)
244  sum += c;
245  if (i == k)
246  sum += b;
247  _vals[index++] = sum / 2.0;
248  }
249  }
250  }
251 }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...

◆ fillGeneralFromInputVector()

void RankThreeTensor::fillGeneralFromInputVector ( const std::vector< Real > &  input)
protected

Definition at line 300 of file RankThreeTensor.C.

Referenced by fillFromInputVector().

301 {
302  if (input.size() != 27)
303  mooseError("To use fillGeneralFromInputVector, your input must have size 27. Yours has size ",
304  input.size());
305 
306  for (unsigned int i = 0; i < N3; ++i)
307  _vals[i] = input[i];
308 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ fillMethodEnum()

MooseEnum RankThreeTensor::fillMethodEnum ( )
static

Static method for use in validParams for getting the "fill_method".

Definition at line 48 of file RankThreeTensor.C.

50 {
51  return MooseEnum("general");
52 }
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:32

◆ L2norm()

Real RankThreeTensor::L2norm ( ) const

(r_ijk*r_ijk)

Definition at line 203 of file RankThreeTensor.C.

204 {
205  Real l2 = 0;
206 
207  for (unsigned int i = 0; i < N3; ++i)
208  l2 += Utility::pow<2>(_vals[i]);
209 
210  return std::sqrt(l2);
211 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ mixedProductRankFour()

RankFourTensor RankThreeTensor::mixedProductRankFour ( const RankTwoTensor a) const

Creates fourth order tensor D=A*b*A where A is rank 3 and b is rank 2.

Parameters
aRankTwoTensor A in the equation above

Definition at line 254 of file RankThreeTensor.C.

255 {
256  RankFourTensor result;
257 
258  unsigned int index = 0;
259  for (unsigned int i = 0; i < N; ++i)
260  for (unsigned int j = 0; j < N; ++j)
261  for (unsigned int k = 0; k < N; ++k)
262  for (unsigned int l = 0; l < N; ++l)
263  {
264  for (unsigned int m = 0; m < N; ++m)
265  for (unsigned int n = 0; n < N; ++n)
266  result._vals[index] += (*this)(m, i, j) * a._coords[m * N + n] * (*this)(n, k, l);
267  index++;
268  }
269 
270  return result;
271 }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
PetscInt m
T _vals[N4]
The values of the rank-four tensor stored by index=(((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) * LIBME...
PetscInt n

◆ operator()() [1/2]

Real& RankThreeTensor::operator() ( unsigned int  i,
unsigned int  j,
unsigned int  k 
)
inline

Gets the value for the index specified. Takes index = 0,1,2.

Definition at line 73 of file RankThreeTensor.h.

74  {
75  return _vals[((i * N + j) * N + k)];
76  }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...

◆ operator()() [2/2]

Real RankThreeTensor::operator() ( unsigned int  i,
unsigned int  j,
unsigned int  k 
) const
inline

Gets the value for the index specified. Takes index = 0,1,2. Used for const.

Definition at line 79 of file RankThreeTensor.h.

80  {
81  return _vals[((i * N + j) * N + k)];
82  }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...

◆ operator*() [1/2]

RealVectorValue RankThreeTensor::operator* ( const RankTwoTensor a) const

r_ijk*a_kl

b_i = r_ijk * a_jk

Definition at line 95 of file RankThreeTensor.C.

96 {
97  RealVectorValue result;
98 
99  for (unsigned int i = 0; i < N; ++i)
100  {
101  Real sum = 0;
102  unsigned int i1 = i * N2;
103  for (unsigned int j1 = 0; j1 < N2; j1 += N)
104  for (unsigned int k = 0; k < N; ++k)
105  sum += _vals[i1 + j1 + k] * a._coords[j1 + k];
106  result(i) = sum;
107  }
108 
109  return result;
110 }
static constexpr unsigned int N2
VectorValue< Real > RealVectorValue
Definition: Assembly.h:32
static constexpr unsigned int N
Dimensionality of rank-three tensor.
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...

◆ operator*() [2/2]

RankThreeTensor RankThreeTensor::operator* ( const Real  a) const

r_ijk*a

Definition at line 112 of file RankThreeTensor.C.

113 {
114  RankThreeTensor result;
115 
116  for (unsigned int i = 0; i < N3; ++i)
117  result._vals[i] = _vals[i] * b;
118 
119  return result;
120 }
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) ...
static constexpr unsigned int N3

◆ operator*=()

RankThreeTensor & RankThreeTensor::operator*= ( const Real  a)

r_ijk *= a

Definition at line 123 of file RankThreeTensor.C.

124 {
125  for (unsigned int i = 0; i < N3; ++i)
126  _vals[i] *= a;
127 
128  return *this;
129 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ operator+()

RankThreeTensor RankThreeTensor::operator+ ( const RankThreeTensor a) const

r_ijkl + a_ijk

Definition at line 161 of file RankThreeTensor.C.

162 {
163  RankThreeTensor result;
164 
165  for (unsigned int i = 0; i < N3; ++i)
166  result._vals[i] = _vals[i] + b._vals[i];
167 
168  return result;
169 }
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) ...
static constexpr unsigned int N3

◆ operator+=()

RankThreeTensor & RankThreeTensor::operator+= ( const RankThreeTensor a)

r_ijk += a_ijk for all i, j, k

Definition at line 152 of file RankThreeTensor.C.

153 {
154  for (unsigned int i = 0; i < N3; ++i)
155  _vals[i] += a._vals[i];
156 
157  return *this;
158 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ operator-() [1/2]

RankThreeTensor RankThreeTensor::operator- ( const RankThreeTensor a) const

r_ijk - a_ijk

Definition at line 181 of file RankThreeTensor.C.

182 {
183  RankThreeTensor result;
184 
185  for (unsigned int i = 0; i < N3; ++i)
186  result._vals[i] = _vals[i] - b._vals[i];
187 
188  return result;
189 }
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) ...
static constexpr unsigned int N3

◆ operator-() [2/2]

RankThreeTensor RankThreeTensor::operator- ( ) const

-r_ijk

Definition at line 192 of file RankThreeTensor.C.

193 {
194  RankThreeTensor result;
195 
196  for (unsigned int i = 0; i < N3; ++i)
197  result._vals[i] = -_vals[i];
198 
199  return result;
200 }
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) ...
static constexpr unsigned int N3

◆ operator-=()

RankThreeTensor & RankThreeTensor::operator-= ( const RankThreeTensor a)

r_ijk -= a_ijk

Definition at line 172 of file RankThreeTensor.C.

173 {
174  for (unsigned int i = 0; i < N3; ++i)
175  _vals[i] -= a._vals[i];
176 
177  return *this;
178 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ operator/()

RankThreeTensor RankThreeTensor::operator/ ( const Real  a) const

r_ijk/a

Definition at line 132 of file RankThreeTensor.C.

133 {
134  RankThreeTensor result;
135 
136  for (unsigned int i = 0; i < N3; ++i)
137  result._vals[i] = _vals[i] / b;
138 
139  return result;
140 }
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) ...
static constexpr unsigned int N3

◆ operator/=()

RankThreeTensor & RankThreeTensor::operator/= ( const Real  a)

r_ijk /= a for all i, j, k

Definition at line 143 of file RankThreeTensor.C.

144 {
145  for (unsigned int i = 0; i < N3; ++i)
146  _vals[i] /= a;
147 
148  return *this;
149 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ operator=()

RankThreeTensor & RankThreeTensor::operator= ( const RankThreeTensor a)

copies values from a into this tensor

Definition at line 87 of file RankThreeTensor.C.

88 {
89  for (unsigned int i = 0; i < N3; ++i)
90  _vals[i] = a._vals[i];
91 
92  return *this;
93 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

◆ print()

void RankThreeTensor::print ( std::ostream &  stm = Moose::out) const

Print the rank three tensor.

◆ rotate() [1/2]

template<class T >
void RankThreeTensor::rotate ( const T &  R)

Rotate the tensor using r_ijk = R_im R_in R_ko r_mno.

Definition at line 204 of file RankThreeTensor.h.

205 {
206  unsigned int index = 0;
207  for (unsigned int i = 0; i < N; ++i)
208  for (unsigned int j = 0; j < N; ++j)
209  for (unsigned int k = 0; k < N; ++k)
210  {
211  unsigned int index2 = 0;
212  Real sum = 0.0;
213  for (unsigned int m = 0; m < N; ++m)
214  {
215  Real a = R(i, m);
216  for (unsigned int n = 0; n < N; ++n)
217  {
218  Real ab = a * R(j, n);
219  for (unsigned int o = 0; o < N; ++o)
220  sum += ab * R(k, o) * _vals[index2++];
221  }
222  }
223  _vals[index++] = sum;
224  }
225 }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
PetscInt m
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
PetscInt n

◆ rotate() [2/2]

void RankThreeTensor::rotate ( const RealTensorValue &  R)

Rotate the tensor using r_ijk = R_im R_in R_ko r_mno.

Definition at line 274 of file RankThreeTensor.C.

275 {
276  RankThreeTensor old = *this;
277 
278  unsigned int index = 0;
279  for (unsigned int i = 0; i < N; ++i)
280  for (unsigned int j = 0; j < N; ++j)
281  for (unsigned int k = 0; k < N; ++k)
282  {
283  Real sum = 0.0;
284  unsigned int index2 = 0;
285  for (unsigned int m = 0; m < N; ++m)
286  {
287  Real a = R(i, m);
288  for (unsigned int n = 0; n < N; ++n)
289  {
290  Real ab = a * R(j, n);
291  for (unsigned int o = 0; o < N; ++o)
292  sum += ab * R(k, o) * old._vals[index2++];
293  }
294  }
295  _vals[index++] = sum;
296  }
297 }
static constexpr unsigned int N
Dimensionality of rank-three tensor.
PetscInt m
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) ...
PetscInt n

◆ zero()

void RankThreeTensor::zero ( )

Zeros out the tensor.

Definition at line 80 of file RankThreeTensor.C.

Referenced by fillFromInputVector().

81 {
82  for (unsigned int i = 0; i < N3; ++i)
83  _vals[i] = 0;
84 }
Real _vals[N3]
The values of the rank-three tensor stored by index=((i * LIBMESH_DIM + j) * LIBMESH_DIM + k) ...
static constexpr unsigned int N3

Friends And Related Function Documentation

◆ dataLoad

template<class T >
void dataLoad ( std::istream &  stream,
T &  v,
void *   
)
friend

Definition at line 428 of file DataIO.h.

429 {
430  stream.read((char *)&v, sizeof(v));
431 }

◆ dataStore

template<class T >
void dataStore ( std::ostream &  stream,
T &  v,
void *   
)
friend

Definition at line 161 of file DataIO.h.

162 {
163 #ifdef LIBMESH_HAVE_CXX11_TYPE_TRAITS
164  static_assert(std::is_polymorphic<T>::value == false,
165  "Cannot serialize a class that has virtual "
166  "members!\nWrite a custom dataStore() "
167  "template specialization!\n\n");
168  static_assert(std::is_trivially_copyable<T>::value,
169  "Cannot serialize a class that is not trivially copyable!\nWrite a custom "
170  "dataStore() template specialization!\n\n");
171 #endif
172 
173  // Moose::out<<"Generic dataStore"<<std::endl;
174  stream.write((char *)&v, sizeof(v));
175 }

Member Data Documentation

◆ _vals

Real RankThreeTensor::_vals[N3]
protected

◆ N

constexpr unsigned int RankThreeTensor::N = LIBMESH_DIM
staticprotected

Dimensionality of rank-three tensor.

Definition at line 175 of file RankThreeTensor.h.

Referenced by doubleContraction(), fillFromPlaneNormal(), mixedProductRankFour(), operator()(), operator*(), RankThreeTensor(), and rotate().

◆ N2

constexpr unsigned int RankThreeTensor::N2 = N * N
staticprotected

Definition at line 176 of file RankThreeTensor.h.

Referenced by doubleContraction(), and operator*().

◆ N3

constexpr unsigned int RankThreeTensor::N3 = N * N * N
staticprotected

The documentation for this class was generated from the following files: