From 7b7da21b155010316eab392490639d204914926b Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Mon, 19 Sep 2022 17:06:29 +0200 Subject: [PATCH] [T] Added IP data setter unit tests --- Tests/ProcessLib/TestIPDataAccess.cpp | 66 ++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/Tests/ProcessLib/TestIPDataAccess.cpp b/Tests/ProcessLib/TestIPDataAccess.cpp index 963f8fcb013..9c8b063ba15 100644 --- a/Tests/ProcessLib/TestIPDataAccess.cpp +++ b/Tests/ProcessLib/TestIPDataAccess.cpp @@ -34,7 +34,7 @@ struct ProcessLib_IPDataAccess : ::testing::Test constexpr int off_diag_size = dim == 2 ? 1 : 3; - static constexpr std::size_t num_int_pts = 10; + constexpr std::size_t num_int_pts = 10; std::vector<IPData<dim>> ip_data(num_int_pts); @@ -52,6 +52,24 @@ struct ProcessLib_IPDataAccess : ::testing::Test return ip_data; } + static std::vector<IPData<Dim::value>> getIPDataNaNs() + { + using KV = typename IPData<dim>::KV; + + constexpr std::size_t num_int_pts = 10; + constexpr double nan = std::numeric_limits<double>::quiet_NaN(); + + std::vector<IPData<dim>> ip_data(num_int_pts); + + for (std::size_t i = 0; i < num_int_pts; ++i) + { + ip_data[i].kelvin = KV::Constant(nan); + ip_data[i].scalar = nan; + } + + return ip_data; + } + static std::vector<double> getScalarData() { return {100, 101, 102, 103, 104, 105, 106, 107, 108, 109}; @@ -162,3 +180,49 @@ TYPED_TEST(ProcessLib_IPDataAccess, GetKelvinVectorDataTransposedOrder) testing::Pointwise(testing::DoubleEq(), this->getKVDataTransposedOrder())); } + +TYPED_TEST(ProcessLib_IPDataAccess, SetScalarData) +{ + constexpr int dim = TypeParam::value; + + auto ip_data = this->getIPDataNaNs(); + + auto const cache = this->getScalarData(); + + auto const num_read = ProcessLib::setIntegrationPointScalarData( + &cache[0], ip_data, &IPData<dim>::scalar); + + ASSERT_EQ(ip_data.size(), num_read); + + auto const ip_data_expected = this->getIPData(); + + for (std::size_t i = 0; i < ip_data_expected.size(); ++i) + { + EXPECT_DOUBLE_EQ(ip_data_expected[i].scalar, ip_data[i].scalar) + << "Values at integration point " << i << " differ."; + } +} + +TYPED_TEST(ProcessLib_IPDataAccess, SetKelvinVectorData) +{ + constexpr int dim = TypeParam::value; + + auto ip_data = this->getIPDataNaNs(); + + auto const cache = this->getKVDataTransposedOrder(); + + auto const num_read = ProcessLib::setIntegrationPointKelvinVectorData<dim>( + &cache[0], ip_data, &IPData<dim>::kelvin); + + ASSERT_EQ(ip_data.size(), num_read); + + auto const ip_data_expected = this->getIPData(); + + for (std::size_t i = 0; i < ip_data_expected.size(); ++i) + { + EXPECT_THAT( + ip_data[i].kelvin, + testing::Pointwise(testing::DoubleEq(), ip_data_expected[i].kelvin)) + << "Values at integration point " << i << " differ."; + } +} -- GitLab