Repository navigation
Avoid very rare NaN in set_cld - #51
Thomas Bendall (tommbendall) wants to merge 15 commits into
Conversation
|
Hi Tom, I think this failure can only happen if frac=0, in which case I think it would be better to avoid calling split_mix_phase entirely. i.e. replace the if test before the call: You'd still need an else clause in the l_combine case to set frac_liq and frac_ice to zero. James |
Thanks, your suggestion is much tidier. I've done that, and checked this against the LFRic-Apps tests. There don't seem to be any KGO changes so this won't require a linked PR. |
James Manners (mo-jmanners)
left a comment
There was a problem hiding this comment.
Code looks fine.
I don't think any of the code changes are now from AI so I think the comment at the top of socrates_set_cld can be removed.
PR Summary
This PR fixes an issue that can cause a NaN in an incredibly rare scenario.
Sci/Tech Reviewer: James Manners (@mo-jmanners)
Code Reviewer:
I saw a
Cloud fraction greater than 1failure fromsocrates_set_cld.F90in a very high-resolution LFRic AMIP run. This was triggered by thefrac_cloudarrays containing a NaN at a single point, but none of the inputs to Socrates contained a NaN.Why this issue is rare
All of these must hold at once:
ccais exactly 1.0 (orarea_fractionexactly 0), sofracis exactly 0.differ, one fraction stays positive after the call to
split_mixed_phase. Then the denominator ispositive, and the result is finite.
Cause
For the failure I saw, the inputs entering Socrates at that cell were:
frac= 0, fromarea_fraction*(1-cca)witharea_fraction = 1and
cca = 1liq_frac= 0.66457766,ice_frac= 1.0mr_cl + conv_liquid_mmr= 3.32288822E-4 + 7.11565488E-4 = 1.0438543104100972E-3
mr_ice + conv_frozen_mmr= 8.8357972E-4 + 1.60274591E-4 = 1.0438543104100972E-3
The sums are equal to 17 digits.
The code tests
frac_liq + frac_ice > epsbefore splitting the overlappingice and liquid fraction. Here it is 1.66, so the splitting code runs.
split_mix_phasethen removes the overlapfrac_mix = liq + ice - frac = 1.66. With equal mixing ratios andfrac = 0, bothfrac_liqandfrac_icecome out exactly 0.The next lines compute
frac*frac_liq/(frac_liq+frac_ice), which is0*0/(0+0) = NaN, and this goes into both cloud types.
Fix
In the stratiform and convective blocks of the two-type ice/liquid
representation, and the stratiform and convective blocks of the four-type
representation, we can test
frac_liq + frac_ice > 0aftersplit_mix_phase. If it is false, both types are set to 0.Otherwise the existing code runs unchanged.
Code Quality Checklist
(Some checks are automatically carried out via the CI pipeline)
Testing
trac.log
Output from Socrates quick_tests
Test Suite Results - lfric_apps - socrates_set_cld_nan/run4
Suite Information
Task Information
✅ succeeded tasks - 442
Security Considerations
Performance Impact
AI Assistance and Attribution
Copilot helped me debug and understand this problem and possible fixes
Documentation
Sci/Tech Review
Please alert the code reviewer via a tag when you have approved the SR
Code Review