1# coding: utf-823# # Leaf energy balance equations4# Based on the following paper:5# Schymanski, S.J. and Or, D. (2016): [Leaf-scale experiments reveal important omission in the Penman-Monteith equation.](http://www.hydrol-earth-syst-sci-discuss.net/hess-2016-363/) Hydrology and Earth System Sciences Discussions, p.1ā33. doi: 10.5194/hess-2016-363.6#7# Author: Stan Schymanski ([email protected])8#9# Note: This worksheet is prepared for the open source software [sage](http://www.sagemath.org). It relies on definitions provided in Worksheet [Worksheet_setup](Worksheet_setup.ipynb).1011# In[1]:1213get_ipython().run_cell_magic(u'capture', u'storage', u"# The above redirects all output of the below commands to the variable 'storage' instead of displaying it.\n# It can be viewed by typing: 'storage()'\n\n# Loading modules, settings and custom functions\nload('temp/Worksheet_setup.sage')")141516# ## Definition of variables17# All variables are also listed in a [Table](#Table-of-symbols) at the end of this document.1819# In[2]:2021var2('alpha_a', 'Thermal diffusivity of dry air',meter^2/second)22var2('a_s', 'Fraction of one-sided leaf area covered by stomata (1 if stomata are on one side only, 2 if they are on both sides)', meter^2/meter^2)23var2('a_sh', 'Fraction of projected area exchanging sensible heat with the air (2)', meter^2/meter^2, value = 2, latexname = 'a_{sh}')24var2('c_pa', 'Specific heat of dry air (1010) ', joule/kilogram/kelvin, latexname = 'c_{pa}', value = 1010)25#var2('c_pamol', 'Molar specific heat of dry air (29.19) ', joule/mole/kelvin, latexname = 'c_{pa,mol}', value = 29.19) # https://en.wikipedia.org/wiki/Heat_capacity#Specific_heat_capacity26var2('C_wa', 'Concentration of water in the free air ',mole/meter^3, latexname = 'C_{wa}')27var2('C_wl', 'Concentration of water in the leaf air space ',mole/meter^3, latexname = 'C_{wl}')28var2('D_va', 'Binary diffusion coefficient of water vapour in air',meter^2/second, latexname = 'D_{va}')29var2('E_lmol', 'Transpiration rate in molar units',mole/second/meter^2,latexname='E_{l,mol}')30var2('E_l', 'Latent heat flux from leaf',joule/second/meter^2)31var2('epsilon_l', 'Longwave emmissivity of the leaf surface (1.0)', value = 1, units = 1/1)32var2('g', 'Gravitational acceleration (9.81)', meter/second^2, value= 9.81)33var2('g_bw', 'Boundary layer conductance to water vapour ',meter/second,latexname='g_{bw}')34var2('g_bwmol', 'Boundary layer conductance to water vapour ',mole/meter^2/second,latexname='g_{bw,mol}')35var2('Gr', 'Grashof number', latexname = 'N_{Gr_L}')36var2('g_sw', 'Stomatal conductance to water vapour',meter/second,latexname='g_{sw}')37var2('g_swmol', 'Stomatal conductance to water vapour',mole/meter^2/second,latexname='g_{sw,mol}')38var2('g_tw', 'Total leaf conductance to water vapour',meter/second,latexname='g_{tw}')39var2('g_twmol', 'Total leaf layer conductance to water vapour',mole/meter^2/second,latexname='g_{tw,mol}')40var2('h_c', 'Average 1-sided convective transfer coefficient', joule/meter^2/second/kelvin)41var2('H_l', 'Sensible heat flux from leaf',joule/second/meter^2)42var2('k_a', 'Thermal conductivity of dry air',joule/second/meter/kelvin)43var2('lambda_E', 'Latent heat of evaporation (2.45e6)',joule/kilogram,value = 2.45e6)44var2('Le', 'Lewis number', latexname = 'N_{Le}')45var2('L_l', 'Characteristic length scale for convection (size of leaf)',meter)46var2('M_N2', 'Molar mass of nitrogen (0.028)',kilogram/mole,value = 0.028)47var2('M_O2', 'Molar mass of oxygen (0.032)',kilogram/mole,value = 0.032)48var2('M_w', 'Molar mass of water (0.018)',kilogram/mole,value = 0.018)49var2('nu_a', 'Kinematic viscosity of dry air',meter^2/second)50var2('Nu', 'Nusselt number',latexname = 'N_{Nu_L}')51var2('P_a', 'Air pressure',pascal)52var2('Pr', 'Prandtl number (0.71)',latexname = 'N_{Pr}',value = 0.71)53var2('P_N2', 'Partial pressure of nitrogen in the atmosphere', pascal, latexname = 'P_{N2}')54var2('P_O2', 'Partial pressure of oxygen in the atmosphere', pascal, latexname = 'P_{O2}')55var2('P_wa', 'Vapour pressure in the atmosphere', pascal, latexname = 'P_{wa}')56var2('P_was', 'Saturation vapour pressure at air temperature', pascal, latexname = 'P_{was}')57var2('P_wl', 'Vapour pressure inside the leaf', pascal, latexname = 'P_{wl}')58var2('r_bw', 'Boundary layer resistance to water vapour, inverse of $g_{bw}$', second/meter, latexname = 'r_{bw}')59var2('r_sw', 'Stomatal resistance to water vapour, inverse of $g_{sw}$', second/meter, latexname = 'r_{sw}')60var2('r_tw', 'Total leaf resistance to water vapour, $r_{bv} + r_{sv}$', second/meter, latexname = 'r_{tw}')61var2('Re_c', 'Critical Reynolds number for the onset of turbulence',latexname='N_{Re_c}')62var2('Re', 'Reynolds number',latexname='N_{Re_L}')63var2('rho_a', 'Density of dry air', kilogram/meter^3)64var2('rho_al', 'Density of air at the leaf surface', kilogram/meter^3)65var2('R_ll', 'Longwave radiation away from leaf',joule/second/meter^2, latexname = 'R_{ll}')66var2('R_mol', 'Molar gas constant (8.314472)',joule/mole/kelvin,latexname='R_{mol}', value = 8.314472)67var2('R_s', 'Solar shortwave flux',joule/second/meter^2)68var2('Sh', 'Sherwood number',latexname = 'N_{Sh_L}')69var2('sigm', 'Stefan-Boltzmann constant (5.67e-8)',joule/second/meter^2/kelvin^4,'real',latexname='\\sigma',value=5.67e-8)70var2('T_a', 'Air temperature',kelvin)71var2('T_l', 'Leaf temperature',kelvin)72var2('T_w', 'Radiative temperature of objects surrounding the leaf', kelvin)73var2('v_w', 'Wind velocity',meter/second)747576# # Mathematical derivations77# ## Leaf energy balance78# The material below follows closely derivations published previously \citep{schymanski_stomatal_2013}, with re-organisation of equations for greater consistence with the present paper.79#80# The leaf energy balance is determined by the dominant energy fluxes between the leaf and its surroundings, including radiative, sensible, and latent energy exchange (linked to mass exchange).81#82#83# In this study we focus on steady-state conditions, in which the energy balance can be written as:84# ##### {eq_Rs_enbal}85# $$ R_s = R_{ll} + H_l + E_l $$86# where $R_s$ absorbed short wave radiation, $R_{ll}$ is the net longwave balance, i.e. the emitted minus the absorbed, $H_l$ is the sensible heat flux away from the leaf and $E_l$ is the latent heat flux away from the leaf. In the above, extensive variables are defined per unit leaf area. Following our previous work \citep{schymanski_stomatal_2013}, this study considers spatially homogeneous planar leaves, i.e. homogenous illumination and a negligible temperature gradient between the two sides of the leaf.87# The net longwave emission is represented by the difference between blackbody radiation at leaf temperature ($T_l$) and that at the temperature of the surrounding objects ($T_w$) \citep{Monteith_principles_2007}:88# ##### {eq_Rll}89# $$R_{ll} = a_{sH} \epsilon_l \sigma (T_{l}^{4} - T_{w}^{4})$$90#91# where $a_{sH}$ is the fraction of projected leaf area exchanging radiative and sensible heat (2 for a planar leaf, 1 for a soil surface), $\epsilon_l$ is the leaf's longwave emmissivity ($\approx 1$) and $\sigma$ is the Stefan-Boltzmann constant.92# Total convective heat transport away from the leaf is represented as:93# ##### {eq_Hl}94# $$H_l = a_{sH} h_c (T_l - T_a)$$95#96# where $h_c$ is the average one-sided convective heat transfer coefficient, determined by properties of the leaf boundary layer.97#98# Latent heat flux ($E_l$, W~m$^{-2}$) is directly related to the transpiration rate ($E_{l,mol}$) by:99# ##### {eq_El}100# $$E_l = E_{l,mol} M_w \lambda_E$$101#102# where $M_w$ is the molar mass of water and $\lambda_E$ the latent heat of vaporisation. $E_{l,mol}$ (mol~m$^{-2}$~s$^{-1}$) was computed in molar units as a function of the concentration of water vapour within the leaf ($C_{wl}$, mol m$^{-3}$) and in the free air ($C_{wa}$, mol m$^{-3}$) \citep[Eq. 6.8]{incropera_fundamentals_2006}:103# ##### {eq_Elmol}104# $$E_{l,mol} = g_{tw}(C_{wl} - C_{wa}) $$105#106# where $g_{tw}$ (m~s$^{-1}$) is the total leaf conductance for water vapour, dependent on stomatal ($g_{sw}$) and boundary layer conductance ($g_{bw}$) in the following way:107# ##### {eq_gtw}108# $$g_{tw} = \frac{1}{\frac{1}{g_{sw}} + \frac{1}{g_{bw}}}$$109#110111# In[3]:112113eq_Rs_enbal = R_s == R_ll + H_l + E_l114units_check(eq_Rs_enbal).simplify_full()115116117# In[4]:118119eq_Rll = R_ll == a_sh*sigm*epsilon_l*(T_l^4 - T_w^4)120units_check(eq_Rll).simplify_full()121122123# In[5]:124125eq_Hl = H_l == a_sh*h_c*(T_l - T_a)126units_check(eq_Hl).simplify_full()127128129# In[6]:130131eq_El = E_l == E_lmol*M_w*lambda_E132units_check(eq_El).simplify_full()133134135# In[7]:136137ustr = str(units_check(M_w*lambda_E))138print str((M_w*lambda_E).subs(cdict)) + ustr139140141# In[8]:142143eq_Elmol = E_lmol == g_tw*(C_wl - C_wa)144units_check(eq_Elmol).simplify_full()145146147# In[9]:148149eq_gtw = g_tw == 1/(1/g_sw + 1/g_bw)150eq_gtw.simplify_full().show()151units_check(eq_gtw).simplify_full()152153154# ## Boundary layer conductance to water vapour155# The total leaf conductance to water vapour is determined by the boundary layer and stomatal conductances and equal to 1 over the sum of their respectife resistances ($g_{tw} = 1/(r_{sw} + r_{bw})$.156# The boundary layer conductance for water vapour is equivalent to the mass transfer coefficient for a wet surface \cite[Eq. 7.41]{incropera_fundamentals_2006}:157# ##### {eq_gbw}158# $$g_{bw} = N_{Sh_L} D_{va}/L_l$$159#160# where $N_{Sh_L}$ is the dimensionless Sherwood number and $D_{va}$ is the diffusivity of water vapour in air.161# If the convection coefficient for heat is known, the one for mass ($g_{bw}$) can readily be calculated from the relation \cite[Eq. 6.60]{incropera_fundamentals_2006}:162# ##### {eq_gbw_hc}163# $$g_{bw} = \frac{a_s h_c}{\rho_a c_{pa} N_{Le}^{1-n}}$$164#165# where $a_s$ is the fraction of one-sided transpiring surface area in relation to the surface area for sensible heat exchange, $c_{pa}$ is the constant-pressure heat capacity of air, $n$ is an empirical constant ($n=1/3$ for general purposes) and $N_{Le}$ is the dimensionless Lewis number, defined as \cite[Eq. 6.57]{incropera_fundamentals_2006}:166# ##### {eq_Le}167# $$N_{Le} = \alpha_a/D_{va}$$168#169# where $\alpha_a$ is the thermal diffusivity of air. The value of $a_s$ was set to 1 for leaves with stomata on one side only, and to 2 for stomata on both sides. Other values could be used for leaves only partly covered by stomata.170171# In[10]:172173eq_gbw = g_bw == D_va*Sh/L_l174units_check(eq_gbw).simplify_full()175eq_gbw_hc = g_bw == a_s*h_c/(rho_a*c_pa*Le^(2/3))176print units_check(eq_gbw_hc).simplify_full()177eq_Le = Le == alpha_a/D_va178units_check(eq_Le).simplify_full()179180181# ## Effect of leaf temperature on the leaf-air vapour concentration gradient182# \label{sec_Tleaf}183# The concentration difference in Eq. [eq_Elmol](#{eq_Elmol}) is a function of the temperature and the vapour pressure differences between the leaf and the free air. Assuming that water vapour behaves like an ideal gas, we can express its concentration as:184# ##### {eq_Cwl}185# $$C_{wl} = \frac{P_{wl}}{R_{mol} T_l}186# $$187#188# where $P_{wl}$ is the vapour pressure inside the leaf, $R_{mol}$ is the universal gas constant and $T_l$ is leaf temperature. A similar relation holds for the vapour concentration in free air, $C_{wa} = P_{wa}/(R_{mol} T_l)$. In this study the vapour pressure inside the leaf is assumed to be the saturation vapour pressure at leaf temperature, which is computed using the Clausius-Clapeyron relation \citep[Eq. B.3]{hartmann_global_1994}:189# ##### {eq_Pwl}190# $$P_{wl} = 611 \exp \left( \frac{\lambda_E M_w}{R_{mol}} \left( \frac{1}{273} - \frac{1}{T_l} \right) \right)191# $$192# where $\lambda_E$ is the latent heat of vaporisation and $M_w$ is the molar mass of water.193#194# Note that the dependence of the leaf-air water concentration difference ($C_{wl} - C_{wa}$) in Eq. [eq_Cwl](#{eq_Cwl}) is very sensitive to leaf temperature. For example if the leaf temperature increases by 5K relative to air temperature, $C_{wl} - C_{wa}$ would double, while if leaf temperature decreased by 6K, $C_{wl} - C_{wa}$ would go to 0 at 70\% relative humidity.195196# <p>Ā </p>197# <p>Ā </p>198199# In[11]:200201eq_Cwl = C_wl == P_wl/(R_mol*T_l)202print units_check(eq_Cwl).simplify_full()203eq_Pwl = P_wl == 611*exp(lambda_E*M_w/R_mol*(1/273 - 1/T_l))204show(eq_Pwl)205206207# ## Concentration or vapour pressure gradient driving transpiration?208#209# Note that $E_{l,mol}$ is commonly expressed as a function of the vapour pressure difference between the free air ($P_{wa}$) and the leaf ($P_{wl}$), in which the conductance ($g_{tw,mol}$) is expressed in molar units (mol~m$^{-2}$~s$^{-1}$):210# ##### {eq_Elmol_conv}211# $$ E_{l,mol} = g_{tw,mol} \frac{P_{wl} - P_{wa}}{P_a}$$212#213# For $P_{wl} = P_{wa}$, Eq. [eq_Elmol](#{eq_Elmol}) can still give a flux, whereas Eq. [eq_Elmol_conv](#{eq_Elmol_conv}) gives zero flux. This is because the concentrations of vapour in air (mol~m$^{-3}$) can differ due to differences in tempertaure, even if the partial vapour pressures are the same (see Eq. [eq_Cwl](#{eq_Cwl})). Therefore, the relation between $g_{tw}$ and $g_{v,mol}$ has an asymptote at the equivalent temperature. It can be obtained by combining Eqs. [eq_Elmol](#{eq_Elmol}) and [eq_Elmol_conv](#{eq_Elmol_conv}) and solving for $g_{tw,mol}$:214# ##### {eq_gtwmol_gtw}215# $$g_{tw,mol} = g_{tw}\frac{P_a(P_{wa} T_l - P_{wl} T_a)}{(P_{wa} - P_{wl}) R_{mol} T_a T_l)}$$216#217# For $T_l = T_a$, the relation simplifies to:218# ##### {eq_gtwmol_gtw_iso}219# $$g_{tw,mol} = g_{tw}\frac{P_a }{R_{mol} T_a}$$220#221# which, for typical values of $P_a$ and $T_a$ amounts to $g_{tw,mol}\approx40$~mol~m$^{-3}g_{tw}$. For all practical purposes, we found that Eqs. [eq_Elmol](#{eq_Elmol}) and [eq_Elmol_conv](#{eq_Elmol_conv}) with $g_{tw,mol} = g_{tw}\frac{P_a }{R_{mol} T_a}$ give similar results when plotted as functions of leaf temperature.222223# In[12]:224225eq_Elmol_conv = E_lmol == g_twmol*(P_wl-P_wa)/P_a226print units_check(eq_Elmol_conv).simplify_full()227soln = solve([eq_Elmol.subs(eq_Cwl, eq_Cwl(C_wl = C_wa, P_wl = P_wa, T_l = T_a)), eq_Elmol_conv], g_twmol, E_lmol)228eq_gtwmol_gtw = soln[0][0]229print units_check(eq_gtwmol_gtw).simplify_full()230eq_gtwmol_gtw_iso = eq_gtwmol_gtw(T_l = T_a).simplify_full()231print units_check(eq_gtwmol_gtw_iso).simplify_full()232233234# ## Model closure235#236# Given climatic forcing as $P_a$, $T_a$, $R_s$, $P_{wa}$ and $v_w$, and leaf-specific parameters $a_s$, $a_{sH}$, $L_l$ and $g_{sw}$, we need to compute $C_{wa}$, $h_c$, $g_{bw}$ and a series of other derived variables, as described below.237#238# The vapour concentration in the free air can be computed from vapour pressure analogously to Eq. [eq_Cwl](#{eq_Cwl}):239# ##### {eq_Cwa}240# $$C_{wa} = \frac{P_{wa}}{R_{mol} T_a}$$241#242# The heat transfer coefficient ($h_c$) for a flat plate can be determined using the non-dimensional Nusselt number ($N_{Nu_L}$):243# ##### {eq_hc}244# $$h_{c} = k_a\frac{N_{Nu_L}}{L_l}$$245#246# where $k_a$ is the thermal conductivity of the air in the boundary layer and $L_l$ is a characteristic length scale of the leaf.247#248# For sufficiently high wind speeds, inertial forces drive the convective heat transport (forced convection) and the relevant dimensionless number is the Reynolds number ($N_{Re_L}$), which defines the balance between inertial and viscous forces \cite[Eq. 6.41]{incropera_fundamentals_2006}:249# ##### {eq_Re}250# $$N_{Re_L} = \frac{v_w L_l}{\nu_a}$$251#252# where $v_w$ is the wind velocity (m s$^{-1}$), $\nu_a$ is the kinematic viscosity of the air and $L_l$ is taken as the length of the leaf in wind direction.253#254# In the absence of wind, buoyancy forces, driven by the density gradient between the air at the surface of the leaf and the free air dominate convective heat exchange (``free'' or ``natural convection''). The relevant dimensionless number here is the Grashof number ($N_{Gr_L}$), which defines the balance between buoyancy and viscous forces \cite[Eqs. 9.3 and 9.65]{incropera_fundamentals_2006}:255# ##### {eq_Gr}256# $$N_{Gr_L} =\frac{g(\frac{\rho_a - \rho_{al}}{\rho_{al}}) L_l^3}{\nu_a^2}$$257#258# where $g$ is gravity, while $\rho_a$ and $\rho_{al}$ are the densities of the gas in the atmosphere and at the leaf surface respectively.259#260# For $N_{Gr_L} \ll N_{Re_L}^2$, forced convection is dominant and free convection can be neglected, whereas for $N_{Gr_L} \gg N_{Re_L}^2$ free convection is dominant and forced convection can be neglected \cite[P. 565]{incropera_fundamentals_2006}. For simplicity, the analysis is limited to forced conditions, which is satisfied by considering wind speeds greater than 0.5~m~s$^{-1}$ for $5 \times 5$ cm leaves. %See leaf_chamber4.sws or leaf_capacitance_steady_state3.sws.261#262# The average Nusselt number under forced convection was calculated as a function of the average Reynolds number and a critical Reynolds number ($N_{Re_c}$) that determines the onset of turbulence and depends on the level of turbulence in the free air stream or leaf surface properties \cite[P. 412]{incropera_fundamentals_2006}263#264# ##### {eq_Nu_forced_all}265# $$N_{Nu_L} = (0.037 N_{Re_L}^{4/5} - C_1)N_{Pr}^{1/3}$$266#267# with268# ##### {eq_C1}269# $$C_1 = 0.037 C_2^{4/5} - 0.664 C_2^{1/2}$$270#271# and272# ##### {eq_C2}273# $$C_2 = \frac{N_{Re_L} + N_{Re_c} - |N_{Re_c} - N_{Re_L}|}{2}$$274#275# Eq. [eq_C2](#{eq_C2}) was introduced to make Eq. [eq_Nu_forced_all](#{eq_Nu_forced_all}) valid for all Reynolds numbers, and following considerations explained in our previous work \citep{schymanski_stomatal_2013}, we chose $N_{Re_c}=3000$ in the present simulations.276277# In[13]:278279eq_Cwa = C_wa == P_wa/(R_mol*T_a)280print units_check(eq_Cwa)281eq_hc = h_c == k_a*Nu/L_l282print units_check(eq_hc)283eq_Re = Re == v_w*L_l/nu_a284print units_check(eq_Re)285eq_Gr = Gr == g*(rho_a - rho_al)/rho_al * L_l^3/nu_a^2286print units_check(eq_Gr)287C2 = (Re + Re_c - (abs(Re - Re_c))/2)288C1 = 0.037*C2^(4/5) - 0.664*C2^(1/2)289eq_Nu_forced_all = Nu == (0.037*Re^(4/5) - C1)*Pr^(1/3)290eq_Nu_forced_all.show()291292293# ### Thermodynamic variables294# In order to simulate steady state leaf temperatures and the leaf energy balance terms using the above equations, it is necessary to calculate $\rho_a$, $D_{wa}$, $\alpha_a$, $k_a$, and $\nu_a$, while $L_l$, $Re_c$ and $g_{sv}$ are input parameters, and $P_{wa}$ and $v_w$ (vapour pressure and wind speed) are part of the environmental forcing.295# $D_{wa}$, $\alpha_a$, $k_a$ and $\nu_a$ were parameterised as functions of air temperature ($T_a$) only, by fitting linear curves to published data \cite[Table A.3]{Monteith_principles_2007}:296# ##### {eq_Dwa}297# $$D_{wa} = (1.49\times 10^{-7})T_a - 1.96\times 10^{-5}$$298#299# ##### {eq_alphaa}300# $$\alpha_a = (1.32\times 10^{-7})T_a - 1.73\times 10^{-5}$$301#302# ##### {eq_ka}303# $$k_a = (6.84\times 10^{-5})T_a + 5.62\times 10^{-3}$$304#305# ##### {eq_nua}306# $$\nu_a = (9\times 10^{-8})T_a - 1.13\times 10^{-5}$$307#308#309# Assuming that air and water vapour behave like an ideal gas, and that dry air is composed of 79\% N$_2$ and 21\% O$_2$, we calculated air density as a function of temperature, vapour pressure and the partial pressures of the other two components using the ideal gas law:310# ##### {eq_rhoa_Pa_Ta}311# $$\rho_a = \frac{n_a M_a}{V_a} = M_a \frac{P_a}{R_{mol} T_a}$$312#313# where $n_a$ is the amount of matter (mol), $M_a$ is the molar mass (kg~mol$^{-1}$), $P_a$ the pressure, $T_a$ the temperature and $R_{mol}$ the molar universal gas constant.314# This equation was used for each component, i.e. water vapour, N$_2$ and O$_2$, where the partial pressures of N$_2$ and O$_2$ are calculated from atmospheric pressure minus vapour pressure, yielding:315# ##### {eq_rhoa_Pwa_Ta}316# $$\rho_a = \frac{M_w P_{wa} + M_{N_2} P_{N_2} + M_{O_2} P_{O_2}}{R_{mol} T_a}$$317#318# where $M_{N_2}$ and $M_{O_2}$ are the molar masses of nitrogen and oxygen respectively, while $P_{N_2}$ and $P_{O_2}$ are their partial pressures, calculated as:319#320# ##### {eq_PN2}321# $$P_{N_2} = 0.79(P_a - P_{wa})$$322#323# and324# ##### {eq_PO2}325# $$P_{O_2} = 0.21(P_a - P_{wa})$$326#327328# In[14]:329330eq_Dva = D_va == 1.49e-07*T_a - 1.96e-05331eq_alphaa = alpha_a == (1.32e-07)*T_a - 1.73e-05332eq_ka = k_a == 6.84e-05*T_a + 5.63e-03333eq_nua = nu_a == 9.e-08*T_a - 1.13e-05334eq_rhoa_Pwa_Ta = rho_a == (M_w*P_wa + M_N2*P_N2 + M_O2*P_O2)/(R_mol*T_a)335print units_check(eq_rhoa_Pwa_Ta)336337338# In[15]:339340eq_Pa = P_a == P_N2 + P_O2 + P_wa341print units_check(eq_Pa)342eq_PN2_PO2 = P_N2 == 0.79/0.21*P_O2343soln = solve([eq_Pa, eq_PN2_PO2], P_O2, P_N2)344eq_PO2 = soln[0][0]345print units_check(eq_PO2)346eq_PN2 = soln[0][1]347units_check(eq_PN2)348349350# In[16]:351352eq_rhoa = eq_rhoa_Pwa_Ta.subs(eq_PN2, eq_PO2)353units_check(eq_rhoa).simplify_full()354355356# ## Example calculations357358# In[17]:359360# Energy balance as a function of variables that are independent of leaf temperature361eqenbalTl = (eq_Rs_enbal - R_s).rhs().subs(eq_El, eq_Hl, eq_Rll).subs(eq_Elmol).subs(eq_Cwl).subs(eq_Pwl)362eqenbalTl.subs(cdict).args()363364365# Below, we create a copy of cdict, which is a dictionary with general constants, generated during the definition of variables at the top of the worksheet, and some example values for external forcing and leaf properties needed to compute steady-state fluxes and leaf temperature:366367# In[18]:368369# Input values370vdict = cdict.copy()371vdict[a_s] = 1.0 # one sided stomata372vdict[g_sw] = 0.01373vdict[T_a] = 273 + 25.5374vdict[T_w] = vdict[T_a] # Wall temperature equal to air temperature375vdict[P_a] = 101325376rha = 1377vdict[P_wa] = rha*eq_Pwl.rhs()(T_l = T_a).subs(vdict)378vdict[L_l] = 0.03379vdict[Re_c] = 3000380vdict[R_s] = 600381vdict[v_w] = 1382383384# Now, we compute all derived variables, using the equations described above.385386# In[19]:387388# Nusselt number389vdict[nu_a] = eq_nua.rhs().subs(vdict)390vdict[Re] = eq_Re.rhs().subs(vdict)391vdict[Nu] = eq_Nu_forced_all.rhs().subs(vdict)392vdict[Nu]393394395# In[20]:396397# h_c398vdict[k_a] = eq_ka.rhs().subs(vdict)399vdict[h_c] = eq_hc.rhs().subs(vdict)400vdict[h_c]401402403# In[21]:404405# gbw406vdict[D_va] = eq_Dva.rhs().subs(vdict)407vdict[alpha_a] = eq_alphaa.rhs().subs(vdict)408vdict[rho_a] = eq_rhoa.rhs().subs(vdict)409vdict[Le] = eq_Le.rhs().subs(vdict)410vdict[g_bw] = eq_gbw_hc.rhs().subs(vdict)411vdict[g_bw]412413414# In[22]:415416# Hl, Rll417vdict[R_ll] = eq_Rll.rhs().subs(vdict)418print vdict[R_ll]419vdict[H_l] = eq_Hl.rhs().subs(vdict)420vdict[H_l]421422423# In[23]:424425# El426vdict[g_tw] = eq_gtw.rhs().subs(vdict)427vdict[C_wa] = eq_Cwl.rhs()(P_wl = P_wa, T_l = T_a).subs(vdict)428vdict[P_wl] = eq_Pwl.rhs().subs(vdict)429vdict[C_wl] = eq_Cwl.rhs().subs(vdict)430vdict[E_lmol] = eq_Elmol.rhs().subs(vdict)431vdict[E_l] = eq_El.rhs().subs(eq_Elmol).subs(vdict)432vdict[E_l]433434435# Now, we have a dictionary with $E_l$, $H_l$ and $R_{ll}$ as functions of leaf temperature ($T_l$) only. At steady state, [eq_Rs_enbal](#{eq_Rs_enbal}) must be satisfied, so we will substitute the above dictionary into eq_Rs_enbal, subtract $R_s$ and do a numerical search for the root of the equation to obtain steady-state leaf temperature:436437# In[24]:438439# Numerical search for steady-state Tl440vdict[T_l] = find_root((eq_Rs_enbal - R_s).rhs().subs(vdict), 273, 373)441vdict[T_l]442443444# Below, we define a function that performs all the above calculations given a dictionary with the instantaneous forcing:445446# In[25]:447448def fun_SS(vdict1):449'''450Steady-state T_l, R_ll, H_l and E_l under forced conditions.451Parameters are given in a dictionary (vdict) with the following entries:452a_s, a_sh, L_l, P_a, P_wa, R_s, Re_c, T_a, g_sw, v_w453'''454vdict = vdict1.copy()455456# Nusselt number457vdict[nu_a] = eq_nua.rhs().subs(vdict)458vdict[Re] = eq_Re.rhs().subs(vdict)459vdict[Nu] = eq_Nu_forced_all.rhs().subs(vdict)460461# h_c462vdict[k_a] = eq_ka.rhs().subs(vdict)463vdict[h_c] = eq_hc.rhs().subs(vdict)464465# gbw466vdict[D_va] = eq_Dva.rhs().subs(vdict)467vdict[alpha_a] = eq_alphaa.rhs().subs(vdict)468vdict[rho_a] = eq_rhoa.rhs().subs(vdict)469vdict[Le] = eq_Le.rhs().subs(vdict)470vdict[g_bw] = eq_gbw_hc.rhs().subs(vdict)471472# Hl, Rll473vdict[R_ll] = eq_Rll.rhs().subs(vdict)474vdict[H_l] = eq_Hl.rhs().subs(vdict)475476# El477vdict[g_tw] = eq_gtw.rhs().subs(vdict)478vdict[C_wa] = eq_Cwl.rhs()(P_wl = P_wa, T_l = T_a).subs(vdict)479vdict[P_wl] = eq_Pwl.rhs().subs(vdict)480vdict[C_wl] = eq_Cwl.rhs().subs(vdict)481vdict[E_lmol] = eq_Elmol.rhs().subs(vdict)482vdict[E_l] = eq_El.rhs().subs(eq_Elmol).subs(vdict)483484# Tl485try:486vdict[T_l] = find_root((eq_Rs_enbal - R_s).rhs().subs(vdict), 273, 373)487except:488print 'too many unknowns for finding T_l: ' + str((eq_Rs_enbal - R_s).rhs().subs(vdict).args())489490# Re-inserting T_l491Tlss = vdict[T_l]492for name1 in [C_wl, P_wl, R_ll, H_l, E_l, E_lmol]:493vdict[name1] = vdict[name1].subs(T_l = Tlss)494495# Test for steady state496if n((E_l + H_l + R_ll - R_s).subs(vdict))>1.:497return 'error in energy balance: El + Hl + Rll - R_s = ' + str(n((E_l + H_l + R_ll - R_s).subs(vdict)))498return vdict499500501# In[26]:502503# Test504vdict = cdict.copy()505#vdict= {}506vdict[a_s] = 1.0 # one sided stomata507vdict[g_sw] = 0.01508vdict[T_a] = 273 + 25.5509vdict[T_w] = vdict[T_a] # Wall temperature equal to air temperature510vdict[P_a] = 101325511rha = 1512vdict[P_wa] = rha*eq_Pwl.rhs()(T_l = T_a).subs(vdict)513vdict[L_l] = 0.03514vdict[Re_c] = 3000515vdict[R_s] = 600516vdict[v_w] = 1517resdict = fun_SS(vdict)518519fun_dict_print(resdict)520521522# ### Calculation using known $T_l$523# If leaf temperature ($T_l$) is known (e.g. measured), but stomatal conductance $g_{sw}$ is not known, we can still calculate $H_l$ and $R_{ll}$, and then obtain $E_l$ from the energy balance equation:524525# In[27]:526527eq_El_enbal = solve(eq_Rs_enbal, E_l)[0]528units_check(eq_El_enbal)529530531# In[28]:532533# Test with known Tl but no g_sw534vdict = cdict.copy()535vdict[a_s] = 1.0 # one sided stomata536537vdict[T_a] = 273 + 25.5538vdict[T_w] = vdict[T_a] # Wall temperature equal to air temperature539vdict[P_a] = 101325540rha = 1541vdict[P_wa] = rha*eq_Pwl.rhs()(T_l = T_a).subs(vdict)542vdict[L_l] = 0.03543vdict[Re_c] = 3000544vdict[R_s] = 600545vdict[v_w] = 1546547vdict[C_wa] = eq_Cwl.rhs()(P_wl = P_wa, T_l = T_a).subs(vdict)548vdict[nu_a] = eq_nua.rhs().subs(vdict)549vdict[Re] = eq_Re.rhs().subs(vdict)550vdict[Nu] = eq_Nu_forced_all.rhs().subs(vdict)551vdict[k_a] = eq_ka.rhs().subs(vdict)552vdict[h_c] = eq_hc.rhs().subs(vdict)553554555vdict[T_l] = 305.65556vdict[H_l] = eq_Hl.rhs().subs(vdict)557vdict[R_ll] = eq_Rll.rhs().subs(vdict)558559eq_El_enbal.subs(vdict)560561562# # Saving definitions to separate file563# In the below, we save the definitions and variables to separate files in the /temp directory, one with the extension .sage, from which we can selectively load functions using564# `%load fun_name filenam.sage`565# and one with the extension .sobj, to be loaded elsewhere using566# `load_session()`567568# In[29]:569570fun_export_ipynb('leaf_enbalance_eqs', 'temp/')571save_session('temp/leaf_enbalance_eqs')572573574# # Table of symbols575576# In[30]:577578# Creating dictionary to substitute names of units with shorter forms579var('m s J Pa K kg mol')580subsdict = {meter: m, second: s, joule: J, pascal: Pa, kelvin: K, kilogram: kg, mole: mol}581var('N_Re_L N_Re_c N_Le N_Nu_L N_Gr_L N_Sh_L')582dict_varnew = {Re: N_Re_L, Re_c: N_Re_c, Le: N_Le, Nu: N_Nu_L, Gr: N_Gr_L, Sh: N_Sh_L}583dict_varold = {v: k for k, v in dict_varnew.iteritems()}584variables = sorted([str(variable.subs(dict_varnew)) for variable in udict.keys()],key=str.lower)585tableheader = [('Variable', 'Description (value)', 'Units')]586tabledata = [('Variable', 'Description (value)', 'Units')]587for variable1 in variables:588variable2 = eval(variable1).subs(dict_varold)589variable = str(variable2)590tabledata.append((eval(variable),docdict[eval(variable)],fun_units_formatted(variable)))591592table(tabledata, header_row=True)593594595# In[ ]:596597598599600601