From 50cc3a47eda24fb2112cf6eb8d87d03d84dfc266 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Wed, 31 Jan 2018 19:05:48 +0100 Subject: [PATCH] [ML] KelvinVec; Fix symmetricTensorToKelvinVector. --- MathLib/KelvinVector.cpp | 1 - MathLib/KelvinVector.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/MathLib/KelvinVector.cpp b/MathLib/KelvinVector.cpp index 94ccd6482bf..966c3fd113c 100644 --- a/MathLib/KelvinVector.cpp +++ b/MathLib/KelvinVector.cpp @@ -124,6 +124,5 @@ kelvinVectorToSymmetricTensor(Eigen::Matrix<double, v.size()); } } - } // namespace KelvinVector } // namespace MathLib diff --git a/MathLib/KelvinVector.h b/MathLib/KelvinVector.h index d57a1eac3b8..307951348d9 100644 --- a/MathLib/KelvinVector.h +++ b/MathLib/KelvinVector.h @@ -9,6 +9,7 @@ #pragma once #include <Eigen/Dense> +#include "BaseLib/Error.h" namespace MathLib { @@ -132,6 +133,8 @@ Eigen::Matrix<double, 3, 3> kelvinVectorToTensor(Eigen::Matrix<double, /// In the 3D case the entries for the xx, yy, zz, xy, yz, and xz components in /// that particular order are stored. /// +/// This is opposite of the symmetricTensorToKelvinVector() +/// /// Only implementations for KelvinVectorSize 4 and 6, and dynamic size vectors /// are provided. template <int KelvinVectorSize> @@ -143,6 +146,37 @@ kelvinVectorToSymmetricTensor(Eigen::Matrix<double, KelvinVectorSize, 1> const& v); +/// Conversion of a short vector representation of a +/// symmetric 3x3 matrix to a Kelvin vector. +/// +/// This is opposite of the kelvinVectorToSymmetricTensor() +/// +/// Only implementations for KelvinVectorSize 4 and 6, and dynamic size vectors +/// are provided. +template <typename Derived> +Eigen::Matrix<double, Eigen::MatrixBase<Derived>::RowsAtCompileTime, 1> +symmetricTensorToKelvinVector(Eigen::MatrixBase<Derived> const& v) +{ + Eigen::Matrix<double, Eigen::MatrixBase<Derived>::RowsAtCompileTime, 1> + result; + if (v.size() == 4) + { + result << v[0], v[1], v[2], v[3] * std::sqrt(2.); + } + else if (v.size() == 6) + { + result << v[0], v[1], v[2], v[3] * std::sqrt(2.), v[4] * std::sqrt(2.), + v[5] * std::sqrt(2.); + } + else + { + OGS_FATAL( + "Symmetric tensor to Kelvin vector conversion expected an input " + "vector of size 4 or 6, but a vector of size %d was given.", + v.size()); + } + return result; +} } // namespace KelvinVector } // namespace MathLib -- GitLab