\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{natbib}
\usepackage{authblk}
\usepackage{hyperref}

%\VignetteIndexEntry{Sperry & Love's hydraulic model}
%\VignettePackage{medfate}

\title{Sperry \& Love's hydraulic model}
\author[1,2]{Miquel De Cáceres}
\affil[1]{Centre Tecnològic Forestal de Catalunya. Ctra. St. Llorenç de Morunys km 2, 25280, Solsona, Catalonia, Spain}
\affil[2]{CREAF, Cerdanyola del Vallès, 08193, Spain}

\begin{document}
\SweaveOpts{concordance=TRUE}

\maketitle
\tableofcontents

<<echo=FALSE>>=
options(width=67)
library(medfate)
@

\section{Implementing supply-loss theory of plant hydraulics}
The supply-loss theory of plant hydraulics was recently presented by Sperry and Love (2015):
\begin{center}
Sperry, J. S., and D. M. Love. 2015. What plant hydraulics can tell us about responses to climate-change droughts. New Phytologist 207:14–27.
\end{center}

The theory uses the physics of flow through soil and xylem to quantify how canopy water supply declines with drought and ceases by hydraulic failure. The theory can be applied to different networks representing the soil-plant continuum, but in our case the continuum is divided into two resistance elements in series, one representing the rhizosphere and the other representing the xylem. 

\subsection{Xylem and rhizosphere vulnerability curves}
Each continuum element has a vulnerability curve that starts at maximum hydraulic conductance ($k_{max}$, flow rate per pressure drop) and monotonically declines as water pressure ($\Psi$) becomes more negative. Vulnerability curves form the basis of the calculations.

The xylem element was assigned a two-parameter Weibull function as the vulnerability curve $k_x(\Psi)$:
\begin{equation}
k_x(\Psi) = k_{xmax}\cdot e^{-((-\Psi/d)^c)}
\end{equation}
where $k_{xmax}$ is the xylem maximum hydraulic conductance (defined as flow per surface unit and per pressure drop), and $c$ and $d$ are species-specific parameters. For examples, if we take the following parameter values:
<<>>==
kxmax = 8.0
c = 2
d = 3
@
the vulnerability curve is (see \texttt{hydraulics.xylemConductance()}):
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
psiVec = seq(-0.1, -7.0, by =-0.01)
k = unlist(lapply(psiVec, hydraulics.xylemConductance, kxmax, c, d))
plot(-psiVec, k, type="l",ylab="Xylem conductance", xlab="Canopy sap pressure (-MPa)", lwd=1.5)
@
\end{center}
The same curve is used to specify the relationship between pressure and conductance in any portion of the flow path along the xylem. The rhizosphere conductance function $k_r(\Psi)$ is modeled as a van Genuchten function (van Genuchten, 1980):
\begin{eqnarray}
k_r(\Psi) &=& k_{rmax} \cdot v^{(n-1)/(2\cdot n)} \cdot ((1-v)^{(n-1)/n}-1)^2 \\
v &=& [(\alpha \Psi)^{n}+1]^{-1}
\end{eqnarray}
where $k_{rmax}$ is the maximum rhizosphere conductance, and $n$ and $\alpha$ are texture-specific parameters (see Leij et al. 1996; Carsel \& Parrish 1988). If we specify the following parameters for three soil texture types:
<<>>==
#Maximum soil conductance
#Textural parameters (1 MPa = 0.00009804139432 cm)
#Sandy clay loam 
krmax1 = 80000000000
alpha1 = 602 #602 MPa-1 = 0.059 cm-1   
n1 = 1.48
#Silt loam
krmax2 = 4000000000
alpha2 = 203 #203 MPa-1 = 0.020 cm-1
n2 = 1.41
#Silty clay
krmax3 = 400000000
alpha3 = 50.99887 #50.99887 MPa-1 = 0.005 cm-1
n3 = 1.09
textures = c("Sandy clay loam","Silt loam", "Silty clay")
@
the corresponding $k_r(\Psi)$ functions are (see \texttt{hydraulics.vanGenuchtenConductance()}):
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
psiVec = seq(-0.01, -7.0, by =-0.01)
k1 = unlist(lapply(psiVec, hydraulics.vanGenuchtenConductance, krmax1, n1, alpha1))
k2 = unlist(lapply(psiVec, hydraulics.vanGenuchtenConductance, krmax2, n2, alpha2))
k3 = unlist(lapply(psiVec, hydraulics.vanGenuchtenConductance, krmax3, n3, alpha3))
plot(-psiVec, k1, type="l", col="black", ylab="Rhizosphere conductance", xlab = "Soil hydraulic pressure (-MPa)",  xlim=c(0, max(-psiVec)), ylim=c(0, 100))
lines(-psiVec, k2, lty=2, lwd=1.5)
lines(-psiVec, k3, lty=3, lwd=1.5)
legend("topright", bty="n", legend=textures, lty=1:3, cex=0.8, lwd=1.5)
@
\end{center}

\subsection{Supply functions}
The supply function describes the rate of water supply (i.e. flow) for transpiration ($E$) as a function of pressure. The steady-state flow rate $E_i$ through each $i$ element of the continuum is related to the flow-induced drop in pressure across that element ($\Delta \Psi_i$) by the integral transform of the element's vulnerability curve $k_i(\Psi)$:
\begin{equation}
E_i(\Delta \Psi_i) = \int_{\Psi_{up}}^{\Psi_{down}}{k_i(\Psi) d\Psi}
\end{equation}
where $\Psi_{up}$ and $\Psi_{down}$ are the upstream and downstream water potential values, respectively. The integral transform assumes infinite discretization of the flow path. 

The supply function can be defined for individual elements of the continuum of the whole soil-plant continuum. In the case of a single xylem element the supply function describes the flow rate as a function of canopy xylem pressure ($\Psi_{canopy}$). It can be calculated by numerical integration or aproximated using an incomplete gamma function. The shape of the supply function starting at different root water potential values ($\Psi_{root}$) is (see \texttt{hydraulics.EXylem()}):
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
psiSoil1 = -0.1
psiSoil2 = -0.5
psiSoil3 = -2.0
psiSoil4 = -3.0
psiVec = seq(-0.1, -7.0, by =-0.01)
E1 = unlist(lapply(psiVec, hydraulics.EXylem, psiSoil1, kxmax, c, d))
E2 = unlist(lapply(psiVec, hydraulics.EXylem, psiSoil2, kxmax, c, d))
E3 = unlist(lapply(psiVec, hydraulics.EXylem, psiSoil3, kxmax, c, d))
E4 = unlist(lapply(psiVec, hydraulics.EXylem, psiSoil4, kxmax, c, d))
# Ec1 = Ecrit(psiSoil1, kxmax, c, d)
# Ec2 = Ecrit(psiSoil2, kxmax, c, d)
# Ec3 = Ecrit(psiSoil3, kxmax, c, d)
# Ec4 = Ecrit(psiSoil4, kxmax, c, d)
Psic = hydraulics.psiCrit(c,d)
plot(-psiVec, E1, type="l", ylab="Xylem flow rate", xlab="Canopy sap pressure (-MPa)", ylim=c(0,20), lwd=1.5)
lines(-psiVec, E2, lty=1, lwd=1.5)
lines(-psiVec, E3, lty=1, lwd=1.5)
lines(-psiVec, E4, lty=1, lwd=1.5)
# points(rep(-Psic,4), c(Ec1,Ec2, Ec3,Ec4))
@
\end{center}
The  supply function of the rhizosphere element relates the flow rate to the pressure inside the roots ($\Psi_{root}$). It is calculated by numerical integration of the van Genuchten function (see \texttt{hydraulics.E2psiVanGenuchten()}). Here we draw the supply function for the rhizosphere starting at different values of bulk soil pressure ($\Psi_{soil}$) and for the same three texture types:
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
Evec = seq(0, 10, by=0.1)
psiSoil1 = -0.01
psiSoil2 = -1.0
psiSoil3 = -2.0
psiSoil4 = -3.0
psiVG11 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil1, krmax1, n1, alpha1))
psiVG12 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil2, krmax1, n1, alpha1))
psiVG13 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil3, krmax1, n1, alpha1))
psiVG14 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil4, krmax1, n1, alpha1))
psiVG21 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil1, krmax2, n2, alpha2))
psiVG22 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil2, krmax2, n2, alpha2))
psiVG23 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil3, krmax2, n2, alpha2))
psiVG24 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil4, krmax2, n2, alpha2))
psiVG31 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil1, krmax3, n3, alpha3))
psiVG32 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil2, krmax3, n3, alpha3))
psiVG33 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil3, krmax3, n3, alpha3))
psiVG34 = unlist(lapply(Evec, hydraulics.E2psiVanGenuchten, psiSoil4, krmax3, n3, alpha3))
plot(-psiVG11, Evec, type="l", col="black", ylab="Rhizosphere flow rate", xlab = "Root sap pressure (-MPa)",  xlim=c(0, 8))
lines(-psiVG21, Evec, col="black", lty=2, lwd=1.5)
lines(-psiVG31, Evec, col="black", lty=3, lwd=1.5)
lines(-psiVG12, Evec, col="black", lty=1, lwd=1.5)
lines(-psiVG22, Evec, col="black", lty=2, lwd=1.5)
lines(-psiVG32, Evec, col="black", lty=3, lwd=1.5)
lines(-psiVG13, Evec, col="black", lty=1, lwd=1.5)
lines(-psiVG23, Evec, col="black", lty=2, lwd=1.5)
lines(-psiVG33, Evec, col="black", lty=3, lwd=1.5)
lines(-psiVG14, Evec, col="black", lty=1, lwd=1.5)
lines(-psiVG24, Evec, col="black", lty=2, lwd=1.5)
lines(-psiVG34, Evec, col="black", lty=3, lwd=1.5)
legend("topright", bty="n", legend=textures, lty=1:3, lwd=1.5, cex=0.8)
@
\end{center}
The nearly vertical lines indicate that for many values of $E_i$ the corresponding drop in water potential through the rhizosphere will be very small. Only for increasingly negative soil water potential values the decrease in water potential through the rhizosphere becomes relevant. Both in the case of a xylem element or a rhyzosphere element the derivative $dE_i/d\Psi$ of the supply function is equal to the corresponding vulnerability curve.

In the network of the two elements in series (rhizosphere + xylem) the supply function has to be calculated by sequentially using the previous supply functions. The $E_i$ is identical for each element and equal to the canopy $E$. Since $\Psi_{soil}$ is known, one first inverts the supply function of the rhizosphere to find $\Psi_{root}$ (see \texttt{hydraulics.E2psiVanGenuchten()}) and then inverts the supply function of the xylem to find $\Psi_{canopy}$ (see \texttt{hydraulics.E2psiXylem()}). The two operations can be summarized in a single supply function describing the potential rate of water supply for transpiration ($E$) as function of the canopy xylem pressure ($\Psi_{canopy}$), starting from different bulk soil ($\Psi_{soil}$) values (see \texttt{hydraulics.supplyFunction()}): 

\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
dE =0.1
kxmax = 8.0
c = 2
d = 3
psi2E11 = hydraulics.supplyFunction(20, psiSoil1, krmax1, kxmax, n1, alpha1, c,d, dE)
psi2E12 = hydraulics.supplyFunction(20, psiSoil2, krmax1, kxmax, n1, alpha1, c,d, dE)
psi2E13 = hydraulics.supplyFunction(20, psiSoil3, krmax1, kxmax, n1, alpha1, c,d, dE)
psi2E14 = hydraulics.supplyFunction(20, psiSoil4, krmax1, kxmax, n1, alpha1, c,d, dE)
psi2E21 = hydraulics.supplyFunction(20, psiSoil1, krmax2, kxmax, n2, alpha2, c,d, dE)
psi2E22 = hydraulics.supplyFunction(20, psiSoil2, krmax2, kxmax, n2, alpha2, c,d, dE)
psi2E23 = hydraulics.supplyFunction(20, psiSoil3, krmax2, kxmax, n2, alpha2, c,d, dE)
psi2E24 = hydraulics.supplyFunction(20, psiSoil4, krmax2, kxmax, n2, alpha2, c,d, dE)
psi2E31 = hydraulics.supplyFunction(20, psiSoil1, krmax3, kxmax, n3, alpha3, c,d, dE)
psi2E32 = hydraulics.supplyFunction(20, psiSoil2, krmax3, kxmax, n3, alpha3, c,d, dE)
psi2E33 = hydraulics.supplyFunction(20, psiSoil3, krmax3, kxmax, n3, alpha3, c,d, dE)
psi2E34 = hydraulics.supplyFunction(20, psiSoil4, krmax3, kxmax, n3, alpha3, c,d, dE)

plot(-psi2E11$PsiPlant, psi2E11$FittedE, type="l", col="black", ylab="Flow rate", xlab = "Canopy sap pressure (-MPa)",  xlim=c(0, 7), ylim=c(0,20), lwd=1)
lines(-psi2E12$PsiPlant, psi2E12$FittedE, lty=1, lwd=1)
lines(-psi2E13$PsiPlant, psi2E13$FittedE, lty=1, lwd=1)
lines(-psi2E14$PsiPlant, psi2E14$FittedE, lty=1, lwd=1)
lines(-psi2E21$PsiPlant, psi2E21$FittedE, lty=2, lwd=1)
lines(-psi2E22$PsiPlant, psi2E22$FittedE, lty=2, lwd=1)
lines(-psi2E23$PsiPlant, psi2E23$FittedE, lty=2, lwd=1)
lines(-psi2E24$PsiPlant, psi2E24$FittedE, lty=2, lwd=1)
lines(-psi2E31$PsiPlant, psi2E31$FittedE, lty=3, lwd=1)
lines(-psi2E32$PsiPlant, psi2E32$FittedE, lty=3, lwd=1)
lines(-psi2E33$PsiPlant, psi2E33$FittedE, lty=3, lwd=1)
lines(-psi2E34$PsiPlant, psi2E34$FittedE, lty=3, lwd=1)
legend("topright", bty="n", legend=textures, lwd=1, lty=1:3, cex=0.8)
@
\end{center}
The supply function for the whole continuum contains much information. The $\Psi$ intercept at $E=0$ represents the predawn canopy sap pressure which integrates the rooted soil moisture profile. As $E$ increments from zero, the disproportionately greater drop in $\Psi_{canopy}$ results from the loss of conductance. As the soil dries the differences in flow due to soil texture become more apparent. The derivative of the whole continuum supply function, $dE/d\Psi$, is not equal to either of the vulnerability curves and it has to be obtained numerically. The derivative functions of the supply functions shown in the previous figure are:
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(-psi2E11$PsiPlant, psi2E11$dEdP, type="l", col="black", ylab="dEdP", xlab = "Canopy sap pressure (-MPa)",  xlim=c(0, 7), ylim=c(0,10), lwd=1)
lines(-psi2E12$PsiPlant, psi2E12$dEdP, lty=1, lwd=1)
lines(-psi2E13$PsiPlant, psi2E13$dEdP, lty=1, lwd=1)
lines(-psi2E14$PsiPlant, psi2E14$dEdP, lty=1, lwd=1)
lines(-psi2E21$PsiPlant, psi2E21$dEdP, lty=2, lwd=1)
lines(-psi2E22$PsiPlant, psi2E22$dEdP, lty=2, lwd=1)
lines(-psi2E23$PsiPlant, psi2E23$dEdP, lty=2, lwd=1)
lines(-psi2E24$PsiPlant, psi2E24$dEdP, lty=2, lwd=1)
lines(-psi2E31$PsiPlant, psi2E31$dEdP, lty=3, lwd=1)
lines(-psi2E32$PsiPlant, psi2E32$dEdP, lty=3, lwd=1)
lines(-psi2E33$PsiPlant, psi2E33$dEdP, lty=3, lwd=1)
lines(-psi2E34$PsiPlant, psi2E34$dEdP, lty=3, lwd=1)
legend("topright", bty="n", legend=textures, lwd=1, lty=1:3, cex=0.8)
@
\end{center}
The derivative $dE/d\Psi_{canopy}$ represents the limiting hydraulic conductance at the downstream end of the continuum, and it falls towards zero for asymptotic critical values ($E_{crit}$).
\subsection{Loss function}
The loss function specifies where the plant regulates its actual transpiration rate along the supply function. The supply function derivative ($dE/d\Psi_{canopy}$) drives the loss function. Soil drought and high demand both push the plant towards lower $dE/d\Psi_{canopy}$ values. A simple rule for a loss function is that stomata should close more as stress pushes $dE/d\Psi_{canopy}$ closer to zero. The loss function needs an input water demand $E'$ (which can be derived using Penman's equation or other approaches). The corresponding $Psi_{canopy}'$ (and hence the unregulated pressure drop $\Delta \Psi'$) is first determined from $E'$ by inverting the supply function. The derivative $dE'/d\Psi_{canopy}'$ corresponding to the demand is also calculated from the supply function. The maximum $dE/d\Psi_{canopy}$ is at the start of the curve ($dE/d\Psi_{max}$) and equals maximum soil-plant conductance. The fraction $(dE'/d\Psi_{canopy}')/(dE/d\Psi_{max})$ drops from 1 to 0 as $E'$ increases, quantifying how close the plant is pushed to the critical point of complete hydraulic failure without stomatal closure. Regulated pressure drop ($\Delta \Psi$) is calculated as:
\begin{equation}
\Delta \Psi = \Delta \Psi' \cdot ((dE'/d\Psi_{canopy}')/(dE/d\Psi_{max}))
\end{equation}
The regulated pressure drop is then used to determine the regulated $\Psi_{canopy}$ and, using again the supply function, find the regulated $E$ value. Due to its formulation,$\Delta \Psi$ reaches a maximum before $dE'/d\Psi_{canopy}' \simeq 0$. At this point $\Delta \Psi$ should saturate with water demand, rather than to show an unrealistic decline with further $E'$ increases. Thus, beyond this $\Delta \Psi$ saturation point the stomata are assumed to be maximally sensitive to water demand by closing sufficiently to keep $E$ and $\Psi_{canopy}$ constant.

The following figure represents the loss function (which is not reducible to a single equation) for a xylem element only starting from three different values of transpiration demand ($E'$) (see \texttt{hydraulics.regulatedPsiXylem()}). Black lines indicate the supply functions corresponding to different upstream pressure values. Each point of the loss function (in gray) is the result of finding unregulated pressure drop from $E'$, determining the regulated drop and determining the corresponding regulated $\Psi_{canopy}$ and $E$, the latter being drawn.
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(-psiVec, unlist(lapply(psiVec, hydraulics.EXylem, -0.25, kxmax, c, d)), type="l", ylab="Transpiration rate", xlab="Canopy sap pressure (-MPa)", xlim = c(0,5))
for(psi in seq(-0.5, -4.5, by=-0.25)) {
  lines(-psiVec, unlist(lapply(psiVec, hydraulics.EXylem, psi, kxmax, c, d)))
}
Ein1 = 4
Ein2 = 8
Ein3 = 15
psiVec = seq(-0.25, -4.5, by =-0.25)
LU1 = rep(NA, length(psiVec))
LR1 = rep(NA, length(psiVec))
PU1 = rep(NA, length(psiVec))
PR1 = rep(NA, length(psiVec))
G1 = rep(NA, length(psiVec))
LU2 = rep(NA, length(psiVec))
LR2 = rep(NA, length(psiVec))
PU2 = rep(NA, length(psiVec))
PR2 = rep(NA, length(psiVec))
G2 = rep(NA, length(psiVec))
LU3 = rep(NA, length(psiVec))
LR3 = rep(NA, length(psiVec))
PU3 = rep(NA, length(psiVec))
PR3 = rep(NA, length(psiVec))
G3 = rep(NA, length(psiVec))
for(i in 1:length(psiVec)) {
  rp1 = hydraulics.regulatedPsiXylem(Ein1, psiVec[i], kxmax, c,d)
  PU1[i] = rp1[1]
  PR1[i] = rp1[2]
  LU1[i] = rp1[3]
  LR1[i] = rp1[4]
  G1[i] = rp1[6]
  rp2 = hydraulics.regulatedPsiXylem(Ein2, psiVec[i], kxmax, c,d)
  PU2[i] = rp2[1]
  PR2[i] = rp2[2]
  LU2[i] = rp2[3]
  LR2[i] = rp2[4]
  G2[i] = rp2[6]
  rp3 = hydraulics.regulatedPsiXylem(Ein3, psiVec[i], kxmax, c,d)
  PU3[i] = rp3[1]
  PR3[i] = rp3[2]
  LU3[i] = rp3[3]
  LR3[i] = rp3[4]
  G3[i] = rp3[6]
}
lines(-PR1, LR1, col="gray", lwd=1.5, lty=1)
lines(-PR2, LR2, col="gray", lwd=1.5, lty=2)
lines(-PR3, LR3, col="gray", lwd=1.5, lty=3)
legend("topleft", col=rep("gray",3), lty=1:3, lwd=1.5, 
       legend=c(paste("E\'=",Ein1,sep=""), paste("E\'=",Ein2,sep=""), paste("E\'=",Ein3,sep="")), bty="n", cex=0.8)
@
\end{center}
The following three graphs illustrate the loss function when considering a two-element network (rhizosphere + xylem) for the three soil texture types (see \texttt{hydraulics.regulatedPsiTwoElements()}):
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
 par(mar=c(4,4,3,1))
 Ein1 = 4
 Ein2 = 8
 Ein3 = 15
 c = 2
 d = 3
 dE = 0.1
 psiVec = seq(-0.01, -2.0, by =-0.03)
 LU1 = rep(NA, length(psiVec))
 LR1 = rep(NA, length(psiVec))
 PU1 = rep(NA, length(psiVec))
 PR1 = rep(NA, length(psiVec))
 G1 = rep(NA, length(psiVec))
 LU2 = rep(NA, length(psiVec))
 LR2 = rep(NA, length(psiVec))
 PU2 = rep(NA, length(psiVec))
 PR2 = rep(NA, length(psiVec))
 G2 = rep(NA, length(psiVec))
 LU3 = rep(NA, length(psiVec))
 LR3 = rep(NA, length(psiVec))
 PU3 = rep(NA, length(psiVec))
 PR3 = rep(NA, length(psiVec))
 G3 = rep(NA, length(psiVec))
 for(i in 1:length(psiVec)) {
   rp1 = hydraulics.regulatedPsiTwoElements(Ein1, psiVec[i], krmax1, kxmax, n1, alpha1, c, d,dE)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/LU1[i]
   rp2 = hydraulics.regulatedPsiTwoElements(Ein2, psiVec[i], krmax1, kxmax, n1, alpha1, c,d,dE)
   PU2[i] = rp2[1]
   PR2[i] = rp2[2]
   LU2[i] = rp2[3]
   LR2[i] = rp2[4]
   G2[i] = LR2[i]/LU2[i]
   rp3 = hydraulics.regulatedPsiTwoElements(Ein3, psiVec[i], krmax1, kxmax, n1, alpha1, c,d,dE)
   PU3[i] = rp3[1]
   PR3[i] = rp3[2]
   LU3[i] = rp3[3]
   LR3[i] = rp3[4]
   G3[i] = LR3[i]/LU3[i]
 }
 plot(-PR1, LR1, type="l", col="black", ylab="Transpiration rate", xlab = "Canopy sap pressure (-MPa)",  main = textures[1],  xlim=c(0, 2.0), ylim=c(0,10), lwd=1.5, lty=1)
 lines(-PR2, LR2, col="gray", lwd=1.5, lty=1)
 lines(-PR3, LR3, col="red", lwd=1.5, lty=1)
 for(i in 1:length(psiVec)) {
   pp = hydraulics.supplyFunction(15, psiVec[i], krmax1, kxmax, n1, alpha1, c,d, dE = dE)
   lines(-pp$PsiPlant, pp$FittedE, col="black", lwd=1, lty=1)
 }
  legend("topleft", col=c("black","gray","red"), lty=1, lwd=1.5, 
        legend=c(paste("E\'=",Ein1,sep=""), paste("E\'=",Ein2,sep=""), paste("E\'=",Ein3,sep="")), 
        bty="n", cex=0.8)
@
\end{center}
\begin{center}
<<fig=TRUE, width=4, height=4.5, echo=FALSE>>==
  par(mar=c(4,4,3,1))
 plot(-psiVec, -(PR1-psiVec), type="l", asp= 1, col="black", ylab="Regulated pressure drop (-MPa)", xlab = "Soil pressure (-MPa)",  main = textures[1],  xlim=c(0, 2.0), ylim=c(0,2), lwd=1.5, lty=1)
 lines(-psiVec, -(PR2-psiVec), col="gray", lwd=1.5, lty=1)
 lines(-psiVec, -(PR3-psiVec), col="red", lwd=1.5, lty=1)
 for(a in seq(0, 5, by=0.25)) abline(a=a, b=-1, col="gray")
  legend("topleft", col=c("black","gray","red"), lty=1, lwd=1.5, 
        legend=c(paste("E\'=",Ein1,sep=""), paste("E\'=",Ein2,sep=""), paste("E\'=",Ein3,sep="")), 
        bty="n", cex=0.8)
@
\end{center}
%' \begin{center}
%' <<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
%'  par(mar=c(4,4,3,1))
%'  pp = hydraulics.supplyFunction(15, psiVec[1], krmax1, kxmax, n1, alpha1, c,d, dE = dE)
%'  plot(-pp$PsiPlant, pp$dEdP, type="l", col="black", ylab="dEdP", xlab = "Canopy sap pressure (-MPa)",  main = textures[1],  xlim=c(0, 2.0), ylim=c(0,10), lwd=1.5, lty=1)
%'  for(i in 2:length(psiVec)) {
%'    pp = hydraulics.supplyFunction(15, psiVec[i], krmax1, kxmax, n1, alpha1, c,d, dE = dE)
%'    lines(-pp$PsiPlant, pp$dEdP, col="black", lwd=1, lty=1)
%'  }
%' @
%' \end{center}  
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
 par(mar=c(4,4,3,1))
 Ein1 = 4
 Ein2 = 8
 Ein3 = 15
 c = 2
 d = 3
 dE = 0.1
 psiVec = seq(-0.25, -4.5, by =-0.25)
 LU1 = rep(NA, length(psiVec))
 LR1 = rep(NA, length(psiVec))
 PU1 = rep(NA, length(psiVec))
 PR1 = rep(NA, length(psiVec))
 G1 = rep(NA, length(psiVec))
 LU2 = rep(NA, length(psiVec))
 LR2 = rep(NA, length(psiVec))
 PU2 = rep(NA, length(psiVec))
 PR2 = rep(NA, length(psiVec))
 G2 = rep(NA, length(psiVec))
 LU3 = rep(NA, length(psiVec))
 LR3 = rep(NA, length(psiVec))
 PU3 = rep(NA, length(psiVec))
 PR3 = rep(NA, length(psiVec))
 G3 = rep(NA, length(psiVec))
 for(i in 1:length(psiVec)) {
   rp1 = hydraulics.regulatedPsiTwoElements(Ein1, psiVec[i], krmax2, kxmax, n2, alpha2, c, d, dE)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/LU1[i]
   rp2 = hydraulics.regulatedPsiTwoElements(Ein2, psiVec[i], krmax2, kxmax, n2, alpha2, c,d, dE)
   PU2[i] = rp2[1]
   PR2[i] = rp2[2]
   LU2[i] = rp2[3]
   LR2[i] = rp2[4]
   G2[i] = LR2[i]/LU2[i]
   rp3 = hydraulics.regulatedPsiTwoElements(Ein3, psiVec[i], krmax2, kxmax, n2, alpha2, c,d, dE)
   PU3[i] = rp3[1]
   PR3[i] = rp3[2]
   LU3[i] = rp3[3]
   LR3[i] = rp3[4]
   G3[i] = LR3[i]/LU3[i]
 }
 plot(-PR1, LR1, type="l", col="black", ylab="Transpiration rate", xlab = "Canopy sap pressure (-MPa)",   main = textures[2], xlim=c(0, 5), ylim=c(0,15), lwd=1.5, lty=2)
 lines(-PR2, LR2, col="gray", lwd=1.5, lty=2)
 lines(-PR3, LR3, col="red", lwd=1.5, lty=2)
 for(i in 1:length(psiVec)) {
   pp = hydraulics.supplyFunction(15, psiVec[i], krmax2, kxmax, n2, alpha2, c,d, dE = dE)
   lines(-pp$PsiPlant, pp$FittedE, col="black", lwd=1, lty=1)
 }
 
 legend("topleft", col=c("black","gray","red"), lty=2, lwd=1.5, 
        legend=c(paste("E\'=",Ein1,sep=""), paste("E\'=",Ein2,sep=""), paste("E\'=",Ein3,sep="")), 
        bty="n", cex=0.8)
@
\end{center}
\begin{center}
<<fig=TRUE, width=4, height=4.5, echo=FALSE>>==
  par(mar=c(4,4,3,1))
 plot(-psiVec, -(PR1-psiVec), type="l", asp= 1, col="black", ylab="Regulated pressure drop (-MPa)", xlab = "Soil pressure (-MPa)",  main = textures[2],  xlim=c(0, 2.0), ylim=c(0,2), lwd=1.5, lty=2)
 lines(-psiVec, -(PR2-psiVec), col="gray", lwd=1.5, lty=2)
 lines(-psiVec, -(PR3-psiVec), col="red", lwd=1.5, lty=2)
 for(a in seq(0, 5, by=0.25)) abline(a=a, b=-1, col="gray")
  legend("topleft", col=c("black","gray","red"), lty=2, lwd=1.5, 
        legend=c(paste("E\'=",Ein1,sep=""), paste("E\'=",Ein2,sep=""), paste("E\'=",Ein3,sep="")), 
        bty="n", cex=0.8)
@
\end{center}

%' \begin{center}
%' <<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
%'  par(mar=c(4,4,3,1))
%'  pp = hydraulics.supplyFunction(15, psiVec[1], krmax2, kxmax, n2, alpha2, c,d, dE = dE)
%'  plot(-pp$PsiPlant, pp$dEdP, type="l", col="black", ylab="dEdP", xlab = "Canopy sap pressure (-MPa)",  main = textures[1],  xlim=c(0, 5.0), ylim=c(0,10), lwd=1.5, lty=1)
%'  for(i in 2:length(psiVec)) {
%'    pp = hydraulics.supplyFunction(15, psiVec[i], krmax2, kxmax, n2, alpha2, c,d, dE = dE)
%'    lines(-pp$PsiPlant, pp$dEdP, col="black", lwd=1, lty=1)
%'  }
%' @
%' \end{center}  
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
 par(mar=c(4,4,3,1))
 psiVec = seq(-0.25, -4.5, by =-0.25)
LU1 = rep(NA, length(psiVec))
 LR1 = rep(NA, length(psiVec))
 PU1 = rep(NA, length(psiVec))
 PR1 = rep(NA, length(psiVec))
 G1 = rep(NA, length(psiVec))
 LU2 = rep(NA, length(psiVec))
 LR2 = rep(NA, length(psiVec))
 PU2 = rep(NA, length(psiVec))
 PR2 = rep(NA, length(psiVec))
 G2 = rep(NA, length(psiVec))
 LU3 = rep(NA, length(psiVec))
 LR3 = rep(NA, length(psiVec))
 PU3 = rep(NA, length(psiVec))
 PR3 = rep(NA, length(psiVec))
 G3 = rep(NA, length(psiVec))
 for(i in 1:length(psiVec)) {
   rp1 = hydraulics.regulatedPsiTwoElements(Ein1, psiVec[i], krmax3, kxmax, n3, alpha3, c, d)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/LU1[i]
   rp2 = hydraulics.regulatedPsiTwoElements(Ein2, psiVec[i], krmax3, kxmax, n3, alpha3, c,d)
   PU2[i] = rp2[1]
   PR2[i] = rp2[2]
   LU2[i] = rp2[3]
   LR2[i] = rp2[4]
   G2[i] = LR2[i]/LU2[i]
   rp3 = hydraulics.regulatedPsiTwoElements(Ein3, psiVec[i], krmax3, kxmax, n3, alpha3, c,d)
   PU3[i] = rp3[1]
   PR3[i] = rp3[2]
   LU3[i] = rp3[3]
   LR3[i] = rp3[4]
   G3[i] = LR3[i]/LU3[i]
 }
 plot(-PR1, LR1, type="l", col="black", ylab="Transpiration rate", xlab = "Canopy sap pressure (-MPa)",  main = textures[3], xlim=c(0, 5), ylim=c(0,15), lwd=1.5, lty=3)
 lines(-PR2, LR2, col="gray", lwd=1.5, lty=3)
 lines(-PR3, LR3, col="red", lwd=1.5, lty=3)
 for(i in 1:length(psiVec)) {
   pp = hydraulics.supplyFunction(15, psiVec[i], krmax3, kxmax, n3, alpha3, c,d, dE = 0.1)
   lines(-pp$PsiPlant, pp$E, col="black", lwd=1, lty=1)
 }
 legend("topleft", col=c("black","gray","red"), lty=3, lwd=1.5, 
        legend=c(paste("E=",Ein1,sep=""), paste("E=",Ein2,sep=""), paste("E=",Ein3,sep="")), 
        bty="n", cex=0.8)
@
\end{center}
\begin{center}
<<fig=TRUE, width=4, height=4.5, echo=FALSE>>==
  par(mar=c(4,4,3,1))
 plot(-psiVec, -(PR1-psiVec), type="l", asp= 1, col="black", ylab="Regulated pressure drop (-MPa)", xlab = "Soil pressure (-MPa)",  main = textures[3],  xlim=c(0, 2.0), ylim=c(0,2), lwd=1.5, lty=3)
 lines(-psiVec, -(PR2-psiVec), col="gray", lwd=1.5, lty=3)
 lines(-psiVec, -(PR3-psiVec), col="red", lwd=1.5, lty=3)
 for(a in seq(0, 5, by=0.25)) abline(a=a, b=-1, col="gray")
  legend("topleft", col=c("black","gray","red"), lty=3, lwd=1.5, 
        legend=c(paste("E\'=",Ein1,sep=""), paste("E\'=",Ein2,sep=""), paste("E\'=",Ein3,sep="")), 
        bty="n", cex=0.8)
@
\end{center}

% \begin{center}
% #' <<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
% #'  par(mar=c(4,4,3,1))
% #'  pp = hydraulics.supplyFunction(15, psiVec[1], krmax3, kxmax, n3, alpha3, c,d, dE = dE)
% #'  plot(-pp$PsiPlant, pp$dEdP, type="l", col="black", ylab="dEdP", xlab = "Canopy sap pressure (-MPa)",  main = textures[1],  xlim=c(0, 5.0), ylim=c(0,10), lwd=1.5, lty=1)
% #'  for(i in 2:length(psiVec)) {
% #'    pp = hydraulics.supplyFunction(15, psiVec[i], krmax3, kxmax, n3, alpha3, c,d, dE = dE)
% #'    lines(-pp$PsiPlant, pp$dEdP, col="black", lwd=1, lty=1)
% #'  }
% #' @
% \end{center}  
\subsection{Rhizosphere maximum conductance $k_{rmax}$}
Rhizosphere vulnerability curves $k_r(\Psi)$ start astronomically high compared with xylem curves $k(\Psi)$, mainly because root surface is much greater than xylem cross-sectional area. Under wet conditions the relatively low xylem conductance limits the loss function. As soils dry, however, the decrease in rhizosphere conductance may become relevant because it becomes closer to the range of xylem conductance. This is shown in the following figure:
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
psiVec = seq(-0.1, -7.0, by =-0.01)
k = unlist(lapply(psiVec, hydraulics.xylemConductance, kxmax, c, d))
plot(-psiVec, k, type="l",ylab="Hydraulic conductance", xlab="Pressure (-MPa)", lwd=1.5)

krmax21 = 16000000000
krmax22 = 8000000000
krmax23 = 4000000000
k1 = unlist(lapply(psiVec, hydraulics.vanGenuchtenConductance, krmax21, n2, alpha2))
k2 = unlist(lapply(psiVec, hydraulics.vanGenuchtenConductance, krmax22, n2, alpha2))
k3 = unlist(lapply(psiVec, hydraulics.vanGenuchtenConductance, krmax23, n2, alpha2))
lines(-psiVec, k1, lty=3, lwd=1.5, col="black")
lines(-psiVec, k2, lty=3, lwd=1.5, col="gray")
lines(-psiVec, k3, lty=3, lwd=1.5, col="red")
 legend("topright", col=c("black","black","gray","red"), lty=c(1,3,3,3), lwd=1.5, legend=c("xylem curve", paste("krmax=",krmax21,sep=""), paste("krmax=",krmax22,sep=""), paste("krmax=",krmax23,sep="")), 
        bty="n", cex=0.8)
@
\end{center}
Decreasing root surface effectively decreases $k_{rmax}$ and makes rhizosphere conductance to become relevant for less dry soils. These differences in soil conductance have an effect on the loss function, which can be primarily xylem-limited if $k_{rmax}$ is large enough, but that becomes increasingly soil-limited for smaller $k_{rmax}$ values. This is illustrated in the following figure (assuming silty loam texture):
\begin{center}
<<fig=TRUE, width=4, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
Ein2 = 4
psiVec = seq(-0.01, -5.0, by =-0.01)
LU1 = rep(NA, length(psiVec))
LR1 = rep(NA, length(psiVec))
PU1 = rep(NA, length(psiVec))
PR1 = rep(NA, length(psiVec))
G1 = rep(NA, length(psiVec))
 LU2 = rep(NA, length(psiVec))
 LR2 = rep(NA, length(psiVec))
 PU2 = rep(NA, length(psiVec))
 PR2 = rep(NA, length(psiVec))
 G2 = rep(NA, length(psiVec))
 LU3 = rep(NA, length(psiVec))
 LR3 = rep(NA, length(psiVec))
 PU3 = rep(NA, length(psiVec))
 PR3 = rep(NA, length(psiVec))
 G3 = rep(NA, length(psiVec))
 for(i in 1:length(psiVec)) {
   rp1 =  hydraulics.regulatedPsiXylem(Ein2, psiVec[i], kxmax, c,d)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/LU1[i]
}
plot(-PR1, LR1, type="l", col="black", ylab="Transpiration rate", xlab = "Canopy sap pressure (-MPa)", xlim=c(0, 5), ylim=c(0,4), lwd=1.5, lty=1)

 for(i in 1:length(psiVec)) {
   rp1 = hydraulics.regulatedPsiTwoElements(Ein2, psiVec[i], krmax21, kxmax, n2, alpha2, c, d, dE = 0.1)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/LU1[i]
   rp2 = hydraulics.regulatedPsiTwoElements(Ein2, psiVec[i], krmax22, kxmax, n2, alpha2, c,d,dE = 0.1)
   PU2[i] = rp2[1]
   PR2[i] = rp2[2]
   LU2[i] = rp2[3]
   LR2[i] = rp2[4]
   G2[i] = LR2[i]/LU2[i]
   rp3 = hydraulics.regulatedPsiTwoElements(Ein2, psiVec[i], krmax23, kxmax, n2, alpha2, c,d,dE = 0.1)
   PU3[i] = rp3[1]
   PR3[i] = rp3[2]
   LU3[i] = rp3[3]
   LR3[i] = rp3[4]
   G3[i] = LR3[i]/LU3[i]
 }
 lines(-PR1, LR1, col="black", lwd=1.5, lty=3)
 lines(-PR2, LR2, col="gray", lwd=1.5, lty=3)
 lines(-PR3, LR3, col="red", lwd=1.5, lty=3)
 legend("topright", col=c("black", "black","gray","red"), lty=c(1,3,3,3), lwd=1.5, 
        legend=c("xylem only", paste("krmax=",krmax1,sep=""), paste("krmax=",krmax2,sep=""), paste("krmax=",krmax3,sep="")), 
        bty="n", cex=0.8)
 
@
\end{center}
Given the uncertainty in rhizosphere $k_r(\Psi)$ models in dry soil and in the area of absorving roots, Sperry and Love (2015) propose a simplifying assumption consisting in that root investment is just sufficient to approach the xylem limit across the $\Psi_{canopy}$ spectrum. Any greater root surface would be wasted for no water gain, and fewer roots would be a waste of investment in cavitation resistance.

\section{Examples}
\subsection{Constant $\Psi_{soil}$}
In this example we illustrate the behavior of the supply-loss hydraulic theory using an  example where $\Psi_{soil}$ is constantly at -1.5 MPa and the water demand (i.e. potential evapotranspiration) changes from day to day during a year, all three soil textures are tested and plant parameters of the xylem vulnerability curve are $k_{xmax} = 8$, $c = 2$ and $d = 3$. Potential evapotranspiration and regulated transpiration rate (both are assumed to be referred to the same conducting area) are:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
data(examplemeteo)
par(mar=c(4,4,1,1))
psiSoil = -1.5
E = examplemeteo$PET
LU1 = rep(NA, length(E))
LR1 = rep(NA, length(E))
PU1 = rep(NA, length(E))
PR1 = rep(NA, length(E))
G1 = rep(NA, length(E))
 LU2 = rep(NA, length(E))
 LR2 = rep(NA, length(E))
 PU2 = rep(NA, length(E))
 PR2 = rep(NA, length(E))
 G2 = rep(NA, length(E))
 LU3 = rep(NA, length(E))
 LR3 = rep(NA, length(E))
 PU3 = rep(NA, length(E))
 PR3 = rep(NA, length(E))
 G3 = rep(NA, length(E))
 for(i in 1:length(E)) {
   rp1 = hydraulics.regulatedPsiTwoElements(E[i], psiSoil, krmax1, kxmax, n1, alpha1, c, d,dE)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/E[i]
   if(E[i]==0) G1[i] = NA
   rp2 = hydraulics.regulatedPsiTwoElements(E[i], psiSoil, krmax2, kxmax, n2, alpha2, c,d,dE)
   PU2[i] = rp2[1]
   PR2[i] = rp2[2]
   LU2[i] = rp2[3]
   LR2[i] = rp2[4]
   G2[i] = LR2[i]/E[i]
   if(E[i]==0) G2[i] = NA
   rp3 = hydraulics.regulatedPsiTwoElements(E[i], psiSoil, krmax3, kxmax, n3, alpha3, c,d,dE)
   PU3[i] = rp3[1]
   PR3[i] = rp3[2]
   LU3[i] = rp3[3]
   LR3[i] = rp3[4]
   G3[i] = LR3[i]/E[i]
   if(E[i]==0) G3[i] = NA
 }

plot(LR1, type="l", col="black", ylab="Transpiration rate", xlab = "DOY", ylim=c(0,8), lwd=1, lty=1)
lines(examplemeteo$PET, lty=1, col="gray", lwd=1)
lines(LR2, lty=2, col="black", lwd=1)
lines(LR3, lty=3, col="black", lwd=1)
legend("topleft", col=c("gray","black","black","black"), legend=c("PET", textures), lty=c(1,1,2,3), bty="n", cex=0.8)
@
\end{center}
The supply-loss hydraulic theory also provides water pressure at the canopy end of the continuum. Here we plot both the unregulated and regulated values:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(PU1, type="l", col="black", ylab="Unregulated Psi_canopy", ylim=c(-10,0), xlab = "DOY", lwd=1, lty=1)
lines(PU2, col="black", lty=2)
lines(PU3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(PR1, type="l", col="black", ylab="Regulated Psi_canopy", ylim=c(-2.5,-1.5), xlab = "DOY", lwd=1, lty=1)
lines(PR2, col="black", lty=2)
lines(PR3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}
Finally, we can also plot the relative canopy conductance as the ratio between water demand and regulated transpiration:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(G1, type="l", col="black", ylab="Relative G", ylim=c(0,1), xlab = "DOY", lwd=1, lty=1)
lines(G2, col="black", lty=2)
lines(G3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}
\subsection{Simple bucket model}
In this second example, we conduct a simplified soil water balance with precipitation as input and field capacity and soil potential dictated by texture:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
E = examplemeteo$PET
P = examplemeteo$Precipitation
barplot(P, col="black", ylab="Precipitation", xlab = "DOY")
@
\end{center}

\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
sand1 = 65
sand2 = 30
sand3 = 10
clay1 = 30
clay2 = 10
clay3 = 50
FC1 = soil.psi2theta(clay1, sand1, -33)
FC2 = soil.psi2theta(clay2, sand2, -33)
FC3 = soil.psi2theta(clay3, sand3, -33)
V1 = FC1*1000
V2 = FC2*1000
V3 = FC3*1000
psiSoil1 = rep(NA, length(E))
psiSoil2 = rep(NA, length(E))
psiSoil3 = rep(NA, length(E))
W1 = rep(1, length(E))
W2 = rep(1, length(E))
W3 = rep(1, length(E))
LU1 = rep(NA, length(E))
LR1 = rep(NA, length(E))
PU1 = rep(NA, length(E))
PR1 = rep(NA, length(E))
G1 = rep(NA, length(E))
 LU2 = rep(NA, length(E))
 LR2 = rep(NA, length(E))
 PU2 = rep(NA, length(E))
 PR2 = rep(NA, length(E))
 G2 = rep(NA, length(E))
 LU3 = rep(NA, length(E))
 LR3 = rep(NA, length(E))
 PU3 = rep(NA, length(E))
 PR3 = rep(NA, length(E))
 G3 = rep(NA, length(E))
 for(i in 1:length(E)) {
   W1[i] = min((W1[i]*V1+P[i])/V1,1.0)
   W2[i] = min((W2[i]*V2+P[i])/V2,1.0)
   W3[i] = min((W3[i]*V3+P[i])/V3,1.0)
   psiSoil1[i] = soil.theta2psi(clay1,sand1,W1[i]*FC1)/1000
   psiSoil2[i] = soil.theta2psi(clay2,sand2,W2[i]*FC2)/1000
   psiSoil3[i] = soil.theta2psi(clay3,sand3,W3[i]*FC3)/1000
   rp1 = hydraulics.regulatedPsiTwoElements(E[i], psiSoil1[i], krmax1, kxmax, n1, alpha1, c, d,dE)
   PU1[i] = rp1[1]
   PR1[i] = rp1[2]
   LU1[i] = rp1[3]
   LR1[i] = rp1[4]
   G1[i] = LR1[i]/E[i]
   if(E[i]==0) G1[i] = NA
   rp2 = hydraulics.regulatedPsiTwoElements(E[i], psiSoil2[i], krmax2, kxmax, n2, alpha2, c,d,dE)
   PU2[i] = rp2[1]
   PR2[i] = rp2[2]
   LU2[i] = rp2[3]
   LR2[i] = rp2[4]
   G2[i] = LR2[i]/E[i]
   if(E[i]==0) G2[i] = NA
   rp3 = hydraulics.regulatedPsiTwoElements(E[i], psiSoil3[i], krmax3, kxmax, n3, alpha3, c,d,dE)
   PU3[i] = rp3[1]
   PR3[i] = rp3[2]
   LU3[i] = rp3[3]
   LR3[i] = rp3[4]
   G3[i] = LR3[i]/E[i]
   if(E[i]==0) G3[i] = NA
   if(i<length(E)) {
    W1[i+1] = min((W1[i]*V1-LR1[i])/V1,1.0)
    W2[i+1] = min((W2[i]*V2-LR2[i])/V2,1.0)
    W3[i+1] = min((W3[i]*V3-LR3[i])/V3,1.0)
   }
 }

plot(LR1, type="l", col="black", ylab="Transpiration rate", xlab = "DOY", ylim=c(0,8), lwd=1, lty=1)
lines(examplemeteo$PET, lty=1, col="gray", lwd=1)
lines(LR2, lty=2, col="black", lwd=1)
lines(LR3, lty=3, col="black", lwd=1)
legend("topleft", col=c("gray","black","black","black"), legend=c("PET", textures), lty=c(1,1,2,3), bty="n", cex=0.8)
@
\end{center}
Variation of soil moisture relative to field capacity is:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(W1, type="l", col="black", ylab="W", ylim=c(0,1), xlab = "DOY", lwd=1, lty=1)
lines(W2, col="black", lty=2)
lines(W3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}

The soil water potential and regulated plant potential values are:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(psiSoil1, type="l", col="black", ylab="Psi_soil", ylim=c(-10,0), xlab = "DOY", lwd=1, lty=1)
lines(psiSoil2, col="black", lty=2)
lines(psiSoil3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(PR1, type="l", col="black", ylab="Regulated Psi_canopy", ylim=c(-4,-0), xlab = "DOY", lwd=1, lty=1)
lines(PR2, col="black", lty=2)
lines(PR3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}
And the relative canopy conductance is:
\begin{center}
<<fig=TRUE, width=7, height=3.5, echo=FALSE>>==
par(mar=c(4,4,1,1))
plot(G1, type="l", col="black", ylab="Relative G", ylim=c(0,1), xlab = "DOY", lwd=1, lty=1)
lines(G2, col="black", lty=2)
lines(G3, col="black", lty=3)
legend("bottomleft", col="black", legend=textures, lty=c(1,2,3), bty="n", cex=0.8)
@
\end{center}
\end{document}