Equilibrium equations#

Shared residuals and SciPy adapters. See How the solver works and how to change equations before modifying their interface.

Scientific equations for SMEW’s nonlinear solves.

To change an equation, edit its *_residual function below. Functions with one unknown return a value; larger systems fill out. The matching *_equations functions pass the results to SciPy’s fsolve. Python uses this file directly; compiled runs require a Cython rebuild after edits.

smew.equations.water_alk_residual(H, Alk, k1, k2, CO2_w, k_w)[source]#

Return prescribed minus calculated aqueous alkalinity at hydrogen H.

Shared by rainwater equilibrium and the alternative soil hydrogen estimate. Parameters after H are (Alk, k1, k2, CO2_w, k_w) in both solvers.

smew.equations.water_alk_equations(p, Alk, k1, k2, CO2_w, k_w)[source]#

SciPy adapter for water_alk_residual(); p contains only H.

smew.equations.biogeochem_residual(p, Alk_tot, n, Zr, s, IC_tot, k1, k2, k_H, k_w, CEC_tot, conv_Al, Al_tot, K1, K2, K3, K4, Mg_tot, Ca_tot, Na_tot, K_tot, K_Ca_Al, K_Ca_Mg, K_Ca_Na, K_Ca_K, K_Ca_H, out)[source]#

Main equilibrium residuals for aqueous/adsorbed species.

State and residual order: Alk, CO2_w, H, R_alk, Al_w, Al, Mg, Ca, Na, K, f_Al, f_Mg, f_Na, f_K, f_H, f_Ca.

smew.equations.biogeochem_equations(p, Alk_tot, n, Zr, s, IC_tot, k1, k2, k_H, k_w, CEC_tot, conv_Al, Al_tot, K1, K2, K3, K4, Mg_tot, Ca_tot, Na_tot, K_tot, K_Ca_Al, K_Ca_Mg, K_Ca_Na, K_Ca_K, K_Ca_H)[source]#
smew.equations.cec_calcium_residual(f_Ca, Al, conv_Al, Ca, Mg, Na, K, H, K_Ca_Al, K_Ca_Mg, K_Ca_Na, K_Ca_K, K_Ca_H)[source]#
smew.equations.cec_calcium_equation(p, Al, conv_Al, Ca, Mg, Na, K, H, K_Ca_Al, K_Ca_Mg, K_Ca_Na, K_Ca_K, K_Ca_H)[source]#

CEC saturation residual for the calcium fraction p[0].

smew.equations.f_cec_alk_to_conc_residual(Ca, f_Ca, K_Ca_Mg, f_Mg, K_Ca_Na, f_Na, K_Ca_K, f_K, Alk_in)[source]#

Solvability equation: 0 = 2*Mg + 2*Ca + Na + K - Alk_in

smew.equations.f_cec_alk_to_conc_equation(p, f_Ca, K_Ca_Mg, f_Mg, K_Ca_Na, f_Na, K_Ca_K, f_K, Alk_in)[source]#

Solvability equation 0 = 2*Mg + 2*Ca + Na + K - Alk_in for the calcium p[0].

smew.equations.total_to_cec_residual(p, H, n, Zr, s, CEC_tot, conv_Al, K1, K2, K3, K4, Ca_tot, Mg_tot, K_tot, Na_tot, f_acid, K_Ca_Al, K_Ca_Mg, K_Ca_Na, K_Ca_K, K_Ca_H, out)[source]#

Residuals for the 13 initial concentrations and CEC fractions.

smew.equations.total_to_cec_equations(p, H, n, Zr, s, CEC_tot, conv_Al, K1, K2, K3, K4, Ca_tot, Mg_tot, K_tot, Na_tot, f_acid, K_Ca_Al, K_Ca_Mg, K_Ca_Na, K_Ca_K, K_Ca_H)[source]#