]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.h
Bugfix: no automatic runway selection with --parkpos=
[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 #include "math/FGTable.h"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 DEFINITIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 #define ID_ATMOSPHERE "$Id: FGAtmosphere.h,v 1.23 2010/09/16 11:01:24 jberndt Exp $"
54
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 FORWARD DECLARATIONS
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58
59 namespace JSBSim {
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 CLASS DOCUMENTATION
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 /** Models the 1976 Standard Atmosphere.
66     @author Tony Peden, Jon Berndt
67     @version $Id: FGAtmosphere.h,v 1.23 2010/09/16 11:01:24 jberndt Exp $
68     @see Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
69          1989, ISBN 0-07-001641-0
70
71     Additionally, various turbulence models are available. They are specified
72     via the property <tt>atmosphere/turb-type</tt>. The following models are
73     available:
74     - 0: ttNone (turbulence disabled)
75     - 1: ttStandard
76     - 2: ttBerndt
77     - 3: ttCulp
78     - 4: ttMilspec (Dryden spectrum)
79     - 5: ttTustin (Dryden spectrum)
80
81     The Milspec and Tustin models are described in the Yeager report cited below.
82     They both use a Dryden spectrum model whose parameters (scale lengths and intensities)
83     are modelled according to MIL-F-8785C. Parameters are modelled differently
84     for altitudes below 1000ft and above 2000ft, for altitudes in between they
85     are interpolated linearly.
86
87     The two models differ in the implementation of the transfer functions
88     described in the milspec.
89
90     To use one of these two models, set <tt>atmosphere/turb-type</tt> to 4 resp. 5,
91     and specify values for <tt>atmosphere/turbulence/milspec/windspeed_at_20ft_AGL-fps<tt>
92     and <tt>atmosphere/turbulence/milspec/severity<tt> (the latter corresponds to
93     the probability of exceedence curves from Fig.&nbsp;7 of the milspec, allowable
94     range is 0 (disabled) to 7). <tt>atmosphere/psiw-rad</tt> is respected as well;
95     note that you have to specify a positive wind magnitude to prevent psiw from
96     being reset to zero.
97
98     Reference values (cf. figures 7 and 9 from the milspec):
99     <table>
100       <tr><td><b>Intensity</b></td>
101           <td><b><tt>windspeed_at_20ft_AGL-fps</tt></b></td>
102           <td><b><tt>severity</tt></b></td></tr>
103       <tr><td>light</td>
104           <td>25 (15 knots)</td>
105           <td>3</td></tr>
106       <tr><td>moderate</td>
107           <td>50 (30 knots)</td>
108           <td>4</td></tr>
109       <tr><td>severe</td>
110           <td>75 (45 knots)</td>
111           <td>6</td></tr>
112     </table>
113
114     @see Yeager, Jessie C.: "Implementation and Testing of Turbulence Models for
115          the F18-HARV" (<a
116          href="http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980028448_1998081596.pdf">
117          pdf</a>), NASA CR-1998-206937, 1998
118
119     @see MIL-F-8785C: Military Specification: Flying Qualities of Piloted Aircraft
120
121 */
122
123 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 CLASS DECLARATION
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
126
127 class FGAtmosphere : public FGModel {
128 public:
129
130   /// Constructor
131   FGAtmosphere(FGFDMExec*);
132   /// Destructor
133   ~FGAtmosphere();
134   /** Runs the Atmosphere model; called by the Executive
135       @return false if no error */
136   bool Run(void);
137   bool InitModel(void);
138   enum tType {ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin} turbType;
139
140   /// Returns the temperature in degrees Rankine.
141   double GetTemperature(void) const {return *temperature;}
142   /** Returns the density in slugs/ft^3.
143       <i>This function may <b>only</b> be used if Run() is called first.</i> */
144   double GetDensity(void)  const {return *density;}
145   /// Returns the pressure in psf.
146   double GetPressure(void)  const {return *pressure;}
147   /// Returns the standard pressure at a specified altitude
148   double GetPressure(double altitude);
149   /// Returns the standard temperature at a specified altitude
150   double GetTemperature(double altitude);
151   /// Returns the standard density at a specified altitude
152   double GetDensity(double altitude);
153   /// Returns the speed of sound in ft/sec.
154   double GetSoundSpeed(void) const {return soundspeed;}
155   /// Returns the absolute viscosity.
156   double GetAbsoluteViscosity(void) const {return intViscosity;}
157   /// Returns the kinematic viscosity.
158   double GetKinematicViscosity(void) const {return intKinematicViscosity;}
159
160   /// Returns the sea level temperature in degrees Rankine.
161   double GetTemperatureSL(void) const { return SLtemperature; }
162   /// Returns the sea level density in slugs/ft^3
163   double GetDensitySL(void)  const { return SLdensity; }
164   /// Returns the sea level pressure in psf.
165   double GetPressureSL(void) const { return SLpressure; }
166   /// Returns the sea level speed of sound in ft/sec.
167   double GetSoundSpeedSL(void) const { return SLsoundspeed; }
168
169   /// Returns the ratio of at-altitude temperature over the sea level value.
170   double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; }
171   /// Returns the ratio of at-altitude density over the sea level value.
172   double GetDensityRatio(void) const { return (*density)*rSLdensity; }
173   /// Returns the ratio of at-altitude pressure over the sea level value.
174   double GetPressureRatio(void) const { return (*pressure)*rSLpressure; }
175   /// Returns the ratio of at-altitude sound speed over the sea level value.
176   double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; }
177
178   /// Tells the simulator to use an externally calculated atmosphere model.
179   void UseExternal(void);
180   /// Tells the simulator to use the internal atmosphere model.
181   void UseInternal(void);  //this is the default
182   /// Gets the boolean that tells if the external atmosphere model is being used.
183   bool External(void) { return useExternal; }
184
185   /// Provides the external atmosphere model with an interface to set the temperature.
186   void SetExTemperature(double t)  { exTemperature=t; }
187   /// Provides the external atmosphere model with an interface to set the density.
188   void SetExDensity(double d)      { exDensity=d; }
189   /// Provides the external atmosphere model with an interface to set the pressure.
190   void SetExPressure(double p)     { exPressure=p; }
191
192   /// Sets the temperature deviation at sea-level in degrees Fahrenheit
193   void SetSLTempDev(double d)  { T_dev_sl = d; }
194   /// Gets the temperature deviation at sea-level in degrees Fahrenheit
195   double GetSLTempDev(void) const { return T_dev_sl; }
196   /// Sets the current delta-T in degrees Fahrenheit
197   void SetDeltaT(double d)  { delta_T = d; }
198   /// Gets the current delta-T in degrees Fahrenheit
199   double GetDeltaT(void) const  { return delta_T; }
200   /// Gets the at-altitude temperature deviation in degrees Fahrenheit
201   double GetTempDev(void) const { return T_dev; }
202   /// Gets the density altitude in feet
203   double GetDensityAltitude(void) const { return density_altitude; }
204
205   // TOTAL WIND access functions (wind + gust + turbulence)
206
207   /// Retrieves the total wind components in NED frame.
208   FGColumnVector3& GetTotalWindNED(void) { return vTotalWindNED; }
209
210   /// Retrieves a total wind component in NED frame.
211   double GetTotalWindNED(int idx) const {return vTotalWindNED(idx);}
212
213   // WIND access functions
214
215   /// Sets the wind components in NED frame.
216   void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
217
218   /// Sets a wind component in NED frame.
219   void SetWindNED(int idx, double wind) { vWindNED(idx)=wind;}
220
221   /// Retrieves the wind components in NED frame.
222   FGColumnVector3& GetWindNED(void) { return vWindNED; }
223
224   /// Retrieves a wind component in NED frame.
225   double GetWindNED(int idx) const {return vWindNED(idx);}
226
227   /** Retrieves the direction that the wind is coming from.
228       The direction is defined as north=0 and increases counterclockwise.
229       The wind heading is returned in radians.*/
230   double GetWindPsi(void) const { return psiw; }
231
232   /** Sets the direction that the wind is coming from.
233       The direction is defined as north=0 and increases counterclockwise to 2*pi (radians). The
234       vertical component of wind is assumed to be zero - and is forcibly set to zero. This function
235       sets the vWindNED vector components based on the supplied direction. The magnitude of
236       the wind set in the vector is preserved (assuming the vertical component is non-zero).
237       @param dir wind direction in the horizontal plane, in radians.*/
238   void SetWindPsi(double dir);
239
240   void SetWindspeed(double speed);
241
242   double GetWindspeed(void) const;
243
244   // GUST access functions
245
246   /// Sets a gust component in NED frame.
247   void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
248
249   /// Sets a turbulence component in NED frame.
250   void SetTurbNED(int idx, double turb) { vTurbulenceNED(idx)=turb;}
251
252   /// Sets the gust components in NED frame.
253   void SetGustNED(double gN, double gE, double gD) { vGustNED(eNorth)=gN; vGustNED(eEast)=gE; vGustNED(eDown)=gD;}
254
255   /// Retrieves a gust component in NED frame.
256   double GetGustNED(int idx) const {return vGustNED(idx);}
257
258   /// Retrieves a turbulence component in NED frame.
259   double GetTurbNED(int idx) const {return vTurbulenceNED(idx);}
260
261   /// Retrieves the gust components in NED frame.
262   FGColumnVector3& GetGustNED(void) {return vGustNED;}
263
264   /** Turbulence models available: ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin */
265   void   SetTurbType(tType tt) {turbType = tt;}
266   tType  GetTurbType() const {return turbType;}
267
268   void   SetTurbGain(double tg) {TurbGain = tg;}
269   double GetTurbGain() const {return TurbGain;}
270
271   void   SetTurbRate(double tr) {TurbRate = tr;}
272   double GetTurbRate() const {return TurbRate;}
273
274   void   SetRhythmicity(double r) {Rhythmicity=r;}
275   double GetRhythmicity() const {return Rhythmicity;}
276
277   double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
278   double GetTurbMagnitude(void) const {return Magnitude;}
279   FGColumnVector3& GetTurbDirection(void) {return vDirection;}
280   FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
281
282   void   SetWindspeed20ft(double ws) { windspeed_at_20ft = ws;}
283   double GetWindspeed20ft() const { return windspeed_at_20ft;}
284
285   /// allowable range: 0-7, 3=light, 4=moderate, 6=severe turbulence
286   void   SetProbabilityOfExceedence( int idx) {probability_of_exceedence_index = idx;}
287   int    GetProbabilityOfExceedence() const { return probability_of_exceedence_index;}
288
289 protected:
290   double rho;
291
292   struct atmType {double Temperature; double Pressure; double Density;};
293   int lastIndex;
294   double h;
295   double htab[8];
296   double StdSLtemperature,StdSLdensity,StdSLpressure,StdSLsoundspeed;
297   double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
298   double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
299   double *temperature, *density, *pressure;
300   double soundspeed;
301   bool useExternal;
302   double exTemperature,exDensity,exPressure;
303   double intTemperature, intDensity, intPressure;
304   double SutherlandConstant, Beta, intViscosity, intKinematicViscosity;
305   double T_dev_sl, T_dev, delta_T, density_altitude;
306   atmType atmosphere;
307   bool StandardTempOnly;
308   bool first_pass;
309
310   double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
311   double TurbGain;
312   double TurbRate;
313   double Rhythmicity;
314   double wind_from_clockwise;
315   double spike, target_time, strength;
316   FGColumnVector3 vDirectiondAccelDt;
317   FGColumnVector3 vDirectionAccel;
318   FGColumnVector3 vDirection;
319   FGColumnVector3 vTurbulenceGrad;
320   FGColumnVector3 vBodyTurbGrad;
321   FGColumnVector3 vTurbPQR;
322
323   // Dryden turbulence model
324   double windspeed_at_20ft; ///< in ft/s
325   int probability_of_exceedence_index; ///< this is bound as the severity property
326   FGTable *POE_Table; ///< probability of exceedence table
327
328   double psiw;
329   FGColumnVector3 vTotalWindNED;
330   FGColumnVector3 vWindNED;
331   FGColumnVector3 vGustNED;
332   FGColumnVector3 vTurbulenceNED;
333
334   /// Calculate the atmosphere for the given altitude, including effects of temperature deviation.
335   void Calculate(double altitude);
336   /// Calculate atmospheric properties other than the basic T, P and rho.
337   void CalculateDerived(void);
338   /// Get T, P and rho for a standard atmosphere at the given altitude.
339   void GetStdAtmosphere(double altitude);
340   void Turbulence(void);
341   void bind(void);
342   void Debug(int from);
343 };
344
345 } // namespace JSBSim
346
347 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
348 #endif
349