44 static const vec unit_tensor2{1., 1., 1., 0., 0., 0.};
59 static const vec norm_weight{1., 1., 1., 2., 2., 2.};
72 static const vec norm_weight{1., 1., 1., .5, .5, .5};
76 double mean3(
const vec&);
88 double norm(
const vec&);
96 double norm(
const vec&);
104 double atan2(
const vec&);
108 template<
typename T> Mat<T>
skew_symm(
const Mat<T>& R) {
109 suanpan_assert([&] {
if(R.n_elem != 3)
throw invalid_argument(
"need 3 element vector"); });
111 Mat<T>
S(3, 3, fill::zeros);
113 S(0, 1) = -(
S(1, 0) = R(2));
114 S(2, 0) = -(
S(0, 2) = R(1));
115 S(1, 2) = -(
S(2, 1) = R(0));
128 const auto angle = arma::norm(R);
132 return {std::cos(.5 * angle), std::sin(.5 * angle) / angle * R};
136 const auto tr_r = arma::trace(R);
137 const auto max_r = arma::max(R.diag());
139 const auto q0 = .5 * std::sqrt(tr_r + 1.);
140 const auto q1 = .25 / q0 * (R(2, 1) - R(1, 2));
141 const auto q2 = .25 / q0 * (R(0, 2) - R(2, 0));
142 const auto q3 = .25 / q0 * (R(1, 0) - R(0, 1));
143 return {q0, q1, q2, q3};
146 for(
auto I = 0; I < 3; ++I)
148 const auto J = (I + 1) % 3;
149 const auto K = (J + 1) % 3;
150 vec q(3, fill::none);
151 q(I) = std::sqrt(.5 * max_r + .25 * (1. - tr_r));
152 const double q0 = .25 / q(I) * (R(
K, J) - R(J,
K));
153 q(J) = .25 / q(I) * (R(J, I) + R(I, J));
154 q(
K) = .25 / q(I) * (R(
K, I) + R(I,
K));
156 return {q0, std::move(q)};
160 throw invalid_argument(
"need either rotation vector or matrix");
163 template<
typename T> Col<T>
to_pseudo(
const Mat<T>& R) {
164 const Mat<T>
S = arma::real(arma::logmat(R));
166 return {
S(2, 1),
S(0, 2),
S(1, 0)};
170 double angle(
const vec&);
173 vec
rotate(
const vec&,
double);
176 double angle(
const vec&);
179 vec
rotate(
const vec&,
double);
191 template<
typename T>
T ramp(
const T in) {
return in >
T(0) ? in :
T(0); }
An Quaternion class.
Definition: Quaternion.hpp:34
Definition: MatrixModifier.hpp:36
T ramp(const T in)
Definition: tensor.h:191
std::enable_if_t<!std::numeric_limits< T >::is_integer, bool > approx_equal(T x, T y, int ulp=2)
Definition: utility.h:58
mat to_green(mat &&)
Definition: tensor.cpp:224
mat to_tensor(const vec &)
Definition: tensor.cpp:248
double invariant3(const vec &)
compute the third invariant of the given 3D strain tensor, could be either normal or deviatoric strai...
Definition: tensor.cpp:105
double norm(const vec &)
Definition: tensor.cpp:302
double invariant2(const vec &)
compute the second invariant of the given 3D strain tensor, could be either normal or deviatoric stra...
Definition: tensor.cpp:93
double invariant1(const vec &)
compute the first invariant of the given 3D strain tensor, could be either normal or deviatoric strai...
Definition: tensor.cpp:82
double double_contraction(const vec &, const vec &)
Definition: tensor.cpp:314
vec to_voigt(const mat &)
Definition: tensor.cpp:273
double lode(vec)
Definition: tensor.cpp:147
vec to_voigt(const mat &)
Definition: tensor.cpp:343
double invariant2(const vec &)
compute the second invariant of the given 3D stress tensor, could be either normal or deviatoric stre...
Definition: tensor.cpp:128
double double_contraction(const vec &, const vec &)
Definition: tensor.cpp:384
vec lode_der(vec)
Definition: tensor.cpp:165
double lode(vec)
Definition: tensor.cpp:156
double invariant3(const vec &)
compute the third invariant of the given 3D stress tensor, could be either normal or deviatoric stres...
Definition: tensor.cpp:140
double invariant1(const vec &)
compute the first invariant of the given 3D stress tensor, could be either normal or deviatoric stres...
Definition: tensor.cpp:117
double norm(const vec &)
Definition: tensor.cpp:372
mat to_tensor(const vec &)
Definition: tensor.cpp:318
double trace3(const vec &)
Only accepts 3D tensor!
Definition: tensor.cpp:189
mat unit_deviatoric_tensor4v2()
Definition: tensor.cpp:60
mat unit_deviatoric_tensor4()
Definition: tensor.cpp:50
double mean3(const vec &)
Definition: tensor.cpp:195
vec dev(const vec &)
Definition: tensor.cpp:197
mat unit_symmetric_tensor4()
Definition: tensor.cpp:68
mat isotropic_stiffness(double, double)
Definition: tensor.cpp:20
mat orthotropic_stiffness(const vec &, const vec &)
Definition: tensor.cpp:34
double trace2(const vec &)
Only accepts 2D tensor!
Definition: tensor.cpp:178
void suanpan_assert(const std::function< void()> &F)
Definition: suanPan.h:284