Skip to content

Commit 7bf17ca

Browse files
committed
wip: add CGVector to halo exchange
1 parent dc5d320 commit 7bf17ca

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

core/src/include/Halo.hpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <vector>
1212

1313
#include "Slice.hpp"
14+
#include "cgVector.hpp"
1415
#include "dgVector.hpp"
1516
#include "include/ModelArray.hpp"
1617
#include "include/ModelArraySlice.hpp"
@@ -53,6 +54,19 @@ class Halo {
5354
intializeHaloMetadata();
5455
}
5556

57+
/*!
58+
* @brief Constructs a halo object from CGVector
59+
*/
60+
template <int N> Halo(CGVector<N>& cgv)
61+
{
62+
m_numComps = 1;
63+
isCG = true;
64+
CGdegree = N;
65+
isVertex = false;
66+
setSpatialDims();
67+
intializeHaloMetadata();
68+
}
69+
5670
/**
5771
* @brief Sets the spatial dimensions of the domain
5872
*
@@ -68,6 +82,11 @@ class Halo {
6882
m_innerNx = metadata.getLocalExtentX();
6983
m_innerNy = metadata.getLocalExtentY();
7084

85+
// extend dimensions for CGVectors
86+
if (isCG) {
87+
m_innerNy = m_innerNy * CGdegree + 1;
88+
m_innerNx = m_innerNx * CGdegree + 1;
89+
}
7190
// extend dimensions by 1 for vertex fields
7291
if (isVertex) {
7392
m_innerNx += 1;
@@ -183,7 +202,9 @@ class Halo {
183202

184203
MPI_Win m_win; // RMA memory window object (used for sharing send buffers between ranks)
185204

186-
bool isVertex; // some ModelArrays can be of type VERTEX
205+
bool isVertex = false; // some ModelArrays can be of type VERTEX
206+
bool isCG = false; // is layout CGVector
207+
int CGdegree = 0;
187208

188209
std::vector<std::vector<double>>
189210
send; // buffer to store halo region that will be read by other ranks

core/test/HaloExchangeCB_test.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414

1515
#include "ModelMPI.hpp"
1616
#include "ModelMetadata.hpp"
17+
#include "cgVector.hpp"
1718
#include "include/DGModelArray.hpp"
1819
#include "include/Halo.hpp"
20+
#include "include/Interpolations.hpp"
1921

2022
namespace Nextsim {
2123

2224
const std::string testFilesDir = TEST_FILES_DIR;
2325
const std::string file = testFilesDir + "/partition_metadata_3_cb.nc";
2426

2527
static const int DG = 3;
28+
static const int CGDEGREE = 2;
2629
static const bool debug = false;
2730

2831
// reference data for each process
@@ -239,7 +242,7 @@ MPI_TEST_CASE("DGField", 3)
239242
}
240243
}
241244

242-
MPI_TEST_CASE("DGVector", 3)
245+
MPI_TEST_CASE("DGVector and CGVector", 3)
243246
{
244247
auto& modelMPI = ModelMPI::getInstance();
245248
auto& metadata = ModelMetadata::getInstance();
@@ -258,13 +261,13 @@ MPI_TEST_CASE("DGVector", 3)
258261
ParametricMesh smesh(CARTESIAN);
259262
smesh.nx = localNx;
260263
smesh.ny = localNy;
261-
smesh.nnodes = localNx * localNy;
262264
smesh.nelements = localNx * localNy;
263-
smesh.vertices.resize(smesh.nelements, Eigen::NoChange);
264-
for (size_t i = 0; i < localNx; ++i) {
265-
for (size_t j = 0; j < localNy; ++j) {
266-
smesh.vertices(i * localNy + j, 0) = i;
267-
smesh.vertices(i * localNy + j, 1) = j;
265+
smesh.nnodes = (localNx + 1) * (localNy + 1);
266+
smesh.vertices.resize(smesh.nnodes, Eigen::NoChange);
267+
for (size_t i = 0; i < localNx + 1; ++i) {
268+
for (size_t j = 0; j < localNy + 1; ++j) {
269+
smesh.vertices(i * (localNy + 1) + j, 0) = i;
270+
smesh.vertices(i * (localNy + 1) + j, 1) = j;
268271
}
269272
}
270273

@@ -304,5 +307,14 @@ MPI_TEST_CASE("DGVector", 3)
304307
}
305308
}
306309
}
310+
311+
// initialize CGVector (after halo exchange on DGVector)
312+
CGVector<CGDEGREE> cgVector;
313+
cgVector.resize_by_mesh(smesh);
314+
Interpolations::DG2CG(smesh, cgVector, testData);
315+
316+
// create halo for testData model array
317+
Halo haloCG(testData);
318+
// haloCG.exchangeHalos(cgVector);
307319
}
308320
}

0 commit comments

Comments
 (0)