FGEnvironment::FGEnvironment()
: _temperature_degc_table(new SGInterpTable),
_pressure_inhg_table(new SGInterpTable),
- _density_slugft3_table(new SGInterpTable),
+ elevation_ft(0),
visibility_m(32000),
- temperature_sea_level_degc(20),
- pressure_sea_level_inhg(28),
- density_sea_level_slugft3(0.0024),
+ temperature_sea_level_degc(15),
+ temperature_degc(15),
+ dewpoint_sea_level_degc(5), // guess
+ dewpoint_degc(5),
+ pressure_sea_level_inhg(29.92),
+ pressure_inhg(29.92),
wind_from_heading_deg(0),
wind_speed_kt(0),
wind_from_north_fps(0),
FGEnvironment::FGEnvironment (const FGEnvironment &env)
: _temperature_degc_table(new SGInterpTable),
_pressure_inhg_table(new SGInterpTable),
- _density_slugft3_table(new SGInterpTable),
elevation_ft(env.elevation_ft),
visibility_m(env.visibility_m),
temperature_sea_level_degc(env.temperature_sea_level_degc),
+ dewpoint_sea_level_degc(env.dewpoint_sea_level_degc),
pressure_sea_level_inhg(env.pressure_sea_level_inhg),
- density_sea_level_slugft3(env.density_sea_level_slugft3),
wind_from_heading_deg(env.wind_from_heading_deg),
wind_speed_kt(env.wind_speed_kt),
wind_from_north_fps(env.wind_from_north_fps),
{
delete _temperature_degc_table;
delete _pressure_inhg_table;
- delete _density_slugft3_table;
}
}
double
-FGEnvironment::get_pressure_sea_level_inhg () const
+FGEnvironment::get_dewpoint_sea_level_degc () const
{
- return pressure_sea_level_inhg;
+ return dewpoint_sea_level_degc;
}
double
-FGEnvironment::get_pressure_inhg () const
+FGEnvironment::get_dewpoint_degc () const
{
- return pressure_inhg;
+ return dewpoint_degc;
+}
+
+double
+FGEnvironment::get_pressure_sea_level_inhg () const
+{
+ return pressure_sea_level_inhg;
}
double
-FGEnvironment::get_density_sea_level_slugft3 () const
+FGEnvironment::get_pressure_inhg () const
{
- return density_sea_level_slugft3;
+ return pressure_inhg;
}
double
FGEnvironment::set_temperature_sea_level_degc (double t)
{
temperature_sea_level_degc = t;
+ if (dewpoint_sea_level_degc > t)
+ dewpoint_sea_level_degc = t;
_recalc_alt_temperature();
+ _recalc_density();
}
void
{
temperature_degc = t;
_recalc_sl_temperature();
+ _recalc_density();
}
void
-FGEnvironment::set_pressure_sea_level_inhg (double p)
+FGEnvironment::set_dewpoint_sea_level_degc (double t)
{
- pressure_sea_level_inhg = p;
- _recalc_alt_pressure();
+ dewpoint_sea_level_degc = t;
+ if (temperature_sea_level_degc < t)
+ temperature_sea_level_degc = t;
+ _recalc_alt_dewpoint();
+ _recalc_density();
}
void
-FGEnvironment::set_pressure_inhg (double p)
+FGEnvironment::set_dewpoint_degc (double t)
{
- pressure_inhg = p;
- _recalc_sl_pressure();
+ dewpoint_degc = t;
+ _recalc_sl_dewpoint();
+ _recalc_density();
}
void
-FGEnvironment::set_density_sea_level_slugft3 (double d)
+FGEnvironment::set_pressure_sea_level_inhg (double p)
{
- density_sea_level_slugft3 = d;
- _recalc_alt_density();
+ pressure_sea_level_inhg = p;
+ _recalc_alt_pressure();
+ _recalc_density();
}
void
-FGEnvironment::set_density_slugft3 (double d)
+FGEnvironment::set_pressure_inhg (double p)
{
- density_slugft3 = d;
- _recalc_sl_density();
+ pressure_inhg = p;
+ _recalc_sl_pressure();
+ _recalc_density();
}
void
{
elevation_ft = e;
_recalc_alt_temperature();
+ _recalc_alt_dewpoint();
_recalc_alt_pressure();
- _recalc_alt_density();
+ _recalc_density();
}
// Atmosphere model.
// Copied from YASim Atmosphere.cxx, with m converted to ft, degK
// converted to degC, Pa converted to inHG, and kg/m^3 converted to
-// slug/ft^3.
+// slug/ft^3; they were then converted to deltas from the sea-level
+// defaults (approx. 15degC, 29.92inHG, and 0.00237slugs/ft^3).
// Original comment from YASim:
// R=287. I chose to correct the temperature to 288.20, since 79F is
// pretty hot for a "standard" atmosphere.
-// Elevation (ft), temperature (degC), pressure (inHG), density (slug/ft^3)
-static double atmosphere_data[][4] = {
- 0, 0.00, 0.000, 0.000000,
- 2952, -5.89, -3.058, -0.000198,
- 5905, -11.74, -5.856, -0.000384,
- 8858, -17.58, -8.413, -0.000556,
- 11811, -23.43, -10.745, -0.000717,
- 14763, -29.27, -12.867, -0.000867,
- 17716, -35.11, -14.794, -0.001006,
- 20669, -40.95, -16.541, -0.001136,
- 23622, -46.79, -18.120, -0.001255,
- 26574, -52.62, -19.544, -0.001366,
- 29527, -58.46, -20.826, -0.001467,
- 32480, -64.29, -21.976, -0.001561,
- 35433, -70.12, -23.005, -0.001647,
- 38385, -71.54, -23.916, -0.001739,
- 41338, -71.54, -24.708, -0.001822,
- 44291, -71.54, -25.395, -0.001894,
- 47244, -71.54, -25.991, -0.001957,
- 50196, -71.54, -26.509, -0.002012,
- 53149, -71.54, -26.959, -0.002059,
- 56102, -71.54, -27.349, -0.002100,
- 59055, -71.54, -27.687, -0.002136,
- 62007, -71.54, -27.981, -0.002167,
- -1, -1, -1, -1
+// Elevation (ft), temperature factor (degK), pressure factor (inHG)
+static double atmosphere_data[][3] = {
+ { 0.00, 1.00, 1.000 },
+ { 2952.76, 0.98, 0.898 },
+ { 5905.51, 0.96, 0.804 },
+ { 8858.27, 0.94, 0.719 },
+ { 11811.02, 0.92, 0.641 },
+ { 14763.78, 0.90, 0.570 },
+ { 17716.54, 0.88, 0.506 },
+ { 20669.29, 0.86, 0.447 },
+ { 23622.05, 0.84, 0.394 },
+ { 26574.80, 0.82, 0.347 },
+ { 29527.56, 0.80, 0.304 },
+ { 32480.31, 0.78, 0.266 },
+ { 35433.07, 0.76, 0.231 },
+ { 38385.83, 0.75, 0.201 },
+ { 41338.58, 0.75, 0.174 },
+ { 44291.34, 0.75, 0.151 },
+ { 47244.09, 0.75, 0.131 },
+ { 50196.85, 0.75, 0.114 },
+ { 53149.61, 0.75, 0.099 },
+ { 56102.36, 0.75, 0.086 },
+ { 59055.12, 0.75, 0.075 },
+ { 62007.87, 0.75, 0.065 },
+ { -1, -1, -1 }
};
void
atmosphere_data[i][1]);
_pressure_inhg_table->addEntry(atmosphere_data[i][0],
atmosphere_data[i][2]);
- _density_slugft3_table->addEntry(atmosphere_data[i][0],
- atmosphere_data[i][3]);
}
}
void
FGEnvironment::_recalc_sl_temperature ()
{
+ // If we're in the stratosphere, leave sea-level temp alone
if (elevation_ft < 38000) {
temperature_sea_level_degc =
- temperature_degc - _temperature_degc_table->interpolate(elevation_ft);
+ (temperature_degc + 273.15)
+ /_temperature_degc_table->interpolate(elevation_ft)
+ - 273.15;
}
- // If we're in the stratosphere, leave sea-level temp alone
}
void
FGEnvironment::_recalc_alt_temperature ()
{
- temperature_degc =
- temperature_sea_level_degc +
- _temperature_degc_table->interpolate(elevation_ft);
+ if (elevation_ft < 38000) {
+ temperature_degc =
+ (temperature_sea_level_degc + 273.15) *
+ _temperature_degc_table->interpolate(elevation_ft) - 273.15;
+ } else {
+ temperature_degc = -56.49; // Stratosphere is constant
+ }
}
void
-FGEnvironment::_recalc_sl_pressure ()
+FGEnvironment::_recalc_sl_dewpoint ()
{
- pressure_sea_level_inhg =
- pressure_inhg - _pressure_inhg_table->interpolate(elevation_ft);
+ // 0.2degC/1000ft
+ // FIXME: this will work only for low
+ // elevations
+ dewpoint_sea_level_degc = dewpoint_degc + (elevation_ft * .0002);
+ if (dewpoint_sea_level_degc > temperature_sea_level_degc)
+ dewpoint_sea_level_degc = temperature_sea_level_degc;
}
void
-FGEnvironment::_recalc_alt_pressure ()
+FGEnvironment::_recalc_alt_dewpoint ()
{
- pressure_inhg =
- pressure_sea_level_inhg + _pressure_inhg_table->interpolate(elevation_ft);
+ // 0.2degC/1000ft
+ // FIXME: this will work only for low
+ // elevations
+ dewpoint_degc = dewpoint_sea_level_degc + (elevation_ft * .0002);
+ if (dewpoint_degc > temperature_degc)
+ dewpoint_degc = temperature_degc;
}
void
-FGEnvironment::_recalc_sl_density ()
+FGEnvironment::_recalc_sl_pressure ()
{
- density_sea_level_slugft3 =
- density_slugft3 - _density_slugft3_table->interpolate(elevation_ft);
+ pressure_sea_level_inhg =
+ pressure_inhg / _pressure_inhg_table->interpolate(elevation_ft);
}
void
-FGEnvironment::_recalc_alt_density ()
+FGEnvironment::_recalc_alt_pressure ()
{
- density_slugft3 =
- density_sea_level_slugft3 +
- _density_slugft3_table->interpolate(elevation_ft);
+ pressure_inhg =
+ pressure_sea_level_inhg * _pressure_inhg_table->interpolate(elevation_ft);
+}
+
+void
+FGEnvironment::_recalc_density ()
+{
+ double pressure_psf = pressure_inhg * 70.7487;
+
+ // adjust for humidity
+ // calculations taken from USA Today (oops!) at
+ // http://www.usatoday.com/weather/basics/density-calculations.htm
+ double temperature_degk = temperature_degc + 273.15;
+ double pressure_mb = pressure_inhg * 33.86;
+ double vapor_pressure_mb =
+ 6.11 * pow(10.0, 7.5 * dewpoint_degc / (237.7 + dewpoint_degc));
+ double virtual_temperature_degk = temperature_degk / (1 - (vapor_pressure_mb / pressure_mb) * (1.0 - 0.622));
+ double virtual_temperature_degr = virtual_temperature_degk * 1.8;
+
+ density_slugft3 = pressure_psf / (virtual_temperature_degr * 1718);
}
// end of environment.cxx