Skip to content
Snippets Groups Projects
Commit df3188dd authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[MaL] Add KelvinVector to symmetric tensor cnv.

This is giving a shortened version of the matrix
in a vector form.
parent 51e1df58
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,8 @@
#include "KelvinVector.h"
#include "BaseLib/Error.h"
namespace MathLib
{
namespace KelvinVector
......@@ -78,5 +80,50 @@ Eigen::Matrix<double, 3, 3> kelvinVectorToTensor(
return m;
}
template <>
Eigen::Matrix<double, 4, 1> kelvinVectorToSymmetricTensor(
Eigen::Matrix<double, 4, 1, Eigen::ColMajor, 4, 1> const& v)
{
Eigen::Matrix<double, 4, 1> m;
m << v[0], v[1], v[2], v[3] / std::sqrt(2.);
return m;
}
template <>
Eigen::Matrix<double, 6, 1> kelvinVectorToSymmetricTensor(
Eigen::Matrix<double, 6, 1, Eigen::ColMajor, 6, 1> const& v)
{
Eigen::Matrix<double, 6, 1> m;
m << v[0], v[1], v[2], v[3] / std::sqrt(2.), v[4] / std::sqrt(2.),
v[5] / std::sqrt(2.);
return m;
}
template <>
Eigen::Matrix<double, Eigen::Dynamic, 1, Eigen::ColMajor, Eigen::Dynamic, 1>
kelvinVectorToSymmetricTensor(Eigen::Matrix<double,
Eigen::Dynamic,
1,
Eigen::ColMajor,
Eigen::Dynamic,
1> const& v)
{
if (v.size() == 4)
{
return kelvinVectorToSymmetricTensor<4>(v);
}
else if (v.size() == 6)
{
return kelvinVectorToSymmetricTensor<6>(v);
}
else
{
OGS_FATAL(
"Kelvin vector to tensor conversion expected an input vector of "
"size 4 or 6, but a vector of size %d was given.",
v.size());
}
}
} // namespace KelvinVector
} // namespace MathLib
......@@ -125,6 +125,24 @@ Eigen::Matrix<double, 3, 3> kelvinVectorToTensor(Eigen::Matrix<double,
KelvinVectorSize,
1> const& v);
/// Conversion of a Kelvin vector to a short vector representation of a
/// symmetric 3x3 matrix.
///
/// In the 2D case the entries for the xx, yy, zz, and xy components are stored.
/// In the 3D case the entries for the xx, yy, zz, xy, yz, and xz components in
/// that particular order are stored.
///
/// Only implementations for KelvinVectorSize 4 and 6, and dynamic size vectors
/// are provided.
template <int KelvinVectorSize>
Eigen::Matrix<double, KelvinVectorSize, 1, Eigen::ColMajor, KelvinVectorSize, 1>
kelvinVectorToSymmetricTensor(Eigen::Matrix<double,
KelvinVectorSize,
1,
Eigen::ColMajor,
KelvinVectorSize,
1> const& v);
} // namespace KelvinVector
} // namespace MathLib
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment