]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGAtmosphere.cpp
Friday the 13th JSBSim update ... :-0 !!!
[flightgear.git] / src / FDM / JSBSim / FGAtmosphere.cpp
1 /*******************************************************************************
2
3  Module:       FGAtmosphere.cpp
4  Author:       Jon Berndt
5                Implementation of 1959 Standard Atmosphere added by Tony Peden 
6  Date started: 11/24/98
7  Purpose:      Models the atmosphere
8  Called by:    FGSimExec
9
10  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
11
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
15  version.
16
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
20  details.
21
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.
25
26  Further information about the GNU General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
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.
33
34 HISTORY
35 --------------------------------------------------------------------------------
36 11/24/98   JSB   Created
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
44
45 ********************************************************************************
46 INCLUDES
47 *******************************************************************************/
48
49 #include "FGAtmosphere.h"
50 #include "FGState.h"
51 #include "FGFDMExec.h"
52 #include "FGFCS.h"
53 #include "FGAircraft.h"
54 #include "FGTranslation.h"
55 #include "FGRotation.h"
56 #include "FGPosition.h"
57 #include "FGAuxiliary.h"
58 #include "FGOutput.h"
59 #include "FGDefs.h"
60 #include "FGMatrix.h"
61
62 static const char *IdSrc = "$Header$";
63 static const char *IdHdr = ID_ATMOSPHERE;
64
65 /*******************************************************************************
66 ************************************ CODE **************************************
67 *******************************************************************************/
68
69
70 FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex),
71                                                     vWindNED(3),
72                                                     vWindUVW(3)
73 {
74     Name = "FGAtmosphere";
75     h = 0;
76     Calculate(h);
77     SLtemperature = temperature;
78     SLpressure    = pressure;
79     SLdensity     = density;
80     SLsoundspeed  = sqrt(SHRATIO*Reng*temperature);
81     useExternal=false;
82     vWindUVW(1)=0;vWindUVW(2)=0;vWindUVW(3)=0;
83     vWindNED(1)=0;vWindNED(2)=0;vWindNED(3)=0;
84 }
85
86
87 FGAtmosphere::~FGAtmosphere()
88 {
89 }
90
91
92 bool FGAtmosphere::Run(void)
93 {
94     //cout << "In FGAtmosphere::Run(void)" << endl;
95     if (!FGModel::Run()) {                 // if false then execute this Run()
96         //do temp, pressure, and density first
97         if (!useExternal) {
98             //cout << "Atmosphere: Using internal model, altitude= ";
99             h = Position->Geth();
100
101             Calculate(h);
102         } else {
103             density = exDensity;
104             pressure = exPressure;
105             temperature = exTemperature;
106             //switch sign of wind components so that they are
107             //in aircraft reference frame.  The classic example is
108             //takeoff or landing where you always want to fly
109             //into the wind.  Suppose that an aircraft is
110             //taking off into the wind on the runway heading
111             //of pure north.  Into the wind means the wind is
112             //flowing to the south (or negative) direction,
113             //and we know that headwinds increase the relative
114             //velocity, so to make a positive delta U from the
115             //southerly wind the sign must be switched.
116             vWindNED *= -1;
117             vWindUVW  = State->GetTl2b()*vWindNED;
118         }
119         soundspeed = sqrt(SHRATIO*Reng*temperature);
120         //cout << "Atmosphere: soundspeed: " << soundspeed << endl;
121         State->Seta(soundspeed);
122
123
124     } else {                               // skip Run() execution this time
125     }
126     return false;
127 }
128
129
130 void FGAtmosphere::Calculate(float altitude)
131 {
132     //see reference [1]
133
134     float slope,reftemp,refpress,refdens;
135     int i=0;
136     float htab[]={0,36089,82020,154198,173882,259183,295272,344484}; //ft.
137     // cout << "Atmosphere:  h=" << altitude << " rho= " << density << endl;
138     if (altitude <= htab[0]) {
139         altitude=0;
140     } else if (altitude >= htab[7]){
141         i = 7;
142         altitude = htab[7];
143     } else {
144         while (htab[i+1] < altitude) {
145             i++;
146         }
147     }
148
149     switch(i) {
150     case 0:     // sea level
151         slope     = -0.0035662; // R/ft.
152         reftemp   = 518.688;    // R
153         refpress  = 2116.17;    // psf
154         refdens   = 0.0023765;  // slugs/cubic ft.
155         break;
156     case 1:     // 36089 ft.
157         slope     = 0;
158         reftemp   = 389.988;
159         refpress  = 474.1;
160         refdens   = 0.0007078;
161         break;
162     case 2:     // 82020 ft.
163         slope     = 0.00164594;
164         reftemp   = 389.988;
165         refpress  = 52.7838;
166         refdens   = 7.8849E-5;
167         break;
168     case 3:     // 154198 ft.
169         slope     = 0;
170         reftemp   = 508.788;
171         refpress  = 2.62274;
172         refdens   = 3.01379E-6;
173         break;
174     case 4:     // 173882 ft.
175         slope     = -0.00246891;
176         reftemp   = 508.788;
177         refpress  = 1.28428;
178         refdens   = 1.47035e-06;
179         break;
180     case 5:     // 259183 ft.
181         slope     = 0;
182         reftemp   = 298.188;
183         refpress  = 0.0222008;
184         refdens   = 4.33396e-08;
185         break;
186     case 6:     // 295272 ft.
187         slope     = 0.00219459;
188         reftemp   = 298.188;
189         refpress  = 0.00215742;
190         refdens   = 4.21368e-09;
191         break;
192     case 7:     // 344484 ft.
193         slope     = 0;
194         reftemp   = 406.188;
195         refpress  = 0.000153755;
196         refdens   = 2.20384e-10;
197         break;
198     }
199
200
201     if (slope == 0) {
202         temperature = reftemp;
203         pressure = refpress*exp(-GRAVITY/(reftemp*Reng)*(altitude-htab[i]));
204         density = refdens*exp(-GRAVITY/(reftemp*Reng)*(altitude-htab[i]));
205     } else {
206         temperature = reftemp+slope*(altitude-htab[i]);
207         pressure = refpress*pow(temperature/reftemp,-GRAVITY/(slope*Reng));
208         density = refdens*pow(temperature/reftemp,-(GRAVITY/(slope*Reng)+1));
209     }
210
211     //cout << "Atmosphere:  h=" << altitude << " rho= " << density << endl;
212
213 }
214
215
216
217