PhreeqcUsers Discussion Forum

Registrations currently disabled due to excessive spam. Please email phreeqcusers at gmail.com to request an account.
Welcome Guest
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Beginners »
  • SELECTED_OUTPUT »
  • Fluoride Speciation, Controlling Factors & Exporting log K
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: Fluoride Speciation, Controlling Factors & Exporting log K  (Read 20952 times)

i_azharkhan

  • Top Contributor
  • Posts: 26
Fluoride Speciation, Controlling Factors & Exporting log K
« on: 11/08/25 09:22 »
Hello everyone,

I?m working on modelling 35 water samples collected from an acid mine drainage site (same general location, but from different spots).
My main objectives are:

1. Calculate the distribution of fluoride species in each sample (F⁻, HF, Al?F complexes, etc.).

2. Identify key factors affecting fluoride speciation?such as pH, ionic strength, major cations/anions, and possible equilibrium with fluoride-bearing minerals.

I have a few specific questions:

Multiple samples: Can we run all 35 samples together in a single PHREEQC input file, or do they need to be run separately?

Output analysis: If we export results to a CSV file after running the model, will it directly identify the key factors controlling fluoride speciation, or will we need to process the output data further (e.g., statistical analysis or correlation) to find those relationships?

Equilibrium phases: Which equilibrium phases are most relevant for fluoride in acidic mine drainage (e.g., fluorite, cryolite, and aluminum fluoride minerals), and how should they be set up in the input?

Exporting log K: From the saturation indices section, how can we export the log K values (equilibrium constants) used for each mineral phase to a CSV or output file?

I have full chemical analyses for all samples (major cations/anions, pH, temperature, etc.) and can format them for PHREEQC?s SOLUTION blocks.

If anyone has example input files, guidance on structuring multiple-sample runs, or advice on interpreting the results to pinpoint fluoride controls, I?d greatly appreciate it.

Thank you!
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #1 on: 11/08/25 15:50 »
Look in the manual at the data block SOLUTION_SPREAD. It allows a tab-delimited table of data where each row is a solution definition. You can enter the data in Excel and then cut and paste into an input file if you want.

When you run the file with a SOLUTION_SPREAD data block, the output file will contain the saturation indices for every mineral of the database that is composed of the elements in the solution.

Data can be written to a tab-delimited output file using the data blocks SELECTED_OUTPUT and USER_PUNCH. USER_PUNCH allows calculation of output values using the Basic functions described in The Basic Interpreter in the manual. One of the functions is LK_PHASE, which give the log K for the phase at the temperature of the calculation.

You will have to study the literature to decide which minerals are relevant to your system.

Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #2 on: 13/08/25 09:10 »
Thank you for your guidance.

I tried running my dataset using the SOLUTION_SPREAD block, but when I run the file, I get errors for all elements saying that the solution ?has not converged.?

Could this be due to certain combinations of concentrations in my samples causing unrealistic charge balance or extremely low/high pH values?
Or is there something in my formatting or units that might be leading to the convergence problem?

Any advice on how to troubleshoot and get the model to converge for all samples would be greatly appreciated.
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #3 on: 13/08/25 14:45 »
Perhaps you have not set the concentration units correctly. Default is mmol/kgw. Use -unots to define mg/L, for example.
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #4 on: 14/08/25 18:02 »
Respected sir, the unit is in mg/L, but I'm still facing the same problem. I will share the input. Please kindly have a look.
Thank you.

SOLUTION_SPREAD
    -units    mg/l
     Al    Alkalinity      Ba      Ca         Cd      Cl          Cu       F       K      Mg         Mn    N(3)    N(5)      Na       P          Pb      pH     S(6)      Sr          Zn      Br        Fe
  mg/l          mg/l    mg/l    mg/l       mg/l    mg/l        mg/l    mg/l    mg/l    mg/l       mg/l    mg/l    mg/l    mg/l    mg/l        mg/l             mg/l    mg/l        mg/l    mg/l      mg/l
    252         17.63    0.03     350    0.04783    8.66       4.558     228    8.45     487     17.267    0.08    24.6    60.8     0.1      0.0089    4.48     3362    1.88       9.392    0.02      0.09
   5.43         35.26    0.16     487    0.04064    8.03        0.15    19.6    8.05     120     16.483    0.96    75.3     239    0.95     0.00018    6.33     2018    7.38       4.064    0.02      0.46
   1397           0.0    0.08     320    1.35149    17.3     100.389     181    3.99    1240     36.954    0.08    14.3    9.25     0.1     0.01164    3.01    14854    0.42     197.612    0.02       212
   0.12         155.8    0.02     860    0.00157     474      0.0809    0.21    8.10    12.4    0.44463    0.08    13.7     391     0.1     0.00002    7.09     2272    0.88       0.179    0.02      0.01
   0.02          22.3    0.04     566    0.00133     419     0.02924    0.43    7.26      11    0.19318    0.08    63.6     384     0.1     0.00003    6.91     1711    0.93       0.109    0.02      0.01
   0.05         164.8    0.05     714    0.00211     904     0.04083    0.24    5.63      59    1.24839    0.08    7.48     453     0.1     0.00001    6.36     1653    0.14     236.886    0.02      0.01
 1030.3           0.0     0.0     254      0.223      14         0.0     149    1.73     898      243.4    0.08    15.1     7.1     0.0       1.652       7     9905     0.0       172.5    0.02       139
   0.01           0.0    0.04     0.0       0.01     0.0        0.01    8.65     0.0     0.0       0.01    0.08     0.0     0.0     0.0        0.01    6.81      0.0     0.0        0.01     0.0      0.02
  60.11           0.0    0.02     0.0       0.01     0.0        1.03    0.51     0.0     0.0      21.44    0.08     0.0     0.0     0.0        0.01    5.21      0.0     0.0         1.7     0.0      0.04
   1539           0.0    0.01     0.0       3.74     0.0       183.8    0.04     0.0     0.0        532    0.08     0.0     0.0     0.0        0.49    3.33      0.0     0.0       354.5     0.0     197.8
 0.1465          22.3     0.0    15.4       1.21     0.0    0.002393    0.39    0.96    2.12       0.01    0.08    18.5    2.32     0.0      0.0009    7.54     14.1     0.0    0.018425     0.0    0.0523
 0.2758          24.1     0.0    16.5       1.23     0.0    0.003488    0.37    1.31    2.11     0.0067    0.08    18.4    2.59     0.0    0.000824    7.56     14.1     0.0        0.02     0.0    0.2237
  3.894         103.3     0.0     474       48.8     0.0     0.01809    13.8    14.4     119      3.759    0.08    16.6    76.9     0.0    0.055257    7.18     1500     0.0    0.100898     0.0     14.86
  0.324         190.2     0.0    68.5        4.8     0.0    0.003904    0.68    2.98    6.75     0.1125    0.08    11.4      61     0.0    0.542209    7.08      112     0.0    0.041691     0.0    0.6535
   34.1         126.2     0.0     634         19     0.0    0.002482    1.43    15.5     222      1.702    0.08    3.71     154     0.0    0.000859     7.3     1470     0.0      0.0209     0.0      70.3
 0.1806            91     0.0     165       16.8     0.0     0.00348     0.9    5.61      40     0.0295    0.08      22    40.2     0.0    0.000538    7.26      476     0.0    0.147055     0.0    0.0521
 0.2568          81.6     0.0    83.1       7.35     0.0    0.003801    0.14     2.3    15.6     0.1349      18      87    8.56     0.0    0.023853    7.17      101     0.0    0.022088     0.0    0.0892
 0.0832          29.6     0.0     100       11.5     0.0    0.002408    0.31    2.91    16.8     0.4923    21.8     209      12     0.0    0.000753    6.68      106     0.0    0.022807     0.0    0.0649
  0.552          24.1     0.0    28.8       3.68     0.0    0.004957    0.36    1.82    3.93     0.0035    0.08    15.3    3.93     0.0    0.000956    7.35     4402     0.0    0.016474     0.0    0.0342
 0.9926          53.7     0.0    28.7       2.35     0.0    0.011647    0.21    1.64     5.3     0.0446    0.08     8.2    6.96     0.0    0.028444    7.73     24.6     0.0    0.034792     0.0      1.08
  1.458          59.3     0.0     237       11.4     0.0    0.011003    2.09    4.27    72.3      1.856    0.08    12.1      39     0.0    0.121578     7.2      830     0.0    0.063056     0.0      2.03
  5.758          55.6     0.0     343        8.2     0.0    0.015322      21    10.9    58.7      8.451    0.08    32.8     226     0.0    0.054212    7.14     1380     0.0    0.302554     0.0     5.346
  102.1          11.1     0.0     514       13.2     0.0    1.109665     103    14.4     341      25.24    0.08    36.3     203     0.0    0.004472    4.77     3098     0.0    2.282672     0.0    0.3502
  63.23          14.8     0.0     520       12.8     0.0    0.596851    67.4    14.2     262       13.8    0.08    38.9     200     0.0    0.000603     5.1     2651     0.0     1.50632     0.0    0.2658
 0.7945         109.8     0.0     454         21     0.0     0.00845    14.6      11     340     0.0221    0.08       4     248     0.0    0.001147       8     2650     0.0    0.014109     0.0    0.5239
    0.0          11.1     0.0     510         12     0.0         0.0    66.7    13.7     292        0.0    0.08    35.4     206     0.0         0.0    5.33     2774     0.0         0.0     0.0       0.0
    0.0           7.4     0.0     520       11.5     0.0         0.0    53.1    13.7     289        0.0    0.08    36.7     200     0.0         0.0    4.99     2802     0.0         0.0     0.0       0.0
  23.66           9.2     0.0     179       6.28     0.0    0.330346    32.4    5.81    80.3      10.07    0.08    35.1    20.9     0.0    0.004062    5.22      715     0.0    1.874565     0.0    0.8982
  2.292          26.8     0.0    47.1       9.19     0.0    0.012326    1.85    3.67    9.69      1.599    0.83      15    10.3     0.0    0.005232     6.5      125     0.0    2.147558     0.0     13.64
 0.6008          29.7     0.0    3.58       7.65     0.0    0.004652    0.93    0.28     0.6     0.0795     6.8    14.5    0.82     0.0    0.583197    6.72     60.2     0.0      0.0396     0.0    0.3729
 0.5907          44.5     0.0     611       5.15     0.0    0.009522    3.56    26.3    78.7     0.0358    0.08    7.64    15.6     0.0    0.003815    7.37    16.98     0.0    0.047802     0.0    0.2901
  2.274         192.7     0.0     517       25.4     0.0    0.009242    28.2    14.6     613      58.76    0.08    4.29     343     0.0    0.000735    3.75     4030     0.0    0.768787     0.0    0.4194
  2.732         247.6     0.0     501       24.2     0.0    0.006868    25.3    11.2     500      48.42    0.08    3.84     366     0.0    0.000937    6.95     3560     0.0    0.335529     0.0    0.5686
   1580           0.0    0.07     334      2.822    11.9     146.804     224    0.57    1775     93.847    0.08    25.5    7.21    0.04     0.00205    2.92    19256    0.27     350.565    0.02      43.5
   0.82            19    0.06     565     0.0501    4.25      0.0637    2.89    12.5     152      6.593    0.08    6.52    9.69    0.04     0.00014    5.12     1990    0.41       1.309    0.02      0.06

SELECTED_OUTPUT 1
    -file                 fluoride_speciation_sample1.csv
    -reset                false
    -solution             true
    -pH                   true
    -temperature          true
    -alkalinity           true
    -totals               F  Al  Ca  Mg  Alkalinity  Fe  Cu
                          Cl  Zn  Sr  N(5)  N(3)  Mn  K
                          Cd  Ba  Br
    -molalities           F-  AlF+2  AlF2+  AlF3
                          AlF4-  CaF+  MgF+  CdF+
                          HF  HF2-  NaF  ZnF+
    -saturation_indices   Fluorite  Barite  Calcite  Basaluminite
                          Gypsum
END

REACTION 1
    Ca(OH)2    1
    0.02 moles in 40 steps
END

EQUILIBRIUM_PHASES 1
    Barite    0 0
    Fluorite  0 0
    Gibbsite  0 0

SELECTED_OUTPUT 2
    -file                 ca_precipitation_sample1.csv
    -reset                false
    -solution             true
    -pH                   true
    -totals               F
    -equilibrium_phases   Fluorite  Gibbsite  Barite
    -saturation_indices   Fluorite  Gibbsite  Barite

USER_GRAPH 1
    -headings               pH F_total
    -axis_titles            "Ca(OH)2" "Fluoride Removal %" "pH"
    -chart_title            "Fluoride Removal with Ca(OH)2 Addition"
    -axis_scale x_axis      0 10 1 1
    -axis_scale y_axis      0 100 10 10
    -axis_scale sy_axis     2 8 1 1
    -initial_solutions      false
    -connect_simulations    true
    -plot_concentration_vs  x
  -start
10 GRAPH_X RXN
20 GRAPH_Y TOT("F") * 19000 (100*(1-TOT("F")/SYS("F")))
30 GRAPH_SY -LA("H+")
  -end
    -active                 true

END
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #5 on: 14/08/25 18:46 »
Post one solution that fails, but use SOLUTION, not solution_spread. I will look at your script if you do that and use the # button above the text box to set off your script.
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #6 on: 15/08/25 16:04 »
Dear respected Sir, Thank you so much.

When I run each solution separately using the SOLUTION block, none of them produce errors; all 35 samples run fine on their own.

However, when I try to run all 35 solutions together in one file using SOLUTION_SPREAD, I get many "did not converge" errors in simulation 1 for multiple elements.

Since all the individual solutions run without issue, I am not sure what is wrong in simulation 1 when they are run together. I also do not know which specific solution in the combined run is causing the problem, because the error message just says simulation 1.

Could you please guide me on how to identify exactly which solution is failing in the combined run?
« Last Edit: 15/08/25 16:07 by i_azharkhan »
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #7 on: 15/08/25 16:19 »
The output file will have the results for each solution in sequence. Each calculation will begin with "Using solution xx". The xx will tell you which solution failed.

If you make a file with one SOLUTION_SPREAD solution that fails, I will look at it. You should not need any additional data blocks if indeed it is the SOLUTION_SPREAD calculation that fails. Unfortunately, the tabs for SOLUTION_SPREAD do not translate in the forum, so I will only edit one SOLUTION_SPREAD entry. Please state the database that you are using.
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #8 on: 15/08/25 17:33 »
Thank you for the clarification.

I checked the output file, and the first 14 solutions run correctly without any errors. However, when it reaches solution 15, it shows the "did not converge" error, and after that, there are no more solutions in the output; the run stops at 15.

I will share SOLUTION 15.

Many thanks for your help.

SOLUTION 15
    temp      25
    pH        7.3
    pe        4
    redox     pe
    units     mg/l
    density   1
    F         1.43
    Cl        19
    N(3)      0.08
    N(5)      3.71
    C(4)      0
    Mg        222
    Ca        634
    Na        154
    K         15.5
    Alkalinity 154
    S(6)      2470
    Cu        0.00248
    Zn        0.0209
    Cd        0.0002
    Pb        0.00086
    Fe        70.3
    Mn        1.702
    Al        34.1
    -water    1 # kg
END
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #9 on: 15/08/25 18:03 »
I think the problem is with your alkalinity. Alkalinity input is the total alkalinity, including carbonate species, but also aluminum and other alkalinity species. In this solution, the alkalinity derived from aluminum is greater than the total alkalinity that you defined.

If you change the Alkalinity heading to C(4), I think the solution will run. At pH 7.3, Alkalinity should be close to C(4), so the error will not be great.

If you add
Code: [Select]
PRINT; -alk
the alkalinity contributions of the various species are printed in a table in the output file.

Logged

MichaelZ20

  • Top Contributor
  • Posts: 174
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #10 on: 15/08/25 18:43 »
Setting C(4) at a small non-zero value (1e-9) also solves the problem
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #11 on: 16/08/25 16:32 »
Respected sir, Thank you so much; it works. I appreciate it.

Sir, I have another request. Can you please have a look at SELECTED_OUTPUT 1, EQUILIBRIUM_PHASES 1, REACTION, USER_GRAPH 1. Is it right, or am I still making any mistakes in it? Also, the USER_PUNCH is not in my input, and to be honest, I don't have any idea what I should need to write and add in this section. If possible, please correct it for me.

Thank you again.
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #12 on: 16/08/25 20:40 »
No, I try not to "check" others' scripts. I can only answer specific questions.
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #13 on: 17/08/25 17:56 »
Okay, sir, thank you, but I have a question.

I set up SELECTED_OUTPUT to export results to a CSV file. The file includes the following headers in the first row:

soln  pH  temp  Alk  mu  F  Al  Ca  Mg  Fe  S(6)  C(4)  Na  K  Cl 
m_F-  m_HF  m_AlF2+  m_AlF3  m_AlF4-  m_CaF+  m_MgF+ 
si_Fluorite  si_Barite  si_Calcite  si_Basaluminite  si_Gypsum

After exporting, I tried to calculate the percentage distribution of fluoride species manually in Excel (e.g.,

%F_free = (m_F- / Total_F) * 100
%F_HF   = (m_HF / Total_F) * 100
%F_AlF2 → = (m_AlF2+ / F) * 100
%F_AlF3 → = (m_AlF3 / F) * 100
%F_AlF4 → = (m_AlF4- / F) * 100
%F_CaF → = (m_CaF+ / F) * 100
%F_MgF → = (m_MgF+ / F) * 100 

For some samples, the results look fine (5%, 10%, etc.), but for others I?m getting strange values in the hundreds or even thousands (e.g., 867%, 9997%).

I think the problem might be in how I?m calculating the percentages or in how the totals are being defined.

My question:
Is there a way in "SELECTED_OUTPUT" (possibly using "USER_PUNCH") to directly calculate and export the actual percentage distribution of fluoride species (%F⁻, %HF, %AlF₂⁺, %AlF₃, %AlF₄⁻, %CaF⁺, %MgF⁺) into the CSV file so that PHREEQC itself ensures the normalisation across all samples?

That would save me from recalculating in Excel and help avoid errors with species totals.

Many thanks!
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #14 on: 17/08/25 19:48 »
You have not accounted for the stoichiometry of the aqueous species. There are 4 moles of F per mole of AlF4-.

Another option is the SYS function which internally accounts for stoichiometry.

Code: [Select]
SOLUTION
pH 7 charge
Al 1
F  3

USER_PRINT
10 t = SYS("F", count , name$ , type$ , moles, 1)
20 FOR i = 1 TO count
30   pct = moles(i) / t * 100
40   PRINT PAD(name$(i), 10), STR_F$(pct, 10, 1)
50   sum = sum + pct
60 NEXT i
70 PRINT PAD("Total", 10), STR_F$(sum, 10, 1)
END
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #15 on: 18/08/25 18:01 »
Respected sir, Thank you for the explanation and for sharing the code example.

I tried adding the SYS("F", ?) block into my input, but I?m still facing the same problem: in the CSV output, some of the percentages still come out strange (some species look fine, but others are much too large).

Maybe I didn?t set up the USER_PUNCH section correctly. Could you please clarify how exactly I should combine the SYS("F", ?) calculation with SELECTED_OUTPUT so that the normalized % values for F species are written directly into the CSV file?

Many thanks again for your help!
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #16 on: 18/08/25 20:48 »
If you want it in the selected output file, it is probably easiest just to write out each species.

Code: [Select]
SOLUTION
pH 7 charge
Al 1
F  3
SELECTED_OUTPUT
-reset false
USER_PUNCH
-heading soln  pH  temp  Alk  mu  F  Al  Ca  Mg  Fe  S(6)  C(4)  Na  K  Cl \
%_F-  %_HF  %_AlF2+  %_AlF3  %_AlF4-  %_CaF+  %_MgF+
10 PUNCH CELL_NO
20 PUNCH -LA("H+")
30 PUNCH TC
40 PUNCH ALK
50 PUNCH MU
60 PUNCH TOT("F"), TOT("Al"), TOT("Ca"), TOT("Mg"), TOT("Fe"), TOT("S(6)")
70 PUNCH TOT("C(4)"), TOT("Na"), TOT("K"), TOT("Cl")
80 t = 100 / TOT("F")
90 PUNCH MOL("F-")*t
100 PUNCH MOL("HF")*t
110 PUNCH 2*MOL("AlF2+")*t
120 PUNCH 3*MOL("AlF3")*t
130 PUNCH 4*MOL("AlF4-")*t
140 PUNCH MOL("CaF+")*t
150 PUNCH MOL("MgF+")*t

END
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #17 on: 28/08/25 08:20 »
Thank you very much, sir, for providing the code.

I have a couple of follow-up questions:

Adding trace elements to SELECTED_OUTPUT
In my dataset, I also have trace elements like Ba, Cd, Cu, Mn, N(3), N(5), Sr, Br, Zn, Pb, and P. Can I add these to the SELECTED_OUTPUT or USER_PUNCH section so that their concentrations (or activities) also appear in the CSV file? I want to investigate their possible role in fluoride removal as well. Also, which molalities and saturation indices do I need to add in SELECTED_OUTPUT as well.

Issue with % values
Even after adding your suggested USER_PUNCH block, the CSV output does not show any percentage columns automatically. When I manually calculate the percentages in Excel, they still look strange (some extremely large or inconsistent, similar to before).

I am attaching the relevant parts of my input file, including:

SELECTED_OUTPUT
EQUILIBRIUM_PHASES
REACTION
USER_PRINT
USER_PUNCH

Could you please review and let me know where I might be making a mistake? I really appreciate your help on this.

SELECTED_OUTPUT 1
    -file                 fluoride_speciation_All.csv
    -reset                false
    -solution             true
    -pH                   true
    -temperature          true
    -alkalinity           true
    -ionic_strength       true
    -totals               F  Al  Ca  Mg  Fe  S(6)  C(4)
                          Na  K  Cl
    -molalities           F-  HF  AlF2+  AlF3
                          AlF4-  CaF+  MgF+  FeF2+
                          FeF3
    -saturation_indices   Fluorite  Barite  Calcite  Basaluminite
                          Gypsum
END

EQUILIBRIUM_PHASES 1
    Barite    0 10
    Fluorite  0 10
    Gibbsite  0 10
END

REACTION 1
    CaCl2      1
    0.02 moles in 40 steps
END

USER_PRINT
10 t = SYS("F", count , name$ , type$ , moles, 1)
20 FOR i = 1 TO count
30   pct = moles(i) / t * 100
40   PRINT PAD(name$(i), 10), STR_F$(pct, 10, 1)
50   sum = sum + pct
60 NEXT i
70 PRINT PAD("Total", 10), STR_F$(sum, 10, 1)
END

USER_PUNCH 1
    -headings soln pH temp Alk mu F Al Ca Mg Fe S(6) C(4) Na K Cl %_F- %_HF %_AlF2+ %_AlF3 %_AlF4- %_CaF+ %_MgF+
    -start
 10 PUNCH CELL_NO
 20 PUNCH -LA("H+")
 30 PUNCH TC
 40 PUNCH ALK
 50 PUNCH MU
 60 PUNCH TOT("F"), TOT("Al"), TOT("Ca"), TOT("Mg"), TOT("Fe"), TOT("S(6)")
 70 PUNCH TOT("C(4)"), TOT("Na"), TOT("K"), TOT("Cl")
 80 t = 100 / TOT("F")
 90 PUNCH MOL("F-")*t
100 PUNCH MOL("HF")*t
110 PUNCH 2*MOL("AlF2+")*t
120 PUNCH 3*MOL("AlF3")*t
130 PUNCH 4*MOL("AlF4-")*t
140 PUNCH MOL("CaF+")*t
150 PUNCH MOL("MgF+")*t
    -end
END

Thank you!
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #18 on: 28/08/25 15:38 »
Yes, you can add more elements with SELECTED_OUTPUT or USER_PUNCH. For USER_PUNCH, refer to the Basic functions listed in the section on the Basic Interpreter.

I have shown you how to calculate percentages. If you have more elements, there may be more aqueous species to consider. For a Ca, Mg, Al, F system, I believe the USER_PUNCH definitions would be correct.

I'm done with this thread, it is getting too long. Please use the # button above the text box to set off scripts.


Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #19 on: 28/08/25 18:58 »
Thank you for the clarification. I just want to confirm one last point: should the USER_PRINT and USER_PUNCH sections always match in terms of calculations and logic?

For example, if I am calculating percentages in USER_PRINT using SYS() or species-specific stoichiometry, do I need to replicate the exact same calculations in USER_PUNCH for the CSV export? Or can they be different (e.g., USER_PRINT for checking and USER_PUNCH for final output)?

Thanks again for all your help!
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #20 on: 28/08/25 22:20 »
USER_PUNCH and USER_PRINT are independent. They are not connected (except possibly for PUT and GET Basic functions).
Logged

i_azharkhan

  • Top Contributor
  • Posts: 26
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #21 on: 10/09/25 09:27 »
Respected Sir,
I have tried several times, but I am still unable to get the percentages directly in the CSV file after running the simulation. The file only contains the parameters that I select in the Selected Output section.
For example, if in total I select the following:

Molalities: F, Al, Ca, Mg, Fe, S(6), C(4)
Saturation Indices: AlF?⁺, AlF₂⁺, AlF₃, AlF₄⁻
Minerals: Fluorite, Barite, Calcite

Then the CSV file contains only these values.
My concern is whether I need to select the percentage of F species separately in the Selected Output section. However, I do not see any option available for percentages in the current menu.

I am also sharing my Selected Output file for your kind guidance. Please advise me on how I can obtain the percentages directly in the CSV file.

SELECTED_OUTPUT 1
    -file                 fluoride_speciation_All.csv
    -reset                false
    -solution             true
    -pH                   true
    -temperature          true
    -alkalinity           true
    -ionic_strength       true
    -totals               F  Al  Ca  Mg  Fe  S(6)  C(4)
                          Na  K  Cl  Ba  Cd  Cu  Mn
                          N(3)  N(5)  Sr  Br  Zn  Pb  P
    -molalities           AlF+2  AlF2+  AlF3  AlF4-
                          CaF+  MgF+  NaF  F-
                          HF  HF2-  H2F2  MnF+
                          ZnF+  CuF+  FeF+  FeF+2
                          FeF2+  FeF3  CdF+  CdF2
                          PbF+  PbF2  PbF3-  PbF4-2
    -saturation_indices   Fluorite  Barite  Calcite  Basaluminite
                          Gypsum  Gibbsite  Fe(OH)3(a)
END
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4296
Re: Fluoride Speciation, Controlling Factors & Exporting log K
« Reply #22 on: 10/09/25 15:25 »
I have explained before how to write percent values to the selected ouput file. Here is a script that prints all of the fluoride species in llnl.dat for the system  containing.

F  Al  Ca  Mg  Fe  S(6)  C(4)
Na  K  Cl  Ba  Cd  Cu  Mn
N(3)  N(5)  Sr  Br  Zn  Pb  P

You can modify as necessary for another database or another system. The sum is not necessary, it is simply a check that the sum of the percentages is 100.

This thread is closed.

Code: [Select]
USER_PUNCH 1
-headings %AlF+2 %AlF2+ %AlF3 %AlF4- %BaF+ %CaF+ %CuF+ %F- %FeF+ %FeF+2 %FeF2+ %H2F2 %H2PO3F %HF %HF2- %HPO3F- %MgF+ %MnF+ %NaF %PO3F-2 %PbF+ %PbF2 %SrF+ %ZnF+  sum%
          10  factor = 100/tot('F')
          40 pct = 1 * MOL('AlF+2') * factor
          50 sum = sum + pct
          60 PUNCH pct
          90 pct = 2 * MOL('AlF2+') * factor
         100 sum = sum + pct
         110 PUNCH pct
         140 pct = 3 * MOL('AlF3') * factor
         150 sum = sum + pct
         160 PUNCH pct
         190 pct = 4 * MOL('AlF4-') * factor
         200 sum = sum + pct
         210 PUNCH pct
         240 pct = 1 * MOL('BaF+') * factor
         250 sum = sum + pct
         260 PUNCH pct
         290 pct = 1 * MOL('CaF+') * factor
         300 sum = sum + pct
         310 PUNCH pct
         340 pct = 1 * MOL('CuF+') * factor
         350 sum = sum + pct
         360 PUNCH pct
         390 pct = 1 * MOL('F-') * factor
         400 sum = sum + pct
         410 PUNCH pct
         440 pct = 1 * MOL('FeF+') * factor
         450 sum = sum + pct
         460 PUNCH pct
         490 pct = 1 * MOL('FeF+2') * factor
         500 sum = sum + pct
         510 PUNCH pct
         540 pct = 2 * MOL('FeF2+') * factor
         550 sum = sum + pct
         560 PUNCH pct
         590 pct = 2 * MOL('H2F2') * factor
         600 sum = sum + pct
         610 PUNCH pct
         640 pct = 1 * MOL('H2PO3F') * factor
         650 sum = sum + pct
         660 PUNCH pct
         690 pct = 1 * MOL('HF') * factor
         700 sum = sum + pct
         710 PUNCH pct
         740 pct = 2 * MOL('HF2-') * factor
         750 sum = sum + pct
         760 PUNCH pct
         790 pct = 1 * MOL('HPO3F-') * factor
         800 sum = sum + pct
         810 PUNCH pct
         840 pct = 1 * MOL('MgF+') * factor
         850 sum = sum + pct
         860 PUNCH pct
         890 pct = 1 * MOL('MnF+') * factor
         900 sum = sum + pct
         910 PUNCH pct
         940 pct = 1 * MOL('NaF') * factor
         950 sum = sum + pct
         960 PUNCH pct
         990 pct = 1 * MOL('PO3F-2') * factor
        1000 sum = sum + pct
        1010 PUNCH pct
        1040 pct = 1 * MOL('PbF+') * factor
        1050 sum = sum + pct
        1060 PUNCH pct
        1090 pct = 2 * MOL('PbF2') * factor
        1100 sum = sum + pct
        1110 PUNCH pct
        1140 pct = 1 * MOL('SrF+') * factor
        1150 sum = sum + pct
        1160 PUNCH pct
        1190 pct = 1 * MOL('ZnF+') * factor
        1200 sum = sum + pct
        1210 PUNCH pct
        1220 PUNCH sum
END
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Beginners »
  • SELECTED_OUTPUT »
  • Fluoride Speciation, Controlling Factors & Exporting log K
 

  • SMF 2.0.19 | SMF © 2021, Simple Machines | Terms and Policies
  • XHTML
  • RSS
  • WAP2