Vitens / phreeqpython

Object-oriented python wrapper for the VIPhreeqc module
Apache License 2.0
68 stars 19 forks source link

Unexpected return value from Solution.total() method #30

Closed scharlton2 closed 1 year ago

scharlton2 commented 1 year ago

I ran the example included on the README.md file of your repository (also see #28) and got bad output from the Solution.total() method.

This file contains a jupyter notebook that demonstrates the discrepancy: phreeqpython-readme.zip

This might be due to a problem with the https://github.com/Vitens/VIPhreeqc codebase.

AbelHeinsbroek commented 1 year ago

Hi!

I think it's high time to update the README.MD, as I think the 0.497 mmol Solution.total responds with is correct. Lets go over the current example:

solution = pp.add_solution_simple({'CaCl2':1.0,'NaHCO3':2.0})
solution.add('NaOH',0.5)
solution.desaturate('Calcite')  # desaturate to SI 0
print(solution.total('Ca'))

We start by defining a solution of 1 mmol CaCl2 and 2 mmol NaHCO3. We then add some sodium hydroxide (NaOH) and tell PHREEQC to precipitate Calcite (CaCO3) to a solubility index of 0.

By precipitating CaCO3 the amount of Ca in solution has to go down, ergo, the concentration of Ca in the solution cannot be 1 mmol.

If you run following code example in PHREEQC:

DATABASE vitens.dat

SOLUTION 0
-temp 25
REACTION 1
CaCl2 1.0
NaHCO3 2.0
1 mmol
SAVE SOLUTION 0
END

USE SOLUTION 0
REACTION 1
NaOH 0.0005
1 mol
SAVE SOLUTION 0
END

USE SOLUTION 0
EQUILIBRIUM PHASES 1
Calcite 0 0
SAVE SOLUTION 0
END 
Reaction step 1.

Using solution 0.   Solution after simulation 2.
Using pure phase assemblage 1.  PHASES 1

-------------------------------Phase assemblage--------------------------------

                                                      Moles in assemblage
Phase               SI  log IAP  log K(T, P)   Initial       Final       Delta

Calcite           0.00    -8.48     -8.48    0.000e+00   5.026e-04   5.026e-04

-----------------------------Solution composition------------------------------

    Elements           Molality       Moles

    C                 1.497e-03   1.497e-03
    Ca                *4.974e-04*   4.974e-04
    Cl                2.000e-03   2.000e-03
    Na                2.500e-03   2.500e-03

Which is the same as PhreeqPython responds with!

scharlton2 commented 1 year ago

Hi,

Yes, my own confirmation bias got me on this one. I was looking at the wrong 'Solution composition'.

Sorry about that.