-
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
2 changed files
with
113 additions
and
40 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
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 |
---|---|---|
|
@@ -5,62 +5,113 @@ | |
* @author Tom Meltzer <[email protected]> | ||
*/ | ||
|
||
#include <cstddef> | ||
#include <doctest/extensions/doctest_mpi.h> | ||
#include <iostream> | ||
|
||
#include "include/DGModelArray.hpp" | ||
#include "include/ModelArraySlice.hpp" | ||
#include "include/ParametricMesh.hpp" | ||
#include "mpi.h" | ||
|
||
#include <array> | ||
|
||
const auto nx = 23; | ||
const auto ny = 17; | ||
const auto nz = 5; | ||
using Slice = ArraySlicer::Slice; | ||
using SliceIter = ArraySlicer::SliceIter; | ||
|
||
const auto nx = 9; | ||
const auto ny = 5; | ||
const auto nz = 3; | ||
|
||
namespace Nextsim { | ||
|
||
TEST_SUITE_BEGIN("ModelMetadata"); | ||
MPI_TEST_CASE("Test getPartitionMetadata closed boundary", 3) | ||
TEST_SUITE_BEGIN("Halo exchange"); | ||
MPI_TEST_CASE("test halo exchange", 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; | ||
} | ||
size_t localNx = nx / test_nb_procs; | ||
size_t offsetX = test_rank * localNx; | ||
ModelArray::setDimension(ModelArray::Dimension::X, nx, localNx, offsetX); | ||
ModelArray::setDimension(ModelArray::Dimension::Y, ny, ny, 0); | ||
|
||
// create example 2D field of size 3x5 (x,y) on each process | ||
auto testfield = ModelArray::HField(); | ||
testfield.resize(); | ||
|
||
std::vector<double> vectorBuffer; | ||
vectorBuffer.resize(x1 - x0); | ||
// Fill with index values | ||
for (auto i = 0; i < vectorBuffer.size(); ++i) { | ||
vectorBuffer[i] = i; | ||
// initialize with mock data | ||
for (size_t j = 0; j < ny; ++j) { | ||
for (size_t i = 0; i < localNx; ++i) { | ||
testfield(i, j) = test_rank * 100 + (i + offsetX) * 10 + j; | ||
} | ||
} | ||
// 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; | ||
|
||
// create example 2D field for dynamics code which needs +1 halo on all edges, leading to +2 in | ||
// x and y i.e., 5x7 on each process | ||
offsetX = test_rank * (localNx + 2); | ||
|
||
// auto dynamicsfield = ModelArray::TwoDFieldHALO(); | ||
// dynamicsfield.resize(); | ||
static const int DG = 3; | ||
|
||
// Create the ParametricMesh object | ||
auto CoordinateSystem = Nextsim::CARTESIAN; | ||
ParametricMesh smesh(CoordinateSystem); | ||
smesh.nx = nx + 2; | ||
smesh.ny = ny + 2; | ||
smesh.nnodes = smesh.nx * smesh.ny; | ||
smesh.nelements = smesh.nnodes; | ||
smesh.vertices.resize(smesh.nelements, Eigen::NoChange); | ||
for (size_t i = 0; i < nx; ++i) { | ||
for (size_t j = 0; j < ny; ++j) { | ||
smesh.vertices(i * ny + j, 0) = i; | ||
smesh.vertices(i * ny + j, 1) = j; | ||
} | ||
} | ||
// DGModelArray::ma2dg<DG>(testfield, dgvec); | ||
|
||
DGVector<DG> dgvec(smesh); | ||
|
||
ModelArraySlice source(testfield, { { {}, {} } }); | ||
|
||
source.copyToDataSlice(dgvec, { { { 1, localNx + 1 }, { 1, ny + 1 } } }); | ||
|
||
int ierr; | ||
enum Edge { BOTTOM, RIGHT, TOP, LEFT, N_EDGE }; | ||
constexpr std::array<Edge, N_EDGE> edges = { BOTTOM, RIGHT, TOP, LEFT }; | ||
std::map<Edge, std::vector<size_t>> neighbours, haloStarts; | ||
|
||
neighbours.try_emplace(BOTTOM, std::vector<size_t>({ 0, 1, 2 })); | ||
neighbours.try_emplace(TOP, std::vector<size_t>({ 0, 1, 2 })); | ||
neighbours.try_emplace(RIGHT, std::vector<size_t>({ 1, 2, 0 })); | ||
neighbours.try_emplace(LEFT, std::vector<size_t>({ 2, 0, 1 })); | ||
|
||
haloStarts.try_emplace(BOTTOM, std::vector<size_t>(3, 12)); | ||
haloStarts.try_emplace(TOP, std::vector<size_t>(3, 0)); | ||
haloStarts.try_emplace(LEFT, std::vector<size_t>(3, 2)); | ||
haloStarts.try_emplace(RIGHT, std::vector<size_t>(3, 0)); | ||
|
||
const long int x0 = offsetX; | ||
const long int x1 = offsetX + localNx; | ||
auto slice = testfield[{ { { 0, localNx }, { { 0 } } } }]; | ||
|
||
std::vector<double> vectorBuffer = std::vector<double>(localNx, -1); | ||
|
||
slice.copyToBuffer(vectorBuffer); | ||
|
||
// ModelArray source(ModelArray::Type::H); | ||
// source.resize(); | ||
// // Fill with data | ||
// for (size_t i = 0; i < nx; ++i) { | ||
// for (size_t j = 0; j < ny; j++) { | ||
// source(i, j) = j + mx * (i); | ||
// } | ||
// } | ||
|
||
// CHECK(source(14, 12) == 12 + mx * (14)); | ||
|
||
// ierr = MPI_Scatterv() | ||
|
||
if (test_rank == 0) { | ||
std::vector<int> neighbour_R = { 1, 2, 0 }; | ||
} else if (test_rank == 1) { | ||
} else if (test_rank == 2) { | ||
} else { | ||
|