Hi!
First of all I'd like to say hi to all as this is my first message to
this list! Hi :)
Then, when messing around with fg, I noticed that the current atmosphere
model is somewhat correct only on troposphere (around 12km or so), and I
think some aircrafts we have can go higher than that.
So I did some improvements on that function. At low altitudes it behaves
(almost) like the old one. It also has latitude dependency, and it
should behave quite well up to 85km. Of course, that is a bit overkill.
However, I have the patch attached, it was done againts the latest git
version with git diff. I hope it is correctly done.
I also plotted some altitude-temperature curves at different latitudes
(0, 37 and 80 degrees). They can be seen here
http://users.tkk.fi/~lapelto2/fgfs_temperature.jpg . The source cites
some references I used so the accuracy could be examined.
Lauri
--
Lauri Peltonen
lauri.pelto...@gmail.com
diff --git a/src/Environment/environment.cxx b/src/Environment/environment.cxx
index dfb8824..7887fbb 100644
--- a/src/Environment/environment.cxx
+++ b/src/Environment/environment.cxx
@@ -38,7 +38,7 @@
#include environment.hxx
-
+
// Atmosphere model.
@@ -119,6 +119,7 @@ _setup_tables ()
void FGEnvironment::_init()
{
elevation_ft = 0;
+latitude_deg = 0;
visibility_m = 32000;
temperature_sea_level_degc = 15;
temperature_degc = 15;
@@ -160,6 +161,7 @@ void
FGEnvironment::copy (const FGEnvironment env)
{
elevation_ft = env.elevation_ft;
+latitude_deg = env.latitude_deg;
visibility_m = env.visibility_m;
temperature_sea_level_degc = env.temperature_sea_level_degc;
temperature_degc = env.temperature_degc;
@@ -358,6 +360,12 @@ FGEnvironment::get_elevation_ft () const
return elevation_ft;
}
+double
+FGEnvironment::get_latitude_deg () const
+{
+ return latitude_deg;
+}
+
void
FGEnvironment::set_visibility_m (double v)
{
@@ -477,6 +485,20 @@ FGEnvironment::set_elevation_ft (double e)
}
void
+FGEnvironment::set_latitude_deg (double alt)
+{
+ latitude_deg = alt;
+
+ // Latitude affects temperature, so recalc everything
+ // that depends on temp
+ _recalc_alt_temperature();
+ _recalc_alt_dewpoint();
+ _recalc_alt_pressure();
+ _recalc_density();
+ _recalc_relative_humidity();
+}
+
+void
FGEnvironment::set_altitude_half_to_sun_m (double alt)
{
altitude_half_to_sun_m = alt;
@@ -540,7 +562,8 @@ void
FGEnvironment::_recalc_sl_temperature ()
{
// If we're in the stratosphere, leave sea-level temp alone
- if (elevation_ft 38000) {
+ // (a little smaller to also work correctly at poles!)
+ if (elevation_ft 28000) {
temperature_sea_level_degc = (temperature_degc + 273.15)
/ _temperature_degc_table-interpolate(elevation_ft)
- 273.15;
@@ -550,11 +573,84 @@ FGEnvironment::_recalc_sl_temperature ()
void
FGEnvironment::_recalc_alt_temperature ()
{
- if (elevation_ft 38000) {
+ // This should calculate troposphere temperature
+ // quite accurately.
+ // In real life tropopause is different elevation in south and north
+ // but the difference is quite small.
+ // Info from: http://www.ux1.eiu.edu/~cfjps/1400/atmos_struct.html
+ // and: http://eospso.gsfc.nasa.gov/eos_homepage/for_scientists/data_products/OurChangingPlanet/PDF/Page_05_new.pdf
+
+ // take the absolute value of lat for simplicity
+ double lat = (latitude_deg 0) ? -latitude_deg : latitude_deg;
+
+ // Using simple interpolation instead of the real curve
+ double tropopause = 51562; // Default tropopause at -30 lat 30
+ if(lat 60) {
+tropopause = 31250 - 104.1 * (lat - 60);
+ } else if(lat 30) {
+tropopause = 51562 - 677.1 * (lat - 30);
+ }
+
+ // This is quite good estimation for elevations below ~35000
+ // We need to calculate this for all elevations above this!
+ double e = elevation_ft;
+ if(e tropopause) e = tropopause;
+
+ if(e = 35000)
+ {
temperature_degc = (temperature_sea_level_degc + 273.15) *
-_temperature_degc_table-interpolate(elevation_ft) - 273.15;
- } else {
-temperature_degc = -56.49; // Stratosphere is constant
+ _temperature_degc_table-interpolate(e) - 273.15;
+ }
+ else
+ {
+// at equator tropopause is much higher than 35000 so new estimation :)
+// Using lapse rate of 6,5 degC / km
+// use the temp @ 35000 as a starting point
+temperature_degc = (temperature_sea_level_degc + 273.15) *
+ _temperature_degc_table-interpolate(35000) - 273.15 - 0.00208 * (e - 35000);
+ }
+
+ // At this point the temperature below tropopause is calculated :)
+ // Continue with upper levels
+
+ if(elevation_ft tropopause)
+ {
+// tropopause is not really constant, so estimate different lapse rates
+double lapse_rate = 0.00053; // at equator
+double pause_top = 93750;
+
+if(lat 60) {
+