Skip to content

Commit 02e4275

Browse files
authored
Merge pull request #281 from KingsburyLab/bugfix
Bugfix in get_viscosity_kinematic
2 parents 3e7489f + 256bc5d commit 02e4275

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ 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.3.2] - 2025-09-15
9+
10+
### Fixed
11+
12+
- `Solution.get_viscosity_kinematic()`: A recent change to get_salt_dict (#258) created a problem with `get_viscosity_kinetmatic`
13+
in which an empty solution would cause the method to return an error. This has been fixed, and unit tests added for both
14+
`get_viscosity_kinematic` and `get_viscosity_dynamic`.
15+
816
## [1.3.1] - 2025-08-18
917

1018
### Fixed

src/pyEQL/solution.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def viscosity_kinematic(self) -> Quantity:
651651
a0 = a1 = b0 = b1 = 0
652652

653653
# retrieve the parameters for the delta G equations
654-
params = self.get_property(salt.formula, "model_parameters.viscosity_eyring")
654+
params = None if salt is None else self.get_property(salt.formula, "model_parameters.viscosity_eyring")
655655
if params is not None:
656656
a0 = ureg.Quantity(params["a0"]["value"]).magnitude
657657
a1 = ureg.Quantity(params["a1"]["value"]).magnitude
@@ -662,11 +662,16 @@ def viscosity_kinematic(self) -> Quantity:
662662
temperature = self.temperature.to("degC").magnitude
663663
G_123 = a0 + a1 * (temperature) ** 0.75
664664
G_23 = b0 + b1 * (temperature) ** 0.5
665+
666+
# calculate the cation mole fraction
667+
# x_cat = self.get_amount(cation, "fraction")
668+
x_cat = self.get_amount(salt.cation, "fraction").magnitude
665669
else:
666670
# TODO - fall back to the Jones-Dole model! There are currently no eyring parameters in the database!
667671
# proceed with the coefficients equal to zero and log a warning
668-
self.logger.warning(f"Viscosity coefficients for {salt.formula} not found. Viscosity will be approximate.")
672+
self.logger.warning(f"Appropriate viscosity coefficients werenot found. Viscosity will be approximate.")
669673
G_123 = G_23 = 0
674+
x_cat = 0
670675

671676
# get the kinematic viscosity of water, returned by IAPWS in m2/s
672677
nu_w = self.water_substance.nu
@@ -678,10 +683,6 @@ def viscosity_kinematic(self) -> Quantity:
678683
# get the MW of water
679684
MW_w = self.get_property(self.solvent, "molecular_weight").magnitude
680685

681-
# calculate the cation mole fraction
682-
# x_cat = self.get_amount(cation, "fraction")
683-
x_cat = self.get_amount(salt.cation, "fraction").magnitude
684-
685686
# calculate the kinematic viscosity
686687
nu = np.log(nu_w * MW_w / MW) + 15 * x_cat**2 + x_cat**3 * G_123 + 3 * x_cat * G_23 * (1 - 0.05 * x_cat)
687688

tests/test_solution.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def s6_Ca():
9797
)
9898

9999

100-
def test_empty_solution_3():
100+
def test_empty_solution():
101101
# create an empty solution
102102
s1 = Solution(database=None)
103103
# It should return type Solution
@@ -118,6 +118,9 @@ def test_empty_solution_3():
118118
assert np.isclose(s1.pE, 8.5)
119119
# it should contain H2O, H+, and OH- species
120120
assert set(s1.components.keys()) == {"H2O(aq)", "OH[-1]", "H[+1]"}
121+
assert np.isclose(s1.density.to('kg/m**3').magnitude, 997.0479, atol=0.1)
122+
assert np.isclose(s1.viscosity_kinematic.to('mm**2/s').magnitude, 0.8917, atol=1e-3) # 1 cSt = 1 mm2/s
123+
assert np.isclose(s1.viscosity_dynamic, s1.viscosity_kinematic * s1.density, atol=1e-8)
121124

122125

123126
@pytest.mark.skipif(platform.machine() == "arm64" and platform.system() == "Darwin", reason="arm64 not supported")

0 commit comments

Comments
 (0)