]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.h
Sync. w. JSBSim
[flightgear.git] / src / FDM / JSBSim / models / FGAtmosphere.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGAtmosphere.h
4  Author:       Jon Berndt
5                Implementation of 1959 Standard Atmosphere added by Tony Peden
6  Date started: 11/24/98
7
8  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
9
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  details.
19
20  You should have received a copy of the GNU General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA  02111-1307, USA.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 HISTORY
28 --------------------------------------------------------------------------------
29 11/24/98   JSB   Created
30 07/23/99   TP    Added implementation of 1959 Standard Atmosphere
31                  Moved calculation of Mach number to FGPropagate
32                  Updated to '76 model
33
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 SENTRY
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37
38 #ifndef FGAtmosphere_H
39 #define FGAtmosphere_H
40
41 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 INCLUDES
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44
45 #include "FGModel.h"
46 #include <math/FGColumnVector3.h>
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 #define ID_ATMOSPHERE "$Id$"
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 namespace JSBSim {
59
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 CLASS DOCUMENTATION
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63
64 /** Models the standard atmosphere.
65     @author Tony Peden, Jon Berndt
66     @version $Id$
67     @see Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
68          1989, ISBN 0-07-001641-0
69 */
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 CLASS DECLARATION
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 class FGAtmosphere : public FGModel {
76 public:
77
78   /// Constructor
79   FGAtmosphere(FGFDMExec*);
80   /// Destructor
81   ~FGAtmosphere();
82   /** Runs the Atmosphere model; called by the Executive
83       @return false if no error */
84   bool Run(void);
85   bool InitModel(void);
86
87   /// Returns the temperature in degrees Rankine.
88   inline double GetTemperature(void) const {return *temperature;}
89   /** Returns the density in slugs/ft^3.
90       <i>This function may <b>only</b> be used if Run() is called first.</i> */
91   inline double GetDensity(void)  const {return *density;}
92   /// Returns the pressure in psf.
93   double GetPressure(void)  const {return *pressure;}
94   /// Returns the standard pressure at a specified altitude
95   double GetPressure(double altitude);
96   /// Returns the standard temperature at a specified altitude
97   inline double GetTemperature(double altitude);
98   /// Returns the standard density at a specified altitude
99   inline double GetDensity(double altitude);
100   /// Returns the speed of sound in ft/sec.
101   inline double GetSoundSpeed(void) const {return soundspeed;}
102
103   /// Returns the sea level temperature in degrees Rankine.
104   inline double GetTemperatureSL(void) const { return SLtemperature; }
105   /// Returns the sea level density in slugs/ft^3
106   inline double GetDensitySL(void)  const { return SLdensity; }
107   /// Returns the sea level pressure in psf.
108   inline double GetPressureSL(void) const { return SLpressure; }
109   /// Returns the sea level speed of sound in ft/sec.
110   inline double GetSoundSpeedSL(void) const { return SLsoundspeed; }
111
112   /// Returns the ratio of at-altitude temperature over the sea level value.
113   inline double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; }
114   /// Returns the ratio of at-altitude density over the sea level value.
115   inline double GetDensityRatio(void) const { return (*density)*rSLdensity; }
116   /// Returns the ratio of at-altitude pressure over the sea level value.
117   inline double GetPressureRatio(void) const { return (*pressure)*rSLpressure; }
118   /// Returns the ratio of at-altitude sound speed over the sea level value.
119   inline double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; }
120
121   /// Tells the simulator to use an externally calculated atmosphere model.
122   void UseExternal(void);
123   /// Tells the simulator to use the internal atmosphere model.
124   void UseInternal(void);  //this is the default
125   /// Gets the boolean that tells if the external atmosphere model is being used.
126   bool External(void) { return useExternal; }
127
128   /// Provides the external atmosphere model with an interface to set the temperature.
129   inline void SetExTemperature(double t)  { exTemperature=t; }
130   /// Provides the external atmosphere model with an interface to set the density.
131   inline void SetExDensity(double d)      { exDensity=d; }
132   /// Provides the external atmosphere model with an interface to set the pressure.
133   inline void SetExPressure(double p)     { exPressure=p; }
134
135   /// Sets the temperature deviation at sea-level in degrees Fahrenheit
136   inline void SetSLTempDev(double d)  { T_dev_sl = d; }
137   /// Gets the temperature deviation at sea-level in degrees Fahrenheit
138   inline double GetSLTempDev(void) const { return T_dev_sl; }
139   /// Sets the current delta-T in degrees Fahrenheit
140   inline void SetDeltaT(double d)  { delta_T = d; }
141   /// Gets the current delta-T in degrees Fahrenheit
142   inline double GetDeltaT(void) const  { return delta_T; }
143   /// Gets the at-altitude temperature deviation in degrees Fahrenheit
144   inline double GetTempDev(void) const { return T_dev; }
145   /// Gets the density altitude in feet
146   inline double GetDensityAltitude(void) const { return density_altitude; }
147
148   /// Sets the wind components in NED frame.
149   inline void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
150
151   /// Retrieves the wind components in NED frame.
152   inline FGColumnVector3& GetWindNED(void) { return vWindNED; }
153
154   /** Retrieves the wind direction. The direction is defined as north=0 and
155       increases counterclockwise. The wind heading is returned in radians.*/
156   inline double GetWindPsi(void) const { return psiw; }
157
158   inline void SetTurbGain(double tt) {TurbGain = tt;}
159   inline void SetTurbRate(double tt) {TurbRate = tt;}
160
161   inline double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
162   inline FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
163
164   void bind(void);
165   void unbind(void);
166
167
168 protected:
169   double rho;
170
171   enum tType {ttStandard, ttBerndt, ttNone} turbType;
172   struct atmType {double Temperature; double Pressure; double Density;};
173
174   int lastIndex;
175   double h;
176   double htab[8];
177   double StdSLtemperature,StdSLdensity,StdSLpressure,StdSLsoundspeed;
178   double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
179   double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
180   double *temperature, *density, *pressure;
181   double soundspeed;
182   bool useExternal;
183   double exTemperature,exDensity,exPressure;
184   double intTemperature, intDensity, intPressure;
185   double T_dev_sl, T_dev, delta_T, density_altitude;
186   atmType atmosphere;
187   bool StandardTempOnly;
188
189   double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
190   double TurbGain;
191   double TurbRate;
192   FGColumnVector3 vDirectiondAccelDt;
193   FGColumnVector3 vDirectionAccel;
194   FGColumnVector3 vDirection;
195   FGColumnVector3 vTurbulence;
196   FGColumnVector3 vTurbulenceGrad;
197   FGColumnVector3 vBodyTurbGrad;
198   FGColumnVector3 vTurbPQR;
199
200   FGColumnVector3 vWindNED;
201   double psiw;
202
203   /// Calculate the atmosphere for the given altitude, including effects of temperature deviation.
204   void Calculate(double altitude);
205   /// Calculate atmospheric properties other than the basic T, P and rho.
206   void CalculateDerived(void);
207   /// Get T, P and rho for a standard atmosphere at the given altitude.
208   void GetStdAtmosphere(double altitude);
209   void Turbulence(void);
210   void Debug(int from);
211 };
212
213 } // namespace JSBSim
214
215 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 #endif
217