Skip to content

Commit 07afe13

Browse files
committed
feat: add halo exchange into dynamics
1 parent bb07d04 commit 07afe13

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

dynamics/src/CGDynamicsKernel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#include <limits>
2121

22+
#ifdef USE_MPI
23+
#include "include/Halo.hpp"
24+
#endif
25+
2226
namespace Nextsim {
2327

2428
template <int DGadvection>
@@ -272,6 +276,14 @@ template <int DGadvection> void CGDynamicsKernel<DGadvection>::prepareIteration(
272276
Interpolations::DG2CG(*smesh, cgA, data.at(ciceName));
273277
VectorManipulations::CGAveragePeriodic(*smesh, cgA);
274278

279+
#ifdef USE_MPI
280+
// Halo object only depends on shape of the array, so we can share it for all DGVectors of the
281+
// same shape
282+
Halo halo(cgH);
283+
halo.exchangeHalos(cgH);
284+
halo.exchangeHalos(cgA);
285+
#endif
286+
275287
// Reinit the gradient of the sea surface height. Not done by
276288
// DataMap as seaSurfaceHeight is always dG(0)
277289
computeGradientOfSeaSurfaceHeight(DynamicsKernel<DGadvection, DGstressComp>::seaSurfaceHeight);

dynamics/src/include/BrittleCGDynamicsKernel.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "include/constants.hpp"
1616
#include <cmath>
1717

18+
#ifdef USE_MPI
19+
#include "include/Halo.hpp"
20+
#endif
21+
1822
namespace Nextsim {
1923

2024
// The brittle momentum solver for CG velocity fields
@@ -116,6 +120,20 @@ template <int DGadvection> class BrittleCGDynamicsKernel : public CGDynamicsKern
116120
{
117121
advectDynamicsFields(tst.step.seconds());
118122

123+
// halo exchange
124+
// - damage, hice, cice
125+
// - s11, s12, s22
126+
// - e11, e12, e22
127+
// - dStressY, dStressX
128+
// - u, v
129+
// Note: only need to create one halo object per array type, dimensionality and size.
130+
#ifdef USE_MPI
131+
Halo halo(hice);
132+
halo.exchangeHalos(static_cast<DGVector<DGadvection>&>(hice));
133+
halo.exchangeHalos(static_cast<DGVector<DGadvection>&>(cice));
134+
halo.exchangeHalos(static_cast<DGVector<DGadvection>&>(damage));
135+
#endif
136+
119137
prepareIteration({ { hiceName, hice }, { ciceName, cice } });
120138

121139
// The timestep for the brittle solver is the solver subtimestep
@@ -128,18 +146,42 @@ template <int DGadvection> class BrittleCGDynamicsKernel : public CGDynamicsKern
128146

129147
projectVelocityToStrain();
130148

149+
#ifdef USE_MPI
150+
Halo haloDGVector(e11);
151+
haloDGVector.exchangeHalos(e11);
152+
haloDGVector.exchangeHalos(e12);
153+
haloDGVector.exchangeHalos(e22);
154+
#endif
155+
131156
std::array<std::reference_wrapper<DGVector<DGstressComp>>, N_TENSOR_ELEMENTS> stress
132157
= { s11, s12, s22 }; // Call the step function on the StressUpdateStep class
133158
// Call the step function on the StressUpdateStep class
134159
stressStep.stressUpdateHighOrder(
135160
params, *smesh, stress, { e11, e12, e22 }, hice, cice, deltaT);
136161

162+
#ifdef USE_MPI
163+
haloDGVector.exchangeHalos(s11);
164+
haloDGVector.exchangeHalos(s12);
165+
haloDGVector.exchangeHalos(s22);
166+
#endif
167+
137168
stressDivergence(); // Compute divergence of stress tensor
138169

170+
#ifdef USE_MPI
171+
Halo haloCGVector(dStressX);
172+
haloCGVector.exchangeHalos(dStressX);
173+
haloCGVector.exchangeHalos(dStressY);
174+
#endif
175+
139176
updateMomentum(tst);
140177

141178
applyBoundaries();
142179

180+
#ifdef USE_MPI
181+
haloCGVector.exchangeHalos(u);
182+
haloCGVector.exchangeHalos(v);
183+
#endif
184+
143185
// Land mask
144186
}
145187

0 commit comments

Comments
 (0)