From 0a7731dd03b0449abc3ef7c76295a142a0ea5827 Mon Sep 17 00:00:00 2001 From: tommelt Date: Mon, 25 Nov 2024 12:21:44 +0000 Subject: [PATCH] wip --- core/test/HaloExchange_test.cpp | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 core/test/HaloExchange_test.cpp diff --git a/core/test/HaloExchange_test.cpp b/core/test/HaloExchange_test.cpp new file mode 100644 index 000000000..933f52734 --- /dev/null +++ b/core/test/HaloExchange_test.cpp @@ -0,0 +1,72 @@ +/*! + * @file ModelMetadata_test.cpp + * + * @date 18 Nov 2024 + * @author Tom Meltzer + */ + +#include +#include + +#include "include/ModelArraySlice.hpp" + +#include + +const auto nx = 23; +const auto ny = 17; +const auto nz = 5; + +namespace Nextsim { + +TEST_SUITE_BEGIN("ModelMetadata"); +MPI_TEST_CASE("Test getPartitionMetadata closed boundary", 3) +{ + + ModelArray::setDimension(ModelArray::Dimension::X, nx, nx / 4, 0); + ModelArray::setDimension(ModelArray::Dimension::Y, ny, ny / 4, 0); + + // Test 1 dimensional slices into and out of common buffer types + // std::vector + OneDField oned(ModelArray::Type::ONED); + oned.resize(); + const auto x0 = 3; + const auto x1 = 11; + auto oneSlice = oned[{ { { x0, x1 } } }]; + + // Check the functions throw when given too small a buffer + std::vector shortBuffer; + shortBuffer.resize(x1 - x0 - 1); + REQUIRE_THROWS(oneSlice = shortBuffer); + REQUIRE_THROWS(oneSlice.copyToBuffer(shortBuffer)); + // Fill the array with index values + for (auto i = 0; i < oned.size(); ++i) { + oned[i] = i; + } + + std::vector vectorBuffer; + vectorBuffer.resize(x1 - x0); + // Fill with index values + for (auto i = 0; i < vectorBuffer.size(); ++i) { + vectorBuffer[i] = i; + } + // assign from the buffer + oneSlice = vectorBuffer; + REQUIRE(oned[x0 - 1] == x0 - 1); + REQUIRE(oned[x1] == x1); + REQUIRE(oned[x0 + 0] == 0); + REQUIRE(oned[x1 - 1] == x1 - x0 - 1); + // Refill with index values + for (auto i = 0; i < oned.size(); ++i) { + oned[i] = i; + } + + if (test_rank == 0) { + } else if (test_rank == 1) { + } else if (test_rank == 2) { + } else { + std::cerr << "only valid for 3 ranks" << std::endl; + exit(1); + } +} + +}