paleolimbot / tidyphreeqc

Tidy geochemical modeling using PHREEQC
22 stars 3 forks source link

SAVE and USE blocks #14

Closed alex-bagnoud closed 2 years ago

alex-bagnoud commented 3 years ago

Dear Paleolimbot,

Thanks a lot for putting together this tidyphreeqc package for R, that's really useful!

I have a question. How the PHREEQC blocks "SAVE" and "USE" are translated in tidyphreeqc?

Basically, I am trying to reproduce that PHREEQC code into tidyphreeqc:

DATABASE c:\phreeqc\database\Amm.dat SOLUTION 1 -Temp 23 -units mg/L -pH 7.79 -water 0.9 Alkalinity 3218 Amm 960 Ca 165 Mg 27.7 K 1 charge_balance

REACTION 1 CO2(g) 1 -2.5e-3 moles

SELECTED_OUTPUT -file 1-centratYLB_filiereClassique.csv -pH -molalities Ca+2 Mg+2 CO2 HCO3- CO3-2 Amm H+ OH- -totals Ca Mg C(4) S(6) -alkalinity -equilibrium_phases Calcite Dolomite -saturation_indices Calcite Dolomite

SAVE solution 1 END

REACTION 2 NaOH 1 0.0415 moles USE solution 1 END

Thanks in advance for your help!

Best regards,

Alexandre

paleolimbot commented 2 years ago

You can use raw text to reproduce blocks that haven't been implemented yet (or if you already have text):

tidyphreeqc::phr_run("
SOLUTION 1
-Temp 23
-units mg/L
-pH 7.79
-water 0.9
Alkalinity 3218
Amm 960
Ca 165
Mg 27.7
K 1 charge_balance

REACTION 1
CO2(g) 1
-2.5e-3 moles

SELECTED_OUTPUT
-file 1-centratYLB_filiereClassique.csv
-pH
-molalities Ca+2 Mg+2 CO2 HCO3- CO3-2 Amm H+ OH-
-totals Ca Mg C(4) S(6)
-alkalinity
-equilibrium_phases Calcite Dolomite
-saturation_indices Calcite Dolomite

SAVE solution 1
END

REACTION 2
NaOH 1
0.0415 moles
USE solution 1
END
                     ")
#> <phr_run_output>
#> PHREEQC run with 1 selected output(s)
#> Raw output at '/var/folders/gt/l87wjg8s7312zs9s7c1fgs900000gn/T//RtmpWvCLG6/file127e443c5f46'
#> as_tibble():
#> # A tibble: 3 × 28
#>   selected_output   sim state   soln dist_x  time  step    pH    pe `Alk(eq/kgw)`
#>   <chr>           <int> <chr>  <int>  <dbl> <dbl> <int> <dbl> <dbl>         <dbl>
#> 1 n1                  1 i_soln     1     NA    NA    NA  7.79  4           0.0645
#> 2 n1                  1 react      1     NA     0     1  8.34 -2.81        0.0645
#> 3 n1                  2 react      1     NA     0     1 10.4  -4.87        0.111 
#> # … with 18 more variables: Ca(mol/kgw) <dbl>, Mg(mol/kgw) <dbl>,
#> #   C(4)(mol/kgw) <dbl>, S(6)(mol/kgw) <dbl>, m_Ca+2(mol/kgw) <dbl>,
#> #   m_Mg+2(mol/kgw) <dbl>, m_CO2(mol/kgw) <dbl>, m_HCO3-(mol/kgw) <dbl>,
#> #   m_CO3-2(mol/kgw) <dbl>, m_Amm(mol/kgw) <dbl>, m_H+(mol/kgw) <dbl>,
#> #   m_OH-(mol/kgw) <dbl>, Calcite <dbl>, d_Calcite <dbl>, Dolomite <dbl>,
#> #   d_Dolomite <dbl>, si_Calcite <dbl>, si_Dolomite <dbl>

Created on 2021-12-07 by the reprex package (v2.0.1)

alex-bagnoud commented 2 years ago

Thanks a lot for your answer! I was hoping that there was a way to save the output of a phr_run() and then to recycle it as an input to a new phr_run().

paleolimbot commented 2 years ago

I think that's beyond the workflow I considered since I'm not a very experienced phreeqc user! If you find something that's useful, feel free to post it on this issue thread (so that others can google it!).