| 1 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | |
| 3 | Header: FGAtmosphere.h |
| 4 | Author: Jon Berndt |
| 5 | Date started: 6/2011 |
| 6 | |
| 7 | ------------- Copyright (C) 2011 Jon S. Berndt ([email protected]) ------------- |
| 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 |
| 11 | Software Foundation; either version 2 of the License, or (at your option) any |
| 12 | later 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 |
| 20 | with this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | |
| 23 | Further information about the GNU Lesser General Public License can also be |
| 24 | found on 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 "models/FGModel.h" |
| 42 | |
| 43 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 44 | FORWARD DECLARATIONS |
| 45 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 46 | |
| 47 | namespace JSBSim { |
| 48 | |
| 49 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 50 | CLASS DOCUMENTATION |
| 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 52 | |
| 53 | /** Models an empty, abstract base atmosphere class. |
| 54 | |
| 55 | <h2> Properties </h2> |
| 56 | @property atmosphere/T-R The current modeled temperature in degrees Rankine. |
| 57 | @property atmosphere/rho-slugs_ft3 |
| 58 | @property atmosphere/P-psf |
| 59 | @property atmosphere/a-fps |
| 60 | @property atmosphere/T-sl-R |
| 61 | @property atmosphere/rho-sl-slugs_ft3 |
| 62 | @property atmosphere/P-sl-psf |
| 63 | @property atmosphere/a-sl-fps |
| 64 | @property atmosphere/theta |
| 65 | @property atmosphere/sigma |
| 66 | @property atmosphere/delta |
| 67 | @property atmosphere/a-ratio |
| 68 | |
| 69 | @author Jon Berndt |
| 70 | */ |
| 71 | |
| 72 | /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | CLASS DECLARATION |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ |
| 75 | |
| 76 | class JSBSIM_API FGAtmosphere : public FGModel { |
| 77 | public: |
| 78 | |
| 79 | /// Enums for specifying temperature units. |
| 80 | enum eTemperature {eNoTempUnit=0, eFahrenheit, eCelsius, eRankine, eKelvin}; |
| 81 | |
| 82 | /// Enums for specifying pressure units. |
| 83 | enum ePressure {eNoPressUnit=0, ePSF, eMillibars, ePascals, eInchesHg}; |
| 84 | |
| 85 | /// Constructor |
| 86 | FGAtmosphere(FGFDMExec*); |
| 87 | |
| 88 | /// Destructor |
| 89 | virtual ~FGAtmosphere(); |
| 90 | |
| 91 | /** Runs the atmosphere forces model; called by the Executive. |
| 92 | Can pass in a value indicating if the executive is directing the simulation to Hold. |
| 93 | @param Holding if true, the executive has been directed to hold the sim from |
| 94 | advancing time. Some models may ignore this flag, such as the Input |
| 95 | model, which may need to be active to listen on a socket for the |
| 96 | "Resume" command to be given. |
| 97 | @return false if no error */ |
| 98 | bool Run(bool Holding) override; |
| 99 | |
| 100 | bool InitModel(void) override; |
| 101 | |
| 102 | // ************************************************************************* |
| 103 | /// @name Temperature access functions. |
| 104 | /// There are several ways to get the temperature, and several modeled temperature |
| 105 | /// values that can be retrieved. |
| 106 | // @{ |
| 107 | /// Returns the actual, modeled temperature at the current altitude in degrees Rankine. |
| 108 | /// @return Modeled temperature in degrees Rankine. |
| 109 | virtual double GetTemperature() const {return Temperature;} |
| 110 | |
| 111 | /// Returns the actual modeled temperature in degrees Rankine at a specified altitude. |
| 112 | /// @param altitude The altitude above sea level (ASL) in feet. |
| 113 | /// @return Modeled temperature in degrees Rankine at the specified altitude. |
| 114 | virtual double GetTemperature(double altitude) const = 0; |
| 115 | |
| 116 | /// Returns the actual, modeled sea level temperature in degrees Rankine. |
| 117 | /// @return The modeled temperature in degrees Rankine at sea level. |
| 118 | virtual double GetTemperatureSL() const { return SLtemperature; } |
| 119 | |
| 120 | /// Returns the ratio of the at-current-altitude temperature as modeled |
| 121 | /// over the sea level value. |
| 122 | virtual double GetTemperatureRatio() const { return GetTemperature()/SLtemperature; } |
| 123 | |
| 124 | /// Returns the ratio of the temperature as modeled at the supplied altitude |
| 125 | /// over the sea level value. |
| 126 | virtual double GetTemperatureRatio(double h) const { return GetTemperature(h)/SLtemperature; } |
| 127 | |
| 128 | /// Sets the Sea Level temperature. |
| 129 | /// @param t the temperature value in the unit provided. |
| 130 | /// @param unit the unit of the temperature. |
| 131 | virtual void SetTemperatureSL(double t, eTemperature unit=eFahrenheit); |
| 132 | |
| 133 | /// Sets the temperature at the supplied altitude. |
| 134 | /// @param t The temperature value in the unit provided. |
| 135 | /// @param h The altitude in feet above sea level. |
| 136 | /// @param unit The unit of the temperature. |
| 137 | virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit) = 0; |
| 138 | //@} |
| 139 | |
| 140 | // ************************************************************************* |
| 141 | /// @name Pressure access functions. |
| 142 | //@{ |
| 143 | /// Returns the pressure in psf. |
| 144 | virtual double GetPressure(void) const {return Pressure;} |
| 145 | |
| 146 | /// Returns the pressure at a specified altitude in psf. |
| 147 | virtual double GetPressure(double altitude) const = 0; |
| 148 | |
| 149 | // Returns the sea level pressure in target units, default in psf. |
| 150 | virtual double GetPressureSL(ePressure to=ePSF) const { return ConvertFromPSF(SLpressure, to); } |
| 151 | |
| 152 | /// Returns the ratio of at-altitude pressure over the sea level value. |
| 153 | virtual double GetPressureRatio(void) const { return Pressure/SLpressure; } |
| 154 | |
| 155 | /** Sets the sea level pressure for modeling. |
| 156 | @param pressure The pressure in the units specified. |
| 157 | @param unit the unit of measure that the specified pressure is |
| 158 | supplied in.*/ |
| 159 | virtual void SetPressureSL(ePressure unit, double pressure); |
| 160 | //@} |
| 161 | |
| 162 | // ************************************************************************* |
| 163 | /// @name Density access functions. |
| 164 | //@{ |
| 165 | /** Returns the density in slugs/ft^3. |
| 166 | This function may only be used if Run() is called first. */ |
| 167 | virtual double GetDensity(void) const {return Density;} |
| 168 | |
| 169 | /** Returns the density in slugs/ft^3 at a given altitude in ft. */ |
| 170 | virtual double GetDensity(double altitude) const; |
| 171 | |
| 172 | /// Returns the sea level density in slugs/ft^3 |
| 173 | virtual double GetDensitySL(void) const { return SLdensity; } |
| 174 | |
| 175 | /// Returns the ratio of at-altitude density over the sea level value. |
| 176 | virtual double GetDensityRatio(void) const { return Density/SLdensity; } |
| 177 | //@} |
| 178 | |
| 179 | // ************************************************************************* |
| 180 | /// @name Speed of sound access functions. |
| 181 | //@{ |
| 182 | /// Returns the speed of sound in ft/sec. |
| 183 | virtual double GetSoundSpeed(void) const {return Soundspeed;} |
| 184 | |
| 185 | /// Returns the speed of sound in ft/sec at a given altitude in ft. |
| 186 | virtual double GetSoundSpeed(double altitude) const; |
| 187 | |
| 188 | /// Returns the sea level speed of sound in ft/sec. |
| 189 | virtual double GetSoundSpeedSL(void) const { return SLsoundspeed; } |
| 190 | |
| 191 | /// Returns the ratio of at-altitude sound speed over the sea level value. |
| 192 | virtual double GetSoundSpeedRatio(void) const { return Soundspeed/SLsoundspeed; } |
| 193 | //@} |
| 194 | |
| 195 | // ************************************************************************* |
| 196 | /// @name Viscosity access functions. |
| 197 | //@{ |
| 198 | /// Returns the absolute viscosity. |
| 199 | virtual double GetAbsoluteViscosity(void) const {return Viscosity;} |
| 200 | |
| 201 | /// Returns the kinematic viscosity. |
| 202 | virtual double GetKinematicViscosity(void) const {return KinematicViscosity;} |
| 203 | //@} |
| 204 | |
| 205 | virtual double GetDensityAltitude() const {return DensityAltitude;} |
| 206 | |
| 207 | virtual double GetPressureAltitude() const {return PressureAltitude;} |
| 208 | |
| 209 | struct Inputs { |
| 210 | double altitudeASL; |
| 211 | double GeodLatitudeDeg; |
| 212 | double LongitudeDeg; |
| 213 | } in; |
| 214 | |
| 215 | static constexpr double StdDaySLtemperature = 518.67; |
| 216 | static constexpr double StdDaySLpressure = 2116.228; |
| 217 | const double StdDaySLsoundspeed; |
| 218 | static constexpr double SHRatio = 1.4; |
| 219 | |
| 220 | protected: |
| 221 | // Sea level conditions |
| 222 | double SLtemperature = 1.8; |
| 223 | double SLdensity = 1.0; |
| 224 | double SLpressure = 1.0; |
| 225 | double SLsoundspeed = 1.0; |
| 226 | // Current actual conditions at altitude |
| 227 | double Temperature = 1.8; |
| 228 | double Density = 0.0; |
| 229 | double Pressure = 0.0; |
| 230 | double Soundspeed = 0.0; |
| 231 | double PressureAltitude = 0.0; |
| 232 | double DensityAltitude = 0.0; |
| 233 | |
| 234 | static constexpr double SutherlandConstant = 198.72; // deg Rankine |
| 235 | static constexpr double Beta = 2.269690E-08; // slug/(sec ft R^0.5) |
| 236 | double Viscosity = 0.0; |
| 237 | double KinematicViscosity = 0.0; |
| 238 | |
| 239 | /// Calculate the atmosphere for the given altitude. |
| 240 | virtual void Calculate(double altitude); |
| 241 | |
| 242 | /// Calculates the density altitude given any temperature or pressure bias. |
| 243 | /// Calculated density for the specified geometric altitude given any temperature |
| 244 | /// or pressure biases is passed in. |
| 245 | /// @param density |
| 246 | /// @param geometricAlt |
| 247 | virtual double CalculateDensityAltitude(double density, double geometricAlt) { return geometricAlt; } |
| 248 | |
| 249 | /// Calculates the pressure altitude given any temperature or pressure bias. |
| 250 | /// Calculated pressure for the specified geometric altitude given any temperature |
| 251 | /// or pressure biases is passed in. |
| 252 | /// @param pressure |
| 253 | /// @param geometricAlt |
| 254 | virtual double CalculatePressureAltitude(double pressure, double geometricAlt) { return geometricAlt; } |
| 255 | |
| 256 | /// Converts to Rankine from one of several unit systems. |
| 257 | double ConvertToRankine(double t, eTemperature unit) const; |
| 258 | |
| 259 | /// Converts from Rankine to one of several unit systems. |
| 260 | double ConvertFromRankine(double t, eTemperature unit) const; |
| 261 | |
| 262 | /// Converts to PSF (pounds per square foot) from one of several unit systems. |
| 263 | double ConvertToPSF(double t, ePressure unit=ePSF) const; |
| 264 | |
| 265 | /// Converts from PSF (pounds per square foot) to one of several unit systems. |
| 266 | double ConvertFromPSF(double t, ePressure unit=ePSF) const; |
| 267 | |
| 268 | /// Check that the pressure is within plausible boundaries. |
| 269 | /// @param msg Message to display if the pressure is out of boundaries |
| 270 | /// @param quiet Don't display the message if set to true |
| 271 | double ValidatePressure(double p, const std::string& msg, bool quiet=false) const; |
| 272 | |
| 273 | /// Check that the temperature is within plausible boundaries. |
| 274 | /// @param msg Message to display if the pressure is out of boundaries |
| 275 | /// @param quiet Don't display the message if set to true |
| 276 | double ValidateTemperature(double t, const std::string& msg, bool quiet=false) const; |
| 277 | |
| 278 | /// @name ISA constants |
| 279 | //@{ |
| 280 | /// Universal gas constant - ft*lbf/R/mol |
| 281 | static constexpr double Rstar = 8.31432 * kgtoslug / KelvinToRankine(fttom * fttom); |
| 282 | /// Mean molecular weight for air - slug/mol |
| 283 | static constexpr double Mair = 28.9645 * kgtoslug / 1000.0; |
| 284 | /** Sea-level acceleration of gravity - ft/s^2. |
| 285 | This constant is defined to compute the International Standard Atmosphere. |
| 286 | It is by definition the sea level gravity at a latitude of 45deg. This |
| 287 | value is fixed whichever gravity model is used by FGInertial. |
| 288 | */ |
| 289 | static constexpr double g0 = 9.80665 / fttom; |
| 290 | /// Specific gas constant for air - ft*lbf/slug/R |
| 291 | static constexpr double Reng0 = Rstar / Mair; |
| 292 | //@} |
| 293 | |
| 294 | double Reng = Reng0; |
| 295 | |
| 296 | virtual void bind(void); |
| 297 | void Debug(int from) override; |
| 298 | |
| 299 | public: |
| 300 | static constexpr double StdDaySLdensity = StdDaySLpressure / (Reng0 * StdDaySLtemperature); |
| 301 | }; |
| 302 | |
| 303 | } // namespace JSBSim |
| 304 | |
| 305 | //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 306 | #endif |