1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Implementation of 1959 Standard Atmosphere added by Tony Peden
8 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
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
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
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.
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.
28 --------------------------------------------------------------------------------
30 07/23/99 TP Added implementation of 1959 Standard Atmosphere
31 Moved calculation of Mach number to FGPropagate
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 #ifndef FGATMOSPHERE_H
39 #define FGATMOSPHERE_H
41 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #include "math/FGColumnVector3.h"
47 #include "math/FGTable.h"
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53 #define ID_ATMOSPHERE "$Id: FGAtmosphere.h,v 1.24 2010/11/18 12:38:06 jberndt Exp $"
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 /** Models the 1976 Standard Atmosphere.
66 @author Tony Peden, Jon Berndt
67 @version $Id: FGAtmosphere.h,v 1.24 2010/11/18 12:38:06 jberndt Exp $
68 @see Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
69 1989, ISBN 0-07-001641-0
71 Additionally, various turbulence models are available. They are specified
72 via the property <tt>atmosphere/turb-type</tt>. The following models are
74 - 0: ttNone (turbulence disabled)
78 - 4: ttMilspec (Dryden spectrum)
79 - 5: ttTustin (Dryden spectrum)
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.
87 The two models differ in the implementation of the transfer functions
88 described in the milspec.
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. 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
98 Reference values (cf. figures 7 and 9 from the milspec):
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>
104 <td>25 (15 knots)</td>
106 <tr><td>moderate</td>
107 <td>50 (30 knots)</td>
110 <td>75 (45 knots)</td>
114 @see Yeager, Jessie C.: "Implementation and Testing of Turbulence Models for
116 href="http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980028448_1998081596.pdf">
117 pdf</a>), NASA CR-1998-206937, 1998
119 @see MIL-F-8785C: Military Specification: Flying Qualities of Piloted Aircraft
123 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
127 class FGAtmosphere : public FGModel {
131 FGAtmosphere(FGFDMExec*);
134 /** Runs the Atmosphere model; called by the Executive
135 @return false if no error */
137 bool InitModel(void);
138 enum tType {ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin} turbType;
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;}
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; }
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; }
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; }
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; }
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; }
205 // TOTAL WIND access functions (wind + gust + turbulence)
207 /// Retrieves the total wind components in NED frame.
208 const FGColumnVector3& GetTotalWindNED(void) const { return vTotalWindNED; }
210 /// Retrieves a total wind component in NED frame.
211 double GetTotalWindNED(int idx) const {return vTotalWindNED(idx);}
213 // WIND access functions
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;}
218 /// Sets a wind component in NED frame.
219 void SetWindNED(int idx, double wind) { vWindNED(idx)=wind;}
221 /// Retrieves the wind components in NED frame.
222 FGColumnVector3& GetWindNED(void) { return vWindNED; }
224 /// Retrieves a wind component in NED frame.
225 double GetWindNED(int idx) const {return vWindNED(idx);}
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; }
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);
240 void SetWindspeed(double speed);
242 double GetWindspeed(void) const;
244 // GUST access functions
246 /// Sets a gust component in NED frame.
247 void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
249 /// Sets a turbulence component in NED frame.
250 void SetTurbNED(int idx, double turb) { vTurbulenceNED(idx)=turb;}
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;}
255 /// Retrieves a gust component in NED frame.
256 double GetGustNED(int idx) const {return vGustNED(idx);}
258 /// Retrieves a turbulence component in NED frame.
259 double GetTurbNED(int idx) const {return vTurbulenceNED(idx);}
261 /// Retrieves the gust components in NED frame.
262 FGColumnVector3& GetGustNED(void) {return vGustNED;}
264 /** Turbulence models available: ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin */
265 void SetTurbType(tType tt) {turbType = tt;}
266 tType GetTurbType() const {return turbType;}
268 void SetTurbGain(double tg) {TurbGain = tg;}
269 double GetTurbGain() const {return TurbGain;}
271 void SetTurbRate(double tr) {TurbRate = tr;}
272 double GetTurbRate() const {return TurbRate;}
274 void SetRhythmicity(double r) {Rhythmicity=r;}
275 double GetRhythmicity() const {return Rhythmicity;}
277 double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
278 double GetTurbMagnitude(void) const {return Magnitude;}
279 const FGColumnVector3& GetTurbDirection(void) const {return vDirection;}
280 const FGColumnVector3& GetTurbPQR(void) const {return vTurbPQR;}
282 void SetWindspeed20ft(double ws) { windspeed_at_20ft = ws;}
283 double GetWindspeed20ft() const { return windspeed_at_20ft;}
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;}
292 struct atmType {double Temperature; double Pressure; double Density;};
296 double StdSLtemperature,StdSLdensity,StdSLpressure,StdSLsoundspeed;
297 double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
298 double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
299 double *temperature, *density, *pressure;
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;
307 bool StandardTempOnly;
310 double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
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;
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
329 FGColumnVector3 vTotalWindNED;
330 FGColumnVector3 vWindNED;
331 FGColumnVector3 vGustNED;
332 FGColumnVector3 vTurbulenceNED;
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);
342 void Debug(int from);
345 } // namespace JSBSim
347 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%