Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMelt committed Nov 25, 2024
1 parent 88f9e68 commit b3882c1
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions core/test/HaloExchange_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*!
* @file ModelMetadata_test.cpp
*
* @date 18 Nov 2024
* @author Tom Meltzer <tdm39@cam.ac.uk>
*/

#include <doctest/extensions/doctest_mpi.h>
#include <iostream>

#include "include/ModelArraySlice.hpp"

#include <array>

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<double> 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<double> 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);
}
}

}

0 comments on commit b3882c1

Please sign in to comment.