]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/atmosphere/FGStandardAtmosphere.h
change file mode to 644
[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.15 2011/08/17 23:56:01 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.15 2011/08/17 23:56:01 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 {return TemperatureBias;}
143
144   /// Returns the temperature gradient to be applied on top of the standard
145   /// temperature gradient.
146   virtual double GetTemperatureDeltaGradient() { return TemperatureDeltaGradient;}
147
148   /// Sets the Sea Level temperature, if it is to be different than the standard.
149   /// This function will calculate a bias - a difference - from the standard
150   /// atmosphere temperature and will apply that bias to the entire
151   /// temperature profile. This is one way to set the temperature bias. Using
152   /// the SetTemperatureBias function will replace the value calculated by
153   /// this function.
154   /// @param t the temperature value in the unit provided.
155   /// @param unit the unit of the temperature.
156   virtual void SetTemperatureSL(double t, eTemperature unit=eFahrenheit);
157
158   /// Sets the temperature at the supplied altitude, if it is to be different
159   /// than the standard temperature.
160   /// This function will calculate a bias - a difference - from the standard
161   /// atmosphere temperature at the supplied altitude and will apply that
162   /// calculated bias to the entire temperature profile. If a graded delta is
163   /// present, that will be included in the calculation - that is, regardless
164   /// of any graded delta present, a temperature bias will be determined so that
165   /// the temperature requested in this function call will be reached.
166   /// @param t The temperature value in the unit provided.
167   /// @param h The altitude in feet above sea level.
168   /// @param unit The unit of the temperature.
169   virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit);
170
171   /// Sets the temperature bias to be added to the standard temperature at all altitudes.
172   /// This function sets the bias - the difference - from the standard
173   /// atmosphere temperature. This bias applies to the entire
174   /// temperature profile. Another way to set the temperature bias is to use the
175   /// SetSLTemperature function, which replaces the value calculated by
176   /// this function with a calculated bias.
177   /// @param t the temperature value in the unit provided.
178   /// @param unit the unit of the temperature.
179   virtual void SetTemperatureBias(eTemperature unit, double t);
180
181   /// Sets a Sea Level temperature delta that is ramped out by 86 km.
182   /// The value of the delta is used to calculate a delta gradient that is
183   /// applied to the temperature at all altitudes below 86 km (282152 ft). 
184   /// For instance, if a temperature of 20 degrees F is supplied, the delta
185   /// gradient would be 20/282152 - or, about 7.09E-5 degrees/ft. At sea level,
186   /// the full 20 degrees would be added to the standard temperature,
187   /// but that 20 degree delta would be reduced by 7.09E-5 degrees for every
188   /// foot of altitude above sea level, so that by 86 km, there would be no
189   /// further delta added to the standard temperature.
190   /// The graded delta can be used along with the a bias to tailor the
191   /// temperature profile as desired.
192   /// @param t the sea level temperature delta value in the unit provided.
193   /// @param unit the unit of the temperature.
194   virtual void SetSLTemperatureGradedDelta(eTemperature unit, double t);
195
196   /// Sets the temperature delta value at the supplied altitude/elevation above
197   /// sea level, to be added to the standard temperature and ramped out by
198   /// 86 km.
199   /// This function computes the sea level delta from the standard atmosphere
200   /// temperature at sea level.
201   /// @param t the temperature skew value in the unit provided.
202   /// @param unit the unit of the temperature.
203   virtual void SetTemperatureGradedDelta(double t, double h, eTemperature unit=eFahrenheit);
204
205   /// This function resets the model to apply no bias or delta gradient to the
206   /// temperature.
207   /// The delta gradient and bias values are reset to 0.0, and the standard
208   /// temperature is used for the entire temperature profile at all altitudes.
209   virtual void ResetSLTemperature();
210   //@}
211
212   //  *************************************************************************
213   /// @name Pressure access functions.
214   //@{
215   /// Returns the pressure at a specified altitude in psf.
216   virtual double GetPressure(double altitude) const;
217
218   /// Returns the standard pressure at a specified altitude in psf
219   virtual double GetStdPressure100K(double altitude) const;
220
221   /// Returns the standard pressure at the specified altitude.
222   virtual double GetStdPressure(double altitude) const;
223
224   /** Sets the sea level pressure for modeling an off-standard pressure
225       profile. This could be useful in the case where the pressure at an
226       airfield is known or set for a particular simulation run.
227       @param pressure The pressure in the units specified (PSF by default).
228       @param unit the unit of measure that the specified pressure is
229                        supplied in.*/
230   virtual void SetPressureSL(double pressure, ePressure unit=ePSF);
231
232   /** Resets the sea level to the Standard sea level pressure, and recalculates
233       dependent parameters so that the pressure calculations are standard. */
234   virtual void ResetSLPressure();
235   //@}
236
237   //  *************************************************************************
238   /// @name Density access functions.
239   //@{
240   /// Returns the standard density at a specified altitude
241   virtual double GetStdDensity(double altitude) const;
242   //@}
243
244   /// Prints the U.S. Standard Atmosphere table.
245   virtual void PrintStandardAtmosphereTable();
246
247 protected:
248   double StdSLtemperature, StdSLdensity, StdSLpressure, StdSLsoundspeed; // Standard sea level conditions
249
250   double TemperatureBias;
251   double TemperatureDeltaGradient;
252   double GradientFadeoutAltitude;
253
254   FGTable* StdAtmosTemperatureTable;
255   std::vector<double> LapseRateVector;
256   std::vector<double> PressureBreakpointVector;
257
258   /// Recalculate the lapse rate vectors when the temperature profile is altered
259   /// in a way that would change the lapse rates, such as when a gradient is applied.
260   /// This function is also called to initialize the lapse rate vector.
261   void CalculateLapseRates();
262
263   /// Calculate (or recalculate) the atmospheric pressure breakpoints at the 
264   /// altitudes in the standard temperature table.
265   void CalculatePressureBreakpoints();
266
267   virtual void bind(void);
268   void Debug(int from);
269 };
270
271 } // namespace JSBSim
272
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 #endif
275