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