Skip to content

Commit

Permalink
Solution: adjust vol for T and P changes + add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkingsbury committed Aug 15, 2023
1 parent 44043c4 commit 6891c32
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/pyEQL/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
12 changes: 11 additions & 1 deletion tests/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import numpy as np
import pytest
from pyEQL import Solution
from pyEQL import Solution, unit


@pytest.fixture()
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 6891c32

Please sign in to comment.