diff --git a/ParameterLib/CoordinateSystem.cpp b/ParameterLib/CoordinateSystem.cpp index 837e6659604b4ab3a5d5b02febfa428cee444403..0dc9fc8bb4acb4c30b5c3b590de7b25eb338cad5 100644 --- a/ParameterLib/CoordinateSystem.cpp +++ b/ParameterLib/CoordinateSystem.cpp @@ -126,6 +126,31 @@ Eigen::Matrix<double, 3, 3> CoordinateSystem::transformation<3>( return t; } +Eigen::Matrix<double, 3, 3> CoordinateSystem::transformation_3d( + SpatialPosition const& pos) const +{ + if (_base[2] != nullptr) + { + return transformation<3>(pos); + } + + auto e0 = (*_base[0])(0 /* time independent */, pos); + auto e1 = (*_base[1])(0 /* time independent */, pos); + Eigen::Matrix<double, 3, 3> t = Eigen::Matrix<double, 3, 3>::Identity(); + t.template topLeftCorner<2, 2>() << e0[0], e1[0], e0[1], e1[1]; + +#ifndef NDEBUG + if (std::abs(t.determinant() - 1) > std::numeric_limits<double>::epsilon()) + { + OGS_FATAL( + "The determinant of the coordinate system transformation matrix is " + "'%g', which is not sufficiently close to unity.", + t.determinant()); + } +#endif // NDEBUG + return t; +} + template <int Dimension> Eigen::Matrix<double, Dimension, Dimension> CoordinateSystem::rotateTensor( std::vector<double> const& values, SpatialPosition const& pos) const diff --git a/ParameterLib/CoordinateSystem.h b/ParameterLib/CoordinateSystem.h index 860647375e4da9767f768420072a7a9ac54d08a9..bc67900416814c7e02a382a31d6edf7939e8c424 100644 --- a/ParameterLib/CoordinateSystem.h +++ b/ParameterLib/CoordinateSystem.h @@ -35,6 +35,9 @@ struct CoordinateSystem final Eigen::Matrix<double, Dimension, Dimension> transformation( SpatialPosition const& pos) const; + Eigen::Matrix<double, 3, 3> transformation_3d( + SpatialPosition const& pos) const; + template <int Dimension> Eigen::Matrix<double, Dimension, Dimension> rotateTensor( std::vector<double> const& values, SpatialPosition const& pos) const;