1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Implementation of 1959 Standard Atmosphere added by Tony Peden
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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>
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 #define ID_ATMOSPHERE "$Id$"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64 /** Models the 1976 Standard Atmosphere.
65 @author Tony Peden, Jon Berndt
67 @see Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
68 1989, ISBN 0-07-001641-0
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75 class FGAtmosphere : public FGModel {
79 FGAtmosphere(FGFDMExec*);
82 /** Runs the Atmosphere model; called by the Executive
83 @return false if no error */
86 enum tType {ttStandard, ttBerndt, ttCulp, ttNone} turbType;
88 /// Returns the temperature in degrees Rankine.
89 inline 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 inline 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 inline double GetSoundSpeed(void) const {return soundspeed;}
104 /// Returns the sea level temperature in degrees Rankine.
105 inline double GetTemperatureSL(void) const { return SLtemperature; }
106 /// Returns the sea level density in slugs/ft^3
107 inline double GetDensitySL(void) const { return SLdensity; }
108 /// Returns the sea level pressure in psf.
109 inline double GetPressureSL(void) const { return SLpressure; }
110 /// Returns the sea level speed of sound in ft/sec.
111 inline double GetSoundSpeedSL(void) const { return SLsoundspeed; }
113 /// Returns the ratio of at-altitude temperature over the sea level value.
114 inline double GetTemperatureRatio(void) const { return (*temperature)*rSLtemperature; }
115 /// Returns the ratio of at-altitude density over the sea level value.
116 inline double GetDensityRatio(void) const { return (*density)*rSLdensity; }
117 /// Returns the ratio of at-altitude pressure over the sea level value.
118 inline double GetPressureRatio(void) const { return (*pressure)*rSLpressure; }
119 /// Returns the ratio of at-altitude sound speed over the sea level value.
120 inline double GetSoundSpeedRatio(void) const { return soundspeed*rSLsoundspeed; }
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; }
129 /// Provides the external atmosphere model with an interface to set the temperature.
130 inline void SetExTemperature(double t) { exTemperature=t; }
131 /// Provides the external atmosphere model with an interface to set the density.
132 inline void SetExDensity(double d) { exDensity=d; }
133 /// Provides the external atmosphere model with an interface to set the pressure.
134 inline void SetExPressure(double p) { exPressure=p; }
136 /// Sets the temperature deviation at sea-level in degrees Fahrenheit
137 inline void SetSLTempDev(double d) { T_dev_sl = d; }
138 /// Gets the temperature deviation at sea-level in degrees Fahrenheit
139 inline double GetSLTempDev(void) const { return T_dev_sl; }
140 /// Sets the current delta-T in degrees Fahrenheit
141 inline void SetDeltaT(double d) { delta_T = d; }
142 /// Gets the current delta-T in degrees Fahrenheit
143 inline double GetDeltaT(void) const { return delta_T; }
144 /// Gets the at-altitude temperature deviation in degrees Fahrenheit
145 inline double GetTempDev(void) const { return T_dev; }
146 /// Gets the density altitude in feet
147 inline double GetDensityAltitude(void) const { return density_altitude; }
149 /// Sets the wind components in NED frame.
150 inline void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
152 /// Retrieves the wind components in NED frame.
153 inline FGColumnVector3& GetWindNED(void) { return vWindNED; }
155 /// Sets gust components in NED frame.
156 inline void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
158 /// Retrieves the gust components in NED frame.
159 inline double GetGustNED(int idx) const {return vGustNED(idx);}
161 /// Retrieves the gust components in NED frame.
162 inline FGColumnVector3& GetGustNED(void) {return vGustNED;}
164 /** Retrieves the wind direction. The direction is defined as north=0 and
165 increases counterclockwise. The wind heading is returned in radians.*/
166 inline double GetWindPsi(void) const { return psiw; }
168 /** Turbulence models available: ttStandard, ttBerndt, ttCulp, ttNone */
169 inline void SetTurbType(tType tt) {turbType = tt;}
170 inline tType GetTurbType() const {return turbType;}
172 inline void SetTurbGain(double tg) {TurbGain = tg;}
173 inline double GetTurbGain() const {return TurbGain;}
175 inline void SetTurbRate(double tr) {TurbRate = tr;}
176 inline double GetTurbRate() const {return TurbRate;}
178 inline void SetRhythmicity(double r) {Rhythmicity=r;}
179 inline double GetRhythmicity() const {return Rhythmicity;}
181 /** Sets wind vortex, clockwise as seen from a point in front of aircraft,
182 looking aft. Units are radians/second. */
183 inline void SetWindFromClockwise(double wC) { wind_from_clockwise=wC; }
184 inline double GetWindFromClockwise(void) const {return wind_from_clockwise;}
186 inline double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
187 double GetTurbMagnitude(void) const {return Magnitude;}
188 FGColumnVector3& GetTurbDirection(void) {return vDirection;}
189 inline FGColumnVector3& GetTurbPQR(void) {return vTurbPQR;}
194 struct atmType {double Temperature; double Pressure; double Density;};
198 double StdSLtemperature,StdSLdensity,StdSLpressure,StdSLsoundspeed;
199 double rSLtemperature,rSLdensity,rSLpressure,rSLsoundspeed; //reciprocals
200 double SLtemperature,SLdensity,SLpressure,SLsoundspeed;
201 double *temperature, *density, *pressure;
204 double exTemperature,exDensity,exPressure;
205 double intTemperature, intDensity, intPressure;
206 double T_dev_sl, T_dev, delta_T, density_altitude;
208 bool StandardTempOnly;
211 double MagnitudedAccelDt, MagnitudeAccel, Magnitude;
215 double wind_from_clockwise;
216 double spike, target_time, strength;
217 FGColumnVector3 vDirectiondAccelDt;
218 FGColumnVector3 vDirectionAccel;
219 FGColumnVector3 vDirection;
220 FGColumnVector3 vTurbulence;
221 FGColumnVector3 vTurbulenceGrad;
222 FGColumnVector3 vBodyTurbGrad;
223 FGColumnVector3 vTurbPQR;
225 FGColumnVector3 vWindNED;
228 FGColumnVector3 vGustNED;
231 /// Calculate the atmosphere for the given altitude, including effects of temperature deviation.
232 void Calculate(double altitude);
233 /// Calculate atmospheric properties other than the basic T, P and rho.
234 void CalculateDerived(void);
235 /// Get T, P and rho for a standard atmosphere at the given altitude.
236 void GetStdAtmosphere(double altitude);
237 void Turbulence(void);
239 void Debug(int from);
242 } // namespace JSBSim
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%