Re: [Flightgear-devel] Atmosphere temperature model

2009-03-20 Thread Lauri Peltonen
 You could have saved yourself a lot of work by posting a question
 before writing all this code.

I don't mind that, because it was just fun to do that. And I wasn't
going to do a temperature model in the first place, but somehow ended
up doing that :)

 The code to do all this has existed for years.  A nice table-driven
 implementation.  It does this and more (notably linking the _pressure_
 versus height dependence to the temperature).  Pressure is kinda
 important for realistic altimetry, engine performance, et cetera.
 Let me know if you are interested in this.

If you mean the table at the top of environment.cxx, yeah I noticed
it. And I use it like before up to 35000ft. I don't know what was the
reason to not use it over that altitude for temperature, it seems to
be quite nice up to 10ft. See
http://users.tkk.fi/~lapelto2/fgfs_temp_graph.jpg . I also notice that
it is used to model pressure at all altitudes. Or do you have some
other table system than that?

I was mostly doing this to add the latitude dependency to the
temperature curves. I'm sure no one would notice that when flying, but
it seemed like a nice thing to do.

In any case, the current -56 degC at altitudes over 38000 is horrible,
and we should either model using the table or something similar to my
system, depending on the accuracy wanted. I don't know if any aircraft
can/should fly in those high altitudes, and if their modeling takes
temperature into account.

Lauri
-- 
Lauri Peltonen
lauri.pelto...@gmail.com

--
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


[Flightgear-devel] Atmosphere temperature model

2009-03-19 Thread Lauri Peltonen
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) {
+  

Re: [Flightgear-devel] Atmosphere temperature model

2009-03-19 Thread John Denker
On 03/19/2009 04:43 PM, Lauri Peltonen wrote:
 
 First of all I'd like to say hi to all as this is my first message to
 this list! Hi :)

Hi.  I hope your contributions meet a better fate than mine have.

 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.

You could have saved yourself a lot of work by posting a question 
before writing all this code.

The code to do all this has existed for years.  A nice table-driven
implementation.  It does this and more (notably linking the _pressure_ 
versus height dependence to the temperature).  Pressure is kinda 
important for realistic altimetry, engine performance, et cetera.
Let me know if you are interested in this.

The code was never seriously considered for incorporation into the 
official version.


--
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel