]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/atmosphere/FGStandardAtmosphere.h
sync with JSB JSBSim CVS
[flightgear.git] / src / FDM / JSBSim / models / atmosphere / FGStandardAtmosphere.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGStandardAtmosphere.h
4  Author:       Jon Berndt
5  Date started: 5/2011
6
7  ------------- Copyright (C) 2011  Jon S. Berndt (jon@jsbsim.org) -------------
8
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
12  version.
13
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
17  details.
18
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.
22
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.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 5/2011   JSB   Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGSTANDARDATMOSPHERE_H
35 #define FGSTANDARDATMOSPHERE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <vector>
42 #include "math/FGTable.h"
43 #include "models/FGAtmosphere.h"
44
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49 #define ID_STANDARDATMOSPHERE "$Id: FGStandardAtmosphere.h,v 1.17 2012/04/13 13:18:27 jberndt Exp $"
50
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55 namespace JSBSim {
56
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
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:
64
65 @code
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
77 @endcode
78
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
84 pressure is used.
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.
89
90   <h2> Properties </h2>
91   @property atmosphere/delta-T
92   @property atmosphere/T-sl-dev-F
93
94   @author Jon Berndt
95   @see "U.S. Standard Atmosphere, 1976", NASA TM-X-74335
96   @version $Id: FGStandardAtmosphere.h,v 1.17 2012/04/13 13:18:27 jberndt Exp $
97 */
98
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 CLASS DECLARATION
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102
103 class FGStandardAtmosphere : public FGAtmosphere {
104 public:
105   /// Constructor
106   FGStandardAtmosphere(FGFDMExec*);
107
108   /// Destructor
109   virtual ~FGStandardAtmosphere();
110
111   bool InitModel(void);
112
113   //  *************************************************************************
114   /// @name Temperature access functions.
115   /// There are several ways to get the temperature, and several modeled temperature
116   /// values that can be retrieved. The U.S. Standard Atmosphere temperature either
117   /// at a specified altitude, or at sea level can be retrieved. These two temperatures
118   /// do NOT include the effects of any bias or delta gradient that may have been
119   /// supplied by the user. The modeled temperature and the modeled temperature
120   /// at sea level can also be retrieved. These two temperatures DO include the
121   /// effects of an optionally user-supplied bias or delta gradient.
122   // @{
123   /// Returns the actual modeled temperature in degrees Rankine at a specified altitude.
124   /// @param altitude The altitude above sea level (ASL) in feet.
125   /// @return Modeled temperature in degrees Rankine at the specified altitude.
126   virtual double GetTemperature(double altitude) const;
127
128   /// Returns the standard temperature in degrees Rankine at a specified altitude.
129   /// @param altitude The altitude in feet above sea level (ASL) to get the temperature at.
130   /// @return The STANDARD temperature in degrees Rankine at the specified altitude.
131   virtual double GetStdTemperature(double altitude) const;
132
133   /// Returns the standard sea level temperature in degrees Rankine.
134   /// @return The STANDARD temperature at sea level in degrees Rankine.
135   virtual double GetStdTemperatureSL() const { return GetStdTemperature(0.0); }
136
137   /// Returns the ratio of the standard temperature at the supplied altitude 
138   /// over the standard sea level temperature.
139   virtual double GetStdTemperatureRatio(double h) const { return GetStdTemperature(h)*rSLtemperature; }
140
141   /// Returns the temperature bias over the sea level value in degrees Rankine.
142   virtual double GetTemperatureBias(eTemperature to) const
143   { if (to == eCelsius || to == eKelvin) return TemperatureBias/1.80; else return TemperatureBias; }
144
145   /// Returns the temperature gradient to be applied on top of the standard
146   /// temperature gradient.
147   virtual double GetTemperatureDeltaGradient(eTemperature to)
148   { if (to == eCelsius || to == eKelvin) return TemperatureDeltaGradient/1.80; else return TemperatureDeltaGradient; }
149
150   /// Sets the Sea Level temperature, if it is to be different than the standard.
151   /// This function will calculate a bias - a difference - from the standard
152   /// atmosphere temperature and will apply that bias to the entire
153   /// temperature profile. This is one way to set the temperature bias. Using
154   /// the SetTemperatureBias function will replace the value calculated by
155   /// this function.
156   /// @param t the temperature value in the unit provided.
157   /// @param unit the unit of the temperature.
158   virtual void SetTemperatureSL(double t, eTemperature unit=eFahrenheit);
159
160   /// Sets the temperature at the supplied altitude, if it is to be different
161   /// than the standard temperature.
162   /// This function will calculate a bias - a difference - from the standard
163   /// atmosphere temperature at the supplied altitude and will apply that
164   /// calculated bias to the entire temperature profile. If a graded delta is
165   /// present, that will be included in the calculation - that is, regardless
166   /// of any graded delta present, a temperature bias will be determined so that
167   /// the temperature requested in this function call will be reached.
168   /// @param t The temperature value in the unit provided.
169   /// @param h The altitude in feet above sea level.
170   /// @param unit The unit of the temperature.
171   virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit);
172
173   /// Sets the temperature bias to be added to the standard temperature at all altitudes.
174   /// This function sets the bias - the difference - from the standard
175   /// atmosphere temperature. This bias applies to the entire
176   /// temperature profile. Another way to set the temperature bias is to use the
177   /// SetSLTemperature function, which replaces the value calculated by
178   /// this function with a calculated bias.
179   /// @param t the temperature value in the unit provided.
180   /// @param unit the unit of the temperature.
181   virtual void SetTemperatureBias(eTemperature unit, double t);
182
183   /// Sets a Sea Level temperature delta that is ramped out by 86 km.
184   /// The value of the delta is used to calculate a delta gradient that is
185   /// applied to the temperature at all altitudes below 86 km (282152 ft). 
186   /// For instance, if a temperature of 20 degrees F is supplied, the delta
187   /// gradient would be 20/282152 - or, about 7.09E-5 degrees/ft. At sea level,
188   /// the full 20 degrees would be added to the standard temperature,
189   /// but that 20 degree delta would be reduced by 7.09E-5 degrees for every
190   /// foot of altitude above sea level, so that by 86 km, there would be no
191   /// further delta added to the standard temperature.
192   /// The graded delta can be used along with the a bias to tailor the
193   /// temperature profile as desired.
194   /// @param t the sea level temperature delta value in the unit provided.
195   /// @param unit the unit of the temperature.
196   virtual void SetSLTemperatureGradedDelta(eTemperature unit, double t);
197
198   /// Sets the temperature delta value at the supplied altitude/elevation above
199   /// sea level, to be added to the standard temperature and ramped out by
200   /// 86 km.
201   /// This function computes the sea level delta from the standard atmosphere
202   /// temperature at sea level.
203   /// @param t the temperature skew value in the unit provided.
204   /// @param unit the unit of the temperature.
205   virtual void SetTemperatureGradedDelta(double t, double h, eTemperature unit=eFahrenheit);
206
207   /// This function resets the model to apply no bias or delta gradient to the
208   /// temperature.
209   /// The delta gradient and bias values are reset to 0.0, and the standard
210   /// temperature is used for the entire temperature profile at all altitudes.
211   virtual void ResetSLTemperature();
212   //@}
213
214   //  *************************************************************************
215   /// @name Pressure access functions.
216   //@{
217   /// Returns the pressure at a specified altitude in psf.
218   virtual double GetPressure(double altitude) const;
219
220   /// Returns the standard pressure at a specified altitude in psf
221   virtual double GetStdPressure100K(double altitude) const;
222
223   /// Returns the standard pressure at the specified altitude.
224   virtual double GetStdPressure(double altitude) const;
225
226   /** Sets the sea level pressure for modeling an off-standard pressure
227       profile. This could be useful in the case where the pressure at an
228       airfield is known or set for a particular simulation run.
229       @param pressure The pressure in the units specified.
230       @param unit the unit of measure that the specified pressure is
231                        supplied in.*/
232   virtual void SetPressureSL(ePressure unit, double pressure);
233
234   /** Resets the sea level to the Standard sea level pressure, and recalculates
235       dependent parameters so that the pressure calculations are standard. */
236   virtual void ResetSLPressure();
237   //@}
238
239   //  *************************************************************************
240   /// @name Density access functions.
241   //@{
242   /// Returns the standard density at a specified altitude
243   virtual double GetStdDensity(double altitude) const;
244   //@}
245
246   /// Prints the U.S. Standard Atmosphere table.
247   virtual void PrintStandardAtmosphereTable();
248
249 protected:
250   double StdSLtemperature, StdSLdensity, StdSLpressure, StdSLsoundspeed; // Standard sea level conditions
251
252   double TemperatureBias;
253   double TemperatureDeltaGradient;
254   double GradientFadeoutAltitude;
255
256   FGTable* StdAtmosTemperatureTable;
257   std::vector<double> LapseRateVector;
258   std::vector<double> PressureBreakpointVector;
259
260   /// Recalculate the lapse rate vectors when the temperature profile is altered
261   /// in a way that would change the lapse rates, such as when a gradient is applied.
262   /// This function is also called to initialize the lapse rate vector.
263   void CalculateLapseRates();
264
265   /// Calculate (or recalculate) the atmospheric pressure breakpoints at the 
266   /// altitudes in the standard temperature table.
267   void CalculatePressureBreakpoints();
268
269   virtual void bind(void);
270   void Debug(int from);
271 };
272
273 } // namespace JSBSim
274
275 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276 #endif
277