18 #ifndef TENSORTOOLBOX_H
19 #define TENSORTOOLBOX_H
33 static const vec unit_tensor2{1., 1., 1., 0., 0., 0.};
48 static const vec norm_weight{1., 1., 1., 2., 2., 2.};
61 static const vec norm_weight{1., 1., 1., .5, .5, .5};
65 double mean3(
const vec&);
77 double norm(
const vec&);
85 double norm(
const vec&);
94 double atan2(
const vec&);
98 template<
typename T> Mat<T>
skew_symm(
const Mat<T>& R) {
99 suanpan_debug([&] {
if(R.n_elem != 3)
throw invalid_argument(
"need 3 element vector"); });
101 Mat<T>
S(3, 3, fill::zeros);
103 S(0, 1) = -(
S(1, 0) = R(2));
104 S(2, 0) = -(
S(0, 2) = R(1));
105 S(1, 2) = -(
S(2, 1) = R(0));
126 const auto tr_r = arma::trace(R);
127 const auto max_r = arma::max(R.diag());
129 const auto q0 = .5 * std::sqrt(tr_r + 1.);
130 const auto q1 = .25 / q0 * (R(2, 1) - R(1, 2));
131 const auto q2 = .25 / q0 * (R(0, 2) - R(2, 0));
132 const auto q3 = .25 / q0 * (R(1, 0) - R(0, 1));
133 return {q0, q1, q2, q3};
136 for(
auto I = 0; I < 3; ++I)
138 const auto J = (I + 1) % 3;
139 const auto K = (J + 1) % 3;
140 vec q(3, fill::none);
141 q(I) = std::sqrt(.5 * max_r + .25 * (1. - tr_r));
142 const double q0 = .25 / q(I) * (R(
K, J) - R(J,
K));
143 q(J) = .25 / q(I) * (R(J, I) + R(I, J));
144 q(
K) = .25 / q(I) * (R(
K, I) + R(I,
K));
146 return {q0, std::move(q)};
150 throw invalid_argument(
"need either rotation vector or matrix");
153 template<
typename T> Col<T>
to_pseudo(
const Mat<T>& R) {
154 const Mat<T>
S = arma::real(arma::logmat(R));
156 return {
S(2, 1),
S(0, 2),
S(1, 0)};
160 double angle(
const vec&);
163 vec
rotate(
const vec&,
double);
166 double angle(
const vec&);
169 vec
rotate(
const vec&,
double);
182 template<
typename T>
T ramp(
const T in) {
return in >
T(0) ? in :
T(0); }
An Quaternion class.
Definition: Quaternion.hpp:34
Mat< T > stress(T X, T Y, unsigned S)
Definition: shapeFunction.h:475
Mat< T > strain(T X, T Y, T V, unsigned S)
Definition: shapeFunction.h:523
Col< T > beam(T int_pts, unsigned order, double length)
Definition: shapeFunction.h:151
T triangle(const Mat< T > &EC)
Definition: shapeFunction.h:107
Definition: MatrixModifier.hpp:36
T ramp(const T in)
Definition: tensorToolbox.h:182
std::enable_if_t<!std::numeric_limits< T >::is_integer, bool > approx_equal(T x, T y, int ulp=2)
Definition: utility.h:46
mat to_green(mat &&)
Definition: tensorToolbox.cpp:224
mat to_tensor(const vec &)
Definition: tensorToolbox.cpp:248
double invariant3(const vec &)
compute the third invariant of the given 3D strain tensor, could be either normal or deviatoric strai...
Definition: tensorToolbox.cpp:105
double norm(const vec &)
Definition: tensorToolbox.cpp:302
double invariant2(const vec &)
compute the second invariant of the given 3D strain tensor, could be either normal or deviatoric stra...
Definition: tensorToolbox.cpp:93
double invariant1(const vec &)
compute the first invariant of the given 3D strain tensor, could be either normal or deviatoric strai...
Definition: tensorToolbox.cpp:82
double double_contraction(const vec &, const vec &)
Definition: tensorToolbox.cpp:314
vec to_voigt(const mat &)
Definition: tensorToolbox.cpp:273
double lode(vec)
Definition: tensorToolbox.cpp:147
vec to_voigt(const mat &)
Definition: tensorToolbox.cpp:343
double invariant2(const vec &)
compute the second invariant of the given 3D stress tensor, could be either normal or deviatoric stre...
Definition: tensorToolbox.cpp:128
double double_contraction(const vec &, const vec &)
Definition: tensorToolbox.cpp:384
vec lode_der(vec)
Definition: tensorToolbox.cpp:165
double lode(vec)
Definition: tensorToolbox.cpp:156
double invariant3(const vec &)
compute the third invariant of the given 3D stress tensor, could be either normal or deviatoric stres...
Definition: tensorToolbox.cpp:140
double invariant1(const vec &)
compute the first invariant of the given 3D stress tensor, could be either normal or deviatoric stres...
Definition: tensorToolbox.cpp:117
double norm(const vec &)
Definition: tensorToolbox.cpp:372
mat to_tensor(const vec &)
Definition: tensorToolbox.cpp:318
double norm(vec &&)
Definition: tensorToolbox.cpp:378
Definition: tensorToolbox.h:25
double trace3(const vec &)
Only accepts 3D tensor!
Definition: tensorToolbox.cpp:189
mat unit_deviatoric_tensor4v2()
Definition: tensorToolbox.cpp:60
mat unit_deviatoric_tensor4()
Definition: tensorToolbox.cpp:50
double mean3(const vec &)
Definition: tensorToolbox.cpp:195
vec dev(const vec &)
Definition: tensorToolbox.cpp:197
mat unit_symmetric_tensor4()
Definition: tensorToolbox.cpp:68
mat isotropic_stiffness(double, double)
Definition: tensorToolbox.cpp:20
mat orthotropic_stiffness(const vec &, const vec &)
Definition: tensorToolbox.cpp:34
double trace2(const vec &)
Only accepts 2D tensor!
Definition: tensorToolbox.cpp:178
void suanpan_debug(const char *M,...)
Definition: print.cpp:64