The BioCro C++ Library
ball_berry_gs.cpp
Go to the documentation of this file.
1#include <cmath> // for std::min
2#include <limits> // for std::numeric_limits
3#include <stdexcept> // for std::range_error
4#include "../framework/constants.h" // for dr_boundary, eps_zero
5#include "../framework/quadratic_root.h" // for quadratic_root_plus
6#include "water_and_air_properties.h" // for saturation_vapor_pressure
7#include "ball_berry_gs.h"
8
9using calculation_constants::eps_zero;
10using physical_constants::dr_boundary;
11
99 double assimilation, // mol / m^2 / s
100 double ambient_c, // mol / mol
101 double ambient_rh, // Pa / Pa
102 double bb_offset, // mol / m^2 / s
103 double bb_slope, // dimensionless from [mol / m^2 / s] / [mol / m^2 / s]
104 double gbw, // mol / m^2 / s
105 double leaf_temperature, // degrees C
106 double ambient_air_temperature // degrees C
107)
108{
109 // If An < 0, set b1 = 0 to ensure that gsw = b0 in Equation (1) as defined
110 // above
111 if (assimilation < 0) {
112 bb_slope = 0.0; // mol / m^2 / s
113 }
114
115 // Determine Cs using Equation (2) as defined above
116 const double Cs = ambient_c -
117 (dr_boundary / gbw) * assimilation; // mol / mol.
118
119 // Check for error conditions (Cs = 0 or Cs < 0)
120 if (Cs < -eps_zero) {
121 throw std::range_error("Thrown in ball_berry_gs: Cs is negative.");
122 } else if (Cs <= eps_zero) {
123 // Stomatal conductance becomes infinite as Cs approaches zero from the
124 // right. In this case, there is no water vapor drawndown across the
125 // stomata, so hs becomes 1.
126 double const inf = std::numeric_limits<double>::infinity();
127 return stomata_outputs{
128 /* .cs = */ 0, // micromol / mol
129 /* .hs = */ 1, // dimensionless
130 /* .gsw = */ inf // mol / m^2 / s
131 };
132 }
133
134 // Calculate some variables that will be used in later equations
135 const double acs = assimilation / Cs; // mol / m^2 / s
136
137 const double swvp_ratio =
138 saturation_vapor_pressure(ambient_air_temperature) /
139 saturation_vapor_pressure(leaf_temperature); // dimensionless
140
141 // Calculate hs using Equation (3) as defined above
142 const double a = bb_slope * acs; // mol / m^2 / s
143 const double b = bb_offset + gbw - a; // mol / m^2 / s
144 const double c = -ambient_rh * gbw * swvp_ratio - bb_offset; // mol / m^2 / s
145
146 // If hs is calculated to be larger than 1, this indicates dew formation. We
147 // do not handle this in BioCro at the moment, so just limit hs to 1.
148 const double hs = std::min(1.0, quadratic_root_plus(a, b, c)); // dimensionless
149
150 if (hs < 0) {
151 throw std::range_error("Thrown in ball_berry_gs: hs is less than 0.");
152 }
153
154 // Calculate stomatal conductance using Equation (1) above
155 double const gswmol = a * hs + bb_offset; // mol / m^2 / s
156
157 return stomata_outputs{
158 /* .cs = */ Cs * 1e6, // micromol / mol
159 /* .hs = */ hs, // dimensionless
160 /* .gsw = */ gswmol // mol / m^2 / s
161 };
162}
stomata_outputs ball_berry_gs(double assimilation, double ambient_c, double ambient_rh, double bb_offset, double bb_slope, double gbw, double leaf_temperature, double ambient_air_temperature)
Calculates steady-state stomatal conductance to water vapor using the Ball-Berry model.
A simple structure for holding the output of stomatal conductance calculations.
double saturation_vapor_pressure(double air_temperature)
Determine saturation water vapor pressure (Pa) from air temperature (degrees C) using the Arden Buck ...