Source code for smew.constants

# SPDX-License-Identifier: AGPL-3.0-only
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 16 14:34:44 2019
"""

import numpy as np
from numba import njit


    
[docs] @njit(nogil=True, error_model="numpy") def CO2_atm(conv_mol: float) -> float: """ Atmospheric CO2. """ return 412E-6/22.41*conv_mol # [mol-conv/l]
[docs] @njit(nogil=True, error_model="numpy") def D_0() -> float: """ Soil CO2 diffusivity. """ return 1.6E-5*3600*24 #free-air diffusion [m2/d]
[docs] @njit(nogil=True, error_model="numpy") def Dw_0() -> float: """ Solute diffusivity in soil water. """ return 1e-9*3600*24 # [m2/d]
[docs] @njit(nogil=True, error_model="numpy") def plant_nutr_f() -> tuple[float, float, float, float]: """ Percentage of nutrients in plant dry matter (ideally plant dependent). Current values are from Kelland's (2020) measurement for sorghum. """ v_f_Ca = 0.005 #suggested 2%, range 0.1 - 5 %, Weil and Bredy 2017 v_f_Mg = 0.001 #suggested, 0.5%, range 0.1 - 1 %, Weil and Bredy 2017 v_f_K = 0.01 #suggested 2%, range 1 - 5 %, Weil and Bredy 2017 v_f_Si = 0.01 #suggested 5%, range 1 - 10%, Epstein 1994, PNAS return v_f_Ca, v_f_Mg, v_f_K, v_f_Si
[docs] @njit(nogil=True, error_model="numpy") def soil_hydraulic_const(soil: str) -> tuple[float, float, float, float]: """ Campbell/Clapp-Hornberger hydraulic parameters. Returns ------- psi_s_log_cm : float antilog of the mean log saturation suction from Clapp & Hornberger (1978), Table 2. [cm H2O]. b : float Campbell exponent [-]. K_s : float Saturated hydraulic conductivity [m/d]. n : float Porosity [-]. """ if soil == "sand": psi_s_log_cm = 3.50 b = 4.05 K_s = 14.0 n = 0.395 elif soil == "loamy sand": psi_s_log_cm = 1.78 b = 4.38 K_s = 13.0 n = 0.410 elif soil == "sandy loam": psi_s_log_cm = 7.18 b = 4.90 K_s = 3.0 n = 0.435 elif soil == "silt loam" or soil == "silty loam": psi_s_log_cm = 56.6 b = 5.30 K_s = 0.62 n = 0.485 elif soil == "silt": # Using silt loam, as there is no separate silt class in Clapp & Hornberger (1978, WRR) Table 2. psi_s_log_cm = 56.6 b = 5.30 K_s = 0.62 n = 0.485 elif soil == "loam": psi_s_log_cm = 14.6 b = 5.39 K_s = 0.6 n = 0.451 elif soil == "sandy clay loam": psi_s_log_cm = 8.63 b = 7.12 K_s = 0.54 n = 0.420 elif soil == "silty clay loam": psi_s_log_cm = 14.6 b = 7.75 K_s = 0.15 n = 0.477 elif soil == "clay loam": psi_s_log_cm = 36.1 b = 8.52 K_s = 0.2 n = 0.476 elif soil == "sandy clay": psi_s_log_cm = 6.16 b = 10.4 K_s = 0.19 n = 0.426 elif soil == "silty clay": psi_s_log_cm = 17.4 b = 10.4 K_s = 0.09 n = 0.492 elif soil == "clay": psi_s_log_cm = 18.6 b = 11.4 K_s = 0.11 n = 0.482 else: raise ValueError("Invalid soil type!") return psi_s_log_cm, b, K_s, n
[docs] @njit(nogil=True, error_model="numpy") def soil_const( soil: str, psi_h_mpa: float=-10.0, psi_w_mpa: float=-3.0, psi_i_mpa: float=-0.03, fc_conductivity_ratio: float = 0.02, ) -> tuple[float, float, float, float, float, float, float]: """ Soil hydraulic constants and moisture thresholds, derived from soil type, water potentials and a relative conductivity threshold for field capacity. :param soil: Soil texture class. :param psi_h_mpa: Water potentials [MPa] used to compute s_h. Defaults to -10 MPa, following Laio et al. (2001). :param psi_w_mpa: Water potentials [MPa] used to compute s_w. Defaults to -3 MPa, following Laio et al. (2001). :param psi_i_mpa: Water potentials [MPa] used to compute s_i. Defaults to -0.03 MPa, following Laio et al. (2001). :param fc_conductivity_ratio: Ratio of hydraulic conductivity to K_s used to define field capacity [-]. Must be in (0, 1]. Defaults to 0.02. :return: Relative saturation at the hygroscopic point (s_h), wilting point (s_w), incipient stress point (s_i), and field capacity (s_fc) [-]; Campbell water retention exponent (b) [-]; saturated hydraulic conductivity (K_s) [m/day]; and soil porosity (n) [-]. """ psi_s_log_cm, b, K_s, n = soil_hydraulic_const(soil) mpa_to_cm = 10197.16213 #from MPa to cm H2O psi_h_cm = abs(psi_h_mpa) * mpa_to_cm psi_w_cm = abs(psi_w_mpa) * mpa_to_cm psi_i_cm = abs(psi_i_mpa) * mpa_to_cm # Campbell/Clapp-Hornberger relation: |psi| = |psi_s| * s^(-b)รน s_h = min(1.0, (psi_s_log_cm / psi_h_cm) ** (1.0 / b)) s_w = min(1.0, (psi_s_log_cm / psi_w_cm) ** (1.0 / b)) s_i = min(1.0, (psi_s_log_cm / psi_i_cm) ** (1.0 / b)) # Arbitrary threshold: L = fc_conductivity_ratio * Ks s_fc = fc_conductivity_ratio ** (1.0 / (3.0 + 2.0*b)) return s_h, s_w, s_i, s_fc, b, K_s, n
[docs] @njit(nogil=True, error_model="numpy") def min_const(mineral: str, conv_mol: float) -> tuple[ float, # MM_min float, # k_diss_H float, # k_diss_w float, # k_diss_OH float, # n_H float, # n_OH float, # E_H float, # E_w float, # E_OH tuple[float, float, float, float, float, float], # min_st float, # K_sp ]: """ EW mineral constants Most values are from Palandri (2004) unless otherwise specified. Solubility product constants (K_sp) are, when available, from Morel et al., (1993) -- https://booksite.elsevier.com/9780120885305/appendices/Web_Appendices.pdf unless otherwise specified. """ if mineral == 'albite': #NaAlSiO3 #rho_min = 2.6*1e6 # [g/m3]: density MM_min = 263/conv_mol # [g/mol-conv] k_diss_H = 10**(-10.16)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-12.56)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 10**(-15.6)*24*3600*conv_mol E_H = 65/conv_mol# [kJ/mol-conv]: activation energies E_w = 70/conv_mol# [kJ/mol-conv] E_OH = 71/conv_mol n_H = 0.457 # reaction order n_OH = - 0.572 min_st = (0.0, 0.0, 0.0, 1.0, 1.0, 3.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(-0.68) elif mineral == 'alkali_feldspar': #K0.41Na0.56Ca0.03Al1.03Si2.97O8 (Kelland et al., 2020) MM_min = 156/conv_mol # [g/mol-conv] k_diss_H = 10**(-10.06)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-12.41)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 10**(-21.2)*24*3600*conv_mol E_H = 51/conv_mol# [kJ/mol-conv]: activation energies E_w = 38/conv_mol# [kJ/mol-conv] E_OH = 94/conv_mol n_H = 0.5 # reaction order n_OH = -0.82 min_st = (0.03, 0.0, 0.41, 0.56, 1.03, 2.97)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'analcime': #NaAlSi2O6(H2O) #rho_min = 2.3*1e6 # [g/m3]: density MM_min = 200/conv_mol # [g/mol-conv] k_diss_H = 0 # [mol-conv m-2 d-1] k_diss_w = 10**(-11)*24*3600*conv_mol # [mol-conv m-2 d-1] #Murphy et al., 1996, 10.2475/ajs.296.2.128 k_diss_OH = 0 E_H = 0 E_w = 8/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0 # reaction order n_OH = 0 min_st = (1.0, 0.0, 0.0, 0.0, 2.0, 2.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(-14.67) elif mineral == 'andesine': #Na0.6Ca0.4Al1.4Si2.6O8 MM_min = 172/conv_mol # [g/mol-conv] k_diss_H = 10**(-8.88)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-11.47)*24*3600*conv_mol k_diss_OH = 0 E_H = 53.5/conv_mol E_w = 57.4/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.541 # reaction order n_OH = 0 min_st = (0.4, 0.0, 0.0, 0.6, 1.4, 2.6)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'apatite': #Ca5(PO4)3(OH) MM_min = 422/conv_mol # [g/mol-conv] k_diss_H = 10**(-4.29)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-6.)*24*3600*conv_mol k_diss_OH = 0 E_H = 250/conv_mol# [kJ/mol-conv]: activation energies E_w = 250/conv_mol E_OH = 1 n_H = 0.17 # reaction order n_OH = 1 min_st = (5.0, 0.0, 0.0, 0.0, 0.0, 0.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'anorthite': #CaAl2Si2O8 #rho_min = 2.73*1e6 # [g/m3]: density MM_min = 278/conv_mol # [g/mol-conv] k_diss_H = 10**(-3.5)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-9.12)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 16.6/conv_mol# [kJ/mol-conv]: activation energies E_w = 17.8/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 1.4 # reaction order n_OH = 1 min_st = (1.0, 0.0, 0.0, 0.0, 2.0, 2.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(9.83) elif mineral == 'augite': #Ca0.9Na0.1Mg0.9Fe0.2Al0.4Ti0.1Si1.9O6 (http://webmineral.com) #rho_min = 2.73*1e6 # [g/m3]: density MM_min = 236/conv_mol # [g/mol-conv] k_diss_H = 10**(-6.82)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-11.97)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 78/conv_mol# [kJ/mol-conv]: activation energies E_w = 78/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.7 # reaction order n_OH = 1 min_st = (0.9, 0.9, 0.0, 0.1, 0.4, 1.9)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'diopside': #MgCaSi2O6 MM_min = 216/conv_mol # [g/mol-conv] k_diss_H = 10**(-6.36)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-11.11)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 96/conv_mol# [kJ/mol-conv]: activation energies E_w = 40/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.71 # reaction order n_OH = 1 min_st = (1.0, 1.0, 0.0, 0.0, 0.0, 2.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(5.30) elif mineral == 'forsterite': #Mg2SiO4 #rho_min = 2.8*1e6 # [g/m3]: density MM_min = 140/conv_mol # [g/mol-conv] k_diss_H = 10**(-6.85)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-10.64)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 67.2/conv_mol# [kJ/mol-conv]: activation energies E_w = 79/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.47 # reaction order n_OH = 1 min_st = (0.0, 2.0, 0.0, 0.0, 0.0, 1.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(7.11) elif mineral == 'Fe_forsterite': #FeMgSiO4 MM_min = 172/conv_mol # [g/mol-conv] k_diss_H = 10**(-6.85)*24*3600*conv_mol #(-5.37) [mol-conv m-2 d-1] k_diss_w = 10**(-10.64)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 67/conv_mol# [kJ/mol-conv]: activation energies E_w = 79/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.47 # reaction order n_OH = 1 min_st = (0.0, 1.0, 0.0, 0.0, 0.0, 1.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'labradorite': #Na0.45Ca0.55Al1.6Si2.4O8 (Dupla Field data, alternative http://webmineral.com/data/Labradorite.shtml) #rho_min = 2.73*1e6 # [g/m3]: density MM_min = 272/conv_mol # [g/mol-conv] k_diss_H = 10**(-7.87)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-10.91)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 42/conv_mol# [kJ/mol-conv]: activation energies E_w = 45/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.6 # reaction order n_OH = 1 min_st = (0.55, 0.0, 0.0, 0.45, 1.6, 2.4)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'leucite': #K(AlSi2O6) MM_min = 218/conv_mol # [g/mol-conv] k_diss_H = 10**(-6.00)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-9.20)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 10**(-10.66)*24*3600*conv_mol E_H = 132/conv_mol# [kJ/mol-conv]: activation energies E_w = 75/conv_mol# [kJ/mol-conv] E_OH = 56.6/conv_mol n_H = 0.7 # reaction order n_OH = -0.2 min_st = (0.0, 0.0, 1.0, 0.0, 1.0, 2.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'nepheline': #Na0.75K0.25(AlSiO4) MM_min = 146/conv_mol # [g/mol-conv] k_diss_H = 10**(-2.73)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-8.56)*24*3600*conv_mol k_diss_OH = 10**(-10.76)*24*3600*conv_mol E_H = 63/conv_mol# [kJ/mol-conv]: activation energies E_w = 65/conv_mol E_OH = 38/conv_mol n_H = 1.13 # reaction order n_OH = -0.2 min_st = (0.0, 0.0, 0.25, 0.75, 1.0, 1.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = np.nan elif mineral == 'muscovite': #KAl3Si3O10(OH)2 MM_min = 398.71/conv_mol # [g/mol-conv] k_diss_H = 10**(-11.85)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_w = 10**(-13.55)*24*3600*conv_mol k_diss_OH = 10**(-14.55)*24*3600*conv_mol E_H = 22/conv_mol# [kJ/mol-conv]: activation energies E_w = 22/conv_mol E_OH = 22/conv_mol n_H = 0.37 # reaction order n_OH = -0.22 min_st = (0.0, 0.0, 1.0, 0.0, 3.0, 3.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(4.54) #Soil and Water Chemistry An Integrative Approach (Michael E. Essington) elif mineral == 'wollastonite': #CaSiO3 #rho_min = 2.9*1e6 # [g/m3]: density MM_min = 116/conv_mol # [g/mol-conv] k_diss_H = 10**(-5.37)*24*3600*conv_mol #(-5.37) [mol-conv m-2 d-1] k_diss_w = 10**(-8.88)*24*3600*conv_mol # [mol-conv m-2 d-1] k_diss_OH = 0 E_H = 54.7/conv_mol# [kJ/mol-conv]: activation energies E_w = 54.7/conv_mol# [kJ/mol-conv] E_OH = 0 n_H = 0.4 # reaction order n_OH = 1 min_st = (1.0, 0.0, 0.0, 0.0, 0.0, 1.0)# Stochiometric coefficients [Ca, Mg, K, Na, Al, Si] K_sp = 10**(6.82) else: raise ValueError("No data for this mineral") return MM_min, k_diss_H, k_diss_w, k_diss_OH, n_H, n_OH, E_H, E_w, E_OH, min_st, K_sp
[docs] @njit(nogil=True, error_model="numpy") def carb_weath_const(conv_mol: float) -> tuple[float, float, float, float, float, float]: """ Carbonate weathering constants """ # Carbonate solubility products #https://booksite.elsevier.com/9780120885305/appendices/Web_Appendices.pdf K_CaCO3 = 10**(-8.35)*conv_mol**2 # Calcite K_MgCO3 = 10**(-7.46)*conv_mol**2 # Magnesite #precipitation rate # modeling formulation follows https://nora.nerc.ac.uk/id/eprint/511084/1/Kirk%20et%20al%202015%20Geochmica%20et%20Cosmochimica%20Acta.pdf # parameter values are defined to reproduce experimental results r_CaCO3 = 3*1e7*(1e-9*1e6/(24*3600))*conv_mol # [mol-conv/d] r_MgCO3 = 1e7*(1e-9*1e6/(24*3600))*conv_mol #dissolution timescale tau_CaCO3 = 30 # [d] tau_MgCO3 = 40 return K_CaCO3, K_MgCO3, r_CaCO3, r_MgCO3, tau_CaCO3, tau_MgCO3
[docs] @njit(nogil=True, error_model="numpy") def K_GT_CEC(soil: str, conv_mol: float) -> tuple[float, float, float, float, float]: """ CEC constants (Gaines-Thomas). Current values are from a meta-analysis of Dutch soils (0-30 cm, https://edepot.wur.nl/31605). Site-specific coefficient estimates can be obtained with soil-water coupled measurements. """ if soil in ['sand', 'loamy sand', 'sandy loam']: K_Ca_Mg = 10**(0.56) #[-] K_Ca_K = 10**(-1.16)*conv_mol #[conc] K_Ca_Na = 10**(0.75)*conv_mol #[conc] K_Ca_H = 10**(-5)*conv_mol #[conc] for tePas et al a better constant is 0.5 1e-9 *conv_mol, K_Ca_Al = 10**(-1.7)/conv_mol #[conc^-1] #heterovalent (make it higher to favor Ca adsorbed) #K_Ca_AlOH = 10**(-1.7) #K_Ca_AlOH2 = 10**(-1.7)*conv_mol elif soil in ['loam', 'silt loam', 'silty loam', 'silt', 'sandy clay loam', 'silty clay loam']: K_Ca_Mg = 10**(0.1) #[-] K_Ca_K = 10**(-2)*conv_mol K_Ca_Na = 10**(0.38)*conv_mol K_Ca_H = 10**(-5.4)*conv_mol K_Ca_Al = 10**(-0.86)/conv_mol #K_Ca_AlOH = 10**(-0.86) #K_Ca_AlOH2 = 10**(-0.86)*conv_mol elif soil in ['clay', 'clay loam', 'silty clay', 'sandy clay']: K_Ca_Mg = 10**(0.39) #[-] K_Ca_K = 10**(-2.42)*conv_mol K_Ca_Na = 10**(0.774)*conv_mol K_Ca_H = 10**(-6.67)*conv_mol K_Ca_Al = 10**(-0.2)/conv_mol #K_Ca_AlOH = 10**(-0.2) #K_Ca_AlOH2 = 10**(-0.2)*conv_mol else: raise ValueError( "Unknown soil type '" + soil + "' in K_GT_CEC. Supported soil types: " "sand, loamy sand, sandy loam, loam, silt loam, silt, " "clay loam, silty clay, clay, sandy clay loam, silty clay loam, sandy clay" ) # K_Na_K = (K_Ca_K/K_Ca_Na)**(1/2)] # K_Na_Al = (K_Ca_Al/K_Ca_Na**3)**(1/2) K_CEC = (K_Ca_Mg, K_Ca_K, K_Ca_Na, K_Ca_Al, K_Ca_H) return K_CEC
[docs] @njit(nogil=True, error_model="numpy") def K_Al(conv_mol: float) -> tuple[float, float, float, float]: """ Aluminium speciation (pag. 398 Weil and Brady). """ pK1 = 5 pK2 = 5.1 pK3 = 6.7 pK4 = 6.2 # A floating-point base preserves negative powers when compiled by Numba. K1 = 10.0**(-pK1)*conv_mol K2 = 10.0**(-pK2)*conv_mol K3 = 10.0**(-pK3)*conv_mol K4 = 10.0**(-pK4)*conv_mol return K1, K2, K3, K4
[docs] @njit(nogil=True, error_model="numpy") def K_C(T_K: float, conv_mol: float) -> tuple[float, float, float, float]: """ Carbonate speciation [Stumm and Morgan, 1996]. """ T_ref = 25+273.15 # [K]: temperature standard conditions #carbonates pk1 = -(-356.309 - 0.0609 * T_K + 21834.37/T_K + 126.8339 * np.log10(T_K) - 1684915/(T_K)**2) pk2 = -(-107.887 - 0.032528 * (T_K) + 5151.79/(T_K) + 38.92561 * np.log10(T_K) - 563713.9/(T_K)**2) pk_w = -(-283.971 + 13323/(T_K) - 0.0507 * (T_K) + 102.24447 * np.log10(T_K) - 1119669/(T_K)**2) k1 = 10**(-pk1)*conv_mol k2 = 10**(-pk2)*conv_mol #water k_w = 10**(-pk_w)*conv_mol**2 #Henry k_H = 0.83*np.exp(2400*(1/T_K-1/T_ref)) return k1, k2, k_w, k_H
[docs] @njit(nogil=True, error_model="numpy") def MM(conv_mol: float) -> tuple[float, float, float, float, float, float, float, float]: """ Molar masses [g/mol]. """ MM_Mg = 24/conv_mol MM_Ca = 40/conv_mol MM_Na = 23/conv_mol MM_K = 39/conv_mol MM_Si = 28/conv_mol MM_C = 12/conv_mol MM_Anions = 62/conv_mol MM_Al = 27/conv_mol return MM_Mg, MM_Ca, MM_Na, MM_K, MM_Si, MM_C, MM_Anions, MM_Al