SensESP 3.0.1
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// dew point
8
10
11void AirDensity::set(const float& /*input*/) {
12 // For more info on the calculation see
13 // https://en.wikipedia.org/wiki/Density_of_air
14
15 const float temp_kelvin = inputs[0];
16 const float temp_celsius = temp_kelvin - 273.15;
17 const float relative_humidity = inputs[1];
18 const float pressure = inputs[2];
19
20 // Saturation vapor pressure of water
21 float saturation_pressure =
22 6.1078 * pow(10, ((7.5 * temp_celsius) / (temp_celsius + 237.3)));
23
24 // Vapor pressure of water
25 const float vapor_pressure_water = relative_humidity * saturation_pressure;
26
27 // Partial pressure of dry air
28 const float partial_pressure_dry_air = pressure - vapor_pressure_water;
29
30 // air density of humid air
31 // const float specific_gas_constant_dry_air = 287.058;
32 // const float specific_gas_constant_water_vapor = 461.495;
33 const float molar_mass_dry_air = 0.0289652;
34 const float molar_mass_water_vapor = 0.01801;
35 const float universal_gas_constant = 8.31446;
36 float air_density_humid_air =
37 ((partial_pressure_dry_air * molar_mass_dry_air) +
38 (vapor_pressure_water * molar_mass_water_vapor)) /
39 (universal_gas_constant * temp_kelvin);
40
41 this->emit(air_density_humid_air);
42}
43
44} // namespace sensesp
virtual void set(const float &input) override
void emit(const float &new_value)