Skip to content

Add Halo Exchange to Dynamics#924

Merged
TomMelt merged 1 commit intodevelopfrom
halo-dynamics
Apr 13, 2026
Merged

Add Halo Exchange to Dynamics#924
TomMelt merged 1 commit intodevelopfrom
halo-dynamics

Conversation

@TomMelt
Copy link
Copy Markdown
Contributor

@TomMelt TomMelt commented Sep 9, 2025

Add Halo Exchange to Dynamics

Fixes #120

Task List

  • Linked an issue above that captures the requirements of this PR
  • Defined the tests that specify a complete and functioning change will be done in separate follow up PR (see issue create idealised test for the MPI dynamics #1071
  • Implemented the source code change that satisfies the tests
  • Commented all code so that it can be understood without additional context
  • No new warnings are generated or they are mentioned below
  • The documentation has been updated (or an issue has been created to do so)
  • Relevant labels (e.g., enhancement, bug) have been applied to this PR
  • This change conforms to the conventions described in the README

Change Description

This PR adds halo exchange functionality to the dynamics and for advected fields.

After adding halo exchange into the dynamics we fix fields like hice for example.

image

Figure 1 hice (left) before halo exchange is added to dyanmics and (right) after.

After adding halo exchange into the advectField function we also fix it for advected fields like tbottom, tsurf and tinterior, for example.

image

Figure 2 tbottom (left) before halo exchange is added to advectField and (right) after.


Test Description

None currently


Documentation Impact

None currently


Other Details

⚠️ Open Problems:

  • AFAIK for Interpolations::DG2CG(smesh, cgVector, DGVector) values inside the "inner" domain (i.e., not halo cells) depends on vertices set outside the inner cells i.e., from neighbouring points on the lattice. This means that you have to halo exchange the DGVector before you halo exchange the CGVector. It is not equivalent to first interpolate from DGVector onto CGVector and then halo exchange the CGVector.
  • We still don't have a solution for how to set vertices outside the main domain (so inner halo boundaries are fine, but points along the edge are not (also periodic boundaries would be an issue)
  • When should halo exchange take place?
    • @Thanduriel raised point that we perhaps need to exchange after dynamics rather than before
    • @timspainNERSC think it should be before and possibly after
    • @TomMelt thinks just before should be enough
    • @einola either should work

Todo

@TomMelt TomMelt self-assigned this Sep 9, 2025
@TomMelt TomMelt added the ICCS Tasks or reviews for the ICCS team label Sep 9, 2025
@TomMelt TomMelt changed the base branch from develop to halo-exchange September 9, 2025 14:07
Base automatically changed from halo-exchange to develop October 2, 2025 09:32
Comment thread .github/workflows/build_docs.yml Fixed
@Thanduriel Thanduriel mentioned this pull request Feb 10, 2026
@TomMelt TomMelt mentioned this pull request Feb 16, 2026
8 tasks
@TomMelt TomMelt changed the base branch from develop to halo-add-corners February 16, 2026 10:40
@TomMelt TomMelt changed the title Halo dynamics Add Halo Exchange to Dynamics Feb 16, 2026
@Thanduriel
Copy link
Copy Markdown
Member

Thanduriel commented Feb 16, 2026

After looking at the code again I now believe that the update is correct as is. The exchange always happens right after a field is updated, ensuring that the correct results are available for subsequent computations.

The only exception are the advected fields in the dynamics that are also modified by the thermodynamics. Here we need to ensure that the halo cells contain the correct values before the advection, either by doing the column physics on the halo cells or by doing an exchange beforehand. Another exchange afterwards should not be strictly necessary but if we do another exchange, I think it might be possible to skip the exchange of stresses (s11,s12,s22), since that computation works purely local on individual cells .

@TomMelt TomMelt marked this pull request as ready for review February 16, 2026 15:34
Copy link
Copy Markdown
Member

@Thanduriel Thanduriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me as-is but I have a few thoughts on possible changes.

Comment thread dynamics/src/CGDynamicsKernel.cpp Outdated
Comment thread dynamics/src/include/BrittleCGDynamicsKernel.hpp Outdated
#ifdef USE_MPI
haloDGVector.exchangeHalos(s11);
haloDGVector.exchangeHalos(s12);
haloDGVector.exchangeHalos(s22);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this exchange is redundant. If all the inputs are correct on the halo cells the computed stress should be as well. Maybe you can try this? I expect the results to be bit-wise identical.

@TomMelt TomMelt added the enhancement New feature or request label Feb 23, 2026
Copy link
Copy Markdown
Member

@einola einola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should modify advectDynamicsField as per my comment on line R132.

There are also questions about redundant exchanges.

Comment thread dynamics/src/include/BrittleCGDynamicsKernel.hpp Outdated
Comment thread dynamics/src/include/BrittleCGDynamicsKernel.hpp Outdated
Comment thread dynamics/src/include/BrittleCGDynamicsKernel.hpp Outdated
Comment thread dynamics/src/CGDynamicsKernel.cpp Outdated
@einola
Copy link
Copy Markdown
Member

einola commented Feb 27, 2026

A possible test would be to run config_benchmark.cfg with one of the high-resolution setups (e.g., init_benchmark_256x256.nc) and simply check for conservation of volume. That is to say, to check if the total sum of hice in the domain is fixed.

This does not check the thermodynamics.

TomMelt added a commit that referenced this pull request Mar 16, 2026
# Add corner neighbours into halo exchange logic

### Task List
- [x] Linked an issue above that captures the requirements of this PR
- [x] Defined the tests that specify a complete and functioning change
- [x] Implemented the source code change that satisfies the tests
- [x] Commented all code so that it can be understood without additional
context
- [x] No new warnings are generated or they are mentioned below
- [x] The documentation has been updated (or an issue has been created
to do so)
- [x] Relevant labels (e.g., enhancement, bug) have been applied to this
PR
- [x] This change conforms to the conventions described in the README

---

# Change Description

This PR has the following key changes:

- adds support for corner neighbours to the existing halo exchange logic
(which previously just exchanged edges)
- add support for `CGVector` and `DGVectorHolder` exchange (this is
required for corners and edges)
- updates metadata tests and closed-boundary (CB) halo test to work with
corner neighbours
- removes the Periodic-Boundary (PB) halo exchange test for now, this
will be addressed in a subsequent PR #1044

---
# Test Description

### `HaloExchangePB_test.cpp`

`HaloExchangeCB_test.cpp` creates test data for all the array types:
- `HField`
- `VertexField`
- `DGField`
- `DGVector`
- `CGVector`

I modified the previous version, so that the model data are created in
such a way that the value of each cell can be calculated based on its
indices. Therefore we can check after exchange that all of the cells
have been exchanged successfully. This also now allows us to change the
number of ranks arbitrarily (assuming you also provide the appropriate
`partition_metadata` file.

### `ModelMetadataCB_test.cpp` and `ModelMetadataPB_test.cpp`

Small modifications have been made to the periodic and closed boundary
`ModelMetadata` tests.

The changes now add the additional corner neighbour metadata and check
that it is ready correctly.

### `partition_metadata_3_cb.cdl` and `partition_metadata_3_pb.cdl`

These files are now generated at compile time by running the `decomp`
tool on a new file `halo_test_mask.cdl`. This is in line with similar
changes introduced by @joewallwork on the XIOS tests.

---
# Other Details

* `domain_decop` git commit has now been bumped to the latest version on
main. This version of the decomp tool contains the corner neighbour
metadata.

### Further work

- Integrating halo exchange to nextsim is handled by PR #924
Base automatically changed from halo-add-corners to develop March 16, 2026 10:28
@TomMelt TomMelt force-pushed the halo-dynamics branch 2 times, most recently from a951eb5 to c31114b Compare March 16, 2026 13:20
@TomMelt TomMelt changed the base branch from develop to fix-halo-constructor-dgvh March 16, 2026 13:20
Base automatically changed from fix-halo-constructor-dgvh to develop March 23, 2026 08:45
Comment thread dynamics/src/include/DynamicsKernel.hpp Outdated
Copy link
Copy Markdown
Member

@Thanduriel Thanduriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good now!

What is the plan for the VP dynamics? Applying the changes from the BrittleCGDynamicsKernel shouldn't be much work now. I approve this regardless but if we don't do it right away, maybe create an issue?

@TomMelt
Copy link
Copy Markdown
Contributor Author

TomMelt commented Apr 13, 2026

Looking good now!

What is the plan for the VP dynamics? Applying the changes from the BrittleCGDynamicsKernel shouldn't be much work now. I approve this regardless but if we don't do it right away, maybe create an issue?

Thanks see issue #1072

@TomMelt TomMelt merged commit 04fa7c6 into develop Apr 13, 2026
9 checks passed
@TomMelt TomMelt deleted the halo-dynamics branch April 13, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ICCS Tasks or reviews for the ICCS team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MPI parallelization of dynamics

5 participants