Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96140
License: OTHER
1
2
# coding: utf-8
3
4
# In[1]:
5
6
get_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.")
7
8
9
# # Equations to compute stomatal conductance based on sizes and densities of stomata
10
# Equation numbers in comments refer to Lehmann & Or, 2013
11
12
# <h2>Definitions of additional variables</h2>
13
14
# In[2]:
15
16
# Following Lehmann_2015_Effects
17
var2('B_l', 'Boundary layer thickness', meter, domain1='positive')
18
var2('g_sp', 'Diffusive conductance of a stomatal pore', mole/second/meter^2, domain1='positive')
19
var2('r_sp', 'Diffusive resistance of a stomatal pore', meter^2*second/mole, domain1='positive')
20
var2('r_vs', 'Diffusive resistance of a stomatal vapour shell', meter^2*second/mole, domain1='positive')
21
var2('r_bwmol', 'Leaf BL resistance in molar units', meter^2*second/mole, domain1='positive', latexname = 'r_{bw,mol}')
22
var2('r_end', 'End correction, representing resistance between evaporating sites and pores', meter^2*second/mole, domain1='positive')
23
var2('A_p', 'Cross-sectional pore area', meter^2, domain1='positive')
24
var2('d_p', 'Pore depth', meter, domain1='positive')
25
var2('V_m', 'Molar volume of air', meter^3/mole, domain1='positive')
26
var2('n_p', 'Pore density', 1/meter^2, domain1='positive')
27
var2('r_p', 'Pore radius (for ellipsoidal pores, half the pore width)', meter, domain1='positive')
28
var2('l_p', 'Pore length', meter, domain1='positive')
29
var2('k_dv', 'Ratio $D_{va}/V_m$', mole/meter/second, domain1='positive', latexname='k_{dv}')
30
var2('s_p', 'Spacing between stomata', meter, domain1='positive')
31
var2('F_p', 'Fractional pore area (pore area per unit leaf area)', meter^2/meter^2, domain1='positive')
32
33
34
# In[3]:
35
36
docdict[V_m]
37
38
39
# ## Equations from Lehmann & Or, 2013
40
41
# In[4]:
42
43
# Eqn1
44
eq_kdv = k_dv == D_va/V_m
45
print units_check(eq_kdv)
46
eq_gsp_A = g_sp == A_p/d_p*k_dv*n_p
47
print units_check(eq_gsp_A)
48
eq_Ap_rp = A_p == pi*r_p^2
49
print units_check(eq_Ap_rp)
50
eq_rsp_A = r_sp == 1/eq_gsp_A.rhs()
51
print units_check(eq_rsp_A)
52
eq_rsp_rp = r_sp == 1/eq_gsp_A.rhs().subs(eq_Ap_rp)
53
print units_check(eq_rsp_rp)
54
55
56
# In[5]:
57
58
# Eq. 2(c)
59
eq_rvs_B = r_vs == (1/(4*r_p) - 1/(pi*s_p))*1/(k_dv*n_p)
60
units_check(eq_rvs_B)
61
62
63
# In[6]:
64
65
# Eq. 2(d)
66
eq_rvs_S = r_vs == (1/(2*pi*r_p) - 1/(pi*s_p))*1/(k_dv*n_p)
67
units_check(eq_rvs_B)
68
69
70
# In[7]:
71
72
# Below Eq. 3(b)
73
assume(n_p>0)
74
eq_sp_np = s_p == 1/sqrt(n_p)
75
units_check(eq_sp_np)
76
77
78
# In[8]:
79
80
# Eq. 2(a)
81
eq_rend_rp = r_end == 1/(4*r_p*k_dv*n_p)
82
units_check(eq_rend_rp)
83
84
85
# In[9]:
86
87
# Eq. 2(b)
88
eq_rend_PW = r_end == log(4*(l_p/2)/r_p)/(2*pi*l_p/2*k_dv*n_p)
89
units_check(eq_rend_PW)
90
91
92
# In[10]:
93
94
eq_gswmol = g_swmol == 1/(r_end + r_sp + r_vs)
95
units_check(eq_gswmol)
96
97
98
# <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>
99
100
# In[11]:
101
102
assume(s_p>0)
103
eq_np_sp = solve(eq_sp_np, n_p)[0]
104
units_check(eq_np_sp)
105
106
107
# In[12]:
108
109
# Eq. 5
110
eq_rbwmol = r_bwmol == B_l/k_dv
111
units_check(eq_rbwmol)
112
113
114
# In[13]:
115
116
docdict[k_dv]
117
118
119
# 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)))$:
120
121
# In[14]:
122
123
# Verification of Eq. 7a
124
eq1 = (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)
125
eq1.simplify_full().show()
126
eq7a = 1/(1 + s_p^2/B_l*(1/(2*r_p) + d_p/(pi*r_p^2)))
127
eq7a.show()
128
(eq1 - eq7a).simplify_full()
129
130
131
# ## Additional equations for calculating conductances of laser perforated foils
132
133
# In[15]:
134
135
# Pore area for circular pores
136
eq_Ap = A_p == pi*r_p^2
137
units_check(eq_Ap)
138
139
140
# In[16]:
141
142
# To deduce pore radius from pore area, assuming circular pore:
143
eq_rp_Ap = solve(eq_Ap_rp, r_p)[0]
144
units_check(eq_rp_Ap)
145
146
147
# In[17]:
148
149
# For regular pore distribution we can derive the pore density from porosity and pore area
150
eq_np = n_p == F_p/A_p
151
152
153
# In[18]:
154
155
# Conversion from mol/m2/s to m/s, i.e. from g_swmol to g_sw
156
eq_gsw_gswmol = solve(eq_gtwmol_gtw(g_tw = g_sw, g_twmol = g_swmol), g_sw)[0]
157
units_check(eq_gsw_gswmol)
158
159
160
# In[19]:
161
162
# Simplification, neglecting effect of leaf-air temperature difference
163
eq_gsw_gswmol_iso = eq_gsw_gswmol(T_l = T_a).simplify_full()
164
units_check(eq_gsw_gswmol_iso)
165
166
167
# In[20]:
168
169
# Saving session so that it can be loaded using load_session().
170
save_session('temp/stomatal_cond_eqs.sobj')
171
172
173
# <h2>Table of symbols</h2>
174
175
# In[21]:
176
177
# Creating dictionary to substitute names of units with shorter forms
178
var('m s J Pa K kg mol')
179
subsdict = {meter: m, second: s, joule: J, pascal: Pa, kelvin: K, kilogram: kg, mole: mol}
180
var('N_Re_L N_Re_c N_Le N_Nu_L N_Gr_L N_Sh_L')
181
dict_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}
182
dict_varold = {v: k for k, v in dict_varnew.iteritems()}
183
variables = sorted([str(variable.subs(dict_varnew)) for variable in udict.keys()],key=str.lower)
184
tableheader = [('Variable', 'Description (value)', 'Units')]
185
tabledata = [('Variable', 'Description (value)', 'Units')]
186
for variable1 in variables:
187
variable2 = eval(variable1).subs(dict_varold)
188
variable = str(variable2)
189
tabledata.append((eval(variable),docdict[eval(variable)],fun_units_formatted(variable)))
190
191
table(tabledata, header_row=True)
192
193
194