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"
61 /*******************************************************************************
62 ************************************ CODE **************************************
63 *******************************************************************************/
66 FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex)
68 Name = "FGAtmosphere";
78 FGAtmosphere::~FGAtmosphere()
83 bool FGAtmosphere::Run(void)
85 if (!FGModel::Run()) { // if false then execute this Run()
94 State->Seta(soundspeed);
95 } else { // skip Run() execution this time
101 float FGAtmosphere::CalcRho(float altitude)
103 //return (0.00237 - 7.0E-08*altitude
104 // + 7.0E-13*altitude*altitude
105 // - 2.0E-18*altitude*altitude*altitude);
106 return GetDensity(altitude);
110 void FGAtmosphere::Calculate(float altitude)
114 float slope,reftemp,refpress,refdens;
116 float htab[]={0,36089,82020,154198,173882,259183,295272,344484}; //ft.
118 if (altitude <= htab[0]) {
120 } else if (altitude >= htab[7]){
124 while (htab[i+1] < altitude) {
131 slope = -0.0035662; // R/ft.
132 reftemp = 518.688; // R
133 refpress = 2116.17; // psf
134 refdens = 0.0023765; // slugs/cubic ft.
148 case 3: // 154198 ft.
152 refdens = 3.01379E-6;
154 case 4: // 173882 ft.
158 refdens = 1.47035e-06;
160 case 5: // 259183 ft.
163 refpress = 0.0222008;
164 refdens = 4.33396e-08;
166 case 6: // 295272 ft.
169 refpress = 0.00215742;
170 refdens = 4.21368e-09;
172 case 7: // 344484 ft.
175 refpress = 0.000153755;
176 refdens = 2.20384e-10;
183 p = refpress*exp(-GRAVITY/(reftemp*Reng)*(altitude-htab[i]));
184 rhos = refdens*exp(-GRAVITY/(reftemp*Reng)*(altitude-htab[i]));
186 T = reftemp+slope*(altitude-htab[i]);
187 p = refpress*pow(T/reftemp,-GRAVITY/(slope*Reng));
188 rhos = refdens*pow(T/reftemp,-(GRAVITY/(slope*Reng)+1));
191 a = sqrt(SHRATIO*Reng*T);
196 float FGAtmosphere::GetTemperature(float altitude)
203 float FGAtmosphere::GetPressure(float altitude)
209 float FGAtmosphere::GetDensity(float altitude)
216 float FGAtmosphere::GetSoundSpeed(float altitude)