Fix floating invalid exceptions in Process_Library.F90 Bergeron code - #1486
Draft
mathomp4 wants to merge 1 commit into
Draft
Fix floating invalid exceptions in Process_Library.F90 Bergeron code#1486mathomp4 wants to merge 1 commit into
mathomp4 wants to merge 1 commit into
Conversation
- Bound t_env in hystpdf iteration to prevent secant solver overshoot into negative temperatures - Guard t_env and pl in line 3053 against negative values prior to real exponentiation (** 1.94) - Clamp f_mass_ice to [0,1] and n_ice_active to >= 0 - Ensure non-negative base before exponentiation in d_crystal computation
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.
Important
Status: Proposed Solution — Needs Testing
This pull request contains a candidate fix for floating invalid exceptions encountered during debug runs. It requires validation through testing (e.g. running the 5-day
c90 L181debug simulation withifort) to confirm stability and verify physical output consistency.Context & Reported Issue
During a
c90 L181run compiled withifortdebug flags, the simulation failed after approximately 5 days of model time with the following traceback:Detailed Root Cause Analysis
Floating Invalid Exception on Real Exponentiation (
** 1.94):Line 3053 in
Process_Library.F90insideBergeron_Partitioncomputes:When compiled with Intel Fortran ($x^y$ with a real non-integer exponent ($y = 1.94$ ) is evaluated via $\exp(1.94 \times \ln(x))$ . If $x \le 0$ , $\ln(x)$ is mathematically undefined for real floating-point arithmetic, immediately trapping with
ifort) debug flags (specifically-fpe0or floating-point trap options enabled), real-number exponentiationforrtl: error (65): floating invalid.If
t_env <= -0.1K (or ift_envbecomes negative during solver iterations),(t_env + 0.1)is non-positive, triggering the crash. Note that while(t_env + 0.1)was likely intended as a non-zero guard,+ 0.1does not prevent the base from being negative ift_env <= -0.1.Solver Overshoot in
hystpdf:In
hystpdf(around lines 2808–2818),t_envis updated iteratively inside thedo n = 1, nmaxloop using a secant method solver:If$n+1$ ),
denombecomes very small, the secant update step can overshoot dramatically, drivingt_envto unphysical negative values (e.g.t_env < 0 K). On the subsequent iteration (hystpdfpasses this negativet_envtoBergeron_Partition(line 2768), triggering the exception at line 3053.Secondary Floating Invalid Vulnerabilities:
d_crystal):**(0.333)will also trapfloating invalidif the term inside parentheses is non-positive.f_mass_ice&n_ice_active):If liquid mass
q_tot_liqbecomes slightly negative due to numerical truncation,f_mass_ice = q_tot_ice / q_tot_masscan exceed1.0, producing negative active ice crystal concentrations (n_ice_active < 0).den_air):den_air = (pl * 100.0) / (MAPL_RGAS * t_env)could divide by zero or yield negative air density ift_env <= 0.Code Changes Summary
hystpdf(line 2825): Clampedt_envto a physically plausible range[100.0, 400.0]K after secant solver updates to prevent iteration overshoot from propagating negative temperature values into subsequent calls.Bergeron_Partition(line 3053 & 3054):t_envin diffusivity calculation:diff = (0.211 * 1013.25 / max(pl + 0.1, 0.1)) * (((max(t_env, 1.0) + 0.1) / MAPL_TICE)**1.94) * 1e-4t_envin air density calculation:den_air = (pl * 100.0) / (MAPL_RGAS * max(t_env, 1.0))Bergeron_Partition(lines 3024–3025):f_mass_iceto[0.0, 1.0]andn_ice_activeto>= 0.0.Bergeron_Partition(line 3060):den_ice > 0.0and guarded the base of**(0.333)withmax(..., 0.0).Verification & Testing Request
Note
This PR is opened as a Draft for review and testing.
c90 L181debug simulation withifortpast the 5-day mark to confirm that the floating invalid error no longer occurs.