diff --git a/CHANGELOG.md b/CHANGELOG.md index 607ae27..4683856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/pyEQL/solution.py b/src/pyEQL/solution.py index 834317e..080cd09 100644 --- a/src/pyEQL/solution.py +++ b/src/pyEQL/solution.py @@ -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,