X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FEnvironment%2Fenvironment.cxx;h=9a5755e3db3d7f8cabeaa89a739547c8b28fb71f;hb=386aefe69358ce41a11c9afeb8f56e26758fe56b;hp=74e1509dcb2130cfa7cec6c67ea26cfcfd5cde10;hpb=40ad35acf764872063e851c722b89621ccf57795;p=flightgear.git diff --git a/src/Environment/environment.cxx b/src/Environment/environment.cxx index 74e1509dc..9a5755e3d 100644 --- a/src/Environment/environment.cxx +++ b/src/Environment/environment.cxx @@ -27,6 +27,8 @@ #include +#include + #include #include #include @@ -34,15 +36,18 @@ #include #include
+#include #include "environment.hxx" - +#include "atmosphere.hxx" //////////////////////////////////////////////////////////////////////// // Atmosphere model. //////////////////////////////////////////////////////////////////////// +#ifdef USING_TABLES + // Calculated based on the ISA standard day, as found at e.g. // http://www.av8n.com/physics/altimetry.htm @@ -109,7 +114,7 @@ _setup_tables () atmosphere_data[i][2]); } } - +#endif //////////////////////////////////////////////////////////////////////// @@ -135,9 +140,12 @@ void FGEnvironment::_init() wind_from_down_fps = 0; thermal_lift_fps = 0; ridge_lift_fps= 0; + local_weather_lift_fps=0; altitude_half_to_sun_m = 1000; altitude_tropo_top_m = 10000; +#ifdef USING_TABLES _setup_tables(); +#endif _recalc_density(); _recalc_relative_humidity(); live_update = true; @@ -175,6 +183,7 @@ FGEnvironment::copy (const FGEnvironment &env) wind_from_down_fps = env.wind_from_down_fps; thermal_lift_fps = env.thermal_lift_fps; ridge_lift_fps= env.ridge_lift_fps; + local_weather_lift_fps = env.local_weather_lift_fps; turbulence_magnitude_norm = env.turbulence_magnitude_norm; turbulence_rate_hz = env.turbulence_rate_hz; } @@ -231,11 +240,11 @@ FGEnvironment::read (const SGPropertyNode * node) maybe_copy_value(this, node, "turbulence/rate-hz", &FGEnvironment::set_turbulence_rate_hz); + // calculate derived properties here to avoid duplicate expensive computations _recalc_ne(); - _recalc_alt_temperature(); + _recalc_alt_pt(); _recalc_alt_dewpoint(); - _recalc_alt_pressure(); _recalc_density(); _recalc_relative_humidity(); @@ -363,6 +372,12 @@ FGEnvironment::get_ridge_lift_fps () const return ridge_lift_fps; } +double +FGEnvironment::get_local_weather_lift_fps () const +{ + return local_weather_lift_fps; +} + double FGEnvironment::get_turbulence_magnitude_norm () const { @@ -397,7 +412,7 @@ FGEnvironment::set_temperature_sea_level_degc (double t) if (dewpoint_sea_level_degc > t) dewpoint_sea_level_degc = t; if( live_update ) { - _recalc_alt_temperature(); + _recalc_alt_pt(); _recalc_density(); } } @@ -408,6 +423,8 @@ FGEnvironment::set_temperature_degc (double t) temperature_degc = t; if( live_update ) { _recalc_sl_temperature(); + _recalc_sl_pressure(); + _recalc_alt_pt(); _recalc_density(); _recalc_relative_humidity(); } @@ -441,7 +458,7 @@ FGEnvironment::set_pressure_sea_level_inhg (double p) { pressure_sea_level_inhg = p; if( live_update ) { - _recalc_alt_pressure(); + _recalc_alt_pt(); _recalc_density(); } } @@ -516,7 +533,16 @@ FGEnvironment::set_ridge_lift_fps (double ri) ridge_lift_fps = ri; if( live_update ) { _recalc_updraft(); + } } + +void +FGEnvironment::set_local_weather_lift_fps (double lwl) +{ + local_weather_lift_fps = lwl; + if( live_update ) { + _recalc_updraft(); + } } void @@ -536,9 +562,8 @@ FGEnvironment::set_elevation_ft (double e) { elevation_ft = e; if( live_update ) { - _recalc_alt_temperature(); + _recalc_alt_pt(); _recalc_alt_dewpoint(); - _recalc_alt_pressure(); _recalc_density(); _recalc_relative_humidity(); } @@ -611,29 +636,37 @@ FGEnvironment::_recalc_ne () void FGEnvironment::_recalc_updraft () { - wind_from_down_fps = thermal_lift_fps + ridge_lift_fps ; + wind_from_down_fps = thermal_lift_fps + ridge_lift_fps + local_weather_lift_fps ; } +// Intended to help with the interpretation of METAR data, +// not for random in-flight outside-air temperatures. 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 + 273.15) - / _temperature_degc_table->interpolate(elevation_ft) - - 273.15; + +#if 0 + { + SG_LOG(SG_GENERAL, SG_DEBUG, "recalc_sl_temperature: using " + << temperature_degc << " @ " << elevation_ft << " :: " << this); } -} +#endif -void -FGEnvironment::_recalc_alt_temperature () -{ - 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 + if (elevation_ft >= ISA_def[1].height) { + SG_LOG(SG_GENERAL, SG_ALERT, "recalc_sl_temperature: " + << "valid only in troposphere, not " << elevation_ft); + return; } + +// Clamp: temperature of the stratosphere, in degrees C: + double t_strato = ISA_def[1].temp - atmodel::freezing; + if (temperature_degc < t_strato) temperature_sea_level_degc = t_strato; + else temperature_sea_level_degc = + temperature_degc + elevation_ft * atmodel::foot * ISA_def[0].lapse; + +// Alternative implemenation: +// else temperature_sea_level_inhg = T_layer(0., elevation_ft * foot, +// pressure_inhg * inHg, temperature_degc + freezing, ISA_def[0].lapse) - freezing; } void @@ -661,15 +694,44 @@ FGEnvironment::_recalc_alt_dewpoint () void FGEnvironment::_recalc_sl_pressure () { - pressure_sea_level_inhg = - pressure_inhg / _pressure_inhg_table->interpolate(elevation_ft); + using namespace atmodel; +#if 0 + { + SG_LOG(SG_GENERAL, SG_ALERT, "recalc_sl_pressure: using " + << pressure_inhg << " and " + << temperature_degc << " @ " << elevation_ft << " :: " << this); + } +#endif + pressure_sea_level_inhg = P_layer(0., elevation_ft * foot, + pressure_inhg * inHg, temperature_degc + freezing, ISA_def[0].lapse) / inHg; } +// This gets called at frame rate, to account for the aircraft's +// changing altitude. +// Called by set_elevation_ft() which is called by FGEnvironmentMgr::update + void -FGEnvironment::_recalc_alt_pressure () +FGEnvironment::_recalc_alt_pt () { - pressure_inhg = - pressure_sea_level_inhg * _pressure_inhg_table->interpolate(elevation_ft); + using namespace atmodel; +#if 0 + { + static int count(0); + if (++count % 1000 == 0) { + SG_LOG(SG_GENERAL, SG_ALERT, + "recalc_alt_pt for: " << elevation_ft + << " using " << pressure_sea_level_inhg + << " and " << temperature_sea_level_degc + << " :: " << this + << " # " << count); + } + } +#endif + double press, temp; + boost::tie(press, temp) = PT_vs_hpt(elevation_ft * foot, + pressure_sea_level_inhg * inHg, temperature_sea_level_degc + freezing); + temperature_degc = temp - freezing; + pressure_inhg = press / inHg; } void @@ -777,7 +839,7 @@ interpolate (const FGEnvironment * env1, const FGEnvironment * env2, env2->get_temperature_sea_level_degc(), fraction)); - result->set_dewpoint_degc + result->set_dewpoint_sea_level_degc (do_interp(env1->get_dewpoint_sea_level_degc(), env2->get_dewpoint_sea_level_degc(), fraction)); @@ -814,9 +876,8 @@ interpolate (const FGEnvironment * env1, const FGEnvironment * env2, // calculate derived properties here to avoid duplicate expensive computations result->_recalc_ne(); - result->_recalc_alt_temperature(); + result->_recalc_alt_pt(); result->_recalc_alt_dewpoint(); - result->_recalc_alt_pressure(); result->_recalc_density(); result->_recalc_relative_humidity();