From 6891c324cf1b73742b05c60f8112edecf9d22830 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 15 Aug 2023 15:46:27 -0400 Subject: [PATCH] Solution: adjust vol for T and P changes + add tests --- CHANGELOG.md | 1 + src/pyEQL/solution.py | 14 ++++++++++++++ tests/test_solution.py | 12 +++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac7d2c2..c19aca90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `Solution`: add tests to confirm that solution density changes with temperature and pressure - `Solution`: add tests for `charge_balance`, `alkalinity`, `hardness` - `Solution`: add support for passing solutes as a `dict` - Implement extensible system for connecting `Solution` to various activity and speciation diff --git a/src/pyEQL/solution.py b/src/pyEQL/solution.py index 4d06488a..bc8f598f 100644 --- a/src/pyEQL/solution.py +++ b/src/pyEQL/solution.py @@ -298,6 +298,13 @@ def temperature(self, temperature: str): temperature: pint-compatible string, e.g. '25 degC' """ self._temperature = unit.Quantity(temperature) + + # update the water substance + self.water_substance = IAPWS95( + T=self.temperature.magnitude, + P=self.pressure.to("MPa").magnitude, + ) + # recalculate the volume self.volume_update_required = True @@ -315,6 +322,13 @@ def pressure(self, pressure: str): pressure: pint-compatible string, e.g. '1.2 atmC' """ self._pressure = unit.Quantity(pressure) + + # update the water substance + self.water_substance = IAPWS95( + T=self.temperature.magnitude, + P=self.pressure.to("MPa").magnitude, + ) + # recalculate the volume self.volume_update_required = True diff --git a/tests/test_solution.py b/tests/test_solution.py index f0bd1434..93421cfe 100644 --- a/tests/test_solution.py +++ b/tests/test_solution.py @@ -8,7 +8,7 @@ import numpy as np import pytest -from pyEQL import Solution +from pyEQL import Solution, unit @pytest.fixture() @@ -116,6 +116,16 @@ def test_alkalinity_hardness_chargebalance(s3, s5, s6): assert np.isclose(s6.hardness.magnitude, 600, rtol=0.005) assert np.isclose(s6.charge_balance, -0.12) +def test_pressure_temperature(s5): + orig_V = s5.volume + s5.temperature = '50 degC' + assert s5.temperature == unit.Quantity('50 degC') + assert s5.volume > orig_V + intermediate_V = s5.volume + s5.pressure = '2 atm' + assert s5.pressure == unit.Quantity('2 atm') + assert s5.volume < intermediate_V + def test_serialization(s1, s2): assert isinstance(s1.as_dict(), dict) s1_new = Solution.from_dict(s1.as_dict())