PhreeqcUsers Discussion Forum

Processes => Mixing => Topic started by: Jean on June 28, 2018, 10:47:33 AM

Title: unknown proportions of a mixing to reach a given pH
Post by: Jean on June 28, 2018, 10:47:33 AM
Given 2 solutions, is it possible to determine what mixing fractions of each will produce a mixing having a given pH (choosen between the pH's of both initial solutions) ?
Title: Re: unknown proportions of a mixing to reach a given pH
Post by: dlparkhurst on June 28, 2018, 04:16:40 PM
First, the pH of a mixture is not necessarily between the pH of the two end members (for the curious, see below), so there may be two mixtures that produce a given pH.

But, no, I don't think there is an automated way to find the mixing proportion that gives a specific pH without some scripting heroics. The simplest approach is to run a series of mixes and interpolate the mixing proportion that gives the desired pH. Here is my heroic attempt that shows pH values outside the values of the end members.

Code: [Select]
SOLUTION 1  SEAWATER FROM NORDSTROM AND OTHERS (1979)
        units   ppm
        pH      8.22
        pe      8.451
        density 1.023
        temp    25.0
        Ca              412.3
        Mg              1291.8
        Na              10768.0
        K               399.1
        Si              4.28
        Cl              19353.0
        Alkalinity      141.682 as HCO3
        S(6)            2712.0
USER_PRINT
10 if (EXISTS(1) = 0) then PUT(TOT("Cl"), 1)
END
SOLUTION 2
END
USE solution 2
EQUILIBRIUM_PHASES
Calcite
CO2(g)  -2.0 10
SAVE solution 2
USER_PRINT
10 if (exists(2) = 0) then PUT(TOT("Cl"),2)
END
USER_GRAPH 1
    -axis_titles            "Mixing fraction" "pH" ""
    -axis_scale x_axis      0 1 auto auto
    -initial_solutions      false
    -connect_simulations    true
    -plot_concentration_vs  x
  -start
10 graph_x (TOT("Cl") - GET(2))/(GET(1) - GET(2))
20 graph_y -LA("H+")
  -end
    -active                 true
END
SOLUTION 3
SELECTED_OUTPUT 3
-file mixes
USER_PUNCH 3
5 n = 41
10 for  i = 1 to n
20   f = (i - 1) / (n - 1)
30   PUNCH "MIX 1", EOL$
40   PUNCH "1 ", 1 - f, EOL$
50   PUNCH "2 ", f, EOL$
60   PUNCH "END", EOL$
70 next i
END
SELECTED_OUTPUT 3
-active false
INCLUDE$ mixes
END
Title: Re: unknown proportions of a mixing to reach a given pH
Post by: John Mahoney on June 29, 2018, 06:30:45 PM
You should be able to solve this problem using PhreePlot.  This is basically a one parameter fitting problem and in PhreePlot it is called a root finder. See the PhreePlot User's guide.

You will need a simple datafile that lists the final pH. it will look like this:

pH_fit
5.5

I named it fixpH.dat, the parameter name is called pH_fit, and  in this case I have selected a pH of 5.5 for the final mixture.

Then you will need a PhreePlot file set up to do a fit.  Copied below but also attached.  This file was called "SIMPLE mix to get pH.ppi"

Code: [Select]
# Example of fitting  root finding a mixture
SPECIATION
  jobtitle                             "mixing proportions"
  calculationType                      fit
  calculationMethod                    1
  database                             "WATEQ4F.dat"
  debug      3
   
FIT
fitMethod        bobyqa
  dataFile                            "fixpH.dat"  # file containing observations and independent variables
  onepass                              true
  mainLoop                             1            # main (iterating) loop starts at first simulation (relative to start of block)
  dependentVariableColumnObs           pH_fit     # column in onepoint.dat
  dependentVariableColumnCalc          pH    # column in selected output
  fitMaxStepSize                       .2
  fitFiniteDiffStepSize                1.0E-05      # initial step size for parameter adjustment
  numberOfFitParameters                1
  fitParameterNames                    "FitMIX" 
  fitLogParameters                     0   
  fitAdjustableParameters              1          # 1 .= adjustable, 0 = fixed
  fitParameterValues                   .1       # initial values
  fitConvergenceCriterion              1e-7
  numericTag    <FIT_diff> = "1-<FitMIX>"
   fitUpperParameterValues                1.                # initial values
   fitLowerParametervalues   0.0 
 
PLOT
  plotfactor 0   # turns off Plotting
CHEMISTRY
PRINT
    -reset     t
SOLUTION 1   CaCO3 Solution
units mg/L
Ca 20
Alkalinity 100
pH 8.3
END

SOLUTION 2
units mg/L
pH 7
REACTION
H2SO4
0.0001 moles
SAVE SOLUTION 2

END
SELECTED_OUTPUT
-file sel.xls
-reset false

USER_PUNCH
-headings pH
-start
10 PUNCH -LA("H+")
-end

 MIX
1 <FitMIX>
2 <FIT_diff>
END

 


In this case we have a calcium carbonate solution pH of 8.3,  mixing with a sulfuric acid solution (this is done so you can go back and easily check the final proportions) with a pH of 3.7.  The Ca, CO3  solution is slightly oversaturated with respect to Calcite, but we are not including equilibrium phases in this simple example.   I just wanted some simple round numbers for the solution 1 composition.

We are going to adjust the FitMIX parameter in the mixing block to get the final pH of 5.5 - just a number I selected.  We use a numerical tag to calculate the other mixing parameter such that the sum of the two parameters equals 1.   

numericTag    <FIT_diff> = "1-<FitMIX>"

We used the bound optimization option BOBYQA to avoid negative mixing values, and in this case we can confine the upper and lower limits for FitMIX

fitUpperParameterValues   1.0                # initial values
fitLowerParametervalues   0.0 

After running the simulation we look at the SIMPLE mix to get pH.log file and we get



0 degrees of freedom.
TSS     =   0.0000000000000E+00
   RSS     =   2.1714825485070E-21
   Max res =   4.6599168967987E-11  (2)

Final estimates (bobyqa)
---------------
      FitMIX            =   1.0094274429310E-01


   Looking at other portions of the log file we see that it took 32 interations.

So the final solution is about 10% of solution 1 the  CaCO3 solution and 90% of solution 2 H2SO4 solution. 

The RSS is exceedingly small because we only have a single data point to fit to, that is the definition of root finding. 

Rerunning in PHREEQC  to confirm using the values from PhreePlot, I get 5.5 for the final pH,  but I needed  to use all the decimal values to get the final number.  It seems to be very sensitive to the mixing proportion.   A simple 0.1 and 0.9 values for the mixture got me 5.468 for the pH, close but not perfect. 


Use this as a template, but it still might take some effort to get your final result.

Final Notes: These tags are case sensitive.   Watch out for other buffering reactions in your system.   
GOOD LUCK
 

 
Title: Re: unknown proportions of a mixing to reach a given pH
Post by: rm on February 08, 2019, 09:35:57 PM
hello-

I was wondering if I know the mixing ratio can I get the pH using PhreePlot as well. Thanks!
Title: Re: unknown proportions of a mixing to reach a given pH
Post by: John Mahoney on February 08, 2019, 11:22:32 PM
I was a little confused about your question did you mean PHREEQC and not PhreePlot?  GOing on what you did ask then Yes,  PhreePlot can run and output regular PHREEQC models.  But  I cannot say that I have ever done that, for such a simple like the one you describe (you now indicate that you have the mixing proportions),  I would just go to PHREEQC if it is just a simple model because setup of PhreePlot is not user friendly as it is a batch type program. 

JOHN