Skip to content
Merged
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
11 changes: 9 additions & 2 deletions src/pyEQL/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ def equilibrate(
# tolerance (in moles) for detecting cases where an element amount
# is no longer balanced because of species that are not recognized
# by PHREEQC.
_atol = 1e-16
_rtol = 0.05 # differing by more than 5%

new_el_dict = solution.get_el_amt_dict(nested=True)
for el in orig_el_dict:
Expand All @@ -770,7 +770,8 @@ def equilibrate(

# If this element went "missing", add back all components that
# contain this element (for any valence value)
if orig_el_amount - new_el_amount > _atol:
# if orig_el_amount - new_el_amount > _atol:
if new_el_amount == 0 and orig_el_amount > 0:
logger.info(
f"PHREEQC discarded element {el} during equilibration. Adding all components for this element."
)
Expand All @@ -782,6 +783,12 @@ def equilibrate(
if component not in solution.components
}
)
elif abs(orig_el_amount - new_el_amount) / orig_el_amount > _rtol:
logger.warning(
f"PHREEQC returned a total Element {el} concentration of {new_el_amount} mol, "
f"which differs from the original concentration of {orig_el_amount}. This "
"should never occur and indicates an error in the PHREEQC database or calculation."
)

# re-adjust charge balance for any missing species
# note that if balance_charge is set, it will have been passed to PHREEQC, so the only reason to re-adjust charge balance here is to account for any missing species.
Expand Down
Loading