Cryptic soil layer indexing bug#1459
Open
mpaiao wants to merge 1 commit into
Open
Conversation
… 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.
Author
|
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. |
cenlinhe
approved these changes
May 28, 2026
Collaborator
cenlinhe
left a comment
There was a problem hiding this comment.
This bug fix looks good to me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.xmloriginally defines dimensionnzSnowLevels(total number of soil plus snowpack layers) as 7. This works when using the default number of soil layers, but causes segmentation violations otherwise.