/
sorption.R
54 lines (52 loc) · 2.04 KB
/
sorption.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#' @title Sorption isotherms
#'
#' @description
#' This function returns the concentration of a substance sorbed to a surface
#' boundary after an equilibrium has established at constant temperature given
#' the concentration(s) \code{x} of the dissolved substance.
#'
#' @param x a numeric vector containing the concentration(s) of the dissolved
#' substance.
#' @param par a numeric vector specifying the function parameters, see examples
#' for details and correct order.
#' @param type a character string indicating the type of sorption isotherm to be used:
#' \code{"linear"} for the linear type,
#' \code{"freundlich"} for the Freundlich isotherm,
#' \code{"langmuir"} for the Langmuir isotherm,
#' \code{"BET"} for the BET model according to Brunauer, Emmet, and Teller
#' \code{"redlich"} for the Redlich-Peterson isotherm.
#'
#' @author
#' Zacharias Steinmetz
#'
#' @examples
#' sorption(1:5, par = c(Kd = 2.5), type = "linear")
#' sorption(1:5, par = c(K = 4, n = 0.6), type = "freundlich")
#' sorption(1:5, par = c(KL = 2, qmax = 10), type = "langmuir")
#' sorption(1:5, par = c(K = 50, qmax = 10, Csat = 10), type = "BET")
#' sorption(1:5, par = c(A = 30, B = 0.8), type = "redlich")
#'
#' @references
#' Atkins, P.W. (2001). \emph{Physical chemistry}, Oxford University Press, Oxford.
#'
#' @export
sorption <- function(x, par, type = "freundlich") {
len <- switch(type,
linear = 1,
freundlich = 2,
langmuir = 2,
redlich = 2,
BET = 3,
{ stop("sorption isotherm (type) unknown", call. = F) })
if(!inherits(par, "numeric") | length(par) != len)
stop(paste("'par' requires a numeric vector of length =", len), call. = F)
eqn <- switch(type,
linear = x * par[1],
freundlich = par[1] * (x^par[2]),
langmuir = (par[1] * par[2] * x) / (1 + par[1] * x),
redlich = (x * par[1]) / (1 + x^par[2]),
BET = (par[1] * par[2] * x) / ((par[3] - x) *
(1 + (((par[1] - 1) * x) / par[3])))
)
return(eqn)
}