Skip to content

Fix a_w() to handle kappa==0 safely#495

Draft
pdziekan with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-code-from-review-comment
Draft

Fix a_w() to handle kappa==0 safely#495
pdziekan with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-code-from-review-comment

Conversation

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown

With the soluble_fraction approach, init_kappa() can set kpa to 0 (when soluble_fraction==0). The previous assert(kappa > 0) in a_w() would fire, and the denominator (rw3 - rd3*(1-kappa) - rd3_insol) collapses to (rw3 - rd3 - rd3_insol), producing 0/0 when there's no liquid water.

  • Relax assertion from kappa > 0 to kappa >= 0
  • Return 1.0 (pure water activity) when kappa == 0 and liquid water exists
  • Existing early return of 0.0 already covers the rw3 <= rd3 + rd3_insol case
assert(kappa >= 0);
if ((rw3 - rd3 - rd3_insol) / si::cubic_meters <= std::nextafter(real_t(0), real_t(1)))
  return real_t(0.);
if (kappa == real_t(0))
  return real_t(1.);
return (rw3 - rd3 - rd3_insol) / (rw3 - rd3 * (real_t(1) - kappa) - rd3_insol);

Copilot AI changed the title [WIP] Fix code based on review comment Fix a_w() to handle kappa==0 safely Jun 24, 2026
Copilot AI requested a review from pdziekan June 24, 2026 13:50
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.

2 participants