Repository navigation
Remove Ion.positive: the conductivity uses concentrations as they are - #23
Merged
Merged
Conversation
jorgensd
force-pushed
the
dokken/proton-membrane
branch
from
November 12, 2026 10:15
135abc7 to
e789910
Compare
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.
What changed
Ionno longer has thepositiveflag.Electrolyte.concentration(name)has nopositiveargument and always returns the concentration with its sign: the field of a transported ion, or the electroneutrality expression for the balanced one.Electrolyte.conductivitynow uses the concentrations as they are. Before, it used the smooth positive part(c + sqrt(c^2 + floor^2)) / 2of each flagged ion.ButlerVolmerand its subclasses still take the positive part of the reduced and oxidized ions, now by callingElectrolyte.positive_partexplicitly. Before, the flag had no effect on them: they always passedpositive=True. TheIondocstring wrongly claimed that the flag controlled the kinetics.Electrolyte.current_densitynow states that it is the charge the ions carry,F sum_j z_j N_j.positive=Trueandpositive=Falsearguments: the 1D, 2D and 3D vanadium demos, the half-cell test fixtures,RedoxHalfCell.minimum_balanced_concentration, and the stoichiometry inkinetics.py. The 1D demo's text now says that the kinetics take the positive part.Why
A concentration can undershoot zero, for example in Newton iterates, in Galerkin oscillations at advection-dominated fronts, or where an active ion runs out at high current.
k_a c_red - k_c c_ox, a negative concentration flips the sign of its term, so the reaction keeps consuming an ion that isn't there and drives it further negative. Nernst'sln(c_ox / c_red)becomes NaN.c >= 0, the positive part differs fromconly by about the floor (1e-14 mol/m^3).-kappa grad(phi) - F sum_j z_j D_j grad(c_j)equalsF sum_j z_j N_jonly ifkappauses the same concentrations. With the flag, conduction did not carry the charge the ions moved wherever a flagged ion went negative.Ions of higher valence
The positive part acts on the concentration, not the charge, so an ion's valence doesn't decide whether it needs one. Valence affects how much an undershoot costs:
z^2 D c. A negative V2+ or SO4 2- concentration lowerskappafour times as much as a monovalent ion would, and V3+ nine times as much. That is a reason to keep these concentrations exact, not to clip them.sum_j z_j c_j / 2over the other ions, so an errordeltain V3+ shifts sulfate by3 delta / 2.RedoxHalfCell.minimum_balanced_concentrationchecks for this.Tests
test_the_current_is_the_charge_the_ions_carryintests/electrochemistry/test_electrolyte.py. It checks that the electrolyte current equalsF sum_j z_j N_jover every ion, including sulfate from electroneutrality.test_positive_ions_take_the_positive_partis replaced bytest_concentrations_keep_their_sign.