Articles | Volume 14, issue 7
https://doi.org/10.5194/gmd-14-4225-2021
https://doi.org/10.5194/gmd-14-4225-2021
Development and technical paper
 | 
06 Jul 2021
Development and technical paper |  | 06 Jul 2021

SolveSAPHE-r2 (v2.0.1): revisiting and extending the Solver Suite for Alkalinity-PH Equations for usage with CO2, HCO3 or CO32− input data

Guy Munhoven
Abstract

The successful and efficient approach at the basis of the Solver Suite for Alkalinity-PH Equations (SolveSAPHE) (Munhoven2013), which determines the carbonate system speciation by calculating pH from total alkalinity (AlkT) and dissolved inorganic carbon (CT), and which converges for any physically sensible pair of such data, has been adapted and further developed to work with AlkTCO2, AlkTHCO3-, and AlkTCO32-. The mathematical properties of the three modified alkalinity–pH equations are explored. It is shown that the AlkTCO2, and AlkTHCO3- problems have one and only one positive root for any physically sensible pair of data (i.e. such that [CO2]>0 and [HCO3-]>0). The space of AlkTCO32- pairs is partitioned into regions where there is either no solution, one solution or where there are two. The numerical solution of the modified alkalinity–pH equations is far more demanding than that for the original AlkTCT pair as they exhibit strong gradients and are not always monotonous. The two main algorithms used in SolveSAPHE v1 have been revised in depth to reliably process the three additional data input pairs. The AlkTCO2 pair is numerically the most challenging. With the Newton–Raphson-based solver, it takes about 5 times as long to solve as the companion AlkTCT pair; the AlkTCO32- pair requires on average about 4 times as much time as the AlkTCT pair. All in all, the secant-based solver offers the best performance. It outperforms the Newton–Raphson-based one by up to a factor of 4 in terms of average numbers of iterations and execution time and yet reaches equation residuals that are up to 7 orders of magnitude lower. Just like the pH solvers from the v1 series, SolveSAPHE-r2 includes automatic root bracketing and efficient initialisation schemes for the iterative solvers. For AlkTCO32- data pairs, it also determines the number of roots and calculates non-overlapping bracketing intervals. An open-source reference implementation of the new algorithms in Fortran 90 is made publicly available for usage under the GNU Lesser General Public Licence version 3 (LGPLv3) or later.

1 Introduction

Among all the aspects of the ongoing global environmental changes (climate change, ocean acidification, etc.), the solution chemistry of carbon dioxide (CO2) is one of the best known. The related chemistry of the carbonate system in the oceans and other aqueous environments is well understood and routinely monitored and modelled. The equilibria between the carbonate system species involves four variables: [CO2] (or equivalently the partial pressure of CO2, pCO2, or its fugacity, fCO2), [HCO3-], [CO32-] and [H+] (or equivalently pH). The speciation, i.e. the determination of the concentrations of the individual species, therefore also requires four constraints. Two of these are given by the equilibrium relationships that characterise the equilibria between dissolved CO2 and HCO3- on one hand, and between HCO3- and CO32- on the other hand, assuming that the respective equilibrium constants are known or can be calculated. Two more independent constraints are thus required to completely characterise the system. These two additional constraints are generally chosen among the four traditional measurables of the system (see, e.g. Dickson et al.2007): (1) the total concentration of dissolved inorganic carbon (DIC), CT=[CO2]+[HCO3-]+[CO32-]; (2) total alkalinity, AlkT; (3) pH and (4) pCO2 or fCO2. Recently, a procedure to measure [CO32-] has been developed as well, thus increasing the number of measurables to five (Byrne and Yao2008; Patsavas et al.2015; Sharp and Byrne2019). This latter has, however, not yet been widely adopted. With these two additional constraints, the concentrations of all the individual species as well as CT and AlkT can then be calculated.

There are 10 different data pairs that can be composed from the set of five independent measurable variables of the carbonate system; there are 15 if we further include HCO3- as a sixth independent variable, although currently not (yet) measurable. Most modellers will call upon CT and AlkT which, besides being measurable, are also conservative and thus convenient for a budgeting approach. Experimentalists will use the pair that best suits their analytical equipment and expertise. Depending on the study requirements, not all pairs are equally attractive though. The analysis of Sharp and Byrne (2019) reveals that it is always advisable to measure pCO2 directly if that variable is required: the uncertainty of calculated pCO2 is always 5 to 10 times as large as that of the directly measured one. [CO32-] can be calculated with lower uncertainty from AlkTCT data than it can be directly measured; calculating it from other data pairs always bears greater uncertainty than directly measuring it. The most peculiar combination of uncertainties affects the results derived from paired measurements of pCO2 and CO32-: they allow to calculate pH with the same uncertainty as if directly measured, thus providing nearly optimal values for the three individually measurable species. The uncertainties of the AlkTCT calculated from it are, however, about 20 times as large as those directly measured. The currently most attractive pairs are AlkTpCO2 and CTpCO2, both of which allow to calculate pH with better and [CO32-] with only slightly larger but still acceptable uncertainty than the direct measurement would offer. Direct [CO32-] measurements, which might be most advisable for tracing carbonate mineral saturation states, are best paired with AlkT or CT (Sharp and Byrne2019). It can nevertheless be expected that, once it becomes more widely used, the measurement uncertainty currently affecting that still young measurable can be reduced and eventually become better than that of [CO32-] calculated from AlkTCT, which is currently the best option (Sharp and Byrne2019).

Overall, 11 out of these 15 possible pairs of independent parameters of the carbonate system can be directly solved or require at most the resolution of a quadratic equation. The remaining four pairs require iterative procedures. Besides the AlkT–CT pair which was addressed in full detail by Munhoven (2013) these are (1) AlkTCO2, (2) AlkTHCO3- and (3) AlkTCO32-. Such calculations are performed to an advanced level of detail with dedicated and highly specialised packages. The review of Orr et al. (2015) offers a systematic analysis of subsisting uncertainties and inconsistencies between 10 such packages, focusing on the sets of equilibrium constants adopted, pressure corrections applied, etc. Here, we do not focus on these aspects but on the design of algorithms that can solve the underlying mathematical problem with as little user input as possible. The aim is to reduce user input to the bare essentials: besides the fundamental information about temperature, salinity, pressure and the thermodynamic data, this ideally had to be any physically meaningful data pair only; the algorithm should be able to derive any other auxiliary information, such as root brackets or starting values for iterations, on its own.

In the companion paper (Munhoven2013), such autonomous algorithms with robust convergence properties for a wide range of environmental conditions are presented for usage with the AlkTCT pair. Here, we are revisiting that approach, extending and adapting it so that the AlkTCO2, AlkTHCO3-, and AlkTCO32- pairs can be processed with the same ease and reliability. For the sake of completeness – and with minimal details only – “recipes” for solving the other 11 explicit cases are provided in the Appendix. Alternative approaches can be found in the literature, such as in Zeebe and Wolf-Gladrow (2001) or Dickson et al. (2007). Dickson et al. (2007) also provide pathways for using triplets or quartets of input data, which only require the knowledge of one of the two dissociation constants or of their ratio, or none of them. That kind of approach is, however, not considered in this study.

2 Theoretical considerations

In the following, it is assumed that the temperature T, salinity S and applied pressure P are given and that adequate values for all the required stoichiometric equilibrium constants are available. It is furthermore assumed that the total concentrations of all the other relevant acid systems (borate, hydrogen sulfate, phosphate, silicate, etc.) are known.

2.1 Revisiting the mathematics of the alkalinity–pH equation

Cornerstone to the speciation calculation is the resolution of the following equation, which I call the “alkalinity–pH equation”, as it derives from the definition of total alkalinity:

(1) R T ( [ H + ] ) Alk nW ( [ H + ] ) + K W [ H + ] - [ H + ] s - Alk T = 0 ,

i.e. Eq. (21) from Munhoven (2013). In this equation, [H+] is the proton concentration expressed on one of the commonly used pH scales (total, seawater) and s is a factor to convert from that scale to the free scale. s depends on temperature, pressure and salinity of the sample and its value is close to 1 (typically between 1.0 and 1.3). The first term on the right-hand side is that part of the total alkalinity that is not related to the water self-ionisation: AlknW([H+])=iAlkA[i]([H+]), where i denumbers the acid systems resulting from the dissolution of acids A[i] whose dissolution products contribute to total alkalinity. For the purpose of this study, AlknW([H+]) is partitioned into carbonate alkalinity, AlkC([H+]), and non-carbonate alkalinity, AlknWC([H+]), since the relevant carbonate system parameters (the concentrations of CO2, HCO3- and CO32- and their sum, CT) are all directly related to AlkC: AlknW([H+])=AlkC([H+])+AlknWC([H+]). Similarly to AlknW, AlknWC admits an infimum and a supremum which can both be derived from the total concentrations of all the acid–base systems considered. We denote these two by AlknWCinf and AlknWCsup, respectively. Equation (1) is thus formally rewritten as

(2) R T ( [ H + ] ) Alk C ( [ H + ] ) + Alk nWC ( [ H + ] ) + K W [ H + ] - [ H + ] s - Alk T = 0 .

The carbonate alkalinity term writes, as a function of CT

(3) Alk C ( [ H + ] ) = K 1 [ H + ] + 2 K 1 K 2 [ H + ] 2 + K 1 [ H + ] + K 1 K 2 C T

where K1 and K2 are the first and second stoichiometric dissociation constants of carbonic acid. The individual carbonate species fractions of CT can be expressed as a function of [H+]:

(4)[CO2]=[H+]2[H+]2+K1[H+]+K1K2CT(5)[HCO3-]=K1[H+][H+]2+K1[H+]+K1K2CT(6)[CO32-]=K1K2[H+]2+K1[H+]+K1K2CT.

Accordingly, AlkC([H+]) may be rewritten in one of the following forms:

(7)AlkC([H+])=K1[H+]+2K1K2[H+]2[CO2](8)AlkC([H+])=K1[H+]+2K1K2K1[H+][HCO3-](9)AlkC([H+])=K1[H+]+2K1K2K1K2[CO32-].
https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f01

Figure 1(a) pH; (b) HCO3- and (c) CO32- concentration isolines in CTAlkT space; (d) CO2, (e) HCO3- and (f) CO32- concentration isolines in pH–AlkT space. Blank areas in panels (d), (e) and (f) represent the pH–AlkT combinations that lead to negative AlkC. The blue and black stars in panels (c) and (f) locate the two possible CT and pH roots for a sample with AlkT=2.3 mmol kg−1 and [CO32-]=0.1mmol kg−1 (one of the dashed isolines, as indicated by the open star symbol in the colour scale). Figure 3 in Deffeyes (1965) is similar to panel (c).

Download

In order to get a first idea about the complications that we might encounter for the solution of the three new data pairs, we start with an exploratory analysis using the Solver Suite for Alkalinity-PH Equations (SolveSAPHE) version 1.0.3 (Munhoven2013–2021). The three panels in the upper row of Fig. 1 show the pH and the HCO3- and CO32- concentration distributions for a reduced SW3 test case from Munhoven (2013), with the CT range extending from 0 to 4 mmol kg−1 and the AlkT range from 1 to 3 mmol kg−1 only. The pH distribution from Fig. 1a is then used to derive the corresponding CO2 (not shown), HCO3- and CO32- concentration distributions (Fig. 1b and c). Since we intend to solve the alkalinity–pH equation for given AlkT, and either of [CO2], [HCO3-] or [CO32-], we furthermore produce the concentration isolines for the three species on a pH–AlkT graph (Fig. 1d, e and f). For the three latter, we first calculated AlkC from AlkT by using Eq. (2). Positive AlkC values were then used with Eqs. (7), (8) and (9) to derive the corresponding [CO2], [HCO3-] and [CO32-], respectively. Blank areas represent the pH–AlkT combinations that lead to negative AlkC.

The V- or U-shaped isolines for HCO3- on the CT–AlkT graph and for CO32- on the CT–AlkT and on the pH–AlkT graphs show that the CTHCO3- and the AlkTCO32- pairs will not always provide unambiguous results. This is illustrated by the blue and black stars in Fig. 1c and f: they both lie on the 100 µmol kg−1 [CO32-] isoline and on the horizontal line drawn through AlkT=2.3mmol kg−1. For that pair of data values, there are thus two compatible CT and correspondingly two possible pH values. On the other hand, with the same AlkT, a [CO32-] of 1 mmol kg−1 would not provide any solution as the 1 mmol kg−1 isoline has its minimum at AlkT=2.63mmol kg−1. Similarly, there are pairs of CT and [HCO3-] values that are compatible with two AlkT values and thus two pH values, and others with none: a vertical line drawn through CT=2.2mmol kg−1 crosses the 2.0 mmol kg−1 isoline for [HCO3-] twice and so that pair of data values leads to two pH solutions; a vertical line drawn through CT=2.05mmol kg−1 does not cross that 2.0 mmol kg−1 isoline for [HCO3-] at all, and that pair of data values does not have any pH solution.

As will be shown below, the SolveSAPHE approach of Munhoven (2013), which is based upon the use of a hybrid iterative solver safeguarded by intrinsic brackets that can be calculated a priori, can be easily adapted for the AlkTCO2 and AlkTHCO3- pairs. According to the outcome of our preliminary analysis above, the AlkTCO32- pair requires a more in-depth analysis. We show that it is nevertheless possible to diagnose the different cases that can theoretically be encountered and, in case there are two solutions, to derive bracketing intervals for each of the two and to isolate them efficiently. For each pair, we (1) establish the analytical properties of the modified alkalinity–pH equation; (2) derive brackets for the root(s); (3) develop a reliable and safe algorithm to solve the problem; (4) design an efficient initialisation scheme. The CTHCO3- pair, which requires only a quadratic equation to be solved, is straightforward to diagnose a priori (see the corresponding recipe in the Appendix).

We will now in turn analyse the mathematical properties of the alkalinity–pH equation that results from the substitution of CT by the concentration of one of its individual species.

2.2 The AlkT–CO2 problem

2.2.1 Mathematical analysis

The AlkTCO2 pair can be dealt with in a similar way to the AlkT–CT pair in the original SolveSAPHE. The AlkC([H+]) term in Eq. (2) is written as in Eq. (7). Equation (2) then becomes

(10) K 1 [ H + ] + 2 K 1 K 2 [ H + ] 2 [ CO 2 ] + Alk nWC ( [ H + ] ) + K W [ H + ] - [ H + ] s - Alk T = 0 .

Just like the AlkC([H+]) expression from Eq. (3) is monotonously decreasing with [H+] for CT fixed, that from Eq. (7) is monotonously decreasing with [H+] for [CO2] fixed. The expression on the left-hand side of Eq. (10) decreases from +∞ to −∞ for [CO2]>0 as [H+] varies from 0+ to +∞. Equation (10) thus always has exactly one positive solution.

2.2.2 Root bracketing

Intrinsic brackets for the solution of Eq. (10) can be derived similarly to what is done in Sect. 5.1 in Munhoven (2013). The lower bound Hinf can be chosen such that

K1Hinf+2K1K2Hinf2[CO2]+KWHinf-Hinfs=AlkT-AlknWCinf,

i.e. as the positive root of the cubic equation:

H3s+(AlkT-AlknWCinf)H2-(K1[CO2]+KW)H-2K1K2[CO2]=0.

Let us denote this cubic by P(H). It is important to notice that P(0)=-2K1K2[CO2]<0 and P(0)=-(K1[CO2]+KW)<0. The equation P(H)=0 has therefore one and only one positive root.

Similarly, the upper bound Hsup can be chosen such that

K1Hsup+2K1K2Hsup2[CO2]+KWHsup-Hsups=AlkT-AlknWCsup,

i.e. as the positive root of the cubic equation

H3s+(AlkT-AlknWCsup)H2-(K1[CO2]+KW)H-2K1K2[CO2]=0,

which also has one and only one positive root for the same reasons as above.

The positive roots of these cubic equations can be found by adopting a strategy similar to that used for the cubic initialisation of the iterative solution in SolveSAPHE (Munhoven2013, Sect. 3.2.2):

  1. locate the local minimum of the cubic, in Hmin>0;

  2. develop the cubic as a quadratic Taylor expansion, Q(H), around that minimum;

  3. solve Q(H)=0 which has two roots and choose the one that is greater than Hmin.

In this particular case, it is, however, not necessary to solve these equations exactly as we only need approximate bounds of the root for safeguarding the iterations while solving Eq. (2). For Hinf, we may actually choose the Hmin of the first cubic which is lower than the positive root and thus sufficient. Regarding Hsup, it should be noticed that P(H)=Q(H)+(H-Hmin)3/s. Accordingly, P(H)>Q(H) for H>Hmin and therefore the greater root of Q(H) for the second cubic is greater than the positive root of that cubic. The greater of the two roots of Q(H) is therefore a sufficient upper bracket and may be used instead of the exact Hsup.

Any bracketing root-finding algorithm can then be used to solve the modified alkalinity pH equation (Eq. 10).

2.3 The AlkT–HCO3- problem

2.3.1 Mathematical analysis

For the AlkTHCO3- pair, the AlkC([H+]) term in Eq. (2) is written as in Eq. (8):

(11) 1 + 2 K 2 [ H + ] [ HCO 3 - ] + Alk nWC ( [ H + ] ) + K W [ H + ] - [ H + ] s - Alk T = 0 .

The expression on the left-hand side of Eq. (11) decreases monotonously from +∞ to −∞ for [HCO3-]>0 fixed as [H+] varies from 0+ to +∞. Equation (11) thus always has exactly one positive solution.

2.3.2 Root bracketing

The lower bound Hinf can be chosen such that

1+2K2Hinf[HCO3-]+KWHinf-Hinfs=AlkT-AlknWCinf,

i.e. as the positive root of the quadratic equation

H2s+(AlkT-AlknWCinf-[HCO3-])H-(2K2[HCO3-]+KW)=0.

Similarly, the upper bound Hsup can be chosen such that

1+2K2Hsup[HCO3+]+KWHsup-Hsups=AlkT-AlknWCsup,

i.e. as the positive root of the quadratic equation

H2s+(AlkT-AlknWCsup-[HCO3-])H-(2K2[HCO3-]+KW)=0.

Both equations always have two roots: one positive and one negative; their product is negative as indicated by the constant term. With the respective positive roots, we have again bounds for the solution of the modified alkalinity–pH equation and any bracketing root-finding algorithm can be used to solve it.

2.4 The AlkT–CO32- problem

Whereas any physically meaningful AlkT–[CO2] or AlkT–[HCO3-] concentration pairs will always provide one and only one [H+] (or equivalently pH) value as demonstrated above, this cannot be the case for every AlkT–[CO3-] pair, as can be deduced from Fig. 1c and f. On one hand, there are two compatible CT values, and equivalently two pH values, for most AlkT–[CO32-] pairs. This little-known fact was already documented in the 1960s (see, e.g. Deffeyes1965)1. On the other hand, there are also AlkT–[CO32-] pairs that do not allow for any solution, as they lead to negative carbonate alkalinity. To our best knowledge, none of the currently available carbonate system speciation programmes take this possibility into account.

2.4.1 Mathematical analysis and root bracketing

The solution of the AlkTCO32- problem thus requires a more in-depth mathematical analysis. To start, we write out Eq. (2) with the AlkC expression for [CO32-] (Eq. 9):

K1[H+]+2K1K2K1K2[CO32-]+AlknWC([H+])+KW[H+]-[H+]s-AlkT=0.

Let us collect all the terms that are related to carbonate or water self-ionisation alkalinity on the left-hand side, introduce the shorthand γ=[CO32-]K2-1s and rewrite the equation as

(12) γ [ H + ] + K W [ H + ] + 2 [ CO 3 2 - ] = Alk T - Alk nWC ( [ H + ] ) .

The value of γ is one of the main controls on the number of roots that this equation has.

  1. If γ<0, the equation has similar mathematical characteristics to the usual alkalinity–pH equation (Eq. 1). It has exactly one root which can be calculated using similar procedures as in the original SolveSAPHE. Please note though that this means that [CO32-]<K2s. Since K2 is of the order of 10−9mol (kg SW)−1 and s is of the order of 1, this case is only relevant for CO32- concentrations of the order of 1 nmol (kg SW)−1 and less.

  2. If γ=0 (i.e. if [CO32-]=K2s), the equation has exactly one root if AlkT-2[CO32-]-AlknWCinf>0, and no root otherwise.

  3. If γ>0, the left-hand side is not monotonous: it decreases from +∞ in [H+]=0+ to a minimum (see below) and then increases back to +∞ as [H+]+. The right-hand side is bounded and strictly increasing over the same interval (Munhoven2013). As a result, the equation has no root if the right-hand side is too low, exactly one if the two curves become tangent and two roots if the right-hand side is great enough.

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f02

Figure 2Schematic representation of the general characteristics of the L([H+];γ) and R([H+];A) components of the alkalinity–pH equation for the AlkT-CO32- pair. The grey band delimits the (monotonous) variations of R([H+];A) for a given alkalinity A. The band moves up and down without being distorted as A is increased, respectively, decreased. For a given pair of AlkTCO32- concentrations, the actual equation to solve is L([H+];γ)=R([H+];AlkT), where γ=[CO32-]K2-1s. γ=0 thus corresponds to [CO32-]=K2s.

Download

To alleviate notation let us define the two parametric functions:

(13)L([H+];γ)=γ[H+]+KW[H+]+2[CO32-](14)R([H+];A)=A-AlknWC([H+]),

where [H+] is the independent variable and γ and A (alkalinity) are parameters. With these two function definitions, Eq. (12) is then rewritten as L([H+];γ)=R([H+];AlkT). Schematic representations of the three γ cases and of the L and R functions are shown in Fig. 2.

Case γ<0

The first case can be handled similarly to the AlkTCO2 and AlkTHCO3- pairs. Equation (12) always has exactly one root with γ<0 as the equation function is monotonous and strictly decreasing with [H+]. Upper and lower bounds for that root can be derived by solving the (quadratic) equations:

(15) γ H inf + K W H inf + 2 [ CO 3 2 - ] = Alk T - Alk nWCinf

for Hinf and

(16) γ H sup + K W H sup + 2 [ CO 3 2 - ] = Alk T - Alk nWCsup

for Hsup, and retaining the respective positive roots of each.

Case γ=0

The second case might be considered to be only mathematically of importance as it only applies for one exact (and thus improbable) CO32- concentration value. For the sake of completeness, I nevertheless solve it.

As mentioned above, if γ=0, Eq. (12) has one solution if and only if AlkT-AlknWCinf>2[CO32-], and no solution otherwise. The root can be easily bracketed from below. It is sufficient to choose Hinf such that

KWHinf=AlkT-2[CO32-]-AlknWCinf

leading to L(Hinf;γ)-R(Hinf;AlkT)>0. The analogue equation for Hsup, with AlknWCinf replaced by AlknWCsup (cf. Eqs. 15 and 16) does not work if AlkT-AlknWCsup2[CO32-]. The newly derived asymptotic approximation for AlknWC([H+]) as [H+]+ (see the “Mathematical and Technical Details” report in the Supplement) nevertheless provides a means to derive an upper bound. It is sufficient to choose Hsup such that

KWHsup=AlkT-2[CO32-]-AlknWCinf-i[ΣA[i]]K1,[i]Hsup,

where i denumbers the acid systems considered, except for the carbonate system, [ΣA[i]] is the total amount of the acid i dissolved and K1,[i] is the first dissociation constant of the acid system i. This equation always has a solution and, taking into account that

AlknWC([H+])<AlknWCinf+i[ΣA[i]]K1,[i][H+],

which is valid for [H+]>0, it is straightforward to show that L(Hsup;γ)-R(Hsup;AlkT)<0 with this choice. Equation (12), which is equivalent to L(H;γ)-R(H;AlkT)=0 thus has a single root between Hinf and Hsup.

Case γ>0

The third case is the most commonly encountered and the most challenging. With γ>0, L([H+];γ) has a minimum and the location of that minimum is a critical parameter in the analysis of this case. Let us denote the location of that minimum by Hmin and the value that L takes there by Lmin:

Hmin=KWγandLmin=2γKW+2[CO32-].

There are two ranges of AlkT values where firm conclusions can be drawn right away.

  1. If R(Hmin;AlkT)>Lmin, i.e. if AlkT>Lmin+AlknWC(Hmin), Eq. (12) has two distinct roots, since R(H;AlkT) is bounded. Furthermore, the roots – let us provisionally denote the lower one H1 and the greater one H2 – are such that H1<Hmin and H2>Hmin. Hmin can thus be used as an upper bracket for H1 and as a lower bracket for H2. However, if AlkT-AlknWCsup>Lmin, the abscissae of the intersection points PLL and PLR (see Fig. 2), which are solutions of

    γH+KWH=AlkT-2[CO32-]-AlknWCsup,

    provide tighter brackets than Hmin.

  2. If AlkT-AlknWCinfLmin, i.e. if AlkTLmin+AlknWCinf, Eq. (12) does not have any roots.

For intermediate values of AlkT, no firm quantitative statement regarding the root(s) of Eq. (12) can be made a priori. As AlkT decreases from Lmin+AlknWC(Hmin) to Lmin+AlknWCinf, Eq. (12) will at first still have two roots, but both are greater than or equal to Hmin. At some intermediate value, L([H+];γ) and R([H+];AlkT) become tangent. At this point, Eq. (12) has one double root, which is the abscissa of that tangent point, Htan. Htan is actually a universally valid separation limit between two roots, if there are any. For lower values of AlkT, the problem does not have any solutions.

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f03

Figure 3Determination of the A value for which the L([H+];γ) and R([H+];A) curves become tangent, or, equivalently, the lowest AlkT value for which the equation L([H+];γ)-R([H+];AlkT)=0 has a solution. Panel (a) shows how relevant characteristic points can be derived by considering the particular R([H+];A) curve that intersects L([H+];γ) at its minimum. Panel (b) shows the locus of the solutions of L([H+];γ)-R([H+];AlkT)=0 in an [H+]-AlkT) graph, i.e. the curve AlkT)=L([H+];γ)+AlkncW([H+]). Please notice that Amin=Lmin+AlkncW(Hmin) denotes the alkalinity value obtained for [H+]=Hmin, and not the minimum value of the curve shown in panel (b). See text for details.

Download

The limiting AlkT value for which the two curves are tangential and the corresponding Htan value can be calculated with a common algorithm to characterise a bracketed local minimum, such as Brent's algorithm (Brent1973). To start, we reconsider L([H+];γ)-R([H+];A)=0 not as an equation in [H+] for given parameter values γ (or, equivalently, [CO32-]) and A, but rather as an implicit definition for A as a function of [H+], for a given γ (here γ>0). This implicit function definition can actually be solved explicitly here:

A([H+])=L([H+];γ)+AlkncW([H+]).

Figure 3 shows how the two problems are related and which information can be derived from the analysis of L([H+];γ) and R([H+];A) to contribute to the solution of the minimisation of A([H+]). The determination of Htan is costly, generally more costly than the subsequent resolution of the pH equation itself. As mentioned right at the beginning of this section, there are extended ranges of AlkT values for which the exact knowledge of Htan is not indispensable. In these situations Hmin may be a sub-optimal but nevertheless sufficient separation limit for the roots (or equal to the double root itself) and cheap to calculate. If available, Htan can be used as an upper bound for the lower and as a lower bound for the greater of the two roots. To start the minimisation algorithm to derive Htan, we can use the three characteristic [H+] values from Fig. 3 as initial conditions. These are Hmin together with the abscissae HL and HR of the intersection points between L([H+];γ) and the horizontal line at Alkmin−AlknWCinf, which are the roots of

γH2-(Alkmin-2[CO32-]-AlknWCinf)H+KW=0.

By construction, Alkmin-AlknWCinf>Lmin=2γKW+2[CO32-]. The discriminant of this quadratic equation is therefore strictly positive and the equation has two positive roots (their sum and their product are positive) as required. It is possible to show that the second derivative of R([H+];A) with respect to [H+] is positive provided that the successive dissociation constants Kj,[i] of the different acid systems (denumbered by i) resulting from the dissociation of an acid Hn[i]A[i] are such that Kj,[i]<12Kj-1,[i],j=2,,n[i] – a very weak constraint as these constants generally differ by a few orders of magnitude. This has been verified to be the case for acid systems with n[i]=1,,12. The underlying technical developments can be found in the “Mathematical and Technical Details” report in the Supplement. R([H+];A) is thus concave, while L([H+];γ) is convex for γ>0. A([H+]) thus has only a single local minimum comprised between HL and HR.

Once Htan is known, the root brackets can be completed by the intersection points between L([H+];γ) and the horizontal line at AlkT−AlknWCinf – corresponding to the PUL and PUR points in Fig. 2 with the grey band shifted down to include the minimum – i.e. by solving the same quadratic equation than for HL and HR, with Alkmin replaced by AlkT. We have again AlkT-AlknWCinf>Lmin, and the equation has two positive roots. With these brackets on the two roots, any safeguarded iterative procedure, such as those implemented in SolveSAPHE, can be used to find the two roots in a controlled way.

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f04

Figure 4(a) Evolution of the concentrations of the different species composing AlkTCT, as a function of pH, for AlkT=2.3 mmol kg−1. CT and the concentrations all of its components reduce to 0 at pH = 11.48 (marked by the long-dashed vertical black line) in this example. The dashed orange line represents the joint contribution of B(OH)4- and OH which are the dominant AlkT contributors at high pH. (b) [CO32-] as a function of pH for different AlkT values (indicated in mmol kg−1 for each curve). Each curve represents a horizontal cross-section at the corresponding AlkT level through the [CO32-] distribution depicted in Fig. 1e.

Download

2.4.2 Two roots: which one to choose?

Since every physical aqueous sample has a pH, the case without roots is essentially a theoretical one: it can actually arise only if the adopted alkalinity composition is not appropriate or if measurement errors are large. The case where an AlkTCO32- data pair is compatible with two different pH values is, on the contrary, the most common one. SolveSAPHE-r2 has been designed as a universal pH solver and as such returns all the roots that a data pair may offer, since there is no universal criterion to decide which one of the two roots is preferable over the other.

However, at the end of the calculations, one of the two has to be chosen. Additional information, qualitative or quantitative, is required to make that decision. This could be a third measurable, but often even qualitative information about, say, the expected pH or the CT range might be sufficient. For typical seawater samples, the greater of the two [H+] solutions will typically be the adequate one, following the “use the larger one” advice of Zeebe and Wolf-Gladrow (2001).

In the analysis of the AlkTCO32- problem above, we determined the AlkT ranges that would, respectively, lead to two, one or no roots, for a given γ, i.e. [CO32-]. To better understand the reasons why and when there are two, one or no roots and what other implications the individual roots have, it is instructive to perform the analysis the other way around: figure out how [CO32-] evolves as a function of pH for a given value of AlkT, and determine the [CO32-] ranges that would, respectively, lead to two, one or no roots. Such an analysis is presented in Fig. 4. For that figure, we have reconsidered the sample composition previously used in Fig. 1c and f. We thus start with AlkT fixed at 2.3 mmol kg−1 and draw the evolution of [CO32-] as a function of pH following

(17) CO 3 ( [ H + ] ; Alk T ) = Alk T - Alk nWC ( [ H + ] ) - K W [ H + ] + [ H + ] s [ H + ] K 2 + 2 ,

obtained by first using Eq. (9) to express [CO32-] as a function of AlkC and [H+], and then Eq. (2) to calculate AlkC as a function of AlkT and [H+] (and the total concentrations of all the other contributing acid–base systems, which we assume to be known, as stated initially). CO2 and HCO3- evolution curves can be derived similarly, by using Eqs. (7) and (8), respectively, instead of Eq. (9). The concentration evolution for the other AlkT contributors can be calculated from their species fraction equations (see, e.g. Munhoven2013). Figure 4a shows the concentration curves for all the species contributing to total alkalinity and dissolved inorganic carbon, for pH values ranging from 3 to 12, and for AlkT=2.3 mmol kg−1; Fig. 4b shows the [CO32-] evolution curves for different AlkT values, ranging from 0.5 to 2.5 mmol kg−1. Solving the AlkTCO32- problem for our showcase sample where [CO32-]=0.1mmol kg−1 thus means drawing a horizontal line through the 0.1 mmol kg−1 concentration level and locating the intersection points with the CO32- curve, if any. There are actually two of them, located at pH = 8.03 and pH = 11.43. With increasing target values for [CO32-], i.e. moving the horizontal line upward, the two pH roots will move closer and closer together, until the maximum of the CO3 curve is touched, at CO3 max=841.7µmol kg−1. At this exact value, there will only be one root: pH = 10.1943. Positioning the line higher up does not allow any intersection with the CO3 curve any more: there are no roots for [CO32-]>CO3 max. As illustrated in Fig. 4b, the value of CO3 max grows as AlkT increases, thus extending the range of [CO32-] that allows for roots. Another noteworthy fact in Fig. 4b is that all the displayed CO32- curves increase to a maximum before declining and reducing to zero at some finite pH. While not all possible curves have that shape (it is possible to show that curves for AlkT<AlknWCinf+2K2s are monotonously decreasing), all of them nevertheless go to zero. The equation CO3([H+];AlkT)=0 actually always has exactly one root, for any given AlkT, since this simply requires that the numerator on the right-hand side of Eq. 17) is 0, i.e. that [H+] is the solution of a standard alkalinity–pH equation where CT=0. Such an equation always has exactly one positive solution, for any physically meaningful set of total concentrations of the different acid–base systems at play and any AlkT value (Munhoven2013). The pH value at that zero-crossing point is furthermore the maximum possible pH for the given AlkT: beyond that value, the ever-growing [OH+] would inevitably make AlkT increase above the fixed value, thus requiring AlkC to become negative, which is not possible.

As can be seen in Fig. 4a, the high-pH solution goes together with CT[CO32-]: CO32- represents only 4.6 % of the CT at pH = 8.03, typical for seawater, but 99.2 % at pH = 11.43. Accordingly CT=0.1008mmol kg−1 at the high-pH root, which is unrealistically low for many natural samples. In the marine realm, this observation regarding the high-pH root is actually correct in general. CO32- represents more than 80 % of DIC for pH >10, and more than 90 % for pH >10.3, as can be calculated from Eq. (6). In Fig. 4b, one can see that the maxima of the CO3 curves are greater than 0.47 mmol kg−1 for AlkT≥1.5mmol kg−1 and that they are located at pH >10. Since the larger of the two solutions is always at a pH greater than or equal to the maximum of the curve that it must intersect, we may conclude that for [CO32-]<0.47mmol kg−1 and AlkT≥1.5mmol kg−1, the greater of the two pH roots always implies that CO32- represents more than 80% of CT. Accordingly, even a rough estimate of one of the other relevant parameters of the carbonate system might be sufficient to reject one of the two roots.

2.5 Initialisation: rationale

Since we have bracketing intervals for each diagnosed root, we may always use the fall-back initial value H0=HinfHsup. This value is, however, often far from optimal. The efficient initialisation strategy of Munhoven (2013) can be generalised and adapted to each of the three pairs. For each case, we choose the most complex AlkT approximation that leads to a cubic equation. If the cubic polynomial behind that equation does not have a local minimum and a local maximum, we use the fall-back value. If such a local minimum and maximum exist, we use the quadratic Taylor expansion around the relevant extremum – this will normally be the maximum if the coefficient of the cubic term is negative, and the minimum if that coefficient is positive. If that quadratic does not have any positive roots, the fall-back initial value is used. The roots for that quadratic are then determined. For problems that have only one positive [H+] solution (AlkTCO2, AlkTHCO3- and AlkTCO32- with γ<0), we consider that root of the quadratic expansion that is greater than the greatest location of the two extrema: if that root is lower than Hinf, we use H0=Hinf; if it is greater than Hsup, we set H0=Hinf. For problems that have two positive [H+] solutions (AlkTCO32- with γ>0 and sufficiently great AlkT), the initial value for determining the greater of the two [H+] solutions can be chosen exactly the same way; the initial value required to calculate the lower of the two [H+] solutions may be more tricky. If the location of the right-hand side extremum is too close to 0, the estimated root of the cubic may be negative. In this case, the quadratic fitted to left-hand extremum should be considered as well and the greater of its roots tested. Because of the symmetries of a cubic, that root can be calculated with a few extra additions only.

The developments for each of the three input pairs are presented in full detail in the “Mathematical and Technical Details” report in the Supplement.

3 Numerical experiments

3.1 Reference Fortran 90 implementation

The SolveSAPHE Fortran 90 library from Munhoven (2013) – hereafter SolveSAPHE v1 – has been revised, cleaned up and upgraded to allow the processing of the additional three pairs. For the purpose of this paper, only the two main solvers have been kept: these are solve_at_general, which uses a Newton–Raphson method, and solve_at_general_sec, which uses the secant method. Both can be still be used with the same application programming interface (API) as in v1. The instances in SolveSAPHE-r2 are, however, only wrappers to the newly added Newton–Raphson-based solve_at_general2 and secant (or more precisely regula falsi) based solve_at_general2_sec both of which are able to process problems that have two roots. They return the number of roots of the problem, as well as their actual values, if any.

In the course of the developments related to the AlkTCO2 pair, the Newton–Raphson-based algorithm showed a few weaknesses. With the AlkTCT pair that SolveSAPHE v1 had been designed for, each non-water alkalinity term was bounded, just like its derivative. Once CO2 takes the role of CT these favourable properties are lost: with [CO2] fixed, the carbonate alkalinity term and its derivative with respect to [H+] become unbounded. Newton iterates can then change by large amounts and floating point over- and underflow errors on the exponential correction became common. The rate of change for Newton–Raphson iterates during each step was therefore limited to a factor of 100. With high CO2 concentration values prescribed, there was another loss of control on the iteration sequence that had not been encountered before. At some iterations, most often at the first one, it happened that one of the two root brackets, say the upper one, was reduced to the iteration value. In the next iteration, that same bound was exceeded by the trial Newton–Raphson iterate, which was then rejected and replaced by a bisection iterate on the interval delimited by the previous iterate and the upper bracket. Since both were identical, the bisection actually produced no variation and falsely led to convergence diagnosis. This has been fixed by changing the interval whereon the bisection step is performed to that delimited by the lower and the upper brackets of the root, which are always different.2 The unbounded variations of the carbonate alkalinity term when one of the individual species was used instead of CT furthermore required to modify the stopping criterion for the iterations: in SolveSAPHE v1, iterations are stopped as soon as the relative difference between successive iterates falls below a set tolerance ϵ (ϵ=10-8 by default). However, iterations for AlkTCO2 and for the greater root of AlkTCO32- were prone to early termination with that stopping criterion, as iterates only slowly changed due to the extreme gradients in the AlkC term of the equation. The stopping criterion is therefore now based upon the width of the bracketing interval, and iterations are stopped as soon as (Hmax-Hmin)<ϵ12(Hmax+Hmin), where Hmax and Hmin are, respectively, the upper and lower brackets of the root, which are continuously updated as iterations progress. As a consequence of this change, the number of bisection steps considerably increased. In order to speed up convergence, most bisection steps were replaced by regula falsi steps on [Hmin,Hmax]. Bisection steps are only used occasionally when either the minimum or maximum root bracket gets updated too often in a row (three times by default) which indicates that the equation values at Hmax and Hmin have strongly different magnitudes. Unfortunately, the number of iterations required for the original SolveSAPHE pair AlkTCT increases with this stopping criterion, without any appreciable gain in precision (compare, e.g. the number of iterations from Fig. 3b and the residuals from Fig. 1d in Munhoven (2013), with the number of iterations required here as reported in Fig. 6 for SW3 and the synthetic overview of the equation residuals reported in Tables S4 and S5 in the “Additional Results” section in the Supplement). For modelling purposes, where AlkTCT is generally the relevant pair of data, SolveSAPHE v1 remains the most efficient choice. Tests have shown that the two safeguarded algorithms from SolveSAPHE v1 typically require 40 %–45 % less computing time than their SolveSAPHE-r2 counterparts.

Table 1Ranges of variation for the input variables for the five test cases. Experiments always considered AlkT and either one of CT, [CO2], [HCO3-] or [CO32-].

Download Print Version | Download XLSX

Finally, as explained above, some AlkTCO32- combinations require the solution of an auxiliary minimisation problem. For this purpose, Brent's algorithm was implemented into SolveSAPHE (translated to Fortran 90 from the Algol 60 version in Brent (1973, Sect. 5.8), taking into account the author's errata reported on https://maths-people.anu.edu.au/~brent/pub/pub011.html (last access: 24 June 2021) and his modifications to the original algorithm as implemented in https://www.netlib.org/go/fmin.f (last access: 24 June 2021).

3.2 Results and discussion

3.2.1 Test case definitions

Results from the three test cases (SW1, SW2 and SW3) from Munhoven (2013) were used as starting points to define sets of AlkTCO2, AlkTHCO3- and AlkTCO32- concentration pairs to drive the test case experiments. Two supplementary cases were added here: BW4 for surface brackish water with S=3.5 and ABW5 (based upon the data of Yao and Millero (1995) for the Framvaren Fjord, Norway) for anoxic brackish water with AlkT and CT values 7 to 9 times higher than in the open ocean, as well as comparatively high alkalinity contributions from phosphates, silicates, sulfides, phosphates and ammonium. For CO2 and CO32-, which are most conveniently handled on a logarithmic concentration scale, the representative ranges were adapted so that the range endpoints are integer powers of 10. The adopted ranges and scales are reported in Table 1. Each of the SW1, SW2 and SW3 test cases is complemented with three sets of temperature, salinity and pressure conditions for typical environments (surface cold, surface warm and deep cold seawater); for BW4, only one such set for cold surface dilute or brackish water is used (T=275.15K, S=3.5) and for ABW5 one set for subsurface brackish water (P=13.5bar, S=22.82).

For the comparison of the computational requirements for the processing of each set of samples, the adopted [CO2], [HCO3-] or [CO32-] distributions are adapted. Although the [CO2], [HCO3-] and [CO32-] ranges for each test case reported on Table 1 have been defined on the basis of their respective distributions calculated from the AlkTCT results and although the adopted grids have the same dimensions, they do not cover exactly the same “samples” in any given test case. To overcome that inconsistency, each test experiment for the intercomparison is first carried out with the AlkTCT pair and the results stored. For the other three pairs, the pH distribution obtained with the AlkTCT pair for the corresponding set of temperature, salinity and pressure is first read in and the corresponding [CO2], [HCO3-] or [CO32-] distribution calculated on the underlying CT–AlkT grid. The so-obtained arrays of species concentrations are then used to define the set of AlkTCO2, AlkTHCO3- and AlkTCO32- data pairs for the benchmark calculations. This way, the test case experiments for the four different characteristic carbonate system concentrations cover exactly the same set of samples in each test case. These sample sets cannot be represented on rectangular [CO2]–AlkT, [HCO3-]–AlkT or [CO32-]–AlkT grids, respectively, which is nevertheless irrelevant for the histogram syntheses presented in Figs. 6 and 7. These variants of the test cases are denoted SW1CT, SW2CT, SW3CT, BW4CT and ABW5CT.

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f05

Figure 5pH distributions for the SW2-sc test case (SW2 under cold surface conditions, where T=273.15K, S=35 and P=0bar), obtained with solve_at_general2_sec: (a) AlkTCO2; (b) AlkTHCO3-; (c) the lower [H+] root (higher pH root) of AlkTCO32-; (d) the greater [H+] root (lower pH root) of AlkTCO32-. The thick dashed grey line in panels (c) and (d) shows the critical limit above which the AlkTCO32- always has two roots. Below this limit, further calculations are required to determine the number of solutions. More details are given in the text and in the Supplement. Please notice the different scales on the horizontal axes and for the pH colour coding in the four panels.

Download

3.2.2 Results

While all the test cases have their specific relevance, we are going to focus on SW2 for most of our discussion here. SW2 covers currently observed seawater samples, thus encompassing SW1, and conditions expected to occur over the next 50 000 years as derived from simulation experiments carried out with MBM-MEDUSA (Munhoven2009). A wider selection of results also for the other cases is presented in the “Additional Results” in the Supplement. pH distributions for the SW2 test case are shown in Fig. 5.

The difficulties posed by AlkTCO2 that were at the origin of most of the amendments to the solver algorithms show up in the histograms for the number of iterations required to reach convergence shown in Fig. 6 for solve_at_general which uses the hybrid Newton–Raphson–regula falsi–bisection scheme and in Fig. 7 for solve_at_general_sec which uses the hybrid secant–regula falsi–bisection scheme. With each one of the two solvers, AlkTCO2 problems require in general more iterations to conclude than the other three pairs. This is especially pronounced with solve_at_general (Fig. 6), where a considerable fraction of the AlkTCO2 samples requires 45 to 55 and more iterations. In comparison, AlkTCT samples typically require about four to eight iterations for naturally occurring compositions, and only in some rare instances more than 20 for the extreme SW3. The other pairs range between these two, AlkTHCO3- coming closest to AlkTCT. ABW5 shows a few deviations from the other tests cases. Here, solving the AlkTCO2 problem with solve_at_general nearly always takes more than 50 iterations, with solve_at_general almost always nine. The solution of AlkTCT for ABW5 with solve_at_general_sec takes considerably more iterations than AlkTCO32- (the fastest), and AlkTCO2 (the second fastest).

Finally, Figs. 6 and 7 demonstrate the superiority of solve_at_general_sec over solve_at_general. All in all, the former requires only one-fourth to one-half of the number of iterations than the latter, and it produces root approximations characterised by equation residuals that are up to 7 orders of magnitude lower than those obtained with the former (see Tables S4 and S5 in the “Additional Results” section in the Supplement). ABW5 again presents an exception to this general pattern: solve_at_general_sec requires typically about twice as many iterations to solve the AlkTCT problem than solve_at_general.

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f06

Figure 6Number of iterations to convergence required by the various data pairs (separately for the lower and the greater [H+] roots of the AlkTCO32- problem), for each of the four test cases, carried out with solve_at_general (using a hybrid Newton–Raphson–regula falsi–bisection method). The absolute maximum numbers of iterations were 58, 67, 64 and 56, for SW2, SW3, BW4 and ABW5, respectively, and 58 for SW1 (not shown).

Download

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f07

Figure 7Number of iterations to convergence required by the various data pairs (separately for the lower and the greater [H+] roots of the AlkTCO32- problem), for each of the four test cases, carried out with solve_at_general_sec (using a hybrid secant–regula falsi–bisection method). The absolute maximum numbers of iterations were respectively 20, 21, 29 and 27, for SW2, SW3, BW4 and ABW5, respectively, and 20 for SW1 (not shown).

Download

All these observations are also reflected in the execution times of the two solvers. The Newton–Raphson-based solver takes more than 5 times as much time for the SW2 test case with AlkTCO2 than with AlkTCT; for AlkTCO32-, it takes 4 times as much (for both roots though, including the solution of the minimisation problem for part of the domain). For AlkTHCO3-, the difference is only 20 %. With the secant-based method, the picture is completely different: AlkTCO2 takes only about 30 % more time than AlkTCT, AlkTCO32- twice as much, whereas AlkTHCO3- executes even about 5 % faster. For the AlkTCO2 pair of input data, the difference between the two solvers is greatest: the secant-based one takes less than one-fourth of the time taken by the Newton–Raphson-based one.

Another key factor that influences the execution times is the initialisation scheme, although the comparisons are not as clear cut as in Munhoven (2013). Safe initialisation with the geometric mean of the root brackets (the fall-back initialisation value mentioned in Sect. 2.5) results in 40 %–60 % increases of the execution times for the AlkTCT and the AlkTHCO3- input pairs, compared to the standard cubic polynomial one. Similar increases are obtained with a constant uniform pH = 8 initialisation. For AlkTCO2, and AlkTCO32-, the differences are much smaller and range between a decrease or an increase of up to 5 %. With these two, the quality of the root brackets seems to be more critical than the initial value.

In the analysis in Sect. 2.4.1, two characteristic thresholds for AlkT have been made out for γ>0: an upper one at Lmin+AlknWC(Hmin), above which the problem always has two [H+] solutions, and a lower one at Lmin+AlknWCinf, below which the problem does not have any solution at all. For intermediate values of AlkT, it is necessary to determine Htan and Alktan to find out how many roots the problem has, and, in case there are two, where the separation between them lies. The minimisation procedure required to determine Htan is computationally expensive as can be seen in Fig. 8 (for SW2-sc). The most probable number of iterations is in all experiments between 21 and 25; the median number is each time 0.9±0.5 higher than the most probable number, due to the skew-symmetric nature of the distribution of the number of iterates, as illustrated in the insert in Fig. 8 (see also Fig. S23 in the “Additional Results” section in the Supplement). The subsequent computation of the roots is much cheaper: for the lower root, the secant-based algorithm most probably takes five iterations, and only occasionally 15–16, and for the greater root, most probably four and only rarely more than nine. The total number of samples in the SW2 test case is 1.95 million. Overall, 10 500 (0.54 %) of these do not have any root for the AlkTCO32- pair and the solution of the minimisation problem is required for 173 445 samples (8.89 %), because Htan is required to separate the two roots. The lower threshold essentially turns out as useless: it ranges at about −28mmol kg−1. This is due to the hydrogen sulfate acid system which strongly dominates the AlknWC minimum in seawater, because of the high total sulfate concentration in seawater (ST28mmolkg-1). For carbonate ion concentrations below 400 µmol kg−1, i.e. for most of the naturally occurring waters, the AlkTCO32- problem will always have two roots and the solution of the auxiliary minimisation problem is not required to characterise them.

https://gmd.copernicus.org/articles/14/4225/2021/gmd-14-4225-2021-f08

Figure 8Number of iterations required by Brent's algorithm in the SW2 test case to solve the auxiliary minimisation problem whose solution determines the number of roots of the AlkTCO32- pair and also provides the separation between the two roots. The white area covers the region where the solution of the minimisation problems is not required as AlkT is sufficiently high so that there were two roots. The insert shows the frequency distribution of the number of iterations required. The black line in the lower right corner traces the limit between regions with two roots and without roots (compare with Fig. 5c and d).

Download

4 Conclusions

The approach adopted in SolveSAPHE (Munhoven2013) to safely determine carbonate speciation in particular, and speciation calculations of mixtures of acids in aqueous solution in general, knowing only the total concentrations of the different acid systems and the total alkalinity of the system was adapted and extended here to use [CO2], [HCO3-] and [CO32-] instead of the total inorganic carbon concentration, CT. The rationale can be entirely transposed to these three pairs: (1) the amended alkalinity–pH equations for AlkTCO2 and for AlkTHCO3- still have one and only one positive solution, while AlkTCO32- may have no solution, or one or two; (2) intrinsic brackets that only depend on a priori available information can be derived for the root of the AlkTCO2 and AlkTHCO3- problems, as well as for the two roots of AlkTCO32- problems that may have to be solved for naturally occurring sample compositions. More uncommon but physically realistic AlkTCO32- problems may additionally require the solution of an auxiliary minimisation problem to determine the threshold AlkT value below which the problem does not have any roots and above which it has two of them. The solution of this problem also provides a separation value of the two roots. To our best knowledge, SolveSAPHE is the first package to offer a complete solution of the AlkTCO32- problem, autonomous above all.

The two safeguarded numerical solvers from SolveSAPHE v1 have been adapted to allow for the solution of problems that may have up to two roots. The Newton–Raphson–bisection-based solver required extensive modifications for the reliable solution of the numerically far more challenging AlkTCO2, AlkTHCO3-, and AlkTCO32- problems. Most bisection steps have been replaced by regula falsi steps for increased convergence speed. The secant–bisection solver only required minimal adaptations. A Fortran 90 reference implementation, SolveSAPHE-r2, was prepared and used to evaluate the performance of the different methods for solving four benchmark problems. While the secant–bisection method was already slightly superior to the Newton–Raphson–bisection method in SolveSAPHE v1, that advantage has now become overwhelming: in SolveSAPHE-r2, it typically requires 2 to 4 times fewer iterations, and for the newly handled pairs, the equation residuals are orders of magnitude lower than the Newton–Raphson–regula falsi–bisection-based solver (typically of the order of 10−1910−18 compared to 10−1310−12).

For carbonate speciation problems posed by AlkT and either one of [CO2], [HCO3-] or [CO32-], the secant-based routine from SolveSAPHE-r2, solve_at_general2_sec, is thus clearly the method of choice; for calculations on the basis of AlkTCT, both solve_at_general and solve_at_general_sec from SolveSAPHE v1 will perform better, although the secant-based solver is marginally faster once again.

Appendix A: The direct cases

For the sake of completeness, I provide here succinct “recipes” to calculate all the different carbonate system related variables, knowing two of them. Many of these were already known in the 1960s (see, e.g. Park1969). The Guide to Best Practices for Ocean CO2 Measurements (Dickson et al.2007) lists the most commonly used pairs and furthermore includes procedures for selected triplets and quartets, for which not all of the equilibrium constants are required. In the following, we assume that there are direct and invertible relationships between [CO2] and the fugacity (fCO2) or the partial pressure (pCO2) of CO2 and between pH and [H+] on any chosen pH scale. We therefore restrict ourselves to [CO2] and [H+].

The conditions for the existence of a solution are generally that the concentrations of H+ and of the DIC species are strictly positive. In some instances, the input data must fulfil additional constraints that are, however, not always straightforward to quantitatively state a priori.

CT and CO2, CT and CO32-

: (1) With these two pairs, the [CO2]/CT fraction (the [CO32-]/CT fraction) is fixed and Eq. (4) (Eq. 6) defines a quadratic equation in [H+] that always allows for exactly one positive solution; (2) calculate the remaining two species concentrations from their respective species fraction; (3) AlkT from Eq. (1). In addition to the positivity of the species concentrations, the following constraints must be met: [CO2]<CT and [CO32-]<CT.

CT and HCO3-

: With this pair, the [HCO3-]/CT fraction, denoted by b hereafter, is fixed, and Eq. (5) becomes a quadratic equation in [H+]. That equation has two positive solutions if b<1/(1+2K2/K1), one double root if b=1/(1+2K2/K1) and no real solutions if b>1/(1+2K2/K1). This is well illustrated in Fig. 1b above: there are CT[HCO3-] combinations that allow for two different AlkT values and, equivalently, two pH values, and there are others that do not allow for any. Please notice that the threshold fraction 1/(1+2K2/K1) is always lower than 1 and the natural a priori constraint requiring that b<1 is thus insufficient to guarantee a solution: for T=275.15K, S=35 and P=0bar, the threshold ratio is 94.48 %.
When there are two roots, one faces a similar dilemma as with the AlkTCO32- problem: which one to choose? Most often, the lower of the two will again be the appropriate one, as that one typically leads to AlkT>CT, whereas the greater one leads to AlkT<CT. This criterion might be sufficient to discriminate between the two – in seawater it generally is – but in some instances additional information, quantitative or qualitative, might be in order.
In general, (1) solve the quadratic equation and choose the appropriate of the two roots; (2) calculate [CO2] and [CO32-] from their respective species fractions; (3) AlkT from Eq. (1).

CO2 and HCO3-

: (1) [H+] from K1; (2) [CO32-] from K2; (3) CT can be calculated from the three carbonate species concentrations; (4) AlkT from Eq. (1).

CO2 and CO32-

: (1) [HCO3-] from [HCO3-]2=K1/K2[CO2][CO32-]; (2) CT from the three carbonate species concentrations; (3) [H+] from K1 or K2; (4) AlkT from Eq. (1).

HCO3- and CO32-

: (1) calculate [H+] from K2; (2) [CO2] from K1; (3) CT from the three carbonate species concentrations; (4) AlkT from Eq. (1).

CO2 and H+

: (1) calculate [HCO3-] from K1; (2) calculate [CO32-] from K2; (3) CT from the three carbonate species concentrations; (4) AlkT from Eq. (1).

HCO3- and H+

: (1) calculate [CO2] from K1; (2) calculate [CO32-] from K2; (3) CT from the three carbonate species concentrations; (4) AlkT from Eq. (1).

CO32- and H+

: (1) calculate [HCO3-] from K2; (2) calculate [CO2] from K1; (3) CT from the three carbonate species concentrations; (4) AlkT from Eq. (1).

AlkT and H+

: (1) CT from Eq. (2); (2) individual species concentrations from the species fractions.
As illustrated in Fig. 1d–f above, there are AlkT[H+] combinations that lead to physically unrealistic negative AlkC. Following Eq. (3), negative AlkC requires negative CT, and vice versa.
The shape of the blank area depends on the non-carbonate contributors to the total alkalinity. In practice, such incompatible combinations are unlikely to arise from measurements, except if the adopted set of AlkT contributors is inappropriate.

CT and H+

: individual species concentrations from the species fractions; AlkT from Eq. (1).

Code availability

All the Fortran 90 codes of SolveSAPHE version 1 series (of which v1.0.3 was used to derive the results presented in Fig. 1) are available on Zenodo from Munhoven (2013–2021) for use under the GNU Lesser General Public Licence version 3 (LGPLv3) or later. The codes for SolveSAPHE-r2 (v2.0.1) that are described in this paper are included in the Supplement and made available for use under the same licence. They are also archived on Zenodo (Munhoven2021). Future bug-fix releases and updates will also be archived there.

Epitalon et al. (2021) have ported SolveSAPHE-r2 to R (not used here) for usage under the GNU General Public License version 2 (GPL-2) or 3 (GPL-3).

Supplement

The supplement related to this article is available online at: https://doi.org/10.5194/gmd-14-4225-2021-supplement.

Competing interests

The author declares that there is no conflict of interest.

Disclaimer

Publisher’s note: Copernicus Publications remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Acknowledgements

James Orr provided the kick-off momentum for me to reconsider SolveSAPHE and to complete it in order to combine AlkT with the individual carbonate system species instead of CT – thank you. Thanks are also due to Jean-Pierre Gattuso for pointing out issues with the colour schemes adopted in the originally submitted version of the manuscript and for guidance about how to address them. The comments and recommendations by the two anonymous referees were most helpful to improve the framing of the paper and the scope of the results. The analysis based upon Fig. 4 was suggested by Anonymous Referee #1 and recommended for inclusion in the manuscript by Anonymous Referee #2.

Financial support

Financial support for this work was provided by the Belgian Fund for Scientific Research – F.R.S.-FNRS (project SERENATA, grant CDR J.0123.19). Guy Munhoven is a research associate with the Belgian Fund for Scientific Research – F.R.S.-FNRS.

Review statement

This paper was edited by Sandra Arndt and reviewed by two anonymous referees.

References

Brent, R. P.: Algorithms for minimization without derivatives, Prentice-Hall, Englewood Cliffs, NJ, 1973. a, b

Byrne, R. H. and Yao, W.: Procedures for measurement of carbonate ion concentrations in seawater by direct spectrophotometric observations of Pb(II) complexation, Mar. Chem., 112, 128–135, https://doi.org/10.1016/j.marchem.2008.07.009, 2008. a

Deffeyes, K. S.: Carbonate Equilibria : A Graphic and Algebraic Approach, Limnol. Oceanogr., 10, 412–426, https://doi.org/10.4319/lo.1965.10.3.0412, 1965. a, b

Dickson, A. G., Sabine, C. L., and Christian, J. R. (Eds.): Guide to Best Practices for Ocean CO2 Measurements, vol. 3, in: PICES Special Publication, Carbon Dioxide Information and Analysis Center, Oak Ridge (TN), available at: https://cdiac.ess-dive.lbl.gov/ftp/oceans/Handbook_2007/Guide_all_in_one.pdf (last access: 24 June 2021), 2007. a, b, c, d

Epitalon, J.-M., Gattuso, J.-P., and Munhoven, G.: SolveSAPHE: Solver Suite for Alkalinity-PH Equations, available at: https://CRAN.R-project.org/package=SolveSAPHE, last access: 24 June 2021. a

Munhoven, G.: Future CCD and CSH variations: Deep-sea impact of ocean acidification, Geochim. Cosmochim. Ac., 73, A917, 2009. a

Munhoven, G.: Mathematics of the total alkalinity–pH equation – pathway to robust and universal solution algorithms: the SolveSAPHE package v1.0.1, Geosci. Model Dev., 6, 1367–1388, https://doi.org/10.5194/gmd-6-1367-2013, 2013. a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q

Munhoven, G.: SolveSAPHE (Solver Suite for Alkalinity-PH Equations) [software], Zenodo, https://doi.org/10.5281/zenodo.3752250, 2013–2021. a, b, c

Munhoven, G.: SolveSAPHE-r2 (Solver Suite for Alkalinity-PH Equations–Release 2) [software], Zenodo, https://doi.org/10.5281/zenodo.4771132, 2021. a

Orr, J. C., Epitalon, J.-M., and Gattuso, J.-P.: Comparison of ten packages that compute ocean carbonate chemistry, Biogeosciences, 12, 1483–1510, https://doi.org/10.5194/bg-12-1483-2015, 2015. a

Park, P. K.: Oceanic CO2 System: An Evaluation of ten Methods of Investigation, Limnol. Oceanogr., 14, 179–186, https://doi.org/10.4319/lo.1969.14.2.0179, 1969. a

Patsavas, M. C., Byrne, R. H., Yang, B., Easley, R. A., Wanninkhof, R., and Liu, X.: Procedures for direct spectrophotometric determination of carbonate ion concentrations : Measurements in US Gulf of Mexico and East Coast waters, Mar. Chem., 168, 80–85, https://doi.org/10.1016/j.marchem.2014.10.015, 2015. a

Sharp, J. D. and Byrne, R. H.: Carbonate ion concentrations in seawater: Spectrophotometric determination at ambient temperatures and evaluation of propagated calculation uncertainties, Mar. Chem., 209, 70–80, https://doi.org/10.1016/j.marchem.2018.12.001, 2019. a, b, c, d

Yao, W. and Millero, F. J.: The Chemistry Of the Anoxic Waters in the Framvaren Fjord, Norway, Aquat. Geochem., 1, 53–88, https://doi.org/10.1007/BF01025231, 1995. a

Zeebe, R. E. and Wolf-Gladrow, D.: CO2 in seawater : Equilibrium, kinetics, isotopes, vol. 65, in: Elsevier Oceanography Series, Elsevier, Amsterdam (NL), ISBN 978-0-444-50579-8, 2001. a, b, c

1

Zeebe and Wolf-Gladrow (2001) appear to be aware of it. In their recipe for given AlkT and [CO32-] (on pp. 276–277), they indicate that the quintic equation to solve with their practical alkalinity approximation has two positive and three negative roots and that the larger positive one should be used (without any further justification, though). As shown here, this statement is not universally true – there are instances where that equation has only one positive or no positive roots. It is nevertheless true for typical seawater and the lower of the two positive roots actually implies unrealistically low, yet physically sensible, CT (see discussion in Sect. 2.4.2 below).

2

Both corrections have been backported to the version 1 branch of SolveSAPHE and are included in v1.1 in the SolveSAPHE archive on Zenodo (Munhoven2013–2021).

Short summary
SolveSAPHE (Munhoven, 2013) was the first package to calculate pH reliably from any physically sensible pair of total alkalinity (AlkT) and dissolved inorganic carbon (CT) data and to do so in an autonomous and efficient way. Here, we extend it to use CO2, HCO3 or CO3 instead of CT. For each one of these pairs, the new SolveSAPHE calculates all of the possible pH values (0, 1, or 2), again without any prior knowledge of the solutions.