Skip to content

Cryptic soil layer indexing bug#1459

Open
mpaiao wants to merge 1 commit into
MPAS-Dev:hotfix-v8.4.1from
mpaiao:mpaiao-pr-nsoil-hotfix
Open

Cryptic soil layer indexing bug#1459
mpaiao wants to merge 1 commit into
MPAS-Dev:hotfix-v8.4.1from
mpaiao:mpaiao-pr-nsoil-hotfix

Conversation

@mpaiao
Copy link
Copy Markdown

@mpaiao mpaiao commented May 26, 2026

This fixes a rather cryptic bug, that occurs when the number of soil layers is not the default (4 layers) for Noah-MP, which results in the model not conserving water.

1. Soil layer indexing bug. Noah-MP uses positive indices for soil layers, and negative indices for snowpack layers. In sub-routine lsm_noahmp_toMPAS, the code copies the depths from Noah-MP to a local structure (zsnsoxy) that assumes indices going from 1 to the number of combined snowpack and soil layers. However, the original code had one error in the conversion logic, which coincidentally worked for the specific case in which the number of soil layers is exactly the number of snowpack ayers plus 1. The proposed change follows the logic used elsewhere in the code and ensures the conversion always works.

2. Hardcoded number of soil plus snow levels. File Registry_noahmp.xml originally defines dimension nzSnowLevels (total number of soil plus snowpack layers) as 7. This works when using the default number of soil layers, but causes segmentation violations otherwise.

@mpaiao
Copy link
Copy Markdown
Author

mpaiao commented May 26, 2026

This PR mirrors the one I submitted to MONAN.

I found this bug as I am working to allow the total number of soil layers (and their thickness) more flexible in MONAN. Happy to point to the subsequent PR if interested in implementing it in MPAS too.

@mgduda mgduda requested review from cenlinhe and mgduda May 27, 2026 20:38
Copy link
Copy Markdown
Collaborator

@cenlinhe cenlinhe left a comment

Choose a reason for hiding this comment

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

This bug fix looks good to me.

@mgduda mgduda changed the base branch from develop to hotfix-v8.4.1 June 4, 2026 22:49
@mgduda
Copy link
Copy Markdown
Contributor

mgduda commented Jun 4, 2026

@mpaiao I think we're now planning for an MPAS v8.4.1 bugfix release within the next week, and we could include this fix in that release. Would you be able to rebase this PR branch off of the v8.4.0 tag? There's no need to create a new PR, and you could just push the rebased branch to mpaiao-pr-nsoil-hotfix to update this PR. If you have any questions, or if I can help at all, just let me know!

… that only occurs when

the code is modified to run with more than four soil layers. The logic in
mpas_atmphys_driver_lsm_noahmp.F can be simplified to a single loop that will always work.
Likewise, Registry_noahmp.xml does not need to have the combined number of soil plus snow
levels (nzSoilLevels) hardcoded, it can be written as the sum of the levels so it
always works.
@mpaiao mpaiao force-pushed the mpaiao-pr-nsoil-hotfix branch from e4e63de to 4e03bc8 Compare June 8, 2026 10:45
@mpaiao
Copy link
Copy Markdown
Author

mpaiao commented Jun 8, 2026

@mgduda I think this is now rebased off of release-v8.4.0, but let me know if this does not look correct.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants