1 /*******************************************************************************
3 Module: FGAtmosphere.cpp
5 Implementation of 1959 Standard Atmosphere added by Tony Peden
7 Purpose: Models the atmosphere
10 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24 Place - Suite 330, Boston, MA 02111-1307, USA.
26 Further information about the GNU General Public License can also be found on
27 the world wide web at http://www.gnu.org.
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31 Models the atmosphere. The equation used below was determined by a third order
32 curve fit using Excel. The data is from the ICAO atmosphere model.
35 --------------------------------------------------------------------------------
37 07/23/99 TP Added implementation of 1959 Standard Atmosphere
38 Moved calculation of Mach number to FGTranslation
39 ********************************************************************************
40 COMMENTS, REFERENCES, and NOTES
41 ********************************************************************************
42 [1] Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
43 1989, ISBN 0-07-001641-0
45 ********************************************************************************
47 *******************************************************************************/
49 #include "FGAtmosphere.h"
51 #include "FGFDMExec.h"
53 #include "FGAircraft.h"
54 #include "FGTranslation.h"
55 #include "FGRotation.h"
56 #include "FGPosition.h"
57 #include "FGAuxiliary.h"
62 /*******************************************************************************
63 ************************************ CODE **************************************
64 *******************************************************************************/
67 FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex),
71 Name = "FGAtmosphere";
74 SLtemperature = temperature;
75 SLpressure = pressure;
77 SLsoundspeed = sqrt(SHRATIO*Reng*temperature);
79 vWindUVW(1)=0;vWindUVW(2)=0;vWindUVW(3)=0;
80 vWindNED(1)=0;vWindNED(2)=0;vWindNED(3)=0;
84 FGAtmosphere::~FGAtmosphere()
89 bool FGAtmosphere::Run(void)
91 //cout << "In FGAtmosphere::Run(void)" << endl;
92 if (!FGModel::Run()) { // if false then execute this Run()
93 //do temp, pressure, and density first
95 //cout << "Atmosphere: Using internal model, altitude= ";
101 pressure = exPressure;
102 temperature = exTemperature;
103 //switch sign of wind components so that they are
104 //in aircraft reference frame. The classic example is
105 //takeoff or landing where you always want to fly
106 //into the wind. Suppose that an aircraft is
107 //taking off into the wind on the runway heading
108 //of pure north. Into the wind means the wind is
109 //flowing to the south (or negative) direction,
110 //and we know that headwinds increase the relative
111 //velocity, so to make a positive delta U from the
112 //southerly wind the sign must be switched.
114 vWindUVW = State->GetTl2b()*vWindNED;
116 soundspeed = sqrt(SHRATIO*Reng*temperature);
117 //cout << "Atmosphere: soundspeed: " << soundspeed << endl;
118 State->Seta(soundspeed);
121 } else { // skip Run() execution this time
127 void FGAtmosphere::Calculate(float altitude)
131 float slope,reftemp,refpress,refdens;
133 float htab[]={0,36089,82020,154198,173882,259183,295272,344484}; //ft.
134 // cout << "Atmosphere: h=" << altitude << " rho= " << density << endl;
135 if (altitude <= htab[0]) {
137 } else if (altitude >= htab[7]){
141 while (htab[i+1] < altitude) {
148 slope = -0.0035662; // R/ft.
149 reftemp = 518.688; // R
150 refpress = 2116.17; // psf
151 refdens = 0.0023765; // slugs/cubic ft.
165 case 3: // 154198 ft.
169 refdens = 3.01379E-6;
171 case 4: // 173882 ft.
175 refdens = 1.47035e-06;
177 case 5: // 259183 ft.
180 refpress = 0.0222008;
181 refdens = 4.33396e-08;
183 case 6: // 295272 ft.
186 refpress = 0.00215742;
187 refdens = 4.21368e-09;
189 case 7: // 344484 ft.
192 refpress = 0.000153755;
193 refdens = 2.20384e-10;
199 temperature = reftemp;
200 pressure = refpress*exp(-GRAVITY/(reftemp*Reng)*(altitude-htab[i]));
201 density = refdens*exp(-GRAVITY/(reftemp*Reng)*(altitude-htab[i]));
203 temperature = reftemp+slope*(altitude-htab[i]);
204 pressure = refpress*pow(temperature/reftemp,-GRAVITY/(slope*Reng));
205 density = refdens*pow(temperature/reftemp,-(GRAVITY/(slope*Reng)+1));
208 //cout << "Atmosphere: h=" << altitude << " rho= " << density << endl;