From ea76fc6cf9fbd51d02a37714e3934efe1eb317d8 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Fri, 2 Sep 2016 10:14:16 +0200 Subject: [PATCH] add some tests for SIM[2|3]D::projectSolution --- src/SIM/Test/TestSIM.C | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/src/SIM/Test/TestSIM.C b/src/SIM/Test/TestSIM.C index 9a535221..102e0c19 100644 --- a/src/SIM/Test/TestSIM.C +++ b/src/SIM/Test/TestSIM.C @@ -10,9 +10,45 @@ //! //============================================================================== +#include "IntegrandBase.h" +#include "IFEM.h" #include "SIM2D.h" +#include "SIM3D.h" #include "gtest/gtest.h" +#include "tinyxml.h" + + +template +class TestProjectSIM : public Dim { +public: + TestProjectSIM(const SIMbase::CharVec& nf) : Dim(nf) + { + Dim::myProblem = new TestProjectIntegrand(Dim::dimension); + } +private: + class TestProjectIntegrand : public IntegrandBase { + public: + TestProjectIntegrand(int dim) : IntegrandBase(dim) {} + + //! \brief Evaluates the secondary solution at a result point. + //! \param[out] s The solution field values at current point + //! \param[in] fe Finite element data at current point + //! \param[in] X Cartesian coordinates of current point + //! \param[in] MNPC Nodal point correspondance for the basis function values + bool evalSol(Vector& s, const FiniteElement& fe, const Vec3& X, + const std::vector& MNPC) const override + { + s.resize(1); + s(1) = X[0] + X[1] + X[2]; + + return true; + } + + size_t getNoFields(int = 2) const override { return 1; } + }; +}; + TEST(TestSIM, UniqueBoundaryNodes) { @@ -27,3 +63,69 @@ TEST(TestSIM, UniqueBoundaryNodes) std::sort(vec.begin(), vec.end()); ASSERT_TRUE(std::unique(vec.begin(), vec.end()) == vec.end()); } + + +TEST(TestSIM2D, ProjectSolution) +{ + TestProjectSIM sim({1}); + sim.createDefaultModel(); + ASSERT_TRUE(sim.preprocess()); + + Matrix ssol; + ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs()))); + + size_t n = 1; + for (size_t j = 0; j < 2; ++j) + for (size_t i = 0; i < 2; ++i) + ASSERT_FLOAT_EQ(ssol(1, n++), i + j); +} + + +TEST(TestSIM2D, ProjectSolutionMixed) +{ + TestProjectSIM sim({1,1}); + sim.createDefaultModel(); + ASSERT_TRUE(sim.preprocess()); + + Matrix ssol; + ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs()))); + + size_t n = 1; + for (size_t j = 0; j < 3; ++j) + for (size_t i = 0; i < 3; ++i) + ASSERT_FLOAT_EQ(ssol(1, n++), i/2.0 + j/2.0); +} + + +TEST(TestSIM3D, ProjectSolution) +{ + TestProjectSIM sim({1}); + sim.createDefaultModel(); + ASSERT_TRUE(sim.preprocess()); + + Matrix ssol; + ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs()))); + + size_t n = 1; + for (size_t k = 0; k < 2; ++k) + for (size_t j = 0; j < 2; ++j) + for (size_t i = 0; i < 2; ++i) + ASSERT_FLOAT_EQ(ssol(1, n++), i + j + k); +} + + +TEST(TestSIM3D, ProjectSolutionMixed) +{ + TestProjectSIM sim({1,1}); + sim.createDefaultModel(); + ASSERT_TRUE(sim.preprocess()); + + Matrix ssol; + ASSERT_TRUE(sim.project(ssol, Vector(sim.getNoDOFs()))); + + size_t n = 1; + for (size_t k = 0; k < 3; ++k) + for (size_t j = 0; j < 3; ++j) + for (size_t i = 0; i < 3; ++i) + ASSERT_FLOAT_EQ(ssol(1, n++), i/2.0 + j/2.0 + k/2.0); +}