Skip to content

Fix catastrophic cancellation in VanGenuchten near theta_range[0] - #98

Merged
gerlero merged 1 commit into
mainfrom
vangenuchten
Aug 27, 2026
Merged

Fix catastrophic cancellation in VanGenuchten near theta_range[0]#98
gerlero merged 1 commit into
mainfrom
vangenuchten

Conversation

@gerlero

@gerlero gerlero commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The functional change is targeted and the added tests cover the intended numerical-stability regression.

Pull request overview

This PR improves numerical stability of the Van Genuchten–Mualem relative conductivity computation near residual saturation to avoid catastrophic cancellation, and adds regression tests that validate values and derivatives in this regime.

Changes:

  • Rewrites VanGenuchten._kr using log1p/expm1 to improve stability for small effective saturations.
  • Adds tests covering Van Genuchten diffusivity and derivatives near residual saturation, plus a float32 _kr regression check.
File summaries
File Description
src/frontx/models.py Replaces the cancellation-prone 1 - (1 - x)**m form in _kr with a stable expm1(log1p()) formulation.
tests/test_models.py Adds regression tests for near-residual behavior and a float32 stability check for _kr.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/frontx/models.py
@codecov-commenter

codecov-commenter commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.25%. Comparing base (fd68425) to head (26c1e70).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #98      +/-   ##
==========================================
+ Coverage   86.05%   86.25%   +0.20%     
==========================================
  Files          13       13              
  Lines         552      553       +1     
==========================================
+ Hits          475      477       +2     
+ Misses         77       76       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gerlero
gerlero merged commit b4ca0a3 into main Aug 27, 2026
9 checks passed
@gerlero
gerlero deleted the vangenuchten branch August 27, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants