From 0d6c774670c46d7cfce985cad62ffa2ff010aa9d Mon Sep 17 00:00:00 2001 From: Norihiro Watanabe <norihiro.watanabe@ufz.de> Date: Thu, 29 Sep 2016 14:20:42 +0200 Subject: [PATCH] test calculating rotation matrices --- Tests/ProcessLib/TestLIE.cpp | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Tests/ProcessLib/TestLIE.cpp diff --git a/Tests/ProcessLib/TestLIE.cpp b/Tests/ProcessLib/TestLIE.cpp new file mode 100644 index 00000000000..6796f65a615 --- /dev/null +++ b/Tests/ProcessLib/TestLIE.cpp @@ -0,0 +1,107 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include <cmath> + +#include <gtest/gtest.h> + +#include <Eigen/Eigen> + +#include "MeshLib/Elements/Line.h" + +#include "ProcessLib/SmallDeformationWithLIE/Common/Utils.h" + + +namespace +{ +typedef MeshLib::Line ElementType; +const unsigned e_nnodes = ElementType::n_all_nodes; + +std::unique_ptr<MeshLib::Line> createLine( + std::array<double, 3> const& a, std::array<double, 3> const& b) +{ + MeshLib::Node** nodes = new MeshLib::Node*[e_nnodes]; + nodes[0] = new MeshLib::Node(a); + nodes[1] = new MeshLib::Node(b); + return std::unique_ptr<MeshLib::Line>{new MeshLib::Line(nodes)}; +} + +std::unique_ptr<MeshLib::Line> createX() +{ + return createLine({{-1.0, 0.0, 0.0}}, {{1.0, 0.0, 0.0}}); +} + +std::unique_ptr<MeshLib::Line> createY() +{ + return createLine({{0.0, -1.0, 0.0}}, {{0.0, 1.0, 0.0}}); +} + +std::unique_ptr<MeshLib::Line> createXY() +{ + // 45degree inclined + return createLine({{0.0, 0.0, 0.0}}, {{2./sqrt(2), 2./sqrt(2), 0.0}}); +} + +const double eps = std::numeric_limits<double>::epsilon(); + +} + +TEST(LIE, rotationMatrixX) +{ + auto e(createX()); + Eigen::Vector3d nv; + ProcessLib::SmallDeformationWithLIE::computeNormalVector(*e, nv); + ASSERT_EQ(0., nv[0]); + ASSERT_EQ(1., nv[1]); + ASSERT_EQ(0., nv[2]); + + Eigen::MatrixXd R(2,2); + ProcessLib::SmallDeformationWithLIE::computeRotationMatrix(nv, 2, R); + + ASSERT_NEAR(1., R(0,0), eps); + ASSERT_NEAR(0., R(0,1), eps); + ASSERT_NEAR(0., R(1,0), eps); + ASSERT_NEAR(1., R(1,1), eps); +} + +TEST(LIE, rotationMatrixY) +{ + auto e(createY()); + Eigen::Vector3d nv; + ProcessLib::SmallDeformationWithLIE::computeNormalVector(*e, nv); + ASSERT_EQ(-1., nv[0]); + ASSERT_EQ(0., nv[1]); + ASSERT_EQ(0., nv[2]); + + Eigen::MatrixXd R(2,2); + ProcessLib::SmallDeformationWithLIE::computeRotationMatrix(nv, 2, R); + + ASSERT_NEAR(0., R(0,0), eps); + ASSERT_NEAR(1., R(0,1), eps); + ASSERT_NEAR(-1., R(1,0), eps); + ASSERT_NEAR(0., R(1,1), eps); +} + +TEST(LIE, rotationMatrixXY) +{ + auto e(createXY()); + Eigen::Vector3d nv; + ProcessLib::SmallDeformationWithLIE::computeNormalVector(*e, nv); + ASSERT_NEAR(-1./sqrt(2), nv[0], eps); + ASSERT_NEAR(1./sqrt(2), nv[1], eps); + ASSERT_EQ(0., nv[2]); + + Eigen::MatrixXd R(2,2); + ProcessLib::SmallDeformationWithLIE::computeRotationMatrix(nv, 2, R); + + ASSERT_NEAR(1./sqrt(2), R(0,0), eps); + ASSERT_NEAR(1./sqrt(2), R(0,1), eps); + ASSERT_NEAR(-1./sqrt(2), R(1,0), eps); + ASSERT_NEAR(1./sqrt(2), R(1,1), eps); +} -- GitLab