From 40336d1f9e247a9c180e31e9a59c8b2f6df474ba Mon Sep 17 00:00:00 2001 From: BillSenior Date: Thu, 9 Jan 2025 14:19:57 +0100 Subject: [PATCH] GRIDEDIT-1548 Added another sample averaging interpolation test --- .../tests/src/SampleInterpolationTests.cpp | 73 ++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/libs/MeshKernel/tests/src/SampleInterpolationTests.cpp b/libs/MeshKernel/tests/src/SampleInterpolationTests.cpp index ab6efe0af..8b3a75892 100644 --- a/libs/MeshKernel/tests/src/SampleInterpolationTests.cpp +++ b/libs/MeshKernel/tests/src/SampleInterpolationTests.cpp @@ -10,7 +10,7 @@ namespace mk = meshkernel; -TEST(SampleInterpolationTests, AveragingInterpolation) +TEST(SampleInterpolationTests, AveragingInterpolationWithPoints) { const mk::UInt numberOfPointsX = 11; const mk::UInt numberOfPointsY = 11; @@ -65,3 +65,74 @@ TEST(SampleInterpolationTests, AveragingInterpolation) EXPECT_NEAR(expectedResult[i], interpolationResult[i], tolerance); } } + +TEST(SampleInterpolationTests, AveragingInterpolationWithMesh) +{ + const mk::UInt numberOfPointsX = 11; + const mk::UInt numberOfPointsY = 11; + const mk::UInt numberOfPoints = numberOfPointsX * numberOfPointsY; + + std::vector xPoints(numberOfPoints); + std::vector yPoints(numberOfPoints); + std::vector data(numberOfPoints); + + // Generate sample data points + double delta = 1000.0; + double x = 0.0; + double y = 0.0; + size_t count = 0; + + for (size_t i = 0; i < numberOfPointsY; ++i) + { + x = 0.0; + + for (size_t j = 0; j < numberOfPointsX; ++j) + { + xPoints[count] = x; + yPoints[count] = y; + data[count] = x; + x += delta; + ++count; + } + + y += delta; + } + + mk::InterpolationParameters params{.m_absoluteSearchRadius = 3.0 * delta, .m_minimumNumberOfSamples = 1}; + mk::SampleAveragingInterpolator interpolator(xPoints, yPoints, mk::Projection::cartesian, params); + + //-------------------------------- + + const mk::UInt meshPointsX = 3; + const mk::UInt meshPointsY = 3; + + const auto mesh = MakeRectangularMeshForTesting(meshPointsX, + meshPointsY, + 3.0 * delta, + 3.0 * delta, + mk::Projection::cartesian, + {0.5 * delta, 0.5 * delta}); + + mesh->ComputeEdgesCenters(); + + //-------------------------------- + + int propertyId = 1; + interpolator.SetData(propertyId, data); + + // Execute + ASSERT_EQ(interpolator.Size(), numberOfPoints); + + const double initialValue = -1.0e20; + std::vector interpolationResult(mesh->GetNumNodes(), initialValue); + std::vector expectedResult{1000.0, 1000.0, 1000.0, 2000.0, 2000.0, 2000.0, 3000.0, 3000.0, 3000.0}; + + interpolator.Interpolate(propertyId, *mesh, mk::Location::Nodes, interpolationResult); + + const double tolerance = 1.0e-8; + + for (size_t i = 0; i < expectedResult.size(); ++i) + { + EXPECT_NEAR(expectedResult[i], interpolationResult[i], tolerance); + } +}