Repository navigation
Avoid division by zero in getMixDiffCoeffsMass - #2191
Merged
Merged
Conversation
g3bk47
marked this pull request as ready for review
November 5, 2026 21:35
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2191 +/- ##
==========================================
- Coverage 77.45% 77.45% -0.01%
==========================================
Files 470 470
Lines 57184 57183 -1
Branches 9195 9195
==========================================
- Hits 44292 44291 -1
Misses 9823 9823
Partials 3069 3069 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
speth
approved these changes
Nov 24, 2026
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.
Changes proposed in this pull request
In the current implementation of
getMixDiffCoeffsMass, a mixture where the mass fraction of one species is 1 will cause a division by zero when calculatingsum2:cantera/src/transport/GasTransport.cpp
Lines 259 to 260 in 25c1ab1
In principle, this is not wrong, since the next line divides by
sum2so thatd[k]is correctly set to zero. However, if Cantera is running in an environment where floating point exceptions are trapped, the code fails:The other diffusion coefficient functions (
getMixDiffCoeffsandgetMixDiffCoeffsMole) explicitly handle this case:cantera/src/transport/GasTransport.cpp
Line 191 in 25c1ab1
cantera/src/transport/GasTransport.cpp
Line 222 in 25c1ab1
The proposed fix is to rearrange the calculation to
double denom = mmw - m_mw[k]*m_molefracs[k]; d[k] = denom / std::max(Tiny, p*(denom*sum1 + m_molefracs[k]*sum2));This should not significantly affect performance, correctly recovers
d[k] = 0for unity mass fraction, makes the code safe to use in environments with floating point trapping and also makes the behavior ofgetMixDiffCoeffsMassconsistent with its counterparts. The treatment withstd::max(Tiny, ...)is consistent with other parts of the transport code, e.g.:cantera/src/transport/MixTransport.cpp
Line 185 in 25c1ab1
AI Statement (required)
Checklist
scons build&scons test) and unit tests address code coverage