Skip to content

Solving an equilibrium ​

Before this page

The tutorial Chemical Equilibrium. The snippets below reuse its calcite system cs and its initial state state, and they are shown rather than executed.

equilibrate works with its defaults on most systems, and the tutorial Chemical Equilibrium relies on them throughout. This page gathers what those defaults are and how each is changed: the back ends and the way the answer is certified, the constraints that replace a fixed temperature and pressure, the derivatives of an equilibrium with respect to its inputs, the settings of the solver, the activity models of the aqueous phase and the declaration of solid solutions.

Choosing a solver ​

ChemistryLab provides two solver extensions. Load whichever fits your workflow:

Extension packagesDefault solverWhen to use
Optimization, OptimizationIpoptIpoptOptimizergeneral-purpose, robust
OptimaSolverOptimaOptimizerpreferred when available

When both are loaded, OptimaSolver provides the default single back end. It runs the active-set iteration of Optima, the one Reaktoro computes its equilibria with; its interior point remains available as OptimaOptimizer(algorithm = :interior_point). Here is what each back end returns on its own, before the dual Newton polishes it, against the certified search; the balance is the worst element row relative to what it holds, the stationarity is scaled as the certificate scales it, and the time is the minimum of three runs on one thread (scripts/bench_coupling/backends.jl, see Reproducing the figures).

casemethodbalancestationarityprovedtime (ms)
calcite in waterOptimaSolver active set6e-156e-12yes0.17
calcite in waterOptimaSolver interior point3e-095e-06no0.75
calcite in waterIpopt6e-151e-03no4.99
calcite in watercertified route4e-163e-16yes0.65
calcite + 1 mmol CO2OptimaSolver active set5e-143e-14yes0.15
calcite + 1 mmol CO2OptimaSolver interior point1e-106e-10no0.47
calcite + 1 mmol CO2Ipopt5e-144e-04no5.06
calcite + 1 mmol CO2certified route4e-153e-16yes0.60
calcite + 50 mmol CO2OptimaSolver active set2e-151e-13yes0.17
calcite + 50 mmol CO2OptimaSolver interior point1e-129e-06no0.24
calcite + 50 mmol CO2Ipopt2e-157e-04no4.82
calcite + 50 mmol CO2certified route6e-153e-16yes0.58
pure waterOptimaSolver active set9e-184e-14yes0.40
pure waterOptimaSolver interior point9e-161e-04no3.17
pure waterIpopt2e-107e-04no11.24
pure watercertified route1e-166e-16yes0.73
CEM I paste w/b 0.30OptimaSolver active set5e-137e-05no5.48
CEM I paste w/b 0.30OptimaSolver interior point3e-098e-03no5.66
CEM I paste w/b 0.30Ipopt2e-063e-03no697.80
CEM I paste w/b 0.30certified route2e-153e-16yes30.93
CEM I paste w/b 0.45OptimaSolver active set5e-135e-04no4.74
CEM I paste w/b 0.45OptimaSolver interior point7e-098e-03no4.98
CEM I paste w/b 0.45Ipopt2e-063e-03no970.90
CEM I paste w/b 0.45certified route1e-151e-16yes10.20
CEM I paste w/b 0.60OptimaSolver active set2e-127e-05no4.45
CEM I paste w/b 0.60OptimaSolver interior point1e-088e-03no5.75
CEM I paste w/b 0.60Ipopt2e-063e-03no811.10
CEM I paste w/b 0.60certified route7e-161e-16yes11.14

On the aqueous systems the active set returns, by itself and within a millisecond, an answer the certificate proves. On a cement paste no back end does: the active set meets the balance to 10⁻¹² but stops short of stationarity, and Ipopt takes about a second. The certified search, started from those answers, proves the paste in a few hundredths of a second, which is why equilibrate certifies by default.

equilibrate(state) does not pick one of them — it proves the answer ​

No single back end certifies every case, so the one-argument equilibrate solves from every start available and keeps the answer optimality_certificate proves optimal: each back end's answer is polished by the dual Newton method, and the first proved answer is returned. The certificate decides rather than ranks, the problem being convex whenever the mixing terms are, so trying several starts is exact, not heuristic.

julia
state_eq = equilibrate(state)                   # certified where it can be (the default)
state_eq = equilibrate(state; certify = false)  # one back end, polished
state_eq = equilibrate(state; certify = true)   # certified, or an error
eq, cert = equilibrate_certified(state)         # when the proof itself is wanted

Pass a solver explicitly — equilibrate(state, OptimaOptimizer()) — to use that one back end without the search. Its answer is still polished, as described next, and certificate = Ref{Any}() receives the certificate of what is returned, nothing when none could be computed.

Trace elements and the certificate ​

Each conservation row is judged on its own scale: the balance of row is met when   , what the row holds, so that an element present as a trace is balanced to the same relative accuracy as a major one. A phase made of such a trace, which cannot hold the amounts in moles the search compares it with, is judged on the scale of what it can hold once the search has sent it away and taken it back a portlandite suspension whose aluminum is a mol seed of ettringite certifies, with the gypsum where a seed of mol puts it.

When no start certifies, equilibrate and equilibrate_certified return the answer with the smallest KKT error and warn, once per session, naming the row furthest out, judged as the certificate judges it. That answer is not an equilibrium. Ask for one with certify = true, which raises UncertifiedEquilibrium instead, the answer and its certificate in the exception:

julia
eq = try
    equilibrate(state; certify = true)
catch e
    e isa UncertifiedEquilibrium || rethrow()
    @show e.certificate.balance_relative    # the worst row, relative to what it holds
    e.state                                  # the answer with the smallest KKT error
end

optimality_certificate checks any state against its budget: balance is the worst row in moles, balance_relative the worst relative to what it holds.

One equilibrium, whatever the back end ​

The back ends do not all solve the same equations. Ipopt minimizes the scalar n⋅μ(n), the interior point of OptimaSolver steers on the gradient μ, and the dual Newton solves the conditions of equilibrium themselves, μ(n) = −Aᵀy on the species present. The gradient of n⋅μ(n) is μ + Jᵀn, where J = ∂μ/∂n, and Jᵀn = 0 is the Gibbs–Duhem relation: where the activity model satisfies it, n⋅μ(n) is the Gibbs energy and the three agree; where it does not, the minimum of n⋅μ(n) is another composition. The ideal model, Pitzer (Pitzer, 1975), Davies on ions and the Debye–Hückel form with one ion size satisfy it; the B-dot model with its ion sizes and linear terms, Davies with a neutral solute and SIT do not. On calcite and carbon dioxide in a sodium chloride solution, Ipopt's answer meets the element balance to 1e-15 mol under every model; its dissolved calcium is the equilibrium's to 2e-6 under the ideal model, and 7e-4 off under Davies, whose dissolved carbon dioxide carries a salting-out term with no partner.

So every back end's answer is polished: the dual Newton is started from it, and the composition it certifies is the one returned. The start then decides how fast the answer is reached, not which answer it is, and a derivative taken through it is that of the composition returned. Without OptimaSolver nothing can polish, and a back end that minimizes n⋅μ(n) refuses a model that breaks the Gibbs–Duhem relation, with an error that names it, rather than return a composition that is not the equilibrium.

What the certified search does first ​

With every activity at one, the equilibrium is a linear program over the pure phases, minimize gᵀn subject to A n = b, n ≥ 0, and the certified search solves it before anything else.

  • A budget that no non-negative amounts of the declared species can meet is refused at once, with the reason in words: the certificate has budget_feasible = false, route = :infeasible, and unplaceable, for instance "the budget asks for −0.001 mol of Ca+2, and every declared species holds it with a non-negative coefficient". There is no equilibrium to search for, and nothing is.

  • Otherwise the vertex of the program, with every other species raised to the amount its multipliers give it, is the first start of the search. On cold cement pastes it certifies twenty to fifty times faster than the recipe as given; a state already near its answer loses nothing.

cert.route says which start the answer came from (:lp_start, :state, :ideal_mixing, :ideal, :continuation or :restart) and cert.n_dual_solves how many solves the search ran. lp_start = false turns the program off.

Explicit solver (always works) ​

Pass the solver as the second positional argument:

julia
using Optimization, OptimizationIpopt
state_eq = equilibrate(state, IpoptOptimizer())

using OptimaSolver
state_eq = equilibrate(state, OptimaOptimizer())

Default shortcut ​

When only one extension is loaded:

julia
using Optimization, OptimizationIpopt
state_eq = equilibrate(state)   # → IpoptOptimizer

using OptimaSolver
state_eq = equilibrate(state)   # → OptimaOptimizer

With both loaded, OptimaSolver always wins:

julia
using Optimization, OptimizationIpopt
using OptimaSolver
state_eq = equilibrate(state)   # → OptimaOptimizer (priority)

Constraints other than fixed T and P ​

A closed system at given temperature and pressure is one case among several. A vessel that exchanges no heat has its temperature determined by the reaction; a titration holds the pH and lets the amount of acid follow. Both are equilibrium problems, and both are stated by saying what is held and what is unknown.

Shown, not executed

The blocks in this section are shown rather than executed. The figures quoted below are the ones test/equilibrium_constraints.jl asserts.

julia
using ChemistryLab, DynamicQuantities, OptimaSolver

# The same calcite system, but adiabatic: no heat leaves, so T is an unknown
st = ChemicalState(cs)
set_quantity!(st, "Cal",  1e-2u"mol")
set_quantity!(st, "H2O@", 1.0u"kg")
set_quantity!(st, "H+",   1e-2u"mol")
set_quantity!(st, "OH-",  1e-10u"mol")

des   = DualEquilibriumSolver(cs, DiluteSolutionModel())
eq_ad = solve(des, st; constraint = Adiabatic())

temperature(eq_ad)      # 298.1996 K — the reaction warms it by 0.0496 K
pH(eq_ad)               # 6.4323, against 6.4329 at fixed temperature
constraintheldunknownvehicle
FixedTP (default)T, P——
Adiabaticthe enthalpy of the initial stateTparameter
FixedEnthalpya prescribed HTparameter
FixedVolumea prescribed VPparameter
SealedVolumethe volume of the initial statePparameter
FixedpH−log₁₀ a(H⁺)the titrant amountcolumn
FixedActivitya of any speciesthe titrant amountcolumn

The two vehicles ​

They are not interchangeable, and the distinction is the same one Reaktoro (Leal et al., 2017) draws.

A prescribed property — an enthalpy, a volume — adds one parameter and one equation to the solver's own square system. Nothing loops around the equilibrium solve: the temperature is an unknown beside the amounts and the element potentials, and the enthalpy balance is one more row of the same Newton system. So an adiabatic solve costs one equation, not a solve per trial temperature.

A prescribed chemical potential — a pH, an activity — adds one column to the conservation matrix instead: an unknown amount of a titrant the system may draw on. The linear rows become A n − A[:, titrant] q = b, so the system is open to that one substance and closed to everything else, and q comes back as part of the answer — it is the reagent consumed, which is what a titration measures.

julia
q = Ref(Float64[])
eq_ph = solve(des, st; constraint = FixedpH(7.0), parameters = q)
q[][1]      # 3.4673e-3 mol of H+ had to be added to hold pH 7

On 10 mmol of calcite in a kilogram of water, whose free pH is 9.90, holding the pH takes more acid the lower the target, and at pH 6 the calcite is gone entirely:

pH heldH⁺ added (mol)calcite left (mol)
61.689e-20
73.467e-37.063e-3
88.648e-49.149e-3
92.504e-49.728e-3

What is checked, and what is refused ​

The adiabatic answer is validated two ways. Against physics: H⁺ + OH⁻ → H₂O comes out at −55.85 kJ/mol at every amount tested, against the accepted −55.8, with nothing fitted to it — the enthalpies come from the database and the temperature is an unknown of the system. And against itself: solving at a fixed temperature equal to the one the adiabatic solve found returns the same composition to 1e-12.

A volume constraint on a condensed system is refused, with the quantity it measured named in the error. The molar volumes of the minerals in Cemdata18 do not depend on pressure — V⁰(1 bar) = V⁰(100 bar) to the last bit for Cal — water's falls by 0.44 % over 100 bar, and the partial volumes of a few aqueous ions vary, OH⁻'s by 8 % over 100 bar. The relative sensitivity (∂V/∂P)·P/V of water alone is 4.5e-5 at 1 bar, some 225 bar to change its volume by one percent, and a paste, whose solids do not move, has less. That is the physics, not a solver limitation: the volume of a nearly incompressible condensed system is fixed by its composition. Declare a gas phase to give the pressure something to do. To report the volume change of a sealed specimen at fixed pressure — what a hydrating binder actually needs — use porosity with a reference state instead.

Constraints need the certifying solver

The prescribed property or potential is an unknown of the dual Newton's own system, so a constraint other than FixedTP requires OptimaSolver and a system with an aqueous phase and H2O@. Asking for one otherwise raises, rather than being silently ignored. equilibrate(state; constraint = ...) goes through the certified path, so the answer still comes with its proof.

Differentiating an equilibrium ​

A ChemicalState carries whatever number type its amounts have, so a composition built from ForwardDiff.Dual values propagates through the speciation, and pH, pOH, porosity and saturation come back as duals too.

Crossing the solve works as well, and without asking any solver to iterate on dual numbers — Ipopt, a C library, does not operate on them. The equilibrium is solved once at the primal values, by the back end chosen and polished, and the sensitivities come from the conditions of equilibrium at the answer, the implicit-function-theorem method:

restricted to the species actually present. One factorization serves every partial derivative, and the result is exact — no step size to choose.

julia
using ChemistryLab, DynamicQuantities, ForwardDiff, OptimaSolver

db = Dict(symbol(s) => s for s in
          build_species(datapath("slop98-inorganic-thermofun.json"); verbose = false))
cs = ChemicalSystem([db[s] for s in split("H2O@ H+ OH- CO2@ HCO3- CO3-2 Ca+2 Cal")])
i_h2o, i_cal, i_co2, i_ca =
    (findfirst(s -> symbol(s) == x, cs.species) for x in ("H2O@", "Cal", "CO2@", "Ca+2"))

f(x) = begin
    n = Any[fill(0.0u"mol", length(cs.species))...]
    n[i_h2o] = 55.5u"mol";  n[i_cal] = 0.05u"mol";  n[i_co2] = x * u"mol"
    eq = equilibrate(ChemicalState(cs, n), OptimaOptimizer())
    ustrip(us"mol", eq.n[i_ca])
end

ForwardDiff.derivative(f, 0.01)     # → 0.163095

Each mole of carbon dioxide added dissolves 0.16 mol of calcite at this point, where 3.7 mmol are dissolved. The certified search, equilibrate(state) or equilibrate_certified, returns the same derivative to fifteen digits: it lifts its answer the same way, with the active set frozen and the constraint's unknowns included, so the titrant a prescribed pH needs or the temperature an adiabatic solve reaches comes back with its derivative too. Both methods lift one level of duals at a time, so that a derivative nested in another (a gradient differentiated again for a Hessian, as an inversion needs) is exact at every level, and both lift whatever carries the duals: the amounts, the temperature, the budget, the standard potentials of the species or the parameters of the activity model. The conditions lifted are those the polished answer satisfies, so the derivative is that of the map the solve returns, which is what a derivative by finite differences of that map would approach. Without OptimaSolver, a single back end falls back to a sensitivity solved in Float64, for the amounts of the state only and one level deep, and refuses the rest rather than return derivatives that are not there.

Why the complementarity conditions cannot be skipped

The stationarity conditions are ∇G − Aᵀy − z = 0, A n = b, nᵢzᵢ = 0, with z ≥ 0 the stability multipliers. The last block partitions the species, and dropping it does not degrade the answer gently — it destroys it. On calcite + CO₂ in water with a gas phase declared, the unreduced system puts the whole response into the absent gas species (n = 5×10⁻¹¹ mol), returning a sensitivity that satisfies the element balance to 4×10⁻¹⁶ and means nothing.

No back-end returns z, so the active set is recovered internally: a species negligible on the scale of the system that nonetheless takes a leading share of the response is pinned, and the system re-solved.

Verified against Reaktoro

On calcite + CO₂ + water, ∂n/∂(CO₂) from this method agrees with the package's own finite differences to 9×10⁻⁵ — the finite-difference truncation error — and with Reaktoro 2.13 reading the same Cemdata18 file, over the same eleven species, under the same (ideal) activity model:

speciesChemistryLab (AD)Reaktoro (FD)rel. diff
H₂O−0.181336−0.1813973.4×10⁻⁴
Ca²⁺+0.151920+0.1519874.4×10⁻⁴
HCO₃⁻+0.333308+0.3334273.6×10⁻⁴
CO₂(aq)+0.818655+0.8186006.7×10⁻⁵
Ca(HCO₃)⁺+0.029333+0.0293381.6×10⁻⁴
calcite−0.181251−0.1813244.0×10⁻⁴

The equilibrium amounts agree to the same order (Ca²⁺ 3.5281×10⁻³ against 3.52902×10⁻³). Reaktoro's own spread across h ∈ {10⁻³, 10⁻⁴, 10⁻⁵} is 7.2×10⁻⁴, so the residual difference sits below the truncation error of the reference on every species.

The absent gas species gets exactly zero from the active-set treatment; the finite-difference reference gives 2×10⁻⁹, the size of its truncation error.

A cross-code comparison has three parameters, not one

Database, species list and activity model all have to match, and each is worth tens of percent here. Reading Cemdata18 in both codes but leaving Reaktoro on its HKF activity model against this package's default DiluteSolutionModel() moves ∂Ca²⁺/∂(CO₂) from +0.1520 to +0.2179 — a 35 % gap that says nothing about either code.

The species list matters just as much. Dropping the aqueous calcium complexes leaves free Ca²⁺ as the only aqueous home for calcium, so ∂Ca²⁺/∂(CO₂) and ∂calcite/∂(CO₂) mirror each other exactly. Restoring CaOH⁺, Ca(CO₃)@ and Ca(HCO₃)⁺ breaks that mirror — the difference is what Ca(HCO₃)⁺ takes up — and both codes break it the same way. The element balance closes to 2×10⁻¹⁶ either way.

Controlling the solver ​

Variable space: :linear vs :log ​

equilibrate accepts a variable_space keyword that selects the optimization variable space:

variable_spaceVariablesRecommended when
Val(:linear)mole amounts nᵢ ≥ 0any start, default
Val(:log)log nᵢrefining a composition already close to the answer

In logarithmic variables, the optimality condition of species i is its amount nᵢ times the gap between its potential and the combination of component potentials its formula implies, so a species held at the regularization floor contributes almost nothing to the optimality test. A starting state in which most species sit at that floor, such as one built from a recipe, then already passes the test of the interior point: from it, an explicit solver in the logarithmic space returns the start or stops without converging. Called without a solver, equilibrate goes through the certified search, whose answer does not depend on this choice; with an explicit solver, the logarithmic space is to be started from a solved state:

julia
state_eq = equilibrate(state, IpoptOptimizer())                        # linear, from the recipe
state_eq_log = equilibrate(state_eq, IpoptOptimizer(); variable_space = Val(:log))

Convergence

Solving a system of equations in chemistry can be a difficult undertaking. The orders of magnitude can vary greatly, and convergence is not guaranteed.


Tolerances ​

Solver options are passed as keyword arguments and forwarded to the optimizer's solve. Ipopt reads reltol as its convergence tolerance tol; it has no counterpart for abstol, which it ignores:

julia
state_eq_tight = equilibrate(state, IpoptOptimizer(); reltol = 1e-12)

OptimaSolver, the default back end once it is loaded, ignores these keywords: its tolerances are the options of the optimizer, OptimaOptimizer(; tol = 1e-12). The answer of equilibrate_certified is judged by its certificate, whatever the back end's tolerance.

Activity models ​

All activity models inherit from AbstractActivityModel. The three in the table below cover ideal behavior through to the extended Debye-Hückel level used by standard geochemical codes; PitzerActivityModel and SITActivityModel extend the range to concentrated solutions, each with its own parameter set.

Choosing a model ​

ModelFormulaValid rangeParameters needed
DiluteSolutionModelRaoult / HenryI ≪ 1 mol/kgnone
HKFActivityModelB-dot extended Debye-HückelI ≲ 1 mol/kgA, B, Ḃ (defaults at 25 °C)
DaviesActivityModelDavies equationI ≲ 0.5 mol/kgA, b (defaults at 25 °C)

activity_model_range returns the bound of this table for a model, and nothing where the table gives no number. None of these formulas announces that it has left its range, so the comparison has to be made: check ionic_strength(eq) <= activity_model_range(model) on any answer that matters. When equilibrate_certified gives up on an answer whose ionic strength is past the bound, its message says so. It is not a formality: measured on blended cement pastes taken to full reaction, the limiting law with a B-dot term (å = 0) did not certify, and with an ion size per ion, HKFActivityModel(), the same budgets did.


DiluteSolutionModel (ideal dilute solution) ​

PhaseLawExpression
Solvent (H₂O)Raoultln a = ln xₛ
Aqueous solutesHenryln a = ln(cᵢ / c°), c° = 1 mol/L
CrystalsPure solidln a = 0
GasIdeal mixtureln a = ln xᵢ + ln(P/P°)
julia
state_eq = equilibrate(state)   # DiluteSolutionModel is the default

HKFActivityModel (extended Debye-Hückel B-dot) ​

Implements the extended Debye-Hückel model of Helgeson (1969) and Helgeson et al. (1981), identical to the model used by PHREEQC (Parkhurst and Appelo, 2013) and EQ3/6.

Ion activity coefficient:

log₁₀ γᵢ = −A zᵢ² √I / (1 + B åᵢ √I)  +  Ḃ I

Neutral aqueous species (salting-out):

log₁₀ γᵢ = Kₙ I

Water activity is computed from the osmotic coefficient via Gibbs-Duhem (not Raoult), which is accurate up to I ≈ 1 mol/kg.

Ionic radius lookup (priority order):

  1. model.å — one common radius for every ion, when given. Short-circuits the rest of the chain.

  2. sp[:å] — explicit value set in species properties.

  3. REJ_HKF — Table 3 of Helgeson et al. (1981) (27 common ions).

  4. REJ_CHARGE_DEFAULT — fallback by formal charge, (Xu et al., 2012) Table H.1-1.

  5. model.å_default (default: the ion size of NaCl, 3.72 Å, (Helgeson et al., 1981) Table 2).

å_default does not impose a common ionic radius

It is the last resort of the chain above, reached only for a charge that neither table covers — in practice |z| ≥ 5. Setting it changes essentially nothing for a real solution. Pass å to impose one common radius, which is what GEM-Selektor (Kulik et al., 2013), PHREEQC's -gamma and most published cement models actually use.

Usage:

julia
# Fixed A, B at 25 °C / 1 bar (fast — suitable for isothermal calculations)
state_eq = equilibrate(state; model=HKFActivityModel())

# Temperature-dependent A and B (recomputed from T, P at each equilibrium solve)
state_eq = equilibrate(state; model=HKFActivityModel(temperature_dependent=true))

# Custom parameters
model = HKFActivityModel(A=0.52, B=0.33, Ḃ=0.04)

# One common ion size, that of NaCl, overriding the per-species tables
model = HKFActivityModel(å = literature_value("Helgeson1981", "nacl_distance_of_closest_approach"))

# å = 0 collapses the denominator to 1: the Debye-Hückel limiting law plus Ḃ I
model = HKFActivityModel(å = 0.0)

The model Cemdata18 prescribes ​

Cemdata18 was derived with, and prescribes, an extended Debye–Hückel equation with one ion-size parameter and one B-dot common to every ion, set by the dominant electrolyte of the solution (Lothenbach et al., 2019; Appendix C, Eq. C.1): 3.67 Å and 0.123 kg/mol for KOH, 3.31 Å and 0.098 for NaOH, with the same B-dot on the neutral species. It is cemdata18_activity_model:

julia
model = cemdata18_activity_model(:KOH)    # or :NaOH

Lothenbach et al. (2019) state it applicable up to about 1 mol/kg of ionic strength, which activity_model_range returns, and which the certificate of equilibrate_certified compares with the ionic strength of each answer (cert.within_activity_range).

Reproducing one particular GEM-Selektor run ​

A GEM-Selektor run of a Portland cement with CEMDATA18, whose printed activity coefficients are the fixture of A CEM I at equilibrium, with every solid solution declared, was configured differently: fitting its coefficients by charge class identifies the Debye–Hückel limiting law, å = 0, with a B-dot of about 0.0976 and none on the neutral species. That is a configuration of that run, not what Cemdata18 prescribes, and the two models give different coefficients at the ionic strength of that run, 0.2097 mol/kg:

julia
using ChemistryLab
I = 0.2097                                   # mol/kg, the ionic strength of that run
log10γ(m, z) = -m.A * z^2 * sqrt(I) / (1 + m.B * something(m.å, 0.0) * sqrt(I)) + m.Ḃ * I
prescribed = cemdata18_activity_model(:KOH; temperature_dependent = false)
that_run = HKFActivityModel(å = 0.0, Ḃ = 0.0976, Kₙ = 0.0)
[(model = name, γ1 = round(10^log10γ(m, 1); digits = 3), γ2 = round(10^log10γ(m, 2); digits = 3))
 for (name, m) in (("Cemdata18, Eq. C.1", prescribed), ("that GEMS run", that_run))]
2-element Vector{@NamedTuple{model::String, γ1::Float64, γ2::Float64}}:
 (model = "Cemdata18, Eq. C.1", γ1 = 0.75, γ2 = 0.265)
 (model = "that GEMS run", γ1 = 0.611, γ2 = 0.121)
Data read above: Lothenbach2019Lothenbach, B. et al. (2019)5 quantities, 8 tables

Lothenbach, B., Kulik, D. A., Matschei, T., Balonis, M., Baquerizo, L., Dilnesa, B., Miron, G. D., Myers, R. J. (2019). Cemdata18: A chemical thermodynamic database for hydrated Portland cements and alkali-activated materials. Cement and Concrete Research 115, 472-506. doi:10.1016/j.cemconres.2018.04.018

Read in Tables 1-3 and Appendix D checked against the source

Transcribed from the accepted manuscript (PDF, 49 pages with line numbers): notes to Table 1 (lines 234-239), Table 2 (lines 247-310), Table 3 (lines 582-600), Appendix C (lines 1474-1483, Eq. C.1 read on the rendered page, its text layer being garbled), Tables D.1 and D.2 (lines 1532-1551), read on the page text and checked value by value; the journal's page numbers are not in that copy

The Guggenheim parameters were typed into the miscibility_gap example, and the solubility products and Appendix D values into test/cemdata18_reference.jl, before this file existed; all agree with the manuscript. Note a attaches to (Al-)ettringite and tricarboaluminate, note b to (Al-)ettringite and Fe-ettringite (the gap in X_Al), note g to C4AH13 and C4AsH12 (monosulfate), note h to C4AsH12 and C4FsH12 (the Al/Fe monosulfate gap, in X_Al). Monocarbonate carries no such note: Cemdata18 does not treat monosulfate and monocarbonate as a solid solution.

Quantities

namevaluedescriptionwhere
edh_ion_size_KOH3.67Common ion-size parameter a_i of the extended Debye-Hueckel equation (C.1) for KOH solutions, in Angstrom. Appendix C, lines 1476-1477
edh_ion_size_NaOH3.31Common ion-size parameter a_i of the extended Debye-Hueckel equation (C.1) for NaOH solutions, in Angstrom. Appendix C, lines 1476-1477
edh_b_gamma_KOH_25C0.123 kg/molCommon third parameter b_y of Eq. (C.1) for a KOH electrolyte at 25 C, printed as '~0.123'. It also multiplies I for uncharged species, log(gamma) = b_y I. Appendix C, line 1481
edh_b_gamma_NaOH_25C0.098 kg/molCommon third parameter b_y of Eq. (C.1) for a NaOH electrolyte at 25 C, printed as '~0.098'. Appendix C, line 1481
edh_validity_ionic_strength1.0 mol/kgEffective molal ionic strength up to which the paper states the extended Debye-Hueckel correction of Eq. (C.1) applicable: 'up to approx. 1 m'. Appendix C, line 1483

Tables

guggenheim_parameters: 4 rows fitted

Table 1, notes a, b, g and h

pairalpha0alpha1gap_fromgap_to
AFt SO4/CO31.670.9460.10.55
AFm SO4/OH0.1882.490.50.97
AFt Al/Fe2.1-0.1690.250.65
AFm Al/Fe1.261.570.450.95
solubility_products: 56 rows

Table 2 (solids, at 1 bar and 25 C) and Table 3 (the hydrotalcite-like phases of the separate modules)

phaseprintedlog_Ks0
ettringite(Al-)ettringite-44.9
tricarboalutricarboaluminate-46.5
Fe-ettringiteFe-ettringite-44.0
thaumasitethaumasite-24.75
C3AH6C3AH6-20.5
C3AS0.41H5.18C3AS0.41H5.18-25.35
C3AS0.84H4.32C3AS0.84H4.32-26.7
C3FH6C3FH6-26.3
C3FS0.84H4.32C3FS0.84H4.32-32.5
C3AFS0.84H4.32C3(F,A)S0.84H4.32-30.2
C3FS1.34H3.32C3FS1.34H3.32-34.2
C4AH19C4AH19-25.45
C4AH13C4AH13-25.25
C2AH7.5C2AH7.5-13.8
CAH10CAH10-7.6
hemicarbonateC4Ac0.5H12-29.13
monocarbonateC4AcH11-31.47
monosulphate14C4AsH14-29.26
monosulphate12C4AsH12-29.23
straetlingiteC2ASH8-19.7
C4AClH10Friedel's salt-27.27
C4AsClH12Kuzel's salt-28.53
mononitrateNitrate-AFm-28.67
Nitrite-AFm-26.24
C4FH13C4FH13-30.75
Fe-hemicarbonateFe-hemicarbonate-30.83
FemonocarbonateFe-monocarbonate-34.59
Fe-monosulphateFe-monosulfate-31.57
Fe-Friedel's salt-28.62
AnhCs (anhydrite)-4.357
GpCsH2 (gypsum)-4.581
hemihydrateCsH0.5 (hemihydrate)-3.59
syngenitesyngenite-7.2
AlOHamAl(OH)3(am)0.24
AlOHmicAl(OH)3(mic)-0.67
GbsAl(OH)3(gibbsite)-1.12
Fe(OH)3(am)Fe(OH)3(am)-2.6
Fe(OH)3(mic)Fe(OH)3(mic)-4.6
FeOOHmicFeOOH(mic)-5.6
GtFeOOH(goethite)-8.6
PortlanditeCH-5.2
Amor-SlSiO2(am)-2.714
QtzSiO2(quartz)-3.746
Mg3AlC0.5OH1/2M6AcH13-33.29
Mg3FeC0.5OH1/2M6FcH13-33.64
M075SHM1.5S2H2.5-28.8
M15SHM1.5SH2.5-23.57
zeoliteP_CaZeolite P(Ca)-20.3
natroliteNatrolite-30.2
chabaziteChabazite-25.8
zeoliteXZeolite X(Na)-20.1
zeoliteYZeolite Y(Na)-25.0
hydrotalciteM4AH10*-56.02
M4A-OH-LDHM4AH10**-49.7
M6A-OH-LDHM6AH12**-72.0
M8A-OH-LDHM8AH14**-94.3
dissolution_products: 179 rows

Table 2 and Table 3, the dissolution reactions to which log Ks0 refers, over the CEMDATA18 primary species and without their water

phasespeciescoefficient
ettringiteCa+26.0
ettringiteAlO2-2.0
ettringiteSO4-23.0
ettringiteOH-4.0
tricarboaluCa+26.0
tricarboaluAlO2-2.0
tricarboaluCO3-23.0
tricarboaluOH-4.0
Fe-ettringiteCa+26.0
Fe-ettringiteFeO2-2.0
Fe-ettringiteSO4-23.0
Fe-ettringiteOH-4.0
thaumasiteCa+23.0
thaumasiteHSiO3-1.0
thaumasiteSO4-21.0
thaumasiteCO3-21.0
thaumasiteOH-1.0
C3AH6Ca+23.0
C3AH6AlO2-2.0
C3AH6OH-4.0
C3AS0.41H5.18Ca+23.0
C3AS0.41H5.18AlO2-2.0
C3AS0.41H5.18HSiO3-0.41
C3AS0.41H5.18OH-3.59
C3AS0.84H4.32Ca+23.0
C3AS0.84H4.32AlO2-2.0
C3AS0.84H4.32HSiO3-0.84
C3AS0.84H4.32OH-3.16
C3FH6Ca+23.0
C3FH6FeO2-2.0
C3FH6OH-4.0
C3FS0.84H4.32Ca+23.0
C3FS0.84H4.32FeO2-2.0
C3FS0.84H4.32HSiO3-0.84
C3FS0.84H4.32OH-3.16
C3AFS0.84H4.32Ca+23.0
C3AFS0.84H4.32AlO2-1.0
C3AFS0.84H4.32FeO2-1.0
C3AFS0.84H4.32HSiO3-0.84
C3AFS0.84H4.32OH-3.16
C3FS1.34H3.32Ca+23.0
C3FS1.34H3.32FeO2-2.0
C3FS1.34H3.32HSiO3-1.34
C3FS1.34H3.32OH-2.66
C4AH19Ca+24.0
C4AH19AlO2-2.0
C4AH19OH-6.0
C4AH13Ca+24.0
C4AH13AlO2-2.0
C4AH13OH-6.0
C2AH7.5Ca+22.0
C2AH7.5AlO2-2.0
C2AH7.5OH-2.0
CAH10Ca+21.0
CAH10AlO2-2.0
hemicarbonateCa+24.0
hemicarbonateAlO2-2.0
hemicarbonateCO3-20.5
hemicarbonateOH-5.0
monocarbonateCa+24.0
monocarbonateAlO2-2.0
monocarbonateCO3-21.0
monocarbonateOH-4.0
monosulphate14Ca+24.0
monosulphate14AlO2-2.0
monosulphate14SO4-21.0
monosulphate14OH-4.0
monosulphate12Ca+24.0
monosulphate12AlO2-2.0
monosulphate12SO4-21.0
monosulphate12OH-4.0
straetlingiteCa+22.0
straetlingiteAlO2-2.0
straetlingiteHSiO3-1.0
straetlingiteOH-1.0
C4AClH10Ca+24.0
C4AClH10AlO2-2.0
C4AClH10Cl-2.0
C4AClH10OH-4.0
C4AsClH12Ca+24.0
C4AsClH12AlO2-2.0
C4AsClH12Cl-1.0
C4AsClH12SO4-20.5
C4AsClH12OH-4.0
mononitrateCa+24.0
mononitrateAlO2-2.0
mononitrateNO3-2.0
mononitrateOH-4.0
C4FH13Ca+24.0
C4FH13FeO2-2.0
C4FH13OH-6.0
Fe-hemicarbonateCa+24.0
Fe-hemicarbonateFeO2-2.0
Fe-hemicarbonateCO3-20.5
Fe-hemicarbonateOH-5.0
FemonocarbonateCa+24.0
FemonocarbonateFeO2-2.0
FemonocarbonateCO3-21.0
FemonocarbonateOH-4.0
Fe-monosulphateCa+24.0
Fe-monosulphateFeO2-2.0
Fe-monosulphateSO4-21.0
Fe-monosulphateOH-4.0
AnhCa+21.0
AnhSO4-21.0
GpCa+21.0
GpSO4-21.0
hemihydrateCa+21.0
hemihydrateSO4-21.0
syngeniteK+2.0
syngeniteCa+21.0
syngeniteSO4-22.0
AlOHamAlO2-1.0
AlOHamOH--1.0
AlOHmicAlO2-1.0
AlOHmicOH--1.0
GbsAlO2-1.0
GbsOH--1.0
Fe(OH)3(am)FeO2-1.0
Fe(OH)3(am)OH--1.0
Fe(OH)3(mic)FeO2-1.0
Fe(OH)3(mic)OH--1.0
FeOOHmicFeO2-1.0
FeOOHmicOH--1.0
GtFeO2-1.0
GtOH--1.0
PortlanditeCa+21.0
PortlanditeOH-2.0
Amor-SlSiO2@1.0
QtzSiO2@1.0
Mg3AlC0.5OHMg+23.0
Mg3AlC0.5OHAlO2-1.0
Mg3AlC0.5OHCO3-20.5
Mg3AlC0.5OHOH-4.0
Mg3FeC0.5OHMg+23.0
Mg3FeC0.5OHFeO2-1.0
Mg3FeC0.5OHCO3-20.5
Mg3FeC0.5OHOH-4.0
M075SHMg+21.5
M075SHSiO2@2.0
M075SHOH-3.0
M15SHMg+21.5
M15SHSiO2@1.0
M15SHOH-3.0
zeoliteP_CaCa+21.0
zeoliteP_CaAlO2-2.0
zeoliteP_CaSiO2@2.0
natroliteNa+2.0
natroliteAlO2-2.0
natroliteSiO2@3.0
chabaziteCa+21.0
chabaziteAlO2-2.0
chabaziteSiO2@4.0
zeoliteXNa+2.0
zeoliteXAlO2-2.0
zeoliteXSiO2@2.5
zeoliteYNa+2.0
zeoliteYAlO2-2.0
zeoliteYSiO2@4.0
hydrotalciteMg+24.0
hydrotalciteAlO2-2.0
hydrotalciteOH-6.0
M4A-OH-LDHMg+24.0
M4A-OH-LDHAlO2-2.0
M4A-OH-LDHOH-6.0
M6A-OH-LDHMg+26.0
M6A-OH-LDHAlO2-2.0
M6A-OH-LDHOH-10.0
M8A-OH-LDHMg+28.0
M8A-OH-LDHAlO2-2.0
M8A-OH-LDHOH-14.0
mononitriteCa+24.0
mononitriteAlO2-2.0
mononitriteNO2-2.0
mononitriteOH-4.0
C4FCl2H10Ca+24.0
C4FCl2H10FeO2-2.0
C4FCl2H10Cl-2.0
C4FCl2H10OH-4.0
solid_standard_properties: 2 rows

Table 1, lines 170 and 177 of the accepted manuscript, read on the rendered page; Cp = a0 + a1 T + a2 T^-2 + a3 T^-0.5

phaseprinteddfG [kJ/mol]dfH [kJ/mol]S [J/(mol*K)]a0 [J/(mol*K)]a1 [J/(mol*K^2)]a2 [J*K/mol]a3 [J/(mol*K^0.5)]V [cm^3/mol]references
mononitriteC4A(NO2)2H10-6606.8-7493.1799.0565.00.99-2.24e6703.0275.0[34-36]
C4FCl2H10C4FCl2H10-5900.1-6528.01286.0481.00.961-16100.01503.0278.0[37]
aqueous_species: 19 rows

Table D.1, the aqueous species with HKF parameters that the package's tests check

speciesdfG [kJ/mol]dfH [kJ/mol]S [J/(mol*K)]Cp [J/(mol*K)]V [cm^3/mol]a1_e1a2_em2a3a4_em4c1c2_em4omega_em5
Al+3-483.71-530.63-325.1-128.7-45.24-3.3802-17.007114.5185-2.075810.7-8.062.753
AlO2--827.48-925.57-30.21-49.049.473.72213.9954-1.5879-2.944115.2391-5.45851.7418
AlOH+2-692.6-767.27-184.9355.97-2.732.0469-2.78136.8376-2.663929.7923-0.34571.7247
Ca+2-552.79-543.07-56.48-30.92-18.44-0.1947-7.2525.2966-2.47929.0-2.5221.2366
Ca(SO4)@-1310.38-1448.4320.92-104.64.72.4079-1.89926.4895-2.7004-8.4942-8.1271-0.001
CaOH+-717.02-751.6528.036.055.762.7243-1.13036.1958-2.732211.1286-2.74930.4496
Cl--131.29-167.1156.74-122.4917.344.0324.8015.563-2.847-4.4-5.7141.456
CO2@-386.02-413.84117.57243.0832.816.24667.47112.8136-3.087940.03258.8004-0.02
CO3-2-527.98-675.31-50.0-289.33-6.062.8524-3.98446.4142-2.6143-3.3206-17.19173.3914
Fe+2-91.5-92.24-105.86-32.44-22.64-0.7867-9.69699.5479-2.37814.786-4.64371.4382
FeO2--368.26-443.8244.35-234.930.452.3837-1.96026.5182-2.6979-13.3207-14.50281.4662
HCO3--586.94-690.0198.45-34.8524.217.56211.15051.2346-2.826612.9395-4.75791.2733
HSiO3--1014.6-1144.6820.92-87.24.532.9735-0.51815.9467-2.75758.1489-7.31231.5511
K+-282.46-252.14101.048.399.013.559-1.4735.435-2.7127.4-1.7910.1927
Mg+2-453.99-465.93-138.07-21.66-22.01-0.8217-8.5998.39-2.3920.8-5.8921.5372
Na+-261.88-240.2858.4138.12-1.211.839-2.2853.256-2.72618.18-2.9810.3306
NO3--110.91-206.89146.94-66.828.667.31616.7824-4.6838-3.05947.7-6.7251.0977
OH--157.27-230.01-10.71-136.34-4.711.25270.07381.8423-2.78214.15-10.3461.7246
SO4-2-744.46-909.718.83-266.0912.928.3014-1.9846-6.2122-2.6971.64-17.9983.1463
aqueous_species_cp: 3 rows

Table D.1, last block: species extrapolated by Cp(T) integration or by a log K(T) fit

speciesdfG [kJ/mol]dfH [kJ/mol]S [J/(mol*K)]Cp [J/(mol*K)]
SiO2@-833.41-887.8641.3444.47
SiO3-2-938.51-1098.74-80.2119.83
CaSiO3@-1517.56-1668.06-136.6888.9
aqueous_cp_polynomial: 1 rows

Table D.1, last block: Cp = a0 + a1 T + a2 T^-2

speciesa0 [J/(mol*K)]a1 [J/(mol*K^2)]a2 [J*K/mol]
SiO2@46.940.034-1.13e6
gases: 7 rows

Table D.2, gaseous species; Cp = a0 + a1 T + a2 T^-2

speciesdfG [kJ/mol]dfH [kJ/mol]S [J/(mol*K)]Cp [J/(mol*K)]V [J/bar]a0 [J/(mol*K)]a1 [J/(mol*K^2)]a2 [J*K/mol]
CH4-50.66-74.81186.2635.752479.023.640.0479-192464.0
CO2-394.39-393.51213.7437.152479.044.220.0088-861904.0
H20.00.0130.6828.822479.027.280.003350208.0
H2O-228.68-242.4187.2540.072479.052.99-0.04355472.0
H2S-33.75-20.63205.7934.22479.032.680.0124-192464.0
N20.00.0191.6129.132479.028.580.0038-50208.0
O20.00.0205.1429.322479.029.960.0042-167360.0

Notes

  • alpha0 and alpha1 are the dimensionless Guggenheim interaction parameters, a0 = alpha0 R T and a1 = alpha1 R T in the Redlich-Kister form. The gap columns are the miscibility gap the parameters reproduce, as the article prints it: X(SO4) in the solid for the AFt pair, X(OH) for the AFm pair. The sign of alpha1 depends on which end-member comes first; with C4AH13 first, as in the miscibility_gap example, the spinodal the parameters give, X(OH) from 0.63 to 0.91, lies inside the printed gap.
  • For the AFt pair the article notes that the parameters are downscaled to a 1 CO2 : 1 SO3 replacement, instead of the 3 CO2 : 3 SO3 of its refs. [4, 7].
  • solubility_products: 'phase' is the package's symbol for the solid and is empty for the two rows of Table 2 the vendored database cannot be checked on, nitrite-AFm (the solid ships as mononitrite, the aqueous NO2- does not) and Fe-Friedel's salt (absent); their dissolution products are under the symbols mononitrite and C4FCl2H10, and their Table 1 properties in solid_standard_properties. 'printed' is the table's own name, without its footnote marks except in the Table 3 rows, where they tell two M4AH10 apart: * marks the tentative value recommended for Portland cement systems (the package's hydrotalcite), ** the tentative values recommended for alkali-activated materials (the MgAl-OH-LDH ideal solid solution).
  • solid_standard_properties: the two Table 1 rows the shipped database is not checked on through Table 2. Both carry the four heat-capacity coefficients as printed. Fe-Friedel's salt carries note k (an ideal solid solution, here with Friedel's salt C4ACl2H10, which carries it too) and note l on its enthalpy and volume: 'typing error in [37], recalculated from Gf and S from [37]. Volume calculated from XRD data [37]', [37] being the thesis of B. Z. Dilnesa (EPFL, 2012). Its a2, printed -1.61x10^4 where the other AFm phases carry a few 10^6, is transcribed as printed; at 25 C it weighs 0.2 J/(mol K) in Cp. Its dfH is consistent with dfG and S at 298.15 K: with the entropies of the elements the Cemdata18 file carries, dfH - T (S - sum of the elements' S) - dfG = -0.02 kJ/mol, and dfG with Table 2: through the Cemdata18 aqueous Gibbs energies, log Ks0 = -28.61 against -28.62 printed. The nitrite-AFm row gives the same log Ks0 to 0.001 through the NO2- of the slop98 database.
  • dissolution_products: Table 2 writes its reactions over Al(OH)4-, Fe(OH)4- and SiO(OH)3- (H3SiO4- for thaumasite); the CEMDATA18 primaries AlO2-, FeO2- and HSiO3- differ from those by 2, 2 and 1 H2O. The coefficients are the table's, the species are the primaries, and the water is left to the hydrogen balance.
  • aqueous_species: Table D.1 heads its volume column V0 (J/bar), but the values are in cm3/mol (Ca+2 at -18.44; -18.44 J/bar would be -184.4 cm3/mol). The HKF columns are the printed numbers of the scaled columns, in the calorimetric units of the HKF papers: a1_e1 holds a1 x 10, a2_em2 a2 x 10^-2, a4_em4 a4 x 10^-4, c2_em4 c2 x 10^-4 and omega_em5 omega x 10^-5.
  • gases: here the volume column is in J/bar (2479 J/bar = 24.79 L/mol, the ideal-gas molar volume at 298.15 K and 1 bar).

The run printed γ = 0.611 for the monovalent ions and 0.121 for the divalent ones, which the second line reproduces and the first does not. To compare with that run, use its model; to follow Cemdata18, use the first:

julia
model = HKFActivityModel(å = 0.0, Ḃ = Ḃ_gems, Kₙ = 0.0)   # that run
model = cemdata18_activity_model(:KOH)                   # the paper

The package default, HKFActivityModel(), is a third model, with an ion size per ion: do not mix it with either in one comparison.

The A and B parameters depend on the water dielectric constant and density and can be computed explicitly via hkf_debye_huckel_params:

julia
ab = hkf_debye_huckel_params(298.15, 1e5)   # → (A=0.5114, B=0.3288)

Valid range

The B-dot model is reliable for I ≲ 1 mol/kg. For higher ionic strengths (brines, evaporites), use PitzerActivityModel.


DaviesActivityModel (Davies equation) ​

Simpler alternative with no species-specific ionic radii (Davies, 1962). Suitable when ionic radii data are unavailable or for rapid screening calculations.

Ion activity coefficient:

log₁₀ γᵢ = −A zᵢ² (√I / (1 + √I)  −  b I)

Water activity uses the Raoult (mole fraction) approximation.

julia
state_eq = equilibrate(state; model=DaviesActivityModel())

# Temperature-dependent A
state_eq = equilibrate(state; model=DaviesActivityModel(temperature_dependent=true))

Custom activity models ​

To implement a custom activity model, define a new subtype and extend activity_model:

julia
struct MyModel <: AbstractActivityModel
    # model parameters
end

function ChemistryLab.activity_model(cs::ChemicalSystem, ::MyModel)
    # Precompute species indices and constants here (called once)
    idx_solvent = only(cs.idx_solvent)
    # ...

    # Return a closure lna(n, p) -> Vector compatible with ForwardDiff
    function lna(n::AbstractVector, p)
        # p contains at minimum: p.ΔₐG⁰overRT, p.T, p.P, p.ϵ
        # n is dimensionless mole vector, same indexing as cs.species
        out = zeros(eltype(n), length(n))
        # ... fill log-activities ...
        return out
    end
    return lna
end

Pass your model to equilibrate or EquilibriumSolver:

julia
state_eq = equilibrate(state; model=MyModel(...))

A custom model should also declare its solute concentration scale. activity_coefficients reads the coefficients of a model without a formula per ion from its closure, as    with the molalities built on the closure's own floor, and it does so only on the molality scale:

julia
ChemistryLab.concentration_scale(::MyModel) = :molality

Solid solutions ​

Pure crystalline species have activity ln a = 0. Solid solutions are mineral phases with variable composition (e.g. C-S-H, AFm, hydrogarnet), where the activity of each end-member depends on its mole fraction within the phase.

Defining end-members and phases ​

End-member species must carry aggregate_state = AS_CRYSTAL. SolidSolutionPhase automatically requalifies any end-member whose class is not already SC_SSENDMEMBER, so database species with SC_COMPONENT can be passed directly.

Workflow A — pass database species directly:

julia
using ChemistryLab

substances = build_species(datapath("cemdata18-thermofun.json"); verbose = false)
dict = Dict(symbol(s) => s for s in substances)

# SolidSolutionPhase requalifies SC_COMPONENT → SC_SSENDMEMBER automatically
ss_hg = SolidSolutionPhase("C3(AF)S0.84H",
    [dict["C3AFS0.84H4.32"], dict["C3FS0.84H4.32"]])

Workflow B — automated via build_solid_solutions and a TOML file:

julia
# Load all phases defined in the TOML
ss_phases = build_solid_solutions(datapath("solid_solutions.toml"), dict)

See the manual page Database extensions, filters and solid solutions for the TOML format and the pre-built data/solid_solutions.toml file shipped with ChemistryLab.

What the shipped file is, and is not

Two of its entries reproduce CEMDATA18 (Lothenbach et al., 2019) phases of the same name. CSHQ is the six-end-member C-S-H of Kulik's downscaled solid solution model (Kulik, 2011); its KSiOH and NaSiOH members carry the uptake of potassium and sodium, whose records name Robie and Hemingway (1995) among their sources, and they are what fixes the pore-solution pH of a Portland cement — leaving them out strands the alkalis in solution. C3(AF)S0.84H is the Fe-siliceous hydrogarnet.

AFm_SO4_OH and AFt_SO4_CO3 carry CEMDATA18's non-ideal parameters, read from data/literature/Lothenbach2019.json, with two instances each because both unmix. Hydrogarnet and Hydrotalcite are deliberate alternatives to the CEMDATA18 phase model, not reproductions of it: GEM-Selektor treats C3AH6, C3FH6 and hydrotalcite as pure phases, and its hydrotalcite solid solution is Mg3AlC0.5OH + Mg3FeC0.5OH at Mg:Al = 3. Reproducing a published GEM-Selektor result means declaring the phases in the script, as above, rather than taking this file wholesale.

Then pass solid_solutions as a keyword to ChemicalSystem:

julia
cs = ChemicalSystem(
    [H2O_sp, dict["C3AFS0.84H4.32"], dict["C3FS0.84H4.32"], ...],
    ["H2O@", "Al+3", ...];           # primaries
    solid_solutions = [ss_hg],       # or solid_solutions = ss_phases
)

Activity models for solid solutions ​

ModelFormulaNotes
IdealSolidSolutionModelln aᵢ = ln xᵢDefault, any number of end-members
RedlichKisterModelln aᵢ = ln xᵢ + ln γᵢ (Margules)Binary only (2 end-members), parameters in J/mol
RegularSolutionModelln γᵢ from one Wᵢⱼ per pairAny number of end-members; convexity from mixing_convexity
SubregularSolutionModelln γᵢ from Wᵢⱼ ≠ Wⱼᵢ per pair and Wᵢⱼₖ per tripleAny number of end-members, asymmetric, after Helffrich and Wood (1989)
MulticomponentRedlichKisterModela series in xᵢ − xⱼ per pair, a term per tripleAny number of end-members, any order, after Redlich and Kister (1948)
VanLaarModelone Wᵢⱼ per pair, one size αᵢ per end-memberAny number of end-members, asymmetric through the sizes, after Holland and Powell (2003)
SublatticeModelln aᵢ = Σₛ mₛ ln y_{s,σₛ(i)}Ideal mixing on sites; CNASH_ss of Myers et al. (2014), CSH3T of Kulik (2011)
CompoundEnergyModelideal site mixing, plus the reference surface of the end-member energies and regular interactions on a siteThe CASH+ C-S-H of Kulik et al. (2022); needs the end-members' standard Gibbs energies

The solid-solution activity is computed inside the aqueous activity closure — no separate activity model is needed. The existing equilibrate(state) call handles solid solutions automatically.

Ideal solid solution ​

julia
ss = SolidSolutionPhase("C3(AF)S0.84H", [em_al, em_fe])   # IdealSolidSolutionModel() by default
cs = ChemicalSystem([...]; solid_solutions=[ss])
state_eq = equilibrate(state)

Non-ideal binary: Redlich-Kister ​

julia
# Cemdata18's AFm SO4/OH binary, from its dimensionless Guggenheim parameters
# (data/literature/Lothenbach2019.json): a = α R T, C4AH13 first.
p  = literature_row("Lothenbach2019", "guggenheim_parameters", "AFm SO4/OH")
RT = R_GAS * 298.15
rk = RedlichKisterModel(a0 = p.alpha0 * RT, a1 = p.alpha1 * RT)   # a2 defaults to 0.0
# It unmixes, so it needs two coexisting compositions:
ss = SolidSolutionPhase("AFm_SO4_OH", [dict["C4AH13"], dict["monosulphate12"]];
                        model = rk, instances = 2)

Activity coefficients (Guggenheim / ThermoCalc convention):

Valid range

RedlichKisterModel requires exactly 2 end-members. For ternary or higher-order solid solutions, use the ideal model (IdealSolidSolutionModel), the symmetric multi-component Margules model (RegularSolutionModel), or an asymmetric one (SubregularSolutionModel, MulticomponentRedlichKisterModel, VanLaarModel).

Integration with aqueous models

Solid-solution activities are computed independently of the aqueous activity model. You can combine HKFActivityModel() for the aqueous phase with any solid-solution model — the same equilibrate call handles both.

Where to go next ​

The theory behind each option is in the chapter Theory: the certificate in Proving that an answer is the answer, the aqueous models in Activity models and the mixing models in Solid solutions. What the choice of model costs in numbers is measured in What the choice of activity model costs and Solid solution models, in numbers. Which entry point to call when a transport or structural code solves an equilibrium at each of its nodes is in Inside a host code.