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 »
  • Processes »
  • Reactive transport modelling »
  • Convergence error
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: Convergence error  (Read 7264 times)

sharmilan

  • Top Contributor
  • Posts: 45
Convergence error
« on: 24/05/22 23:42 »
Dear Phreeqc experts,

In my chemical equilibrium model, I am receiving the below error.

ERROR: ERROR: Did not converge on g (diffuse layer excess)

could anyone explain how to avoid this problem in my chemical equilibrium model?

Thank you
S.Sharmilan
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4262
Re: Convergence error
« Reply #1 on: 25/05/22 15:19 »
The error is related to the calculation of the composition of the diffuse layer for a surface.

There are two options for the diffuse-layer calculation: -donnan or -diffuse_layer (Borkovec). The -donnan option is much more stable numerically. the -diffuse_layer option is much more subject to convergence problems. So try the -donnan option if you have not.

There could be other issues with charge balance, the thickness of the diffuse layer, or high concentrations. I can't say without more information.

Logged

sharmilan

  • Top Contributor
  • Posts: 45
Re: Convergence error
« Reply #2 on: 25/05/22 20:30 »
Thank you for your reply.

I am using the Donnan model for my surface complexation. Due to other convergence problems, the chemical equilibrium model is throwing the error message fastly. But, the chemical equilibrium model is stuck by the diffuse layer convergence problems without showing an error message easily (it takes more time to throw the error message).

Therefore, could you advise is there any way to speed up or skip that step where the phreeqc_RM model is showing a convergence problem in the diffuse layer?

Thank you
sharmilan.
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4262
Re: Convergence error
« Reply #3 on: 25/05/22 21:20 »
I don't quite understand what you want to happen when there is a convergence problem in the diffuse-layer calculation.

There is a section of code in model.cpp (~5133) that handles the error. If you comment out this section, the model will continue to run as if the surface calculation was successful.

   if (g_iterations >= itmax)
   {
      pr.all = TRUE;
      pr.surface = TRUE;
      pr.species = TRUE;
      pr.use = TRUE;
      print_all();
      error_msg("Did not converge on g (diffuse layer excess)", STOP);
   }
Logged

sharmilan

  • Top Contributor
  • Posts: 45
Re: Convergence error
« Reply #4 on: 27/05/22 23:36 »
Thank you for your reply.

A) Due to convergence problems other than a convergence problem in the diffuse-layer calculation, Phreeqc_RM automatically takes chemical equilibrium data (solution, phases, surface complexation, and etc) from the previous step for the next step calculation. but in a convergence problem in the diffuse-layer calculation, data from the current failure step were taken by Phreeqc_RM code for the next step calculation. As result, I could not continue loop calculation while occurring convergence problem in the diffuse-layer calculation. Could you advise me on how can I continue my chemical equilibrium calculation?   

B) In the Reaction keyword, I didn't include the Al element in the input data. but Phreeqc_RM is taking a certain amount of Al element automatically in REACTION (please see attached file). Could you tell me what is the problem in my chemical equilibrium model?

Thank you
sharmilan.

------------------------------------
Reading input data for simulation 1.
------------------------------------

   KNOBS
   iterations 300
   step_size 10
   pe_step_size 5
   tolerance 1.000000e-15
   diagonal_scale false
   SOLUTION 1
   temp 9.3173
   pH 7.0
   pe 4.0
   units mol/kgw
   density 1.023
   water 1.000000000000E+00
   END
-------------------------------------------
Beginning of initial solution calculations.
-------------------------------------------

Initial solution 1.   

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

   Elements           Molality       Moles

   Pure water     

----------------------------Description of solution----------------------------

                                       pH  =   7.000   
                                       pe  =   4.000   
                        Activity of water  =   1.000
                 Ionic strength (mol/kgw)  =   6.380e-08
                       Mass of water (kg)  =   1.000e+00
                 Total alkalinity (eq/kg)  =  -7.249e-08
                         Temperature (°C)  =   9.32
                  Electrical balance (eq)  =   7.249e-08
 Percent error, 100*(Cat-|An|)/(Cat+|An|)  =  56.81
                               Iterations  =   0
                                  Total H  = 1.110167e+02
                                  Total O  = 5.550837e+01

----------------------------Distribution of species----------------------------

                                               Log       Log       Log    mole V
   Species          Molality    Activity  Molality  Activity     Gamma   cm³/mol

   H+              1.001e-07   1.000e-07    -7.000    -7.000    -0.000      0.00
   OH-             2.756e-08   2.755e-08    -7.560    -7.560    -0.000     (0) 
   H2O             5.551e+01   1.000e+00     1.744     0.000     0.000     18.02
H(0)          1.757e-25
   H2              8.785e-26   8.785e-26   -25.056   -25.056     0.000     (0) 
O(0)          0.000e+00
   O2              0.000e+00   0.000e+00   -47.417   -47.417     0.000     (0) 

------------------------------Saturation indices-------------------------------

  Phase               SI** log IAP   log K(282 K,   1 atm)

  H2(g)           -22.00    -22.00   -0.00  H2
  H2O(g)           -1.91      0.00    1.91  H2O
  O2(g)           -44.67     44.00   88.67  O2

**For a gas, SI = log10(fugacity). Fugacity = pressure * phi / 1 atm.
  For ideal gases, phi = 1.

------------------
End of simulation.
------------------

------------------------------------
Reading input data for simulation 2.
------------------------------------

   REACTION 1
   C 4.544421722336E-03
   Ca 8.757485029940E-03
   Cl 5.466760217995E-01
   K 8.899800521712E-03
   Mg 4.649249125694E-02
   Na 4.115011527252E-01
   S 2.685254491018E-02
   END
------------------
End of simulation.
------------------

------------------------------------
Reading input data for simulation 3.
------------------------------------

   USE solution 1
   USE reaction 1
   SAVE solution 1
   END
-----------------------------------------
Beginning of batch-reaction calculations.
-----------------------------------------

Reaction step 1.

Using solution 1.   
Using reaction 1.   

Reaction 1.   

     1.000e+00 moles of the following reaction have been added:

                    Relative
   Reactant            moles

   C                    0.00454
   Ca                   0.00876
   Cl                   0.54668
   K                    0.00890
   Mg                   0.04649
   Na                   0.41150
   S                    0.02685

                    Relative
   Element             moles
   Al                   0.01751
   C                    0.00454
   Ca                   0.00876
   Cl                   0.54668
   K                    0.00890
   Mg                   0.04649
   Na                   0.41150
   O                    0.03503
   S                    0.02685

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

   Elements           Molality       Moles

   Al                1.752e-02   1.751e-02
   C                 4.546e-03   4.544e-03
   Ca                8.761e-03   8.757e-03
   Cl                5.469e-01   5.467e-01
   K                 8.903e-03   8.900e-03
   Mg                4.651e-02   4.649e-02
   Na                4.117e-01   4.115e-01
   S                 2.686e-02   2.685e-02

----------------------------Description of solution----------------------------

                                       pH  =   6.127      Charge balance
                                       pe  =  -2.407      Adjusted to redox equilibrium
                        Activity of water  =   0.982
                 Ionic strength (mol/kgw)  =   6.373e-01
                       Mass of water (kg)  =   9.996e-01
                 Total alkalinity (eq/kg)  =  -2.143e-01
                       Total CO2 (mol/kg)  =   4.546e-03
                         Temperature (°C)  =   9.32
                  Electrical balance (eq)  =   7.249e-08
 Percent error, 100*(Cat-|An|)/(Cat+|An|)  =   0.00
                               Iterations  =  20
                                  Total H  = 1.110167e+02
                                  Total O  = 5.554340e+01

----------------------------Distribution of species----------------------------

                                               Log       Log       Log    mole V
   Species          Molality    Activity  Molality  Activity     Gamma   cm³/mol

   H+              8.936e-07   7.467e-07    -6.049    -6.127    -0.078      0.00
   OH-             4.202e-09   3.622e-09    -8.377    -8.441    -0.064     (0) 
   H2O             5.551e+01   9.819e-01     1.744    -0.008     0.000     18.02
Al            1.752e-02
   Al(OH)+2        8.145e-03   1.491e-03    -2.089    -2.826    -0.737     (0) 
   Al+3            4.676e-03   3.037e-04    -2.330    -3.518    -1.187     (0) 
   AlO+            1.913e-03   1.343e-03    -2.718    -2.872    -0.154     (0) 
   Al(SO4)+        1.564e-03   1.097e-03    -2.806    -2.960    -0.154     (0) 
   AlO2H           7.700e-04   7.700e-04    -3.113    -3.113     0.000     (0) 
   AlO2-           3.336e-04   2.341e-04    -3.477    -3.631    -0.154     (0) 
   Al(SO4)2-       1.211e-04   8.500e-05    -3.917    -4.071    -0.154     (0) 
C(-4)         3.468e-09
   CH4             3.468e-09   3.468e-09    -8.460    -8.460     0.000     (0) 
C(4)          4.546e-03
   CO2             2.473e-03   2.473e-03    -2.607    -2.607     0.000     (0) 
   HCO3-           1.597e-03   1.092e-03    -2.797    -2.962    -0.165     (0) 
   Mg(HCO3)+       2.494e-04   1.751e-04    -3.603    -3.757    -0.154     (0) 
   NaHCO3          1.821e-04   1.821e-04    -3.740    -3.740     0.000     (0) 
   Ca(HCO3)+       4.282e-05   3.005e-05    -4.368    -4.522    -0.154     (0) 
   NaCO3-          6.318e-07   4.434e-07    -6.199    -6.353    -0.154     (0) 
   Mg(CO3)         5.145e-07   5.145e-07    -6.289    -6.289     0.000     (0) 
   CO3-2           1.962e-07   4.714e-08    -6.707    -7.327    -0.619     (0) 
   CaCO3           1.188e-07   1.188e-07    -6.925    -6.925     0.000     (0) 
Ca            8.761e-03
   Ca+2            8.461e-03   2.098e-03    -2.073    -2.678    -0.606     (0) 
   CaSO4           2.567e-04   2.567e-04    -3.591    -3.591     0.000     (0) 
   Ca(HCO3)+       4.282e-05   3.005e-05    -4.368    -4.522    -0.154     (0) 
   CaCO3           1.188e-07   1.188e-07    -6.925    -6.925     0.000     (0) 
   Ca(OH)+         1.147e-10   8.049e-11    -9.941   -10.094    -0.154     (0) 
Cl(-1)        5.469e-01
   Cl-             5.469e-01   3.486e-01    -0.262    -0.458    -0.196     (0) 
Cl(7)         0.000e+00
   ClO4-           0.000e+00   0.000e+00  -169.719  -169.942    -0.223     (0) 
H(0)          6.373e-11
   H2              3.187e-11   3.187e-11   -10.497   -10.497     0.000     (0) 
K             8.903e-03
   K+              8.867e-03   5.652e-03    -2.052    -2.248    -0.196     (0) 
   KSO4-           3.608e-05   2.532e-05    -4.443    -4.596    -0.154     (0) 
   KOH             5.980e-12   5.980e-12   -11.223   -11.223     0.000     (0) 
Mg            4.651e-02
   Mg+2            4.442e-02   1.355e-02    -1.352    -1.868    -0.516     (0) 
   Mg(SO4)         1.842e-03   1.842e-03    -2.735    -2.735     0.000     (0) 
   Mg(HCO3)+       2.494e-04   1.751e-04    -3.603    -3.757    -0.154     (0) 
   Mg(CO3)         5.145e-07   5.145e-07    -6.289    -6.289     0.000     (0) 
   Mg(OH)+         2.341e-08   1.643e-08    -7.631    -7.784    -0.154     (0) 
Na            4.117e-01
   Na+             4.102e-01   2.913e-01    -0.387    -0.536    -0.149     (0) 
   Na(SO4)-        1.306e-03   9.169e-04    -2.884    -3.038    -0.154     (0) 
   NaHCO3          1.821e-04   1.821e-04    -3.740    -3.740     0.000     (0) 
   NaCO3-          6.318e-07   4.434e-07    -6.199    -6.353    -0.154     (0) 
   NaOH            7.053e-10   7.053e-10    -9.152    -9.152     0.000     (0) 
O(0)          0.000e+00
   O2              0.000e+00   0.000e+00   -76.552   -76.552     0.000     (0) 
S(-2)         1.884e-03
   HS-             1.884e-03   1.283e-03    -2.725    -2.892    -0.167     (0) 
S(2)          1.893e-07
   S2O3-2          9.466e-08   1.733e-08    -7.024    -7.761    -0.737     (0) 
S(4)          7.020e-14
   SO3-2           7.020e-14   1.303e-14   -13.154   -13.885    -0.731     (0) 
S(6)          2.498e-02
   H2S             1.637e-02   1.637e-02    -1.786    -1.786     0.000     (0) 
   SO4-2           3.358e-03   6.528e-04    -2.474    -3.185    -0.711     (0) 
   Mg(SO4)         1.842e-03   1.842e-03    -2.735    -2.735     0.000     (0) 
   Al(SO4)+        1.564e-03   1.097e-03    -2.806    -2.960    -0.154     (0) 
   Na(SO4)-        1.306e-03   9.169e-04    -2.884    -3.038    -0.154     (0) 
   CaSO4           2.567e-04   2.567e-04    -3.591    -3.591     0.000     (0) 
   Al(SO4)2-       1.211e-04   8.500e-05    -3.917    -4.071    -0.154     (0) 
   KSO4-           3.608e-05   2.532e-05    -4.443    -4.596    -0.154     (0) 
   HSO4-           4.496e-08   3.156e-08    -7.347    -7.501    -0.154     (0) 
   HSO3-           1.967e-13   1.381e-13   -12.706   -12.860    -0.154     (0) 
   S-2             9.383e-16   1.718e-16   -15.028   -15.765    -0.737     (0) 

------------------------------Saturation indices-------------------------------

  Phase               SI** log IAP   log K(282 K,   1 atm)

  AlOHam            4.67     -9.77  -14.44  Al(OH)3
  AlOHmic           5.43     -9.77  -15.20  Al(OH)3
  Anh              -1.65     -5.86   -4.21  CaSO4
  Arg              -1.75    -10.00   -8.26  CaCO3
  Brc              -7.59     10.37   17.96  Mg(OH)2
  C12A7          -203.29    -21.74  181.55  (CaO)12(Al2O3)7
  C2AClH5         -12.56      2.76   15.32  Ca2AlCl(OH)6(H2O)2
  C2AH65          -21.67      9.33   31.00  Ca2Al(OH)7(H2O)3
  C2AH7.5         -15.51     -0.43   15.07  Ca2Al2(OH)10(H2O)2.5
  C3A             -66.24      9.20   75.44  (CaO)3Al2O3
  C3AH6           -28.59      9.15   37.74  Ca3Al2O6(H2O)6
  C4AClH10        -25.13      5.52   30.65  Ca4Al2Cl2(OH)12(H2O)4
  C4AH11          -45.39     18.68   64.07  Ca4Al2(OH)14(H2O)4
  C4AH13          -43.35     18.66   62.01  Ca4Al2(OH)14(H2O)6
  C4AH19          -42.82     18.61   61.43  Ca4Al2(OH)14(H2O)12
  C4AsClH12       -24.89      4.37   29.26  Ca4Al2Cl(SO4)0.5(OH)12(H2O)6
  CA              -10.27     -9.94    0.33  CaOAl2O3
  CA2               1.09    -29.45  -30.54  CaO(Al2O3)2
  CAH10            -2.08    -10.02   -7.94  CaOAl2O3(H2O)10
  Cal              -1.60    -10.00   -8.40  CaCO3
  CH4(g)           -5.74    -49.32  -43.58  CH4
  CO2(g)           -1.36    -19.57  -18.21  CO2
  Dis-Dol          -3.02    -19.20  -16.18  CaMg(CO3)2
  ettringite      -19.98     -8.65   11.34  ((H2O)2)Ca6Al2(SO4)3(OH)12(H2O)24
  ettringite03_ss  -6.66     -2.88    3.78  (SO4)Ca2Al0.6666667(OH)4(H2O)8.6666667
  ettringite05     -9.99     -4.32    5.67  Ca3Al(SO4)1.5(OH)6(H2O)13
  ettringite13    -53.18     -8.50   44.68  Ca6Al2(SO4)3(OH)12(H2O)7
  Ettringite13_des -53.18     -8.50   44.68  Ca6Al2(SO4)3(OH)12(H2O)7
  ettringite30    -20.69     -8.63   12.06  Ca6Al2(SO4)3(OH)12(H2O)24
  ettringite9     -59.64     -8.47   51.18  Ca6Al2(SO4)3(OH)12(H2O)3
  Ettringite9_des -59.64     -8.47   51.18  Ca6Al2(SO4)3(OH)12(H2O)3
  Gbs               6.11     -9.77  -15.88  Al(OH)3
  Gp               -1.28     -5.88   -4.60  CaSO4(H2O)2
  Gr               -0.47    -34.44  -33.97  C
  H2(g)            -7.44     -7.44   -0.00  H2
  H2O(g)           -1.92     -0.01    1.91  H2O
  H2S(g)           -1.01    -45.17  -44.16  H2S
  hemicarbonat10.5 -36.27      8.89   45.16  (CaO)3Al2O3(CaCO3)0.5(CaO2H2)0.5(H2O)10
  hemicarbonate   -34.28      8.88   43.16  (CaO)3Al2O3(CaCO3)0.5(CaO2H2)0.5(H2O)11.5
  hemicarbonate9  -39.59      8.91   48.50  (CaO)3Al2O3(CaCO3)0.5(CaO2H2)0.5(H2O)8.5
  hemihydrate      -2.46     -5.87   -3.41  CaSO4(H2O)0.5
  hydrotalcite     -8.36     21.92   30.29  Mg4Al2O7(H2O)10
  K2O             -80.50      7.75   88.25  K2O
  K2SO4            -5.63     -7.68   -2.05  K2SO4
  Lim             -24.91      9.57   34.47  CaO
  M4A-OH-LDH      -15.03     21.92   36.96  Mg4Al2(OH)14(H2O)3
  M6A-OH-LDH      -30.21     42.66   72.87  Mg6Al2(OH)18(H2O)3
  M8A-OH-LDH      -45.38     63.40  108.79  Mg8Al2(OH)22(H2O)3
  Mg2AlC0.5OH      -5.70      1.18    6.88  Mg2Al(OH)6(CO3)0.5(H2O)2
  Mg3AlC0.5OH     -13.26     11.54   24.80  Mg3Al(OH)8(CO3)0.5(H2O)2.5
  Mgs              -1.15     -9.19   -8.04  MgCO3
  monocarbonate   -27.01     -0.90   26.11  Ca4Al2CO9(H2O)11
  monocarbonate05 -13.50     -0.45   13.06  Ca2AlC0.5O4.5(H2O)5.5
  monocarbonate9  -31.57     -0.88   30.69  Ca4Al2CO9(H2O)9
  monosulphate10_5 -26.75      3.25   29.99  Ca4Al2SO10(H2O)10.5
  monosulphate12  -25.24      3.24   28.48  Ca4Al2SO10(H2O)12
  monosulphate1205 -12.62      1.62   14.24  Ca2AlS0.5O5(H2O)6
  monosulphate14  -25.32      3.22   28.54  Ca4Al2SO10(H2O)14
  monosulphate16  -25.07      3.21   28.27  Ca4Al2SO10(H2O)16
  monosulphate9   -29.11      3.26   32.38  Ca4Al2SO10(H2O)9
  Na2O            -59.69     11.17   70.87  Na2O
  Na2SO4           -3.96     -4.26   -0.29  Na2SO4
  O2(g)           -73.81     14.86   88.67  O2
  Ord-Dol          -2.40    -19.20  -16.80  CaMg(CO3)2
  Portlandite     -14.51      9.56   24.07  Ca(OH)2
  Sulfur            0.36    -37.73  -38.09  S
  syngenite        -6.11    -13.55   -7.44  K2Ca(SO4)2H2O
  tricarboalu03   -10.38     -7.02    3.36  (CO3)Ca2Al0.6666667(OH)4(H2O)8.6666667

**For a gas, SI = log10(fugacity). Fugacity = pressure * phi / 1 atm.
  For ideal gases, phi = 1.

------------------
End of simulation.
------------------
Logged

dlparkhurst

  • Global Moderator
  • *****
  • Posts: 4262
Re: Convergence error
« Reply #5 on: 28/05/22 01:07 »
I thought we had agreed that adding all of the elements as a REACTION was not a good idea for PhreeqcRM, but you are persistent.

To recover from this kind of error, you may need to save the state of your system (all the current definitions of solutions and reactants) at intervals. When the calculation fails, you would need to recover the last good state and retry the calculation (probably with smaller time steps). There are methods StateSave, StateApply, and StateDelete, that would allow you to recover.  Alternatively, you may be able to use DUMP to save the state of a cell, and then recover, but without modification, DUMP writes to a file, which would be a slow process. Another possibility is to use the "utility" or another IPhreeqc (or perhaps just another cell) to do the calculation, where you transfer the data for a cell, do the calculation, and transfer it back when it succeeds, or retry if it fails. Sounds possible, but you may need to dig into IPhreeqc methods.

You can use either phase names or element names in REACTION. Phreeqc looks for PHASE names first, and, if not found as a phase, then assumes the reactant is an element name. My guess is that you have defined a phase with PHASES with the name "Ca" that contains Al and O. If so, you should use a different name in your PHASES definition.
Logged

sharmilan

  • Top Contributor
  • Posts: 45
Re: Convergence error
« Reply #6 on: 28/05/22 16:04 »
First of all, thank you for pointing out that the same notation as "Ca" exists in the phase database. According to your advice, I have added the element composition of the solution through the SOLUTION keyword in my chemical equilibrium model. And, I have found this problem due to checking the solution through the REACTION keyword.

Thank you
sharmilan.
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Processes »
  • Reactive transport modelling »
  • Convergence error
 

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