1
0
Fork 0

Add temperature calculation for ISA METAR scenario

Required commit in fgdata branch for ISA METAR scenario
This commit is contained in:
James Turner 2023-07-25 15:03:06 +01:00
parent c54fba1095
commit fcc112c780
5 changed files with 62 additions and 27 deletions

View file

@ -99,6 +99,8 @@ void FGClimate::bind()
_tiedProperties.Tie( "snow-level-m", &_snow_level);
_tiedProperties.Tie( "wind-speed-mps", &_wind_speed);
_tiedProperties.Tie( "wind-direction-deg", &_wind_direction);
_tiedProperties.Tie("is-isa", &_is_isa);
}
void FGClimate::unbind ()
@ -214,6 +216,7 @@ void FGClimate::update(double dt)
// calculate sea level parameters from ground level parameters
// adapted from metarproperties.cxx
FGEnvironment dummy;
dummy.set_is_isa(_is_isa);
dummy.set_live_update(false);
dummy.set_elevation_ft(_gl.elevation_m*SG_METER_TO_FEET);
dummy.set_dewpoint_degc(_gl.dewpoint);

View file

@ -192,6 +192,8 @@ private:
double _wind_direction = -99999.0; // wind direction in degrees
char _metar[256] = "";
bool _is_isa = false;
};
#endif // _FGCLIMATE_HXX

View file

@ -115,25 +115,26 @@ _setup_tables ()
void FGEnvironment::_init()
{
live_update = false;
elevation_ft = 0;
visibility_m = 32000;
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;
density_slugft3 = 0;
turbulence_magnitude_norm = 0;
turbulence_rate_hz = 1;
wind_from_heading_deg = 0;
wind_speed_kt = 0;
wind_from_north_fps = 0;
wind_from_east_fps = 0;
wind_from_down_fps = 0;
altitude_half_to_sun_m = 1000;
altitude_tropo_top_m = 10000;
is_isa = false;
live_update = false;
elevation_ft = 0;
visibility_m = 32000;
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;
density_slugft3 = 0;
turbulence_magnitude_norm = 0;
turbulence_rate_hz = 1;
wind_from_heading_deg = 0;
wind_speed_kt = 0;
wind_from_north_fps = 0;
wind_from_east_fps = 0;
wind_from_down_fps = 0;
altitude_half_to_sun_m = 1000;
altitude_tropo_top_m = 10000;
#ifdef USING_TABLES
_setup_tables();
#endif
@ -188,6 +189,7 @@ FGEnvironment::copy (const FGEnvironment &env)
altitude_half_to_sun_m = env.altitude_half_to_sun_m;
altitude_tropo_top_m = env.altitude_tropo_top_m;
live_update = env.live_update;
is_isa = env.is_isa;
}
static inline bool
@ -252,6 +254,11 @@ FGEnvironment::read (const SGPropertyNode * node)
maybe_copy_value(this, node, "turbulence/rate-hz",
&FGEnvironment::set_turbulence_rate_hz);
const SGPropertyNode* child = node->getNode("atmosphere/is-isa");
if (child != 0 && child->hasValue()) {
set_is_isa(child->getBoolValue());
}
// calculate derived properties here to avoid duplicate expensive computations
_recalc_ne();
_recalc_alt_pt();
@ -480,6 +487,11 @@ FGEnvironment::get_elevation_ft () const
return elevation_ft;
}
bool FGEnvironment::get_is_isa() const
{
return is_isa;
}
void
FGEnvironment::set_visibility_m (double v)
{
@ -641,6 +653,10 @@ FGEnvironment::set_altitude_tropo_top_m (double alt)
}
}
void FGEnvironment::set_is_isa(bool isa)
{
is_isa = isa;
}
void
FGEnvironment::_recalc_hdgspd ()
@ -687,15 +703,23 @@ FGEnvironment::_recalc_sl_temperature ()
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;
double temperature_shift = 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;
if (is_isa) {
// The "International Standard Atmosphere" METAR scenario in use
temperature_sea_level_degc = 15.0;
temperature_degc = temperature_sea_level_degc - temperature_shift;
} else {
// Clamp: temperature of the stratosphere, in degrees C:
double t_strato = ISA_def[1].temp - atmodel::freezing;
temperature_sea_level_degc = temperature_degc < t_strato
? t_strato
: temperature_degc + temperature_shift;
// Alternative implemenation:
// temperature_sea_level_inhg = T_layer(0., elevation_ft * foot,
// pressure_inhg * inHg, temperature_degc + freezing, ISA_def[0].lapse) - freezing;
}
}
void

View file

@ -100,6 +100,8 @@ public:
virtual bool set_live_update(bool live_update);
virtual void set_is_isa(bool isa);
virtual bool get_is_isa() const;
FGEnvironment & interpolate (const FGEnvironment & env2, double fraction, FGEnvironment * result) const;
private:
@ -146,6 +148,7 @@ private:
double wind_from_down_fps;
bool live_update;
bool is_isa;
simgear::TiedPropertyList _tiedProperties;
};

View file

@ -192,6 +192,9 @@ Item {
}
} else {
_config.setArg("metar", _weatherScenarios.metarForItem(index))
var isISA = _weatherScenarios.nameForItem(index) == "International Standard Atmosphere";
_config.setProperty("/environment/climate/is-isa", isISA);
}
// either way, set the scenario name since Local-Weather keys off