Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pyEQL/presets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Partial pressures of reactive gases in atmosphere
# Obtained from https://www.noaa.gov/jetstream/atmosphere on 12/15/25
# (N2=78.084%, O2=20.946%, CO2=0.042%)
ATMOSPHERE = {"N2": -0.1074379, "CO2": -3.3767507, "O2": -0.6788989}
# The entry "N2": -0.1074379 was removed from ATMOSPHERE because the inert N2 is incorrectly reacting with O2 to form NO3-.
# See related discussion on the PHREEQC forum:https://phreeqcusers.org/index.php?topic=2371.0
ATMOSPHERE = {"CO2": -3.3767507, "O2": -0.6788989}

# The amount, in moles, of an assemblage of pure phases that can react
# reversibly with the aqueous phase.
Expand Down
13 changes: 8 additions & 5 deletions tests/test_engine_phreeqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ def test_init_engines():
s.engine._destroy_ppsol()
assert s.engine.ppsol is None


def test_osmotic_pressure():
s1 = Solution([["Na+", "1 mol/L"], ["SO4-2", "0.5 mol/L"]], engine="phreeqc")
s2 = Solution([["Na+", "1 mol/L"], ["SO4-2", "0.5 mol/L"]], engine="ideal")
assert np.isclose(s1.osmotic_pressure.to("MPa").magnitude, s2.osmotic_pressure.to("MPa").magnitude), f"PHREEQC = {s1.osmotic_pressure.to('MPa').magnitude} MPa, Ideal = {s2.osmotic_pressure.to('MPa').magnitude} MPa"
assert np.isclose(s1.osmotic_pressure.to("MPa").magnitude, s2.osmotic_pressure.to("MPa").magnitude), (
f"PHREEQC = {s1.osmotic_pressure.to('MPa').magnitude} MPa, Ideal = {s2.osmotic_pressure.to('MPa').magnitude} MPa"
)


def test_conductivity(s1):
Expand Down Expand Up @@ -388,7 +391,7 @@ def test_alkalinity():
def test_equilibrate_2L():
solution = Solution({"Cu+2": "1 umol/L", "O-2": "1 umol/L"}, volume="2 L", engine="phreeqc")
solution.equilibrate(atmosphere=True)
assert np.isclose(solution.get_total_amount("Cu", "umol").magnitude, 1.9999998687384424)
assert np.isclose(solution.get_total_amount("Cu", "umol").magnitude, 1.9999, atol=1e-1) # PHREEQCUI - 2e-06


def test_equilibrate_unrecognized_component():
Expand Down Expand Up @@ -420,6 +423,6 @@ def test_equilibrate_with_atm():
s1 = Solution({}, pH=7.0, volume="1 L", engine="phreeqc")
s1.equilibrate(atmosphere=True)
# PHREEQCUI final CO2, O2, and N2 concentrations were slightly adjusted for consistency with wrapper outputs
assert np.isclose(s1.get_amount("CO2(aq)", "mol/L").magnitude, 1.3839163960791439e-05) # PHREQCUI - 1.389e-05
assert np.isclose(s1.get_amount("O2(aq)", "mol/L").magnitude, 0.00025982718533575387) # PHREEQCUI - 2.615e-04
assert np.isclose(s1.get_amount("N2(aq)", "mol/L").magnitude, 0.0005043306329272451) # PHREEQCUI - 5.064e-04
assert np.isclose(s1.get_amount("CO2(aq)", "mol/kg").magnitude, 0.00001429, atol=1e-6) # PHREQCUI - 1.429e-05
assert np.isclose(s1.get_amount("O2(aq)", "mol/kg").magnitude, 0.0002683, atol=1e-6) # PHREEQCUI - 2.683e-04
assert np.isclose(s1.get_amount("N2(aq)", "mol/kg").magnitude, 0) # PHREEQCUI - 0
14 changes: 9 additions & 5 deletions tests/test_engine_phreeqc2026.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ def test_init_engines():
s.engine._destroy_ppsol()
assert s.engine.ppsol is None


def test_osmotic_pressure():
s1 = Solution([["Na+", "1 mol/L"], ["SO4-2", "0.5 mol/L"]], engine="phreeqc2026")
s2 = Solution([["Na+", "1 mol/L"], ["SO4-2", "0.5 mol/L"]], engine="ideal")
assert np.isclose(s1.osmotic_pressure.to("MPa").magnitude, s2.osmotic_pressure.to("MPa").magnitude), f"PHREEQC2026 = {s1.osmotic_pressure.to('MPa').magnitude} MPa, Ideal = {s2.osmotic_pressure.to('MPa').magnitude} MPa"
assert np.isclose(s1.osmotic_pressure.to("MPa").magnitude, s2.osmotic_pressure.to("MPa").magnitude), (
f"PHREEQC2026 = {s1.osmotic_pressure.to('MPa').magnitude} MPa, Ideal = {s2.osmotic_pressure.to('MPa').magnitude} MPa"
)


def test_conductivity(s1):
# even an empty solution should have some conductivity
Expand Down Expand Up @@ -392,7 +396,7 @@ def test_alkalinity():
def test_equilibrate_2L():
solution = Solution({"Cu+2": "1 umol/L", "O-2": "1 umol/L"}, volume="2 L", engine="phreeqc2026")
solution.equilibrate(atmosphere=True)
assert np.isclose(solution.get_total_amount("Cu", "umol").magnitude, 1.9999998687384424)
assert np.isclose(solution.get_total_amount("Cu", "umol").magnitude, 1.999, atol=1e-1) # PHREEQCUI - 2e-06


def test_equilibrate_unrecognized_component():
Expand Down Expand Up @@ -424,6 +428,6 @@ def test_equilibrate_with_atm():
s1 = Solution({}, pH=7.0, volume="1 L", engine="phreeqc2026")
s1.equilibrate(atmosphere=True)
# PHREEQCUI final CO2, O2, and N2 concentrations were slightly adjusted for consistency with wrapper outputs
assert np.isclose(s1.get_amount("CO2(aq)", "mol/L").magnitude, 1.397209520185121e-05) # PHREQCUI - 1.389e-05
assert np.isclose(s1.get_amount("O2(aq)", "mol/L").magnitude, 0.00025982718533575387) # PHREEQCUI - 2.615e-04
assert np.isclose(s1.get_amount("N2(aq)", "mol/L").magnitude, 0.0005043306329272451) # PHREEQCUI - 5.064e-04
assert np.isclose(s1.get_amount("CO2(aq)", "mol/kg").magnitude, 0.00001429, atol=1e-6) # PHREQCUI - 1.429e-05
assert np.isclose(s1.get_amount("O2(aq)", "mol/kg").magnitude, 0.0002683, atol=1e-6) # PHREEQCUI - 2.683e-04
assert np.isclose(s1.get_amount("N2(aq)", "mol/kg").magnitude, 0) # PHREEQCUI - 0
Loading