# 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:

:

# Checking for essm version installed
import pkg_resources
pkg_resources.get_distribution("essm").version

:

'0.4.2.dev5'

:

from IPython.core.display import display, HTML
display(HTML("<style>.container { width:150% !important; }</style>"))

:

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)

:

import scipy as sc
# Import various functions from sympy
from sympy import Derivative, Eq, exp, log, solve, Symbol

:

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:

:

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])

:

 Symbol Name Description Definition Default value Units $\alpha_a$ alpha_a Thermal diffusivity of dry air. - m$^{2}$ s$^{-1}$ $\lambda_E$ lambda_E Latent heat of evaporation. 2450000.0 J kg$^{-1}$ $\nu_a$ nu_a Kinematic viscosity of dry air. - m$^{2}$ s$^{-1}$ $\rho_a$ rho_a Density of dry air. - kg m$^{-3}$ $\sigma$ sigm Stefan-Boltzmann constant. 5.67e-08 J s$^{-1}$ m$^{-2}$ K$^{-4}$ $c_{pa,mol}$ c_pamol Molar specific heat of dry air. https://en.wikipedia.org/wiki/Heat_capacity#Specific_heat_capacity 29.19 J K$^{-1}$ mol$^{-1}$ $c_{pa}$ c_pa Specific heat of dry air. 1010.0 J K$^{-1}$ kg$^{-1}$ $c_{pv}$ c_pv Specific heat of water vapour at 300 K. http://www.engineeringtoolbox.com/water-vapor-d_979.html 1864 J K$^{-1}$ kg$^{-1}$ $C_{wa}$ C_wa Concentration of water in air. - mol m$^{-3}$ $D_{va}$ D_va Binary diffusion coefficient of water vapour in air. - m$^{2}$ s$^{-1}$ $g$ g Gravitational acceleration. 9.81 m s$^{-2}$ $h_c$ h_c Average 1-sided convective heat transfer coefficient. - J K$^{-1}$ s$^{-1}$ m$^{-2}$ $k_a$ k_a Thermal conductivity of dry air. - J K$^{-1}$ m$^{-1}$ s$^{-1}$ $M_w$ M_w Molar mass of water. 0.018 kg mol$^{-1}$ $M_{air}$ M_air Molar mass of air. http://www.engineeringtoolbox.com/molecular-mass-air-d_679.html 0.02897 kg mol$^{-1}$ $M_{N_2}$ M_N2 Molar mass of nitrogen. 0.028 kg mol$^{-1}$ $M_{O_2}$ M_O2 Molar mass of oxygen. 0.032 kg mol$^{-1}$ $N_{Gr_L}$ Gr Grashof number. - 1 $N_{Le}$ Le Lewis number. - 1 $N_{Nu_L}$ Nu Average Nusselt number over given length. - 1 $N_{Pr}$ Pr Prandtl number (0.71 for air). - 1 $N_{Re_c}$ Re_c Critical Reynolds number for the onset of turbulence. - 1 $N_{Re_L}$ Re Average Reynolds number over given length. - 1 $P_a$ P_a Air pressure. - Pa $P_{N2}$ P_N2 Partial pressure of nitrogen. - Pa $P_{O2}$ P_O2 Partial pressure of oxygen. - Pa $P_{was}$ P_was Saturation water vapour pressure at air temperature. - Pa $P_{wa}$ P_wa Water vapour pressure in the atmosphere. - Pa $R_d$ R_d Downwelling global radiation. - W m$^{-2}$ $R_s$ R_s Solar shortwave flux per area. - J s$^{-1}$ m$^{-2}$ $R_u$ R_u Upwelling global radiation. - W m$^{-2}$ $R_{mol}$ R_mol Molar gas constant. 8.314472 J K$^{-1}$ mol$^{-1}$ $T_0$ T0 Freezing point in Kelvin. 273.15 K $T_a$ T_a Air temperature. - K $v_w$ v_w Wind velocity. - m s$^{-1}$ $x_{N2}$ x_N2 Mole fraction of nitrogen in dry air. 0.79 1 $x_{O2}$ x_O2 Mole fraction of oxygen in dry air. 0.21 1

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:

:

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

:

 eq_Le Le as function of alpha_a and D_va. (Eq. B3 in :cite:schymanski_leaf-scale_2017) $N_{Le} = \frac{\alpha_a}{D_{va}}$ eq_Cwa C_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_all Nu as function of Re and Re_c under forced conditions. (Eqs. B13--B15 in :cite:schymanski_leaf-scale_2017) $N_{Nu_L} = - \frac{\sqrt{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_Dva D_va as a function of air temperature. (Table A.3 in :cite:monteith_principles_2007) $D_{va} = T_a p_1 - p_2$ eq_alphaa alpha_a as a function of air temperature. (Table A.3 in :cite:monteith_principles_2007) $\alpha_a = T_a p_1 - p_2$ eq_ka k_a as a function of air temperature. (Table A.3 in :cite:monteith_principles_2007) $k_a = T_a p_1 + p_2$ eq_nua nu_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_Ta rho_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_Pa Calculate 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_PO2 Calculate 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_PO2 Calculate 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_PN2 Calculate 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_rhoa Calculate 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:

:

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])

:

 Symbol Name Description Definition Default value Units $A_i$ A_i Conducting area of insulation material. - m$^{2}$ $c_{pi}$ c_pi Heat capacity of insulation material. - J K$^{-1}$ kg$^{-1}$ $dT_i$ dT_i Temperature increment of insulation material. - K $L_i$ L_i Thickness of insulation material. - m $lambda_i$ lambda_i Heat conductivity of insulation material. - J K$^{-1}$ m$^{-1}$ s$^{-1}$ $Q_i$ Q_i Heat conduction through insulation material. - J s$^{-1}$ $rho_i$ rho_i Density of insulation material. - kg m$^{-3}$

### Leaf chamber mass balance¶

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

:

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

:

 Symbol Name Description Definition Default value Units $F_{in,mol,a}$ F_in_mola Molar flow rate of dry air into chamber. - mol s$^{-1}$ $F_{in,mol,w}$ F_in_molw Molar flow rate of water vapour into chamber. - mol s$^{-1}$ $F_{in,v}$ F_in_v Volumetric flow rate into chamber. - m$^{3}$ s$^{-1}$ $F_{out,mol,a}$ F_out_mola Molar flow rate of dry air out of chamber. - mol s$^{-1}$ $F_{out,mol,w}$ F_out_molw Molar flow rate of water vapour out of chamber. - mol s$^{-1}$ $F_{out,v}$ F_out_v Volumetric flow rate out of chamber. - m$^{3}$ s$^{-1}$ $H_c$ H_c Chamber height. - m $L_A$ L_A Leaf area. - m$^{2}$ $L_c$ L_c Chamber length. - m $n_c$ n_c molar mass of gas in chamber. - mol $P_{w,in}$ P_w_in Vapour pressure of incoming air. - Pa $P_{w,out}$ P_w_out Vapour pressure of outgoing air. - Pa $R_{H,in}$ R_H_in Relative humidity of incoming air. - 1 $T_d$ T_d Dew point temperature of incoming air. - K $T_{in}$ T_in Temperature of incoming air. - K $T_{out}$ T_out Temperature of outgoing air (= chamber T_a). - K $T_{room}$ T_room Lab air temperature. - K $V_c$ V_c Chamber volume. - m$^{3}$ $W_c$ W_c Chamber width. - m

## Bibliography¶

[ ]: