Repository navigation
Keep advection on next to inactive cells, add advection_bank_correction - #448
maartenvanormondt wants to merge 5 commits into
Conversation
Add an optional depth- and flux-weighted correction for upwind advection near shallow banks. Keep advection enabled at inactive-cell edges while preserving masking near boundaries and wave makers.
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active finding remains because the documented advlim = 9999.9 sentinel still allows the advection value to be clamped, so the limiter-disable behavior is not implemented as promised.
1 open issue
What changed in this PR
This PR updates SFINCS advection handling near inactive-cell boundaries and adds an optional bank-correction method for the upw1 scheme.
Changes:
- Preserves advection next to inactive cells while retaining masking near open boundaries and wave makers.
- Adds the
advection_bank_correctionoption with input parsing, NetCDF metadata, and documentation. - Updates advection-related comments and parameter descriptions.
| File | Description |
|---|---|
| source/src/sfincs_ncoutput.F90 | Adds advection_bank_correction to the map-file NetCDF metadata. |
| source/src/sfincs_momentum.f90 | Implements bank-correction weighting for upw1 advection terms and updates the advlim documentation. |
| source/src/sfincs_input.f90 | Reads the new advection option and updates the advlim comment. |
| source/src/sfincs_domain.f90 | Refines advection-mask handling to exclude dummy missing-neighbor indices. |
| source/src/sfincs_data.f90 | Declares the new advection configuration flag. |
| docs/parameters.rst | Documents the advection_bank_correction parameter. |
Review effort: Lite
Explain that 9999.9 is a high threshold, not a special value that disables the limiter.
Leynse
left a comment
There was a problem hiding this comment.
Thanks, and thanks for stating clearly that change 1 alters results. I checked the reasoning: inactive quadtree cells are removed from np, so their faces point to the dummy index with kcuv = 0, and next to open boundaries and wave makers the mask still applies. The bank correction is safe against division by zero (a dry or dummy partner gives wt = 0 before any division), all partner indices stay within the arrays, and no GPU data needs to change.
Blocking
- Change 1 changes results by default, and is not tested yet. Neither of the two test cases runs this code path, and the testbed has not been run on this branch. Since there is no keyword to get the old behaviour back, I'd like to see the full testbed (CPU and GPU) with the differences explained before merging. A regular multi-row or quadtree case with
advection = 1next to inactive cells would show the effect of change 1 on its own. - No Linux CPU or GPU build. The new code is inside the OpenACC momentum kernel, so nvfortran and the GPU path have not been exercised.
Non-blocking
- Change 1 is partial at refinement transitions (
sfincs_domain.f90:2243-2244,2275-2282). A combined uv point whose second fine face is missing (the fine cell is inactive) getscuv_index_uv2 = dummy, sokcuv = 0at an index<= npuv + ncuv, and it still switches advection off. The same holds for Neumann cells that are reset tokcs = 0(sfincs_boundaries.f90:759). Is that intended? If so, the description ("a missing neighbour no longer switches advection off") could mention it. advection_maskcomment (sfincs_input.f90:210) still says "mask advection near dry cells". After this PR it only applies next to open boundaries and wave makers.- No warning with
advection_scheme = original.advection_bank_correctionis only used in the upw1 branch; awrite_logwarning when it is set with another scheme would help. - Style.
sfincs_input.f90:211is one column out of alignment with the lines around it, and the comment block atsfincs_momentum.f90:502-510wraps unevenly (line 502 is about 170 characters). - Testing of the new option. No testbed case for
advection_bank_correctionyet.
Questions
- Next to a closed wall, the tangential neighbour (
u_ndm/u_num) falls back to the point itself (zero gradient) when the neighbouring cell is missing, but to the dummy (u = 0) when the cell exists without that face. Is that asymmetry acceptable? With the bank correction on, a dummy partner getswt = 0, i.e. free slip. - Was the bank correction checked with subgrid, where
huis a grid-average depth and the ratiohu_k / humixes partly wet faces?
Suggestion
- The
advlimentry indocs/parameters.rstcould use the same "a high value like 9999.9 switches the limiter off" wording as the new code comment.
|
Thanks Tim, thorough review. Answers below; the code changes are in the next commit on this branch. Non-blocking points
Suggestion. Done: the These changes are comments, documentation and one warning. Checked with a release build on Windows, one thread: Your questions
Blocking points Both are fair. Could you run the test bed on this branch yourself, CPU and GPU, together with the Linux builds? You have the Linux and GPU set-up, and I do not have it here. What to expect: differences against |
Warn when advection bank correction is enabled with a scheme other than upw1. Clarify the advection mask, limiter, and bank correction comments.
Split the advlim comment in compute_fluxes over two lines, and note in parameters.rst that advection_bank_correction is available from SFINCS v2.5.1 onwards. Co-Authored-By: SFINCS <sfincs@deltares.nl>
Add a line to the known issues in developments.rst that advection is no longer switched off next to inactive cells, so models with advection can give slightly different results near the edge of the active domain. Wrap the long comment in set_advection_mask. Co-Authored-By: SFINCS <sfincs@deltares.nl>
|
Thanks Maarten, the fixes in 0519cd2 look good. One more question on the bank correction, not blocking: A wet partner face with Exactly zero flux on a wet face mainly happens at thin dams, closed faces and structures, where free slip is arguably what you want, and stagnant water hardly ever reaches exactly 0. So I see it as a matter of definition rather than a bug. Is this intended? If so, could the comment say that a partner with zero flux is treated as a wall (free slip)? |
Leynse
left a comment
There was a problem hiding this comment.
Okay checked. Merge after running testbed
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>

Description
Two changes to the advection term in
compute_fluxes. The first changes results for some models; the second is an option that is off by default.1. Advection is no longer switched off next to inactive cells (changes results)
set_advection_maskswitches advection off at every uv point that has a neighbouring uv point withkcuv /= 1. That is meant for open boundaries and wave makers. It also catches uv points next to an inactive cell, because a missing neighbour points to the dummy indexnpuv + ncuv + 1, wherekcuv = 0. The edge of the active domain is a closed wall, not an open boundary, so there is no reason to switch advection off there.With this PR a missing neighbour no longer switches advection off. Next to open boundary points and wave maker points nothing changes.
Two cases in which advection is still switched off next to an inactive cell (pointed out in the review, not changed here): at a refinement transition, a combined uv point whose second fine face is missing (the fine cell is inactive) gets
kcuv = 0at a regular index, not the dummy index, so its neighbours are still masked. The same holds next to a Neumann cell that is reset to inactive because it has no valid neighbour.Which models are affected: models with
advection = 1andadvection_mask = 1(both default) on a quadtree grid or a regular grid with more than one row, at uv points next to inactive cells. There the advection term is now included. There is no keyword to get the old behaviour back. Regular one-row models are not affected: for those the mask was never applied.2. New option
advection_bank_correction(default off)A dry uv point has
u = 0. In the upw1 scheme the velocity differences with the four neighbouring uv points then treat every step of a bank that follows the grid as a real 90 degree corner, which slows down the flow along the bank. Withadvection_bank_correction = 1each of those differences is weighted withthe larger of the depth ratio and the flux ratio between neighbour
kand the uv point. Only the terms withdu/dxanddu/dyare weighted. Only foradvection_scheme = upw1.Also: the comment on
advliminsfincs_input.f90andsfincs_momentum.f90now says that a value like 9999.9 is so high that the cap has no effect (the default stays 1.0), the map file gets the attributeadvection_bank_correction, anddocs/parameters.rsthas an entry for it.Test. Release build on Windows, one thread, against
main(f2845d9):advection_bank_correction = 1against 0urban_drainage_charleston(no advection)Thacker1D(advection on, regular grid of one row)Neither case exercises change 1: the first has no advection, the second is a one-row model. The effect of change 1 has not been isolated in a test yet.
Checklist
Compilation
Testing (for additions to the code)
If this PR modifies model functionality:
If this PR adds model functionality:
Documentation
HydroMT-SFINCS
Self Review
Additional Notes
advection_maskhas no entry inparameters.rst; this PR does not add one.bates-wiggle-advection: Swap flux and velocity arrays instead of copying them #445 (array swap), Add cbrt keyword for a fast cube root in the friction term, remove the h73 table #446 (cbrt), Add wet-area wiggle suppression as an option (wiggle_detect) #447 (wiggle suppression) and Keep advection on next to inactive cells, add advection_bank_correction #448 (advection). Each is based onmainand they can be merged in any order. They add lines at the same places (the OpenMP private list insfincs_momentum.f90, the logical flags insfincs_data.f90, keyword lines insfincs_input.f90, attributes insfincs_ncoutput.F90, entries inparameters.rst), so the ones merged later will have small conflicts where both sides are to be kept.🤖 Generated with Claude Code