Skip to content

Fix out-of-grid neighbour lookup for Neumann (msk=6) boundary cells - #452

Open
Leynse wants to merge 1 commit into
mainfrom
fix/neumann-neighbour-lookup
Open

Leynse wants to merge 1 commit into
mainfrom
fix/neumann-neighbour-lookup

Conversation

@Leynse

@Leynse Leynse commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

find_quadtree_cell_by_index had no bounds check and returned i1 - 1 (the last cell of the previous level) when binary_search missed; find_sfincs_cell then indexed index_sfincs_in_quadtree(0) out of bounds. In find_boundary_indices the last valid neighbour wins, so for west-edge msk=6 cells the out-of-grid (n, m-1) lookup overwrote the correct (n, m+1) neighbour. All west-edge cells copied the water level of one unrelated cell, which pumped water into the model and made it unstable.

Return 0 for indices outside the grid and for a missed search, and only look up the SFINCS index for a valid quadtree cell. Models without msk=6 cells give bit-identical results.

Description

Please briefly describe the purpose of this pull request and the main changes introduced.

Checklist

Before marking this PR as Ready for Review, please confirm:

Compilation

  • Compiles and runs successfully on Windows
  • Compiles and runs successfully on Linux (CPU)
  • Compiles and runs successfully on Linux (GPU)

Testing (for additions to the code)

If this PR modifies model functionality:
 

  • Testbed has been run, and significant performance change has been adressed

If this PR adds model functionality:
 

  • A conceptual test has been added to the testbed.
  • A real-world test case has been added to the testbed.

Documentation

  • Relevant documentation has been updated to reflect the changes.
  • Examples, tutorials, or user guides have been updated where necessary.

HydroMT-SFINCS

Self Review

Additional Notes

find_quadtree_cell_by_index had no bounds check and returned i1 - 1
(the last cell of the previous level) when binary_search missed;
find_sfincs_cell then indexed index_sfincs_in_quadtree(0) out of bounds.
In find_boundary_indices the last valid neighbour wins, so for west-edge
msk=6 cells the out-of-grid (n, m-1) lookup overwrote the correct
(n, m+1) neighbour. All west-edge cells copied the water level of one
unrelated cell, which pumped water into the model and made it unstable.

Return 0 for indices outside the grid and for a missed search, and
only look up the SFINCS index for a valid quadtree cell. Models without
msk=6 cells give bit-identical results.

Co-Authored-By: SFINCS <sfincs@deltares.nl>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Approval should be deferred because the boundary-indexing and Neumann-selection changes lack executable regression or build/test evidence, leaving west-edge msk=6 behavior and CPU/GPU consistency unverified.

No open issues 🎉

What changed in this PR

This PR fixes invalid neighbour resolution for Neumann (msk=6) boundary cells on quadtree grids, preventing out-of-grid lookups and incorrect water-level propagation.

Changes:

  • Added bounds checks and safe handling of missed searches in find_quadtree_cell_by_index.
  • Guarded SFINCS-index lookup when no valid quadtree cell exists.
  • Preserved valid neighbour selection for boundary cells.
File Description
source/​src/​sfincs_quadtree.F90 Validates quadtree coordinates and safely handles out-of-grid coordinates and unsuccessful searches.
source/​src/​sfincs_boundaries.f90 Prevents SFINCS-index lookup when the resolved quadtree cell is invalid.

Review effort: Lite

Leynse added a commit that referenced this pull request Nov 19, 2026
Merge the current heads of bugfix/snapwave-wave-force-dissipation
(5f349be), fix/boundary-corner-water-level (0073407) and
fix/neumann-boundary-robustness (ff5e5bf, includes
fix/neumann-neighbour-lookup), on top of #445-#448. In compute_fluxes,
keep the array swap of #445 instead of the q0/uv0 copy loop, and add
kcs to the present list for the Neumann water level at kcuv = 6 faces.

Co-Authored-By: SFINCS <sfincs@deltares.nl>

@maartenvanormondt maartenvanormondt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks okay to me (I think).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants