R/slow_pool.R

Defines functions slow_y slow_y_ss k_s

Documented in k_s slow_y slow_y_ss

#########################################################
# functions comprise algorithm to calculate slow C pool #
#########################################################

#' @title Calculate the \code{k_s} parameter
#' @description Calculates the model \code{k_s} parameter, a precursor parameter to calculating the
#' steady-state slow carbon pool.
#' @param tfac A numeric vector indicating the model temperature factor, calculated using
#' \code{tfac()}.
#' @param wfac A numeric vector indicating the model water factor, calculated using \code{wfac()}.
#' @param tillfac A numeric vector indicating the model tillage factor, selected with
#' \code{tillfac()}.
#' @param params A named list containing model parameters. Defaults to the package default parameter
#' set \code{soilc_params}.
#' @export
k_s <- function(tfac, wfac, tillfac, params = soilc_params) params$kfacs$be * tfac * wfac * tillfac

#' @title Calculate the steady-state slow soil carbon pool
#' @description Calculates the steady-state version of the modelled slow soil carbon pool, in
#' tonnes C ha^-1.
#' @param c_input Numeric vector indicating combined carbon inputs for the model, in tonnes C ha^-1.
#' @param lignin_frac Numeric vector indicating lignin fraction of the carbon inputs, fractional.
#' @param active_y_ss Numeric vector indicating the steady-state version of the modelled active soil
#' carbon pool, in tonnes C ha^-1.
#' @param k_a Numeric vector containing the model \code{k_a} parameter, calculated using
#' \code{k_a()}.
#' @param k_s Numeric vector indicating the \code{k_s} parameter, calculated using \code{k_s}.
#' @param sand_frac A numeric scalar or vector indicating the sand proportion in the soil mineral
#' makeup, fractional.
#' @param params A named list containing model parameters. Defaults to the package default parameter
#' set \code{soilc_params}.
#' @export
slow_y_ss <- function(c_input, lignin_frac, active_y_ss, k_a, k_s, sand_frac, params = soilc_params) { #nolint
  ((c_input * lignin_frac * params$f3$be) + (active_y_ss * k_a * f4(sand_frac, params))) / k_s
}

#' @title Calculate the slow soil carbon pool
#' @description Calculates the rolling version of the modelled slow soil carbon pool, in
#' tonnes C ha^-1.
#' @param k_s A numeric vector containing the model \code{k_s} parameter, calculated using
#' \code{k_s()}.
#' @param slow_y_ss A numeric vector containing the steady-state version of the modelled slow soil
#' carbon pool, in tonnes C ha^-1.
#' @importFrom purrr accumulate2
#' @export
slow_y <- function(k_s, slow_y_ss) {
  slow_y_ss %>%
    accumulate2(k_s[2:length(k_s)], function(x, y, z) x + (y - x) * min(1, z)) %>%
    as.numeric()
}
aj-sykes92/soilc.ipcc documentation built on March 19, 2021, 11:52 a.m.