Fix possible divide-by-zero error in MoL code#381
Open
Thomas Bendall (tommbendall) wants to merge 4 commits intoMetOffice:mainfrom
Open
Fix possible divide-by-zero error in MoL code#381Thomas Bendall (tommbendall) wants to merge 4 commits intoMetOffice:mainfrom
Thomas Bendall (tommbendall) wants to merge 4 commits intoMetOffice:mainfrom
Conversation
Update stable for vn3.1
James Kent (jameskent-metoffice)
approved these changes
Mar 25, 2026
Contributor
James Kent (jameskent-metoffice)
left a comment
There was a problem hiding this comment.
This is a very small change to fix a possible divide by zero in the Koren kernels. The method chosen is sensible. There are kgo changes in tests that run with MoL and Koren, but all the plots look good and I am happy they are correct. Approved for science review.
iboutle
approved these changes
Mar 25, 2026
Contributor
|
Benjamin Went (@MetBenjaminWent) this PR it appears is blocking #326, and I think any KGO changing PR is likely to encounter the issues that this PR fixes - therefore it would be good if we could prioritise getting this on to help other PRs along. |
28 tasks
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.
PR Summary
Sci/Tech Reviewer: James Kent (@jameskent-metoffice)
Code Reviewer: Benjamin Went (@MetBenjaminWent)
A calculation in the Koren limiter for the MoL scheme involves the calculation
r = y / x, which has been written as:to avoid a potential divide-by-zero error. However, this can still lead to a divide-by-zero error in the case that
x = -SMALL_R_TRAN. This PR fixes that by changing the calculation to:This cannot be zero in the denominator, and is generally equal to
y / xsinceABS(x)*sign(1.0, x) = x.The other improvement is that now
r = 0ify = 0.Results
Plots showing the change to the lfric_atm MoL test can be found in this PDF:
results_mol_division_fix_lfric_atm.pdf
Code Quality Checklist
Testing
trac.log
Test Suite Results - lfric_apps - mol_division_fix/run2
Suite Information
Task Information
✅ succeeded tasks - 1511
Security Considerations
Performance Impact
AI Assistance and Attribution
Documentation
PSyclone Approval
Sci/Tech Review
(Please alert the code reviewer via a tag when you have approved the SR)
Code Review