SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
air_density.cpp
Go to the documentation of this file.
1#include "air_density.h"
2
3#include <cmath>
4
5namespace sensesp {
6
7// air density
8
10 : Transform<std::tuple<float, float, float>, float>() {}
11
12void AirDensity::set(const std::tuple<float, float, float>& input) {
13 // For more info on the calculation see
14 // https://en.wikipedia.org/wiki/Density_of_air
15
16 const float temp_kelvin = std::get<0>(input);
17 const float temp_celsius = temp_kelvin - 273.15;
18 const float relative_humidity = std::get<1>(input);
19 const float pressure = std::get<2>(input);
20
21 // Saturation vapor pressure of water
22 float saturation_pressure =
23 6.1078 * pow(10, ((7.5 * temp_celsius) / (temp_celsius + 237.3)));
24
25 // Vapor pressure of water
26 const float vapor_pressure_water = relative_humidity * saturation_pressure;
27
28 // Partial pressure of dry air
29 const float partial_pressure_dry_air = pressure - vapor_pressure_water;
30
31 // air density of humid air
32 // const float specific_gas_constant_dry_air = 287.058;
33 // const float specific_gas_constant_water_vapor = 461.495;
34 const float molar_mass_dry_air = 0.0289652;
35 const float molar_mass_water_vapor = 0.01801;
36 const float universal_gas_constant = 8.31446;
37 float air_density_humid_air =
38 ((partial_pressure_dry_air * molar_mass_dry_air) +
39 (vapor_pressure_water * molar_mass_water_vapor)) /
40 (universal_gas_constant * temp_kelvin);
41
42 this->emit(air_density_humid_air);
43}
44
45} // namespace sensesp
virtual void set(const std::tuple< float, float, float > &input) override
The main Transform class. A transform is identified primarily by the type of value that is produces (...
Definition transform.h:68
void emit(const T &new_value)