JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
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
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 
72 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 CLASS DECLARATION
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75 
76 class FGAtmosphere : public FGModel {
77 public:
78 
80  enum eTemperature {eNoTempUnit=0, eFahrenheit, eCelsius, eRankine, eKelvin};
81 
83  enum ePressure {eNoPressUnit=0, ePSF, eMillibars, ePascals, eInchesHg};
84 
87 
89  virtual ~FGAtmosphere();
90 
98  bool Run(bool Holding) override;
99 
100  bool InitModel(void) override;
101 
102  // *************************************************************************
106  // @{
109  virtual double GetTemperature() const {return Temperature;}
110 
114  virtual double GetTemperature(double altitude) const = 0;
115 
118  virtual double GetTemperatureSL() const { return SLtemperature; }
119 
122  virtual double GetTemperatureRatio() const { return GetTemperature()/SLtemperature; }
123 
126  virtual double GetTemperatureRatio(double h) const { return GetTemperature(h)/SLtemperature; }
127 
131  virtual void SetTemperatureSL(double t, eTemperature unit=eFahrenheit);
132 
137  virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit) = 0;
139 
140  // *************************************************************************
142 
143  virtual double GetPressure(void) const {return Pressure;}
145 
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 
153  virtual double GetPressureRatio(void) const { return Pressure/SLpressure; }
154 
159  virtual void SetPressureSL(ePressure unit, double pressure);
161 
162  // *************************************************************************
164 
165 
167  virtual double GetDensity(void) const {return Density;}
168 
170  virtual double GetDensity(double altitude) const;
171 
173  virtual double GetDensitySL(void) const { return SLdensity; }
174 
176  virtual double GetDensityRatio(void) const { return Density/SLdensity; }
178 
179  // *************************************************************************
181 
182  virtual double GetSoundSpeed(void) const {return Soundspeed;}
184 
186  virtual double GetSoundSpeed(double altitude) const;
187 
189  virtual double GetSoundSpeedSL(void) const { return SLsoundspeed; }
190 
192  virtual double GetSoundSpeedRatio(void) const { return Soundspeed/SLsoundspeed; }
194 
195  // *************************************************************************
197 
198  virtual double GetAbsoluteViscosity(void) const {return Viscosity;}
200 
202  virtual double GetKinematicViscosity(void) const {return KinematicViscosity;}
204 
205  virtual double GetDensityAltitude() const {return DensityAltitude;}
206 
207  virtual double GetPressureAltitude() const {return PressureAltitude;}
208 
209  struct Inputs {
210  double altitudeASL;
211  } in;
212 
213  static constexpr double StdDaySLtemperature = 518.67;
214  static constexpr double StdDaySLpressure = 2116.228;
215  static const double StdDaySLsoundspeed;
216 
217 protected:
218  double SLtemperature, SLdensity, SLpressure, SLsoundspeed; // Sea level conditions
219  double Temperature, Density, Pressure, Soundspeed; // Current actual conditions at altitude
220 
221  double PressureAltitude;
222  double DensityAltitude;
223 
224  static constexpr double SutherlandConstant = 198.72; // deg Rankine
225  static constexpr double Beta = 2.269690E-08; // slug/(sec ft R^0.5)
226  double Viscosity, KinematicViscosity;
227 
229  virtual void Calculate(double altitude);
230 
236  virtual double CalculateDensityAltitude(double density, double geometricAlt) { return geometricAlt; }
237 
243  virtual double CalculatePressureAltitude(double pressure, double geometricAlt) { return geometricAlt; }
244 
246  double ConvertToRankine(double t, eTemperature unit) const;
247 
249  double ConvertFromRankine(double t, eTemperature unit) const;
250 
252  double ConvertToPSF(double t, ePressure unit=ePSF) const;
253 
255  double ConvertFromPSF(double t, ePressure unit=ePSF) const;
256 
258 
259  static constexpr double Rstar = 8.31432 * kgtoslug / KelvinToRankine(fttom * fttom);
262  static constexpr double Mair = 28.9645 * kgtoslug / 1000.0;
268  static constexpr double g0 = 9.80665 / fttom;
270  static double Reng;
272 
273  static constexpr double SHRatio = 1.4;
274 
275  virtual void bind(void);
276  void Debug(int from) override;
277 };
278 
279 } // namespace JSBSim
280 
281 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
282 #endif
JSBSim::FGFDMExec
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGAtmosphere::eTemperature
eTemperature
Enums for specifying temperature units.
Definition: FGAtmosphere.h:80
JSBSim::FGAtmosphere::ConvertToRankine
double ConvertToRankine(double t, eTemperature unit) const
Converts to Rankine from one of several unit systems.
Definition: FGAtmosphere.cpp:169
JSBSim::FGAtmosphere::GetDensityRatio
virtual double GetDensityRatio(void) const
Returns the ratio of at-altitude density over the sea level value.
Definition: FGAtmosphere.h:176
JSBSim::FGAtmosphere::GetPressure
virtual double GetPressure(void) const
Returns the pressure in psf.
Definition: FGAtmosphere.h:144
JSBSim::FGModel
Base class for all scheduled JSBSim models.
Definition: FGModel.h:68
JSBSim::FGAtmosphere::GetSoundSpeedSL
virtual double GetSoundSpeedSL(void) const
Returns the sea level speed of sound in ft/sec.
Definition: FGAtmosphere.h:189
JSBSim::FGAtmosphere::GetKinematicViscosity
virtual double GetKinematicViscosity(void) const
Returns the kinematic viscosity.
Definition: FGAtmosphere.h:202
JSBSim::FGAtmosphere::ePressure
ePressure
Enums for specifying pressure units.
Definition: FGAtmosphere.h:83
JSBSim::FGAtmosphere::SetPressureSL
virtual void SetPressureSL(ePressure unit, double pressure)
Sets the sea level pressure for modeling.
Definition: FGAtmosphere.cpp:135
JSBSim::FGAtmosphere::ConvertToPSF
double ConvertToPSF(double t, ePressure unit=ePSF) const
Converts to PSF (pounds per square foot) from one of several unit systems.
Definition: FGAtmosphere.cpp:221
JSBSim::FGAtmosphere::g0
static constexpr double g0
Sea-level acceleration of gravity - ft/s^2.
Definition: FGAtmosphere.h:268
JSBSim::FGJSBBase::KelvinToRankine
static constexpr double KelvinToRankine(double kelvin)
Converts from degrees Kelvin to degrees Rankine.
Definition: FGJSBBase.h:216
JSBSim::FGAtmosphere::Rstar
static constexpr double Rstar
Universal gas constant - ft*lbf/R/mol.
Definition: FGAtmosphere.h:260
JSBSim::FGAtmosphere::ConvertFromPSF
double ConvertFromPSF(double t, ePressure unit=ePSF) const
Converts from PSF (pounds per square foot) to one of several unit systems.
Definition: FGAtmosphere.cpp:245
JSBSim::FGAtmosphere::Reng
static double Reng
Specific gas constant for air - ft*lbf/slug/R.
Definition: FGAtmosphere.h:270
JSBSim::FGAtmosphere::GetDensitySL
virtual double GetDensitySL(void) const
Returns the sea level density in slugs/ft^3.
Definition: FGAtmosphere.h:173
JSBSim::FGAtmosphere::GetAbsoluteViscosity
virtual double GetAbsoluteViscosity(void) const
Returns the absolute viscosity.
Definition: FGAtmosphere.h:199
JSBSim::FGAtmosphere::GetTemperatureSL
virtual double GetTemperatureSL() const
Returns the actual, modeled sea level temperature in degrees Rankine.
Definition: FGAtmosphere.h:118
JSBSim::FGAtmosphere
Models an empty, abstract base atmosphere class.
Definition: FGAtmosphere.h:76
JSBSim::FGAtmosphere::GetSoundSpeed
virtual double GetSoundSpeed(void) const
Returns the speed of sound in ft/sec.
Definition: FGAtmosphere.h:183
JSBSim::FGAtmosphere::GetTemperatureRatio
virtual double GetTemperatureRatio(double h) const
Returns the ratio of the temperature as modeled at the supplied altitude over the sea level value.
Definition: FGAtmosphere.h:126
JSBSim::FGAtmosphere::Calculate
virtual void Calculate(double altitude)
Calculate the atmosphere for the given altitude.
Definition: FGAtmosphere.cpp:107
JSBSim::FGAtmosphere::SetTemperatureSL
virtual void SetTemperatureSL(double t, eTemperature unit=eFahrenheit)
Sets the Sea Level temperature.
Definition: FGAtmosphere.cpp:162
JSBSim::FGAtmosphere::Inputs
Definition: FGAtmosphere.h:209
JSBSim::FGAtmosphere::GetSoundSpeedRatio
virtual double GetSoundSpeedRatio(void) const
Returns the ratio of at-altitude sound speed over the sea level value.
Definition: FGAtmosphere.h:192
JSBSim::FGAtmosphere::GetPressureRatio
virtual double GetPressureRatio(void) const
Returns the ratio of at-altitude pressure over the sea level value.
Definition: FGAtmosphere.h:153
JSBSim::FGAtmosphere::ConvertFromRankine
double ConvertFromRankine(double t, eTemperature unit) const
Converts from Rankine to one of several unit systems.
Definition: FGAtmosphere.cpp:195
JSBSim::FGAtmosphere::GetTemperature
virtual double GetTemperature() const
Returns the actual, modeled temperature at the current altitude in degrees Rankine.
Definition: FGAtmosphere.h:109
JSBSim::FGAtmosphere::SetTemperature
virtual void SetTemperature(double t, double h, eTemperature unit=eFahrenheit)=0
Sets the temperature at the supplied altitude.
JSBSim::FGAtmosphere::CalculatePressureAltitude
virtual double CalculatePressureAltitude(double pressure, double geometricAlt)
Calculates the pressure altitude given any temperature or pressure bias.
Definition: FGAtmosphere.h:243
JSBSim::FGAtmosphere::GetTemperatureRatio
virtual double GetTemperatureRatio() const
Returns the ratio of the at-current-altitude temperature as modeled over the sea level value.
Definition: FGAtmosphere.h:122
JSBSim::FGAtmosphere::FGAtmosphere
FGAtmosphere(FGFDMExec *)
Constructor.
Definition: FGAtmosphere.cpp:60
JSBSim::FGAtmosphere::~FGAtmosphere
virtual ~FGAtmosphere()
Destructor.
Definition: FGAtmosphere.cpp:72
JSBSim::FGAtmosphere::Mair
static constexpr double Mair
Mean molecular weight for air - slug/mol.
Definition: FGAtmosphere.h:262
JSBSim::FGAtmosphere::Run
bool Run(bool Holding) override
Runs the atmosphere forces model; called by the Executive.
Definition: FGAtmosphere.cpp:94
JSBSim::FGAtmosphere::GetDensity
virtual double GetDensity(void) const
Returns the density in slugs/ft^3.
Definition: FGAtmosphere.h:167
JSBSim::FGAtmosphere::CalculateDensityAltitude
virtual double CalculateDensityAltitude(double density, double geometricAlt)
Calculates the density altitude given any temperature or pressure bias.
Definition: FGAtmosphere.h:236