Skip to content

Commit 70e779a

Browse files
author
stineb
committed
Added (maximum rate of RuBP regeneration) to the list of returned variables by the function. Made and to public functions, exported as part of the rpmodel package.
1 parent 60eda06 commit 70e779a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1325
-465
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Package: rpmodel
22
Type: Package
33
Title: P-Model
4-
Version: 1.0.4
4+
Version: 1.0.5
55
Authors@R: person( "Benjamin", "Stocker", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2697-9096") )
66
Maintainer: Benjamin Stocker <[email protected]>
7-
Description: Implements the P-model (Stocker et al., 2019 <doi:10.5194/gmd-2019-200>), predicting acclimated parameters of the enzyme kinetics of C3 photosynthesis, assimilation, and dark respiration rates as a function of the environment (temperature, CO2, vapour pressure deficit, light, atmospheric pressure).
7+
Description: Implements the P-model (Stocker et al., 2020 <doi:10.5194/gmd-13-1545-2020>), predicting acclimated parameters of the enzyme kinetics of C3 photosynthesis, assimilation, and dark respiration rates as a function of the environment (temperature, CO2, vapour pressure deficit, light, atmospheric pressure).
88
License: GPL-3
99
Encoding: UTF-8
1010
LazyData: true
11-
RoxygenNote: 7.0.0
11+
RoxygenNote: 7.1.0
1212
Imports: rlang
1313
Suggests: dplyr, purrr, tidyr, knitr
1414
VignetteBuilder: knitr

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(calc_density_h2o)
34
export(calc_ftemp_arrh)
45
export(calc_ftemp_inst_rd)
56
export(calc_ftemp_inst_vcmax)
@@ -8,4 +9,5 @@ export(calc_gammastar)
89
export(calc_kmm)
910
export(calc_patm)
1011
export(calc_soilmstress)
12+
export(calc_viscosity_h2o)
1113
export(rpmodel)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@
1616
## rpmodel 1.0.4
1717

1818
* Bugfix: vectorized all outputs from `rpmodel()`.
19+
20+
## rpmodel 1.0.5
21+
22+
* Added `jmax` (maximum rate of RuBP regeneration) to the list of returned variables by the `rpmodel()` function.
23+
* Made `calc_viscosity_h2o()` and `calc_density_h2o()` to public functions, exported as part of the rpmodel package.

R/calc_density_h2o.R

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#' Density of water
2+
#'
3+
#' Calculates the density of water as a function of temperature and atmospheric
4+
#' pressure, using the Tumlirz Equation.
5+
#'
6+
#' @param tc numeric, air temperature (tc), degrees C
7+
#' @param p numeric, atmospheric pressure (p), Pa
8+
#'
9+
#' @return numeric, density of water, kg/m^3
10+
#'
11+
#' @examples print("Density of water at 20 degrees C and standard atmospheric pressure:")
12+
#' print(calc_density_h2o(20, 101325))
13+
#'
14+
#' @references F.H. Fisher and O.E Dial, Jr. (1975) Equation of state of
15+
#' pure water and sea water, Tech. Rept., Marine Physical
16+
#' Laboratory, San Diego, CA.
17+
#'
18+
#' @export
19+
#'
20+
calc_density_h2o <- function( tc, p ){
21+
22+
# Calculate lambda, (bar cm^3)/g:
23+
my_lambda <- 1788.316 +
24+
21.55053*tc +
25+
-0.4695911*tc*tc +
26+
(3.096363e-3)*tc*tc*tc +
27+
-(7.341182e-6)*tc*tc*tc*tc
28+
29+
# Calculate po, bar
30+
po <- 5918.499 +
31+
58.05267*tc +
32+
-1.1253317*tc*tc +
33+
(6.6123869e-3)*tc*tc*tc +
34+
-(1.4661625e-5)*tc*tc*tc*tc
35+
36+
# Calculate vinf, cm^3/g
37+
vinf <- 0.6980547 +
38+
-(7.435626e-4)*tc +
39+
(3.704258e-5)*tc*tc +
40+
-(6.315724e-7)*tc*tc*tc +
41+
(9.829576e-9)*tc*tc*tc*tc +
42+
-(1.197269e-10)*tc*tc*tc*tc*tc +
43+
(1.005461e-12)*tc*tc*tc*tc*tc*tc +
44+
-(5.437898e-15)*tc*tc*tc*tc*tc*tc*tc +
45+
(1.69946e-17)*tc*tc*tc*tc*tc*tc*tc*tc +
46+
-(2.295063e-20)*tc*tc*tc*tc*tc*tc*tc*tc*tc
47+
48+
# Convert pressure to bars (1 bar <- 100000 Pa)
49+
pbar <- (1e-5)*p
50+
51+
# Calculate the specific volume (cm^3 g^-1):
52+
v <- vinf + my_lambda/(po + pbar)
53+
54+
# Convert to density (g cm^-3) -> 1000 g/kg; 1000000 cm^3/m^3 -> kg/m^3:
55+
rho <- (1e3/v)
56+
57+
return(rho)
58+
}
59+
60+

R/calc_viscosity_h2o.R

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#' Viscosity of water
2+
#'
3+
#' Calculates the viscosity of water as a function of temperature and atmospheric
4+
#' pressure.
5+
#'
6+
#' @param tc numeric, air temperature (tc), degrees C
7+
#' @param p numeric, atmospheric pressure (p), Pa
8+
#'
9+
#' @return numeric, viscosity of water (mu), Pa s
10+
#'
11+
#' @examples print("Density of water at 20 degrees C and standard atmospheric pressure:")
12+
#' print(calc_density_h2o(20, 101325))
13+
#'
14+
#' @references Huber, M. L., R. A. Perkins, A. Laesecke, D. G. Friend, J. V.
15+
#' Sengers, M. J. Assael, ..., K. Miyagawa (2009) New
16+
#' international formulation for the viscosity of H2O, J. Phys.
17+
#' Chem. Ref. Data, Vol. 38(2), pp. 101-125.
18+
#'
19+
#' @export
20+
#'
21+
calc_viscosity_h2o <- function( tc, p ) {
22+
23+
# Define reference temperature, density, and pressure values:
24+
tk_ast <- 647.096 # Kelvin
25+
rho_ast <- 322.0 # kg/m^3
26+
mu_ast <- 1e-6 # Pa s
27+
28+
# Get the density of water, kg/m^3
29+
rho <- calc_density_h2o(tc, p)
30+
31+
# Calculate dimensionless parameters:
32+
tbar <- (tc + 273.15)/tk_ast
33+
tbarx <- tbar^(0.5)
34+
tbar2 <- tbar^2
35+
tbar3 <- tbar^3
36+
rbar <- rho/rho_ast
37+
38+
# Calculate mu0 (Eq. 11 & Table 2, Huber et al., 2009):
39+
mu0 <- 1.67752 + 2.20462/tbar + 0.6366564/tbar2 - 0.241605/tbar3
40+
mu0 <- 1e2*tbarx/mu0
41+
42+
# Create Table 3, Huber et al. (2009):
43+
h_array <- array(0.0, dim=c(7,6))
44+
h_array[1,] <- c(0.520094, 0.0850895, -1.08374, -0.289555, 0.0, 0.0) # hj0
45+
h_array[2,] <- c(0.222531, 0.999115, 1.88797, 1.26613, 0.0, 0.120573) # hj1
46+
h_array[3,] <- c(-0.281378, -0.906851, -0.772479, -0.489837, -0.257040, 0.0) # hj2
47+
h_array[4,] <- c(0.161913, 0.257399, 0.0, 0.0, 0.0, 0.0) # hj3
48+
h_array[5,] <- c(-0.0325372, 0.0, 0.0, 0.0698452, 0.0, 0.0) # hj4
49+
h_array[6,] <- c(0.0, 0.0, 0.0, 0.0, 0.00872102, 0.0) # hj5
50+
h_array[7,] <- c(0.0, 0.0, 0.0, -0.00435673, 0.0, -0.000593264) # hj6
51+
52+
# Calculate mu1 (Eq. 12 & Table 3, Huber et al., 2009):
53+
mu1 <- 0.0
54+
ctbar <- (1.0/tbar) - 1.0
55+
# print(paste("ctbar",ctbar))
56+
# for i in xrange(6):
57+
for (i in 1:6){
58+
coef1 <- ctbar^(i-1)
59+
# print(paste("i, coef1", i, coef1))
60+
coef2 <- 0.0
61+
for (j in 1:7){
62+
coef2 <- coef2 + h_array[j,i] * (rbar - 1.0)^(j-1)
63+
}
64+
mu1 <- mu1 + coef1 * coef2
65+
}
66+
mu1 <- exp( rbar * mu1 )
67+
# print(paste("mu1",mu1))
68+
69+
# Calculate mu_bar (Eq. 2, Huber et al., 2009)
70+
# assumes mu2 = 1
71+
mu_bar <- mu0 * mu1
72+
73+
# Calculate mu (Eq. 1, Huber et al., 2009)
74+
mu <- mu_bar * mu_ast # Pa s
75+
76+
return( mu )
77+
}

0 commit comments

Comments
 (0)