]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGAtmosphere.h
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / FGAtmosphere.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGAtmosphere.h
4  Author:       Jon Berndt
5  Date started: 6/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 FGATMOSPHERE_H
35 #define FGATMOSPHERE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <vector>
42 #include "models/FGModel.h"
43
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 DEFINITIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 #define ID_ATMOSPHERE "$Id: FGAtmosphere.h,v 1.30 2012/04/13 13:18:28 jberndt Exp $"
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 FORWARD DECLARATIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 namespace JSBSim {
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS DOCUMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 /** Models an empty, abstract base atmosphere class.
61
62   <h2> Properties </h2>
63   @property atmosphere/T-R The current modeled temperature in degrees Rankine.
64   @property atmosphere/rho-slugs_ft3
65   @property atmosphere/P-psf
66   @property atmosphere/a-fps
67   @property atmosphere/T-sl-R
68   @property atmosphere/rho-sl-slugs_ft3
69   @property atmosphere/P-sl-psf
70   @property atmosphere/a-sl-fps
71   @property atmosphere/theta
72   @property atmosphere/sigma
73   @property atmosphere/delta
74   @property atmosphere/a-ratio
75
76   @author Jon Berndt
77   @version $Id: FGAtmosphere.h,v 1.30 2012/04/13 13:18:28 jberndt Exp $
78 */
79
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 CLASS DECLARATION
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83
84 class FGAtmosphere : public FGModel {
85 public:
86
87   /// Enums for specifying temperature units.
88   enum eTemperature {eNoTempUnit=0, eFahrenheit, eCelsius, eRankine, eKelvin};
89
90   /// Enums for specifying pressure units.
91   enum ePressure {eNoPressUnit=0, ePSF, eMillibars, ePascals, eInchesHg};
92
93   /// Constructor
94   FGAtmosphere(FGFDMExec*);
95
96   /// Destructor
97   virtual ~FGAtmosphere();
98
99   /** Runs the atmosphere forces model; called by the Executive.
100       Can pass in a value indicating if the executive is directing the simulation to Hold.
101       @param Holding if true, the executive has been directed to hold the sim from 
102                      advancing time. Some models may ignore this flag, such as the Input
103                      model, which may need to be active to listen on a socket for the
104                      "Resume" command to be given.
105       @return false if no error */
106   bool Run(bool Holding);
107
108   bool InitModel(void);
109
110   //  *************************************************************************
111   /// @name Temperature access functions.
112   /// There are several ways to get the temperature, and several modeled temperature
113   /// values that can be retrieved.
114   // @{
115   /// Returns the actual, modeled temperature at the current altitude in degrees Rankine.
116   /// @return Modeled temperature in degrees Rankine.
117   virtual double GetTemperature() const {return Temperature;}
118
119   /// Returns the actual modeled temperature in degrees Rankine at a specified altitude.
120   /// @param altitude The altitude above sea level (ASL) in feet.
121   /// @return Modeled temperature in degrees Rankine at the specified altitude.
122   virtual double GetTemperature(double altitude) const = 0; 
123
124   /// Returns the actual, modeled sea level temperature in degrees Rankine.
125   /// @return The modeled temperature in degrees Rankine at sea level.
126   virtual double GetTemperatureSL() const { return GetTemperature(0.0); }
127
128   /// Returns the ratio of the at-current-altitude temperature as modeled
129   /// over the sea level value.
130   virtual double GetTemperatureRatio() const { return GetTemperature()*rSLtemperature; }
131
132   /// Returns the ratio of the temperature as modeled at the supplied altitude
133   /// over the sea level value.
134   virtual double GetTemperatureRatio(double h) const { return GetTemperature(h)*rSLtemperature; }
135
136   /// Sets the Sea Level temperature.
137   /// @param t the temperature value in the unit provided.
138   /// @param unit the unit of the temperature.
139   virtual void SetTemperatureSL(double t, eTemperature unit=eFahrenheit);
140
141   /// Sets the temperature at the supplied altitude.
142   /// @param t The temperature value in the unit provided.
143   /// @param h The altitude in feet above sea level.
144   /// @param unit The unit of the temperature.
145   virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit) = 0;
146   //@}
147
148   //  *************************************************************************
149   /// @name Pressure access functions.
150   //@{
151   /// Returns the pressure in psf.
152   virtual double GetPressure(void)  const {return Pressure;}
153
154   /// Returns the pressure at a specified altitude in psf.
155   virtual double GetPressure(double altitude) const = 0;
156
157   /// Returns the sea level pressure in psf.
158   virtual double GetPressureSL(void) const { return SLpressure; }
159
160   /// Returns the ratio of at-altitude pressure over the sea level value.
161   virtual double GetPressureRatio(void) const { return Pressure*rSLpressure; }
162
163   /** Sets the sea level pressure for modeling.
164       @param pressure The pressure in the units specified.
165       @param unit the unit of measure that the specified pressure is
166                   supplied in.*/
167   virtual void SetPressureSL(ePressure unit, double pressure);
168   //@}
169
170   //  *************************************************************************
171   /// @name Density access functions.
172   //@{
173   /** Returns the density in slugs/ft^3.
174       This function may only be used if Run() is called first. */
175   virtual double GetDensity(void)  const {return Density;}
176
177   /** Returns the density in slugs/ft^3 at a given altitude in ft. */
178   virtual double GetDensity(double altitude) const;
179
180   /// Returns the sea level density in slugs/ft^3
181   virtual double GetDensitySL(void)  const { return SLdensity; }
182
183   /// Returns the ratio of at-altitude density over the sea level value.
184   virtual double GetDensityRatio(void) const { return Density*rSLdensity; }
185   //@}
186
187   //  *************************************************************************
188   /// @name Speed of sound access functions.
189   //@{
190   /// Returns the speed of sound in ft/sec.
191   virtual double GetSoundSpeed(void) const {return Soundspeed;}
192
193   /// Returns the sea level speed of sound in ft/sec.
194   virtual double GetSoundSpeedSL(void) const { return SLsoundspeed; }
195
196   /// Returns the ratio of at-altitude sound speed over the sea level value.
197   virtual double GetSoundSpeedRatio(void) const { return Soundspeed*rSLsoundspeed; }
198   //@}
199
200   //  *************************************************************************
201   /// @name Viscosity access functions.
202   //@{
203   /// Returns the absolute viscosity.
204   virtual double GetAbsoluteViscosity(void) const {return Viscosity;}
205
206   /// Returns the kinematic viscosity.
207   virtual double GetKinematicViscosity(void) const {return KinematicViscosity;}
208   //@}
209
210   virtual double GetDensityAltitude() const {return DensityAltitude;}
211
212   virtual double GetPressureAltitude() const {return PressureAltitude;}
213
214   struct Inputs {
215     double altitudeASL;
216   } in;
217
218 protected:
219   double    SLtemperature,    SLdensity,    SLpressure,    SLsoundspeed; // Sea level conditions
220   double      Temperature,      Density,      Pressure,      Soundspeed; // Current actual conditions at altitude
221   double   rSLtemperature,   rSLdensity,   rSLpressure,   rSLsoundspeed; // Reciprocal of sea level conditions
222
223   double PressureAltitude;
224   double DensityAltitude;
225
226   const double SutherlandConstant, Beta;
227   double Viscosity, KinematicViscosity;
228
229   /// Calculate the atmosphere for the given altitude.
230   void Calculate(double altitude);
231
232   // Converts to Rankine from one of several unit systems.
233   virtual double ConvertToRankine(double t, eTemperature unit) const;
234   
235   // Converts to PSF (pounds per square foot) from one of several unit systems.
236   virtual double ConvertToPSF(double t, ePressure unit=ePSF) const;
237
238   virtual void bind(void);
239   void Debug(int from);
240 };
241
242 } // namespace JSBSim
243
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245 #endif
246