From 5eb5153837e55ce6e21f3d34325f1528a3e60991 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Tue, 13 Feb 2018 23:34:49 +0100 Subject: [PATCH] [MaL] KelvinVector; Assert cols==1 and use rows. --- MathLib/KelvinVector.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/MathLib/KelvinVector.h b/MathLib/KelvinVector.h index 313e822c938..499843e13c3 100644 --- a/MathLib/KelvinVector.h +++ b/MathLib/KelvinVector.h @@ -163,13 +163,24 @@ template <typename Derived> Eigen::Matrix<double, Eigen::MatrixBase<Derived>::RowsAtCompileTime, 1> symmetricTensorToKelvinVector(Eigen::MatrixBase<Derived> const& v) { + static_assert( + (Eigen::MatrixBase<Derived>::ColsAtCompileTime == 1) || + (Eigen::MatrixBase<Derived>::ColsAtCompileTime == Eigen::Dynamic), + "KelvinVector must be a column vector"); + if (v.cols() != 1) + { + OGS_FATAL( + "KelvinVector must be a column vector, but input has %d columns.", + v.cols()); + } + Eigen::Matrix<double, Eigen::MatrixBase<Derived>::RowsAtCompileTime, 1> result; - if (v.size() == 4) + if (v.rows() == 4) { result << v[0], v[1], v[2], v[3] * std::sqrt(2.); } - else if (v.size() == 6) + else if (v.rows() == 6) { result << v[0], v[1], v[2], v[3] * std::sqrt(2.), v[4] * std::sqrt(2.), v[5] * std::sqrt(2.); -- GitLab