From c48c5e8bb5f642fa0bff5c4f4a65e03e45c6d942 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Mon, 26 Aug 2019 13:39:50 +0200 Subject: [PATCH] [MaL] Symmetric tensor to KV from std::vector. Checks vector size and does the mapping to Eigen vector. --- MathLib/KelvinVector.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/MathLib/KelvinVector.h b/MathLib/KelvinVector.h index fc83db6d785..b484f6e1895 100644 --- a/MathLib/KelvinVector.h +++ b/MathLib/KelvinVector.h @@ -206,6 +206,34 @@ symmetricTensorToKelvinVector(Eigen::MatrixBase<Derived> const& v) return result; } +/// Conversion of a short vector representation of a symmetric 3x3 matrix to a +/// Kelvin vector. +/// +/// This overload takes a std::vector for the tensor values. +template <int DisplacementDim> +KelvinVectorType<DisplacementDim> symmetricTensorToKelvinVector( + std::vector<double> const& values) +{ + constexpr int kelvin_vector_size = + KelvinVectorDimensions<DisplacementDim>::value; + + if (values.size() != kelvin_vector_size) + { + OGS_FATAL( + "Symmetric tensor to Kelvin vector conversion expected an input " + "vector of size %d, but a vector of size %d was given.", + kelvin_vector_size, values.size()); + } + + return symmetricTensorToKelvinVector( + Eigen::Map<typename MathLib::KelvinVector::KelvinVectorType< + DisplacementDim> const>( + values.data(), + MathLib::KelvinVector::KelvinVectorDimensions< + DisplacementDim>::value, + 1)); +} + /// Rotation tensor for Kelvin mapped vectors and tensors. It is meant to be /// used for rotation of stress/strain tensors epsilon:Q and tangent stiffness /// tensors Q*C*Q^t. -- GitLab