📚 The CoCalc Library - books, templates and other resources
License: OTHER
1# coding: utf-823# In[1]:45get_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# Setting up worksheet and importing equations from other worksheets\nload('temp/Worksheet_setup.sage')\nload_session('temp/leaf_enbalance_eqs.sobj')\nfun_loadvars(dict_vars) # any variables defined using var2() are saved with their attributes in dict_vars. Here we re-define them based on dict_vars from the other worksheet.")678# # Equations to compute stomatal conductance based on sizes and densities of stomata9# Equation numbers in comments refer to Lehmann & Or, 20131011# <h2>Definitions of additional variables</h2>1213# In[2]:1415# Following Lehmann_2015_Effects16var2('B_l', 'Boundary layer thickness', meter, domain1='positive')17var2('g_sp', 'Diffusive conductance of a stomatal pore', mole/second/meter^2, domain1='positive')18var2('r_sp', 'Diffusive resistance of a stomatal pore', meter^2*second/mole, domain1='positive')19var2('r_vs', 'Diffusive resistance of a stomatal vapour shell', meter^2*second/mole, domain1='positive')20var2('r_bwmol', 'Leaf BL resistance in molar units', meter^2*second/mole, domain1='positive', latexname = 'r_{bw,mol}')21var2('r_end', 'End correction, representing resistance between evaporating sites and pores', meter^2*second/mole, domain1='positive')22var2('A_p', 'Cross-sectional pore area', meter^2, domain1='positive')23var2('d_p', 'Pore depth', meter, domain1='positive')24var2('V_m', 'Molar volume of air', meter^3/mole, domain1='positive')25var2('n_p', 'Pore density', 1/meter^2, domain1='positive')26var2('r_p', 'Pore radius (for ellipsoidal pores, half the pore width)', meter, domain1='positive')27var2('l_p', 'Pore length', meter, domain1='positive')28var2('k_dv', 'Ratio $D_{va}/V_m$', mole/meter/second, domain1='positive', latexname='k_{dv}')29var2('s_p', 'Spacing between stomata', meter, domain1='positive')30var2('F_p', 'Fractional pore area (pore area per unit leaf area)', meter^2/meter^2, domain1='positive')313233# In[3]:3435docdict[V_m]363738# ## Equations from Lehmann & Or, 20133940# In[4]:4142# Eqn143eq_kdv = k_dv == D_va/V_m44print units_check(eq_kdv)45eq_gsp_A = g_sp == A_p/d_p*k_dv*n_p46print units_check(eq_gsp_A)47eq_Ap_rp = A_p == pi*r_p^248print units_check(eq_Ap_rp)49eq_rsp_A = r_sp == 1/eq_gsp_A.rhs()50print units_check(eq_rsp_A)51eq_rsp_rp = r_sp == 1/eq_gsp_A.rhs().subs(eq_Ap_rp)52print units_check(eq_rsp_rp)535455# In[5]:5657# Eq. 2(c)58eq_rvs_B = r_vs == (1/(4*r_p) - 1/(pi*s_p))*1/(k_dv*n_p)59units_check(eq_rvs_B)606162# In[6]:6364# Eq. 2(d)65eq_rvs_S = r_vs == (1/(2*pi*r_p) - 1/(pi*s_p))*1/(k_dv*n_p)66units_check(eq_rvs_B)676869# In[7]:7071# Below Eq. 3(b)72assume(n_p>0)73eq_sp_np = s_p == 1/sqrt(n_p)74units_check(eq_sp_np)757677# In[8]:7879# Eq. 2(a)80eq_rend_rp = r_end == 1/(4*r_p*k_dv*n_p)81units_check(eq_rend_rp)828384# In[9]:8586# Eq. 2(b)87eq_rend_PW = r_end == log(4*(l_p/2)/r_p)/(2*pi*l_p/2*k_dv*n_p)88units_check(eq_rend_PW)899091# In[10]:9293eq_gswmol = g_swmol == 1/(r_end + r_sp + r_vs)94units_check(eq_gswmol)959697# <p>It actually does not seem to make much sense to add r_end to the resistances, as it does not reflect the geometry of the inter-cellular air space! Also eq_rvs_B is the correct one to use for stomata, as eq_rvs_S is valid for droplets, not holes!</p>9899# In[11]:100101assume(s_p>0)102eq_np_sp = solve(eq_sp_np, n_p)[0]103units_check(eq_np_sp)104105106# In[12]:107108# Eq. 5109eq_rbwmol = r_bwmol == B_l/k_dv110units_check(eq_rbwmol)111112113# In[13]:114115docdict[k_dv]116117118# Below, we compare our system of equations to Eq. 7a in Lehmann & Or (2015), i.e. we check if $\frac{r_{bwmol}}{r_{tot}} = 1/(1 + s_p^2/B_l*(1/(2*r_p) + d_p/(\pi*r_p^2)))$:119120# In[14]:121122# Verification of Eq. 7a123eq1 = (r_bwmol/(2*r_end + r_sp + r_bwmol)).subs(eq_rend_rp, eq_rsp_rp, eq_rvs_B, eq_rbwmol).subs(eq_np_sp)124eq1.simplify_full().show()125eq7a = 1/(1 + s_p^2/B_l*(1/(2*r_p) + d_p/(pi*r_p^2)))126eq7a.show()127(eq1 - eq7a).simplify_full()128129130# ## Additional equations for calculating conductances of laser perforated foils131132# In[15]:133134# Pore area for circular pores135eq_Ap = A_p == pi*r_p^2136units_check(eq_Ap)137138139# In[16]:140141# To deduce pore radius from pore area, assuming circular pore:142eq_rp_Ap = solve(eq_Ap_rp, r_p)[0]143units_check(eq_rp_Ap)144145146# In[17]:147148# For regular pore distribution we can derive the pore density from porosity and pore area149eq_np = n_p == F_p/A_p150151152# In[18]:153154# Conversion from mol/m2/s to m/s, i.e. from g_swmol to g_sw155eq_gsw_gswmol = solve(eq_gtwmol_gtw(g_tw = g_sw, g_twmol = g_swmol), g_sw)[0]156units_check(eq_gsw_gswmol)157158159# In[19]:160161# Simplification, neglecting effect of leaf-air temperature difference162eq_gsw_gswmol_iso = eq_gsw_gswmol(T_l = T_a).simplify_full()163units_check(eq_gsw_gswmol_iso)164165166# In[20]:167168# Saving session so that it can be loaded using load_session().169save_session('temp/stomatal_cond_eqs.sobj')170171172# <h2>Table of symbols</h2>173174# In[21]:175176# Creating dictionary to substitute names of units with shorter forms177var('m s J Pa K kg mol')178subsdict = {meter: m, second: s, joule: J, pascal: Pa, kelvin: K, kilogram: kg, mole: mol}179var('N_Re_L N_Re_c N_Le N_Nu_L N_Gr_L N_Sh_L')180dict_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}181dict_varold = {v: k for k, v in dict_varnew.iteritems()}182variables = sorted([str(variable.subs(dict_varnew)) for variable in udict.keys()],key=str.lower)183tableheader = [('Variable', 'Description (value)', 'Units')]184tabledata = [('Variable', 'Description (value)', 'Units')]185for variable1 in variables:186variable2 = eval(variable1).subs(dict_varold)187variable = str(variable2)188tabledata.append((eval(variable),docdict[eval(variable)],fun_units_formatted(variable)))189190table(tabledata, header_row=True)191192193194