-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |