]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.h
ed7bfcf93357af35236e4532ae67449a5d53fc59
[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 Lesser 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 Lesser General Public License for more
18  details.
19
20  You should have received a copy of the GNU Lesser 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 Lesser 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 1976 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   enum tType {ttStandard, ttBerndt, ttCulp, ttNone} turbType;
87
88   /// Returns the temperature in degrees Rankine.
89   double GetTemperature(void) const {return *temperature;}
90   /** Returns the density in slugs/ft^3.
91       <i>This function may <b>only</b> be used if Run() is called first.</i> */
92   double GetDensity(void)  const {return *density;}
93   /// Returns the pressure in psf.
94   double GetPressure(void)  const {return *pressure;}
95   /// Returns the standard pressure at a specified altitude
96   double GetPressure(double altitude);
97   /// Returns the standard temperature at a specified altitude
98   double GetTemperature(double altitude);
99   /// Returns the standard density at a specified altitude
100   double GetDensity(double altitude);
101   /// Returns the speed of sound in ft/sec.
102   double GetSoundSpeed(void) const {return soundspeed;}
103
104   /// Returns the sea level temperature in degrees Rankine.
105   double GetTemperatureSL(void) const { return SLtemperature; }
106   /// Returns the sea level density in slugs/ft^3
107   double GetDensitySL(void)  const { return SLdensity; }
108   /// Returns the sea level pressure in psf.
109   double GetPressureSL(void) const { return SLpressure; }
110   /// Returns the sea level speed of sound in ft/sec.
111   double GetSoundSpeedSL(void) const { return SLsoundspeed; }
112
113   /// Returns the ratio of at-altitude temperature over the sea level value.
114   double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; }
115   /// Returns the ratio of at-altitude density over the sea level value.
116   double GetDensityRatio(void) const { return (*density)*rSLdensity; }
117   /// Returns the ratio of at-altitude pressure over the sea level value.
118   double GetPressureRatio(void) const { return (*pressure)*rSLpressure; }
119   /// Returns the ratio of at-altitude sound speed over the sea level value.
120   double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; }
121
122   /// Tells the simulator to use an externally calculated atmosphere model.
123   void UseExternal(void);
124   /// Tells the simulator to use the internal atmosphere model.
125   void UseInternal(void);  //this is the default
126   /// Gets the boolean that tells if the external atmosphere model is being used.
127   bool External(void) { return useExternal; }
128
129   /// Provides the external atmosphere model with an interface to set the temperature.
130   void SetExTemperature(double t)  { exTemperature=t; }
131   /// Provides the external atmosphere model with an interface to set the density.
132   void SetExDensity(double d)      { exDensity=d; }
133   /// Provides the external atmosphere model with an interface to set the pressure.
134   void SetExPressure(double p)     { exPressure=p; }
135
136   /// Sets the temperature deviation at sea-level in degrees Fahrenheit
137   void SetSLTempDev(double d)  { T_dev_sl = d; }
138   /// Gets the temperature deviation at sea-level in degrees Fahrenheit
139   double GetSLTempDev(void) const { return T_dev_sl; }
140   /// Sets the current delta-T in degrees Fahrenheit
141   void SetDeltaT(double d)  { delta_T = d; }
142   /// Gets the current delta-T in degrees Fahrenheit
143   double GetDeltaT(void) const  { return delta_T; }
144   /// Gets the at-altitude temperature deviation in degrees Fahrenheit
145   double GetTempDev(void) const { return T_dev; }
146   /// Gets the density altitude in feet
147   double GetDensityAltitude(void) const { return density_altitude; }
148
149   // TOTAL WIND access functions (wind + gust + turbulence)
150
151   /// Retrieves the total wind components in NED frame.
152   FGColumnVector3& GetTotalWindNED(void) { return vTotalWindNED; }
153
154   /// Retrieves a total wind component in NED frame.
155   double GetTotalWindNED(int idx) const {return vTotalWindNED(idx);}
156
157   // WIND access functions
158
159   /// Sets the wind components in NED frame.
160   void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
161
162   /// Sets a wind component in NED frame.
163   void SetWindNED(int idx, double wind) { vWindNED(idx)=wind;}
164
165   /// Retrieves the wind components in NED frame.
166   FGColumnVector3& GetWindNED(void) { return vWindNED; }
167
168   /// Retrieves a wind component in NED frame.
169   double GetWindNED(int idx) const {return vWindNED(idx);}
170
171   /** Retrieves the direction that the wind is coming from.
172       The direction is defined as north=0 and increases counterclockwise.
173       The wind heading is returned in radians.*/
174   double GetWindPsi(void) const { return psiw; }
175
176   /** Sets the direction that the wind is coming from.
177       The direction is defined as north=0 and increases counterclockwise to 2*pi (radians). The
178       vertical component of wind is assumed to be zero - and is forcibly set to zero. This function
179       sets the vWindNED vector components based on the supplied direction. The magnitude of
180       the wind set in the vector is preserved (assuming the vertical component is non-zero).
181       @param dir wind direction in the horizontal plane, in radians.*/
182   void SetWindPsi(double dir);
183
184   void SetWindspeed(double speed);
185
186   double GetWindspeed(void) const;
187
188   // GUST access functions
189
190   /// Sets a gust component in NED frame.
191   void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
192
193   /// Sets the gust components in NED frame.
194   void SetGustNED(double gN, double gE, double gD) { vGustNED(eNorth)=gN; vGustNED(eEast)=gE; vGustNED(eDown)=gD;}
195
196   /// Retrieves a gust component in NED frame.
197   double GetGustNED(int idx) const {return vGustNED(idx);}
198
199   /// Retrieves the gust components in NED frame.
200   FGColumnVector3& GetGustNED(void) {return vGustNED;}
201
202   /** Turbulence models available: ttStandard, ttBerndt, ttCulp, ttNone */
203   void   SetTurbType(tType tt) {turbType = tt;}
204   tType  GetTurbType() const {return turbType;}
205
206   void   SetTurbGain(double tg) {TurbGain = tg;}
207   double GetTurbGain() const {return TurbGain;}
208
209   void   SetTurbRate(double tr) {TurbRate = tr;}
210   double GetTurbRate() const {return TurbRate;}
211
212   void   SetRhythmicity(double r) {Rhythmicity=r;}
213   double GetRhythmicity() const {return Rhythmicity;}
214
215   /** Sets wind vortex, clockwise as seen from a point in front of aircraft,
216       looking aft. Units are radians/second. */
217   void   SetWindFromClockwise(double wC) { wind_from_clockwise=wC; }
218   double GetWindFromClockwise(void) const {return wind_from_clockwise;}
219
220   double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
221   double GetTurbMagnitude(void) const {return Magnitude;}
222   FGColumnVector3& GetTurbDirection(void) {return vDirection;}
223   FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
224
225 protected:
226   double rho;
227
228   struct atmType {double Temperature; double Pressure; double Density;};
229   int lastIndex;
230   double h;
231   double htab[8];
232   double StdSLtemperature,StdSLdensity,StdSLpressure,StdSLsoundspeed;
233   double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
234   double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
235   double *temperature, *density, *pressure;
236   double soundspeed;
237   bool useExternal;
238   double exTemperature,exDensity,exPressure;
239   double intTemperature, intDensity, intPressure;
240   double T_dev_sl, T_dev, delta_T, density_altitude;
241   atmType atmosphere;
242   bool StandardTempOnly;
243   bool first_pass;
244
245   double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
246   double TurbGain;
247   double TurbRate;
248   double Rhythmicity;
249   double wind_from_clockwise;
250   double spike, target_time, strength;
251   FGColumnVector3 vDirectiondAccelDt;
252   FGColumnVector3 vDirectionAccel;
253   FGColumnVector3 vDirection;
254   FGColumnVector3 vTurbulenceGrad;
255   FGColumnVector3 vBodyTurbGrad;
256   FGColumnVector3 vTurbPQR;
257
258   double psiw;
259   FGColumnVector3 vTotalWindNED;
260   FGColumnVector3 vWindNED;
261   FGColumnVector3 vGustNED;
262   FGColumnVector3 vTurbulenceNED;
263
264   /// Calculate the atmosphere for the given altitude, including effects of temperature deviation.
265   void Calculate(double altitude);
266   /// Calculate atmospheric properties other than the basic T, P and rho.
267   void CalculateDerived(void);
268   /// Get T, P and rho for a standard atmosphere at the given altitude.
269   void GetStdAtmosphere(double altitude);
270   void Turbulence(void);
271   void bind(void);
272   void Debug(int from);
273 };
274
275 } // namespace JSBSim
276
277 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278 #endif
279