1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Header: FGStandardAtmosphere.h
7 ------------- Copyright (C) 2011 Jon S. Berndt (jon@jsbsim.org) -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 You should have received a copy of the GNU Lesser General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU Lesser General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGSTANDARDATMOSPHERE_H
35 #define FGSTANDARDATMOSPHERE_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "models/FGModel.h"
43 #include "math/FGTable.h"
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 #define ID_STANDARDATMOSPHERE "$Id: FGStandardAtmosphere.h,v 1.9 2011/06/13 12:06:21 jberndt Exp $"
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 /** Models the 1976 U.S. Standard Atmosphere, with the ability to modify the
62 temperature and pressure. A base feature of the model is the temperature
63 profile that is stored as an FGTable object with this data:
66 GeoMet Alt Temp GeoPot Alt GeoMet Alt
67 (ft) (deg R) (km) (km)
68 --------- -------- ---------- ----------
69 0.0 518.67 // 0.000 0.000
70 36151.6 390.0 // 11.000 11.019
71 65823.5 390.0 // 20.000 20.063
72 105518.4 411.6 // 32.000 32.162
73 155347.8 487.2 // 47.000 47.350
74 168677.8 487.2 // 51.000 51.413
75 235570.9 386.4 // 71.000 71.802
76 282152.2 336.5; // 84.852 86.000
79 The pressure is calculated at lower altitudes through the use of two equations
80 that are presented in the U.S. Standard Atmosphere document (see references).
81 Density, kinematic viscosity, speed of sound, etc., are all calculated based
82 on various constants and temperature and pressure. At higher altitudes (above
83 86 km (282152 ft) a different and more complicated method of calculating
85 The temperature may be modified through the use of several methods. Ultimately,
86 these access methods allow the user to modify the sea level standard temperature,
87 and/or the sea level standard pressure, so that the entire profile will be
88 consistently and accurately calculated.
91 @property atmosphere/T-R The current modeled temperature in degrees Rankine.
92 @property atmosphere/rho-slugs_ft3
93 @property atmosphere/P-psf
94 @property atmosphere/a-fps
95 @property atmosphere/T-sl-R
96 @property atmosphere/rho-sl-slugs_ft3
97 @property atmosphere/P-sl-psf
98 @property atmosphere/a-sl-fps
99 @property atmosphere/theta
100 @property atmosphere/sigma
101 @property atmosphere/delta
102 @property atmosphere/a-ratio
103 @property atmosphere/delta-T
104 @property atmosphere/T-sl-dev-F
107 @see "U.S. Standard Atmosphere, 1976", NASA TM-X-74335
108 @version $Id: FGStandardAtmosphere.h,v 1.9 2011/06/13 12:06:21 jberndt Exp $
111 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
115 class FGStandardAtmosphere : public FGModel {
118 /// Enums for specifying temperature units.
119 enum eTemperature {eNoTempUnit=0, eFahrenheit, eCelsius, eRankine, eKelvin};
121 /// Enums for specifying pressure units.
122 enum ePressure {eNoPressUnit=0, ePSF, eMillibars, ePascals, eInchesHg};
125 FGStandardAtmosphere(FGFDMExec*);
127 ~FGStandardAtmosphere();
128 /** Runs the standard atmosphere forces model; called by the Executive.
129 Can pass in a value indicating if the executive is directing the simulation to Hold.
130 @param Holding if true, the executive has been directed to hold the sim from
131 advancing time. Some models may ignore this flag, such as the Input
132 model, which may need to be active to listen on a socket for the
133 "Resume" command to be given.
134 @return false if no error */
135 bool Run(bool Holding);
136 bool InitModel(void);
138 // *************************************************************************
139 /// @name Temperature access functions.
140 /// There are several ways to get the temperature, and several modeled temperature
141 /// values that can be retrieved. The U.S. Standard Atmosphere temperature either
142 /// at a specified altitude, or at sea level can be retrieved. These two temperatures
143 /// do NOT include the effects of any bias or delta gradient that may have been
144 /// supplied by the user. The modeled temperature and the modeled temperature
145 /// at sea level can also be retrieved. These two temperatures DO include the
146 /// effects of an optionally user-supplied bias or delta gradient.
148 /// Returns the actual, modeled temperature at the current altitude in degrees Rankine.
149 /// @return Modeled temperature in degrees Rankine.
150 virtual double GetTemperature() const {return Temperature;}
152 /// Returns the actual modeled temperature in degrees Rankine at a specified altitude.
153 /// @param altitude The altitude above sea level (ASL) in feet.
154 /// @return Modeled temperature in degrees Rankine at the specified altitude.
155 virtual double GetTemperature(double altitude) const;
157 /// Returns the actual, modeled sea level temperature in degrees Rankine.
158 /// @return The modeled temperature in degrees Rankine at sea level.
159 virtual double GetTemperatureSL() const { return GetTemperature(0.0); }
161 /// Returns the standard temperature in degrees Rankine at a specified altitude.
162 /// @param altitude The altitude in feet above sea level (ASL) to get the temperature at.
163 /// @return The STANDARD temperature in degrees Rankine at the specified altitude.
164 virtual double GetStdTemperature(double altitude) const;
166 /// Returns the standard sea level temperature in degrees Rankine.
167 /// @return The STANDARD temperature at sea level in degrees Rankine.
168 virtual double GetStdTemperatureSL() const { return GetStdTemperature(0.0); }
170 /// Returns the ratio of the at-current-altitude temperature as modeled
171 /// over the standard sea level value.
172 virtual double GetTemperatureRatio() const { return GetTemperature()*rSLtemperature; }
174 /// Returns the ratio of the temperature as modeled at the supplied altitude
175 /// over the standard sea level value.
176 virtual double GetTemperatureRatio(double h) const { return GetTemperature(h)*rSLtemperature; }
178 /// Returns the ratio of the standard temperature at the supplied altitude
179 /// over the standard sea level temperature.
180 virtual double GetStdTemperatureRatio(double h) const { return GetStdTemperature(h)*rSLtemperature; }
182 /// Returns the temperature bias over the sea level value in degrees Rankine.
183 virtual double GetTemperatureBias(eTemperature to) const {return TemperatureBias;}
185 /// Returns the temperature gradient to be applied on top of the standard
186 /// temperature gradient.
187 virtual double GetTemperatureDeltaGradient() { return TemperatureDeltaGradient;}
189 /// Sets the Sea Level temperature, if it is to be different than the standard.
190 /// This function will calculate a bias - a difference - from the standard
191 /// atmosphere temperature and will apply that bias to the entire
192 /// temperature profile. This is one way to set the temperature bias. Using
193 /// the SetTemperatureBias function will replace the value calculated by
195 /// @param t the temperature value in the unit provided.
196 /// @param unit the unit of the temperature.
197 virtual void SetSLTemperature(double t, eTemperature unit=eFahrenheit);
199 /// Sets the temperature at the supplied altitude, if it is to be different
200 /// than the standard temperature.
201 /// This function will calculate a bias - a difference - from the standard
202 /// atmosphere temperature at the supplied altitude and will apply that
203 /// calculated bias to the entire temperature profile.
204 /// @param t The temperature value in the unit provided.
205 /// @param h The altitude in feet above sea level.
206 /// @param unit The unit of the temperature.
207 virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit) {};
209 /// Sets the temperature bias to be added to the standard temperature at all altitudes.
210 /// This function sets the bias - the difference - from the standard
211 /// atmosphere temperature. This bias applies to the entire
212 /// temperature profile. Another way to set the temperature bias is to use the
213 /// SetSLTemperature function, which replaces the value calculated by
214 /// this function with a calculated bias.
215 /// @param t the temperature value in the unit provided.
216 /// @param unit the unit of the temperature.
217 virtual void SetTemperatureBias(double t, eTemperature unit=eFahrenheit);
219 /// Sets a Sea Level temperature delta that is ramped out by 86 km.
220 /// The value of the delta is used to calculate a delta gradient that is
221 /// applied to the temperature at all altitudes below 86 km (282152 ft).
222 /// For instance, if a temperature of 20 degrees F is supplied, the delta
223 /// gradient would be 20/282152 - or, about 7.09E-5 degrees/ft. At sea level,
224 /// the full 20 degrees would be added to the standard temperature,
225 /// but that 20 degree delta would be reduced by 7.09E-5 degrees for every
226 /// foot of altitude above sea level, so that by 86 km, there would be no
227 /// further delta added to the standard temperature.
228 /// The graded delta can be used along with the a bias to tailor the
229 /// temperature profile as desired.
230 /// @param t the sea level temperature delta value in the unit provided.
231 /// @param unit the unit of the temperature.
232 virtual void SetSLTemperatureGradedDelta(double t, eTemperature unit=eFahrenheit);
234 /// Sets the temperature delta value at the supplied altitude/elevation above
235 /// sea level, to be added to the standard temperature and ramped out by
237 /// This function computes the sea level delta from the standard atmosphere
238 /// temperature at sea level.
239 /// @param t the temperature skew value in the unit provided.
240 /// @param unit the unit of the temperature.
241 virtual void SetTemperatureGradedDelta(double t, double h, eTemperature unit=eFahrenheit);
243 /// This function resets the model to apply no bias or delta gradient to the
245 /// The delta gradient and bias values are reset to 0.0, and the standard
246 /// temperature is used for the entire temperature profile at all altitudes.
247 virtual void ResetSLTemperature();
250 // *************************************************************************
251 /// @name Pressure access functions.
253 /// Returns the pressure in psf.
254 virtual double GetPressure(void) const {return Pressure;}
256 /// Returns the pressure at a specified altitude in psf.
257 virtual double GetPressure(double altitude) const;
259 /// Returns the standard pressure at a specified altitude in psf
260 virtual double GetStdPressure100K(double altitude) const;
262 /// Returns the standard pressure at the specified altitude.
263 virtual double GetStdPressure(double altitude) const;
265 /// Returns the sea level pressure in psf.
266 virtual double GetPressureSL(void) const { return SLpressure; }
268 /// Returns the ratio of at-altitude pressure over the sea level value.
269 virtual double GetPressureRatio(void) const { return Pressure*rSLpressure; }
271 /** Sets the sea level pressure for modeling an off-standard pressure
272 profile. This could be useful in the case where the pressure at an
273 airfield is known or set for a particular simulation run.
274 @param pressure The pressure in the units specified (PSF by default).
275 @param unit the unit of measure that the specified pressure is
277 virtual void SetSeaLevelPressure(double pressure, ePressure unit=ePSF);
279 /** Resets the sea level to the Standard sea level pressure, and recalculates
280 dependent parameters so that the pressure calculations are standard. */
281 virtual void ResetSLPressure();
284 // *************************************************************************
285 /// @name Density access functions.
287 /** Returns the density in slugs/ft^3.
288 This function may only be used if Run() is called first. */
289 virtual double GetDensity(void) const {return Density;}
291 /** Returns the density in slugs/ft^3 at a given altitude in ft. */
292 virtual double GetDensity(double altitude) const;
294 /// Returns the standard density at a specified altitude
295 virtual double GetStdDensity(double altitude) const;
297 /// Returns the sea level density in slugs/ft^3
298 virtual double GetDensitySL(void) const { return SLdensity; }
300 /// Returns the ratio of at-altitude density over the sea level value.
301 virtual double GetDensityRatio(void) const { return Density*rSLdensity; }
304 // *************************************************************************
305 /// @name Speed of sound access functions.
307 /// Returns the speed of sound in ft/sec.
308 virtual double GetSoundSpeed(void) const {return Soundspeed;}
310 /// Returns the sea level speed of sound in ft/sec.
311 virtual double GetSoundSpeedSL(void) const { return SLsoundspeed; }
313 /// Returns the ratio of at-altitude sound speed over the sea level value.
314 virtual double GetSoundSpeedRatio(void) const { return Soundspeed*rSLsoundspeed; }
317 // *************************************************************************
318 /// @name Viscosity access functions.
320 /// Returns the absolute viscosity.
321 virtual double GetAbsoluteViscosity(void) const {return Viscosity;}
323 /// Returns the kinematic viscosity.
324 virtual double GetKinematicViscosity(void) const {return KinematicViscosity;}
327 /* /// Gets the density altitude in feet */
328 // virtual double GetDensityAltitude(void) const { return density_altitude; }
330 /// Prints the U.S. Standard Atmosphere table.
331 virtual void PrintStandardAtmosphereTable();
334 double StdSLtemperature, StdSLdensity, StdSLpressure, StdSLsoundspeed; // Standard sea level conditions
335 double SLtemperature, SLdensity, SLpressure, SLsoundspeed; // Sea level conditions
336 double Temperature, Density, Pressure, Soundspeed; // Current actual conditions at altitude
337 double rSLtemperature, rSLdensity, rSLpressure, rSLsoundspeed; // Reciprocal of sea level conditions
339 double PressureAltitude;
340 double DensityAltitude;
342 double TemperatureBias;
343 double TemperatureDeltaGradient;
344 double GradientFadeoutAltitude;
346 FGTable* StdAtmosTemperatureTable;
347 std::vector<double> LapseRateVector;
348 std::vector<double> PressureBreakpointVector;
350 const double SutherlandConstant, Beta;
351 double Viscosity, KinematicViscosity;
353 /// Calculate the atmosphere for the given altitude, including effects of temperature deviation.
354 void Calculate(double altitude);
356 /// Recalculate the lapse rate vectors when the temperature profile is altered
357 /// in a way that would change the lapse rates, such as when a gradient is applied.
358 /// This function is also called to initialize the lapse rate vector.
359 void CalculateLapseRates();
361 /// Calculate (or recalculate) the atmospheric pressure breakpoints at the
362 /// altitudes in the standard temperature table.
363 void CalculatePressureBreakpoints();
365 // Converts to Rankine from one of several unit systems.
366 virtual double ConvertToRankine(double t, eTemperature unit) const;
368 // Converts to PSF (pounds per square foot) from one of several unit systems.
369 virtual double ConvertToPSF(double t, ePressure unit=ePSF) const;
371 virtual void bind(void);
372 void Debug(int from);
375 } // namespace JSBSim
377 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%