Skip to content

fix: div by zero guard in find0_quadratic - #1106

Merged
Debraheem merged 3 commits into
mainfrom
blb/fix-find0_quadratic-guard
Nov 4, 2026
Merged

Debraheem merged 3 commits into
mainfrom
blb/fix-find0_quadratic-guard

Conversation

@AstroBarker

Copy link
Copy Markdown
Contributor

Summary

In #1103 I hit a division by zero error in the wind_fed_bbhmxb test case during the iterative solve for the mass transfer rate. This occurred in what would be the final few timesteps when the mass transfer rate had fallen to near zero. With mass transfer rates at roundoff the solver struggled to "converge" and pushed the mdot_lo mdot_hi bracket width to zero. This led to a division by zero in find0_quadratic. This wasn't really caused by anything in #1103, but the changes there perturbed the roundoff-level arithmetic just so to take a different path through the mass transfer solve.

Note

The test sets implicit_scheme_tiny_factor = 0d0 which is what let the zero width bracket not register as converged. Setting that to the default 1d-6, for example, bypassed the issue as well.

Fix

When the denominator in find0_quadratic is zero (which is the consequence of the bracket width reaching zero), set ierr = -= to fall back to the safer find0 which should handle the case.

 ! Guard against an unlikely, but unfortunate, division by 0.
 if (denom == 0) then
    ierr = -1
    return
 end if

@AstroBarker
AstroBarker requested a review from Debraheem November 3, 2026 19:56
@Debraheem Debraheem added bug Something isn't working numerics issues with math/num/mtx modules labels Nov 3, 2026

@Debraheem Debraheem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps tweak the chang

Comment thread docs/source/changelog.rst Resolved
AstroBarker and others added 2 commits November 3, 2026 15:39
Co-authored-by: Ebraheem Farag <63124736+Debraheem@users.noreply.github.com>
@Debraheem
Debraheem merged commit 0b2e6bb into main Nov 4, 2026
5 checks passed
@Debraheem

Copy link
Copy Markdown
Member

merged, since this is passing testing.

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

Labels

bug Something isn't working numerics issues with math/num/mtx modules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants