Skip to content

Commit

Permalink
Fix erroneous guard statement
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Jul 28, 2024
1 parent 9291d27 commit 1326d59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.4] - 2024-07-28

### Fixed

- `Solution`: Fix a bug in`pH` charge balancing that erroneously prevented charge
balancing from occurring in certain cases, and raised an error.

## [1.1.3] - 2024-07-28

### Fixed
Expand Down
7 changes: 2 additions & 5 deletions src/pyEQL/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2306,11 +2306,8 @@ def _adjust_charge_balance(self, atol=1e-8) -> None:
start_imbalance = C_hplus - K_W / C_hplus
new_imbalance = start_imbalance - cb
# calculate the new concentration of H+ that will balance the charge
# solve H^2 - new_imbalance H - K_W = 0, so a=1, b=-new_imbalance, c=-K_W
# check b^2 - 4ac; are there any real roots?
if new_imbalance**2 - 4 * 1 * K_W < 0:
self.logger.error("Cannot balance charge by adjusting pH. The imbalance is too large.")
return
# 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
# b^2-4ac > 0
new_hplus = max(
[
(new_imbalance + np.sqrt(new_imbalance**2 + 4 * 1 * K_W)) / 2,
Expand Down

0 comments on commit 1326d59

Please sign in to comment.