Skip to content

Commit 8c565ae

Browse files
authored
Merge pull request #155 from KingsburyLab/bugfix
Fix erroneous guard statement in pH charge balancing
2 parents 9291d27 + 1326d59 commit 8c565ae

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.4] - 2024-07-28
9+
10+
### Fixed
11+
12+
- `Solution`: Fix a bug in`pH` charge balancing that erroneously prevented charge
13+
balancing from occurring in certain cases, and raised an error.
14+
815
## [1.1.3] - 2024-07-28
916

1017
### Fixed

src/pyEQL/solution.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -2306,11 +2306,8 @@ def _adjust_charge_balance(self, atol=1e-8) -> None:
23062306
start_imbalance = C_hplus - K_W / C_hplus
23072307
new_imbalance = start_imbalance - cb
23082308
# calculate the new concentration of H+ that will balance the charge
2309-
# solve H^2 - new_imbalance H - K_W = 0, so a=1, b=-new_imbalance, c=-K_W
2310-
# check b^2 - 4ac; are there any real roots?
2311-
if new_imbalance**2 - 4 * 1 * K_W < 0:
2312-
self.logger.error("Cannot balance charge by adjusting pH. The imbalance is too large.")
2313-
return
2309+
# solve H^2 - new_imbalance H - K_W = 0, so a=1, b=-new_imbalance, c=-K_W. Note that this is guaranteed to have real roots as
2310+
# b^2-4ac > 0
23142311
new_hplus = max(
23152312
[
23162313
(new_imbalance + np.sqrt(new_imbalance**2 + 4 * 1 * K_W)) / 2,

0 commit comments

Comments
 (0)