Improve numerical stability of exchange current density and OCPs#5371
Merged
MarcBerliner merged 30 commits intomainfrom Feb 5, 2026
Merged
Improve numerical stability of exchange current density and OCPs#5371MarcBerliner merged 30 commits intomainfrom
MarcBerliner merged 30 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5371 +/- ##
==========================================
+ Coverage 98.03% 98.32% +0.28%
==========================================
Files 327 328 +1
Lines 28690 28941 +251
==========================================
+ Hits 28126 28455 +329
+ Misses 564 486 -78 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
BradyPlanden
reviewed
Feb 4, 2026
Member
BradyPlanden
left a comment
There was a problem hiding this comment.
Thanks @MarcBerliner - this is looking good. Just a few questions / comments
BradyPlanden
previously approved these changes
Feb 5, 2026
Member
BradyPlanden
left a comment
There was a problem hiding this comment.
Looks great, thanks @MarcBerliner! Just one non-blocking comment
Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com>
BradyPlanden
approved these changes
Feb 5, 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.
Description
Exchange current densities include
sqrt(c_e),sqrt(c_s), andsqrt(c_max - c_s)terms that blow up when concentrations -> 0/c_max. Inverse BV kinetics doarcsinh(j/j0), which also blows up whenj0is small or causes divide by zero errors forj0=0. These cause solver failures in edge casesThis PR adds regularised versions of two expressions:
RegPower(x, a): approximates|x|^a * sign(x)but stays linear near zero (based on modelica'sregPow)Arcsinh2(a, b): computesarcsinh(a/b)while avoiding blowup/division by zero errors asb -> 0Major changes:
Sqrt/Power->RegPowerto make them more numerically stable at small concentrations1e-6/stoto a more complicated logarithmic expression, whose parameters were tuned to provide a barrier of 1 mV atsto = 0.001and 1000 mV atsto = 0. This is a significant from the previous version because we no longer have an asymptote as sto -> 0. Some calculations that relied on this assumption, like the ESOH solver, will have slightly different answers in this extreme limit. Most usecases will not changeType of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)
Important checks:
Please confirm the following before marking the PR as ready for review:
nox -s pre-commitnox -s testsnox -s doctests