Importable variables and equations

This jupyter notebook can be found at: https://github.com/environmentalscience/essm/blob/master/docs/examples/importable_variables_equations.ipynb

Below, we will import some generic python packages that are used in this notebook:

[1]:
# Checking for essm version installed
import pkg_resources
pkg_resources.get_distribution("essm").version
[1]:
'0.4.2.dev5'
[14]:
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:150% !important; }</style>"))
[4]:
from IPython.display import display
from sympy import init_printing, latex
init_printing()
from sympy.printing import StrPrinter
StrPrinter._print_Quantity = lambda self, expr: str(expr.abbrev)    # displays short units (m instead of meter)
[5]:
import scipy as sc
# Import various functions from sympy
from sympy import Derivative, Eq, exp, log, solve, Symbol
[6]:
from essm.variables.utils import generate_metadata_table, ListTable

General physics variables and equations

Variables

Pre-defined thermodynamics variables can be imported from essm.variables.physics.thermodynamics:

[7]:
import essm.variables.physics.thermodynamics as physics_vars
vars = ['physics_vars.' + name for name in physics_vars.__all__]
generate_metadata_table([eval(name) for name in vars])
[7]:
SymbolNameDescriptionDefinitionDefault valueUnits
$\alpha_a$alpha_aThermal diffusivity of dry air.-m$^{2}$ s$^{-1}$
$\lambda_E$lambda_ELatent heat of evaporation.2450000.0J kg$^{-1}$
$\nu_a$nu_aKinematic viscosity of dry air.-m$^{2}$ s$^{-1}$
$\rho_a$rho_aDensity of dry air.-kg m$^{-3}$
$\sigma$sigmStefan-Boltzmann constant.5.67e-08J s$^{-1}$ m$^{-2}$ K$^{-4}$
$c_{pa,mol}$c_pamolMolar specific heat of dry air. https://en.wikipedia.org/wiki/Heat_capacity#Specific_heat_capacity 29.19J K$^{-1}$ mol$^{-1}$
$c_{pa}$c_paSpecific heat of dry air.1010.0J K$^{-1}$ kg$^{-1}$
$c_{pv}$c_pvSpecific heat of water vapour at 300 K. http://www.engineeringtoolbox.com/water-vapor-d_979.html 1864J K$^{-1}$ kg$^{-1}$
$C_{wa}$C_waConcentration of water in air.-mol m$^{-3}$
$D_{va}$D_vaBinary diffusion coefficient of water vapour in air.-m$^{2}$ s$^{-1}$
$g$gGravitational acceleration.9.81m s$^{-2}$
$h_c$h_cAverage 1-sided convective heat transfer coefficient.-J K$^{-1}$ s$^{-1}$ m$^{-2}$
$k_a$k_aThermal conductivity of dry air.-J K$^{-1}$ m$^{-1}$ s$^{-1}$
$M_w$M_wMolar mass of water.0.018kg mol$^{-1}$
$M_{air}$M_airMolar mass of air. http://www.engineeringtoolbox.com/molecular-mass-air-d_679.html 0.02897kg mol$^{-1}$
$M_{N_2}$M_N2Molar mass of nitrogen.0.028kg mol$^{-1}$
$M_{O_2}$M_O2Molar mass of oxygen.0.032kg mol$^{-1}$
$N_{Gr_L}$GrGrashof number.-1
$N_{Le}$LeLewis number.-1
$N_{Nu_L}$NuAverage Nusselt number over given length.-1
$N_{Pr}$PrPrandtl number (0.71 for air).-1
$N_{Re_c}$Re_cCritical Reynolds number for the onset of turbulence.-1
$N_{Re_L}$ReAverage Reynolds number over given length.-1
$P_a$P_aAir pressure.-Pa
$P_{N2}$P_N2Partial pressure of nitrogen.-Pa
$P_{O2}$P_O2Partial pressure of oxygen.-Pa
$P_{was}$P_wasSaturation water vapour pressure at air temperature.-Pa
$P_{wa}$P_waWater vapour pressure in the atmosphere.-Pa
$R_d$R_dDownwelling global radiation.-W m$^{-2}$
$R_s$R_sSolar shortwave flux per area.-J s$^{-1}$ m$^{-2}$
$R_u$R_uUpwelling global radiation.-W m$^{-2}$
$R_{mol}$R_molMolar gas constant.8.314472J K$^{-1}$ mol$^{-1}$
$T_0$T0Freezing point in Kelvin.273.15K
$T_a$T_aAir temperature.-K
$v_w$v_wWind velocity.-m s$^{-1}$
$x_{N2}$x_N2Mole fraction of nitrogen in dry air.0.791
$x_{O2}$x_O2Mole fraction of oxygen in dry air.0.211

Each of the above can also be imported one-by-one, using its Name, e.g.:

from essm.variables.physics.thermodynamics import R_mol

Equations

General equations based on the above variables can be imported from essm.equations.physics.thermodynamics:

[8]:
import essm.equations.physics.thermodynamics as physics_eqs
modstr = 'physics_eqs.'
eqs = [name for name in physics_eqs.__all__]
table = ListTable()
#table.append(('Name', 'Description', 'Equation'))
for name in eqs:
    table.append((name, eval(modstr+name).__doc__, latex('$'+latex(eval(modstr+name))+'$')))
table
[8]:
eq_LeLe as function of alpha_a and D_va. (Eq. B3 in :cite:`schymanski_leaf-scale_2017`) $N_{Le} = \frac{\alpha_a}{D_{va}}$
eq_CwaC_wa as a function of P_wa and T_a. (Eq. B9 in :cite:`schymanski_leaf-scale_2017`) $C_{wa} = \frac{P_{wa}}{R_{mol} T_a}$
eq_Nu_forced_allNu as function of Re and Re_c under forced conditions. (Eqs. B13--B15 in :cite:`schymanski_leaf-scale_2017`) $N_{Nu_L} = - \frac{\sqrt[3]{N_{Pr}} \left(- 37 N_{Re_L}^{\frac{4}{5}} + 37 \left(N_{Re_L} + N_{Re_c} - \frac{\left|{N_{Re_L} - N_{Re_c}}\right|}{2}\right)^{\frac{4}{5}} - 664 \sqrt{N_{Re_L} + N_{Re_c} - \frac{\left|{N_{Re_L} - N_{Re_c}}\right|}{2}}\right)}{1000}$
eq_DvaD_va as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $D_{va} = T_a p_1 - p_2$
eq_alphaaalpha_a as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $\alpha_a = T_a p_1 - p_2$
eq_kak_a as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $k_a = T_a p_1 + p_2$
eq_nuanu_a as a function of air temperature. (Table A.3 in :cite:`monteith_principles_2007`) $\nu_a = T_a p_1 - p_2$
eq_rhoa_Pwa_Tarho_a as a function of P_wa and T_a. (Eq. B20 in :cite:`schymanski_leaf-scale_2017`) $\rho_a = \frac{M_{N_2} P_{N2} + M_{O_2} P_{O2} + M_w P_{wa}}{R_{mol} T_a}$
eq_PaCalculate air pressure. From partial pressures of N2, O2 and H2O, following Dalton's law of partial pressures. $P_a = P_{N2} + P_{O2} + P_{wa}$
eq_PN2_PO2Calculate P_N2 as a function of P_O2. It follows Dalton's law of partial pressures. $P_{N2} = \frac{P_{O2} x_{N2}}{x_{O2}}$
eq_PO2Calculate P_O2 as a function of P_a, P_N2 and P_wa.$P_{O2} = \frac{P_a x_{O2} - P_{wa} x_{O2}}{x_{N2} + x_{O2}}$
eq_PN2Calculate P_N2 as a function of P_a, P_O2 and P_wa.$P_{N2} = \frac{P_a x_{N2} - P_{wa} x_{N2}}{x_{N2} + x_{O2}}$
eq_rhoaCalculate rho_a from T_a, P_a and P_wa.$\rho_a = \frac{x_{N2} \left(M_{N_2} P_a - P_{wa} \left(M_{N_2} - M_w\right)\right) + x_{O2} \left(M_{O_2} P_a - P_{wa} \left(M_{O_2} - M_w\right)\right)}{R_{mol} T_a x_{N2} + R_{mol} T_a x_{O2}}$

Variables for leaf chamber model

These refer to the model by Schymanski & Or (2017) and ongoing work.

Leaf chamber insulation

Variables related to the model by can be imported from essm.variables.chamber.insulation:

[12]:
import essm.variables.chamber.insulation as chamber_ins
vars = ['chamber_ins.' + name for name in chamber_ins.__all__]
generate_metadata_table([eval(name) for name in vars])
[12]:
SymbolNameDescriptionDefinitionDefault valueUnits
$A_i$A_iConducting area of insulation material.-m$^{2}$
$c_{pi}$c_piHeat capacity of insulation material.-J K$^{-1}$ kg$^{-1}$
$dT_i$dT_iTemperature increment of insulation material.-K
$L_i$L_iThickness of insulation material.-m
$lambda_i$lambda_iHeat conductivity of insulation material.-J K$^{-1}$ m$^{-1}$ s$^{-1}$
$Q_i$Q_iHeat conduction through insulation material.-J s$^{-1}$
$rho_i$rho_iDensity of insulation material.-kg m$^{-3}$

Leaf chamber mass balance

Variables related to the model by can be imported from essm.variables.chamber.mass:

[13]:
import essm.variables.chamber.mass as chamber_mass
vars = ['chamber_mass.' + name for name in chamber_mass.__all__]
generate_metadata_table([eval(name) for name in vars])
/home/stan/Programs/essm/essm/variables/_core.py:89: UserWarning: "essm.variables.leaf.energy_water:L_A" will be overridden by "essm.variables.chamber.mass:<class 'essm.variables.chamber.mass.L_A'>"
  instance[expr] = instance
[13]:
SymbolNameDescriptionDefinitionDefault valueUnits
$F_{in,mol,a}$F_in_molaMolar flow rate of dry air into chamber.-mol s$^{-1}$
$F_{in,mol,w}$F_in_molwMolar flow rate of water vapour into chamber.-mol s$^{-1}$
$F_{in,v}$F_in_vVolumetric flow rate into chamber.-m$^{3}$ s$^{-1}$
$F_{out,mol,a}$F_out_molaMolar flow rate of dry air out of chamber.-mol s$^{-1}$
$F_{out,mol,w}$F_out_molwMolar flow rate of water vapour out of chamber.-mol s$^{-1}$
$F_{out,v}$F_out_vVolumetric flow rate out of chamber.-m$^{3}$ s$^{-1}$
$H_c$H_cChamber height.-m
$L_A$L_ALeaf area.-m$^{2}$
$L_c$L_cChamber length.-m
$n_c$n_cmolar mass of gas in chamber.-mol
$P_{w,in}$P_w_inVapour pressure of incoming air.-Pa
$P_{w,out}$P_w_outVapour pressure of outgoing air.-Pa
$R_{H,in}$R_H_inRelative humidity of incoming air.-1
$T_d$T_dDew point temperature of incoming air.-K
$T_{in}$T_inTemperature of incoming air.-K
$T_{out}$T_outTemperature of outgoing air (= chamber T_a).-K
$T_{room}$T_roomLab air temperature.-K
$V_c$V_cChamber volume.-m$^{3}$
$W_c$W_cChamber width.-m