OGS 6.1.0-1699-ge946d4c5f
KelvinVector.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <Eigen/Dense>
12 #include "BaseLib/Error.h"
13 
14 namespace MathLib
15 {
19 namespace KelvinVector
20 {
22 template <int DisplacementDim>
24 
25 template <>
27 {
28  static int const value = 4;
29 };
30 
31 template <>
33 {
34  static int const value = 6;
35 };
36 
37 //
38 // Kelvin vector and matrix templates for given displacement dimension.
39 //
40 
44 template <int DisplacementDim>
45 using KelvinVectorType =
46  Eigen::Matrix<double,
48  1,
49  Eigen::ColMajor>;
50 
54 template <int DisplacementDim>
55 using KelvinMatrixType =
56  Eigen::Matrix<double,
57  KelvinVectorDimensions<DisplacementDim>::value,
58  KelvinVectorDimensions<DisplacementDim>::value,
59  Eigen::RowMajor>;
60 
64 template <int KelvinVectorSize>
65 struct Invariants final
66 {
67  static_assert(KelvinVectorSize == 4 || KelvinVectorSize == 6,
68  "KelvinVector invariants for vectors of size different than "
69  "4 or 6 is not allowed.");
72  static Eigen::Matrix<double, KelvinVectorSize, KelvinVectorSize> const
76  static Eigen::Matrix<double, KelvinVectorSize, KelvinVectorSize> const
79  static Eigen::Matrix<double, KelvinVectorSize, 1> const identity2;
80 
82  static double determinant(
83  Eigen::Matrix<double, KelvinVectorSize, 1> const& v);
84 
87  static double equivalentStress(
88  Eigen::Matrix<double, KelvinVectorSize, 1> const& deviatoric_v);
89 
91  static double FrobeniusNorm(
92  Eigen::Matrix<double, KelvinVectorSize, 1> const& deviatoric_v);
93 
96  static double J2(
97  Eigen::Matrix<double, KelvinVectorSize, 1> const& deviatoric_v);
98 
101  static double J3(
102  Eigen::Matrix<double, KelvinVectorSize, 1> const& deviatoric_v);
103 
105  static double trace(Eigen::Matrix<double, KelvinVectorSize, 1> const& v);
106 
109  static Eigen::Vector3d diagonal(
110  Eigen::Matrix<double, KelvinVectorSize, 1> const& v);
111 };
112 
113 //
114 // Inverses of a Kelvin vector.
115 //
116 
119 template <int KelvinVectorSize>
120 Eigen::Matrix<double, KelvinVectorSize, 1, Eigen::ColMajor, KelvinVectorSize, 1>
121 inverse(Eigen::Matrix<double,
122  KelvinVectorSize,
123  1,
124  Eigen::ColMajor,
125  KelvinVectorSize,
126  1> const& v);
127 
130 template <int KelvinVectorSize>
131 Eigen::Matrix<double, 3, 3> kelvinVectorToTensor(Eigen::Matrix<double,
132  KelvinVectorSize,
133  1,
134  Eigen::ColMajor,
135  KelvinVectorSize,
136  1> const& v);
137 
140 template <int DisplacementDim>
142  Eigen::Matrix<double, 3, 3> const& m);
143 
155 template <int KelvinVectorSize>
156 Eigen::Matrix<double, KelvinVectorSize, 1, Eigen::ColMajor, KelvinVectorSize, 1>
157 kelvinVectorToSymmetricTensor(Eigen::Matrix<double,
158  KelvinVectorSize,
159  1,
160  Eigen::ColMajor,
161  KelvinVectorSize,
162  1> const& v);
163 
171 template <typename Derived>
172 Eigen::Matrix<double, Eigen::MatrixBase<Derived>::RowsAtCompileTime, 1>
173 symmetricTensorToKelvinVector(Eigen::MatrixBase<Derived> const& v)
174 {
175  static_assert(
176  (Eigen::MatrixBase<Derived>::ColsAtCompileTime == 1) ||
177  (Eigen::MatrixBase<Derived>::ColsAtCompileTime == Eigen::Dynamic),
178  "KelvinVector must be a column vector");
179  if (v.cols() != 1)
180  {
181  OGS_FATAL(
182  "KelvinVector must be a column vector, but input has %d columns.",
183  v.cols());
184  }
185 
186  Eigen::Matrix<double, Eigen::MatrixBase<Derived>::RowsAtCompileTime, 1>
187  result;
188  if (v.rows() == 4)
189  {
190  result.resize(4, 1);
191  result << v[0], v[1], v[2], v[3] * std::sqrt(2.);
192  }
193  else if (v.rows() == 6)
194  {
195  result.resize(6, 1);
196  result << v[0], v[1], v[2], v[3] * std::sqrt(2.), v[4] * std::sqrt(2.),
197  v[5] * std::sqrt(2.);
198  }
199  else
200  {
201  OGS_FATAL(
202  "Symmetric tensor to Kelvin vector conversion expected an input "
203  "vector of size 4 or 6, but a vector of size %d was given.",
204  v.size());
205  }
206  return result;
207 }
208 } // namespace KelvinVector
209 } // namespace MathLib
210 
211 #include "KelvinVector-impl.h"
static Eigen::Matrix< double, KelvinVectorSize, 1 > const identity2
Kelvin mapping of 2nd order identity tensor.
Definition: KelvinVector.h:79
Eigen::Matrix< double, Eigen::MatrixBase< Derived >::RowsAtCompileTime, 1 > symmetricTensorToKelvinVector(Eigen::MatrixBase< Derived > const &v)
Definition: KelvinVector.h:173
Kelvin vector dimensions for given displacement dimension.
Definition: KelvinVector.h:23
Eigen::Matrix< double, KelvinVectorDimensions< DisplacementDim >::value, KelvinVectorDimensions< DisplacementDim >::value, Eigen::RowMajor > KelvinMatrixType
Definition: KelvinVector.h:59
Eigen::Matrix< double, 3, 3 > kelvinVectorToTensor(Eigen::Matrix< double, 4, 1, Eigen::ColMajor, 4, 1 > const &v)
static Eigen::Matrix< double, KelvinVectorSize, KelvinVectorSize > const deviatoric_projection
Definition: KelvinVector.h:69
Eigen::Matrix< double, 4, 1 > kelvinVectorToSymmetricTensor(Eigen::Matrix< double, 4, 1, Eigen::ColMajor, 4, 1 > const &v)
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
static Eigen::Matrix< double, KelvinVectorSize, KelvinVectorSize > const spherical_projection
Definition: KelvinVector.h:77
Eigen::Matrix< double, 4, 1, Eigen::ColMajor, 4, 1 > inverse(Eigen::Matrix< double, 4, 1, Eigen::ColMajor, 4, 1 > const &v)
KelvinVectorType< DisplacementDim > tensorToKelvin(Eigen::Matrix< double, 3, 3 > const &m)
Eigen::Matrix< double, KelvinVectorDimensions< DisplacementDim >::value, 1, Eigen::ColMajor > KelvinVectorType
Definition: KelvinVector.h:49