1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 FGATMOSPHERE_H
35 #define FGATMOSPHERE_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 #include "models/FGModel.h"
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 #define ID_ATMOSPHERE "$Id: FGAtmosphere.h,v 1.29 2011/07/10 20:18:14 jberndt Exp $"
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 /** Models an empty, abstract base atmosphere class.
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
77 @version $Id: FGAtmosphere.h,v 1.29 2011/07/10 20:18:14 jberndt Exp $
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
84 class FGAtmosphere : public FGModel {
87 /// Enums for specifying temperature units.
88 enum eTemperature {eNoTempUnit=0, eFahrenheit, eCelsius, eRankine, eKelvin};
90 /// Enums for specifying pressure units.
91 enum ePressure {eNoPressUnit=0, ePSF, eMillibars, ePascals, eInchesHg};
94 FGAtmosphere(FGFDMExec*);
97 virtual ~FGAtmosphere();
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);
108 bool InitModel(void);
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.
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;}
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;
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); }
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; }
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; }
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);
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;
148 // *************************************************************************
149 /// @name Pressure access functions.
151 /// Returns the pressure in psf.
152 virtual double GetPressure(void) const {return Pressure;}
154 /// Returns the pressure at a specified altitude in psf.
155 virtual double GetPressure(double altitude) const = 0;
157 /// Returns the sea level pressure in psf.
158 virtual double GetPressureSL(void) const { return SLpressure; }
160 /// Returns the ratio of at-altitude pressure over the sea level value.
161 virtual double GetPressureRatio(void) const { return Pressure*rSLpressure; }
163 /** Sets the sea level pressure for modeling.
164 @param pressure The pressure in the units specified (PSF by default).
165 @param unit the unit of measure that the specified pressure is
167 virtual void SetPressureSL(double pressure, ePressure unit=ePSF);
170 // *************************************************************************
171 /// @name Density access functions.
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;}
177 /** Returns the density in slugs/ft^3 at a given altitude in ft. */
178 virtual double GetDensity(double altitude) const;
180 /// Returns the sea level density in slugs/ft^3
181 virtual double GetDensitySL(void) const { return SLdensity; }
183 /// Returns the ratio of at-altitude density over the sea level value.
184 virtual double GetDensityRatio(void) const { return Density*rSLdensity; }
187 // *************************************************************************
188 /// @name Speed of sound access functions.
190 /// Returns the speed of sound in ft/sec.
191 virtual double GetSoundSpeed(void) const {return Soundspeed;}
193 /// Returns the sea level speed of sound in ft/sec.
194 virtual double GetSoundSpeedSL(void) const { return SLsoundspeed; }
196 /// Returns the ratio of at-altitude sound speed over the sea level value.
197 virtual double GetSoundSpeedRatio(void) const { return Soundspeed*rSLsoundspeed; }
200 // *************************************************************************
201 /// @name Viscosity access functions.
203 /// Returns the absolute viscosity.
204 virtual double GetAbsoluteViscosity(void) const {return Viscosity;}
206 /// Returns the kinematic viscosity.
207 virtual double GetKinematicViscosity(void) const {return KinematicViscosity;}
210 virtual double GetDensityAltitude() const {return DensityAltitude;}
212 virtual double GetPressureAltitude() const {return PressureAltitude;}
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
223 double PressureAltitude;
224 double DensityAltitude;
226 const double SutherlandConstant, Beta;
227 double Viscosity, KinematicViscosity;
229 /// Calculate the atmosphere for the given altitude.
230 void Calculate(double altitude);
232 // Converts to Rankine from one of several unit systems.
233 virtual double ConvertToRankine(double t, eTemperature unit) const;
235 // Converts to PSF (pounds per square foot) from one of several unit systems.
236 virtual double ConvertToPSF(double t, ePressure unit=ePSF) const;
238 virtual void bind(void);
239 void Debug(int from);
242 } // namespace JSBSim
244 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%