| 1 | #ifndef _ATMOSPHERE_HPP |
| 2 | #define _ATMOSPHERE_HPP |
| 3 | |
| 4 | namespace FGTestApi { namespace PrivateAccessor { namespace FDM { class Accessor; } } } |
| 5 | |
| 6 | namespace yasim { |
| 7 | |
| 8 | //constexpr int Atmosphere::numColumns {4}; |
| 9 | |
| 10 | class Atmosphere { |
| 11 | friend class ::FGTestApi::PrivateAccessor::FDM::Accessor; |
| 12 | |
| 13 | static const int numColumns {4}; |
| 14 | |
| 15 | public: |
| 16 | enum Column { |
| 17 | ALTITUDE, |
| 18 | TEMPERATURE, |
| 19 | PRESSURE, |
| 20 | DENSITY |
| 21 | }; |
| 22 | void setTemperature(float t) { _temperature = t; } |
| 23 | void setPressure(float p) { _pressure = p; } |
| 24 | void setDensity(float d) { _density = d; } |
| 25 | |
| 26 | //set temperature, pressure and density to standard values for given altitude |
| 27 | void setStandard(float altitude); |
| 28 | |
| 29 | float getTemperature() const { return _temperature; } |
| 30 | float getPressure() const { return _pressure; } |
| 31 | float getDensity() const { return _density; } |
| 32 | float speedFromMach(float mach); |
| 33 | float speedFromVCAS(float vcas); |
| 34 | float machFromSpeed(float spd); |
| 35 | |
| 36 | // static methods |
| 37 | static float getStdTemperature(float alt); |
| 38 | static float getStdPressure(float alt); |
| 39 | static float getStdDensity(float alt); |
| 40 | |
| 41 | static float calcVCAS(float spd, float pressure, float temp); |
| 42 | static float calcVEAS(float spd, float pressure, float temp, float density); |
| 43 | static float calcMach(float spd, float temp); |
| 44 | static float calcStdDensity(float pressure, float temp); |
| 45 | |
| 46 | static float speedFromMach(float mach, float temp); |
| 47 | static float speedFromVCAS(float vcas, float pressure, float temp); |
| 48 | |
| 49 | // Given ambient ("0") pressure/density/temperature values, |
| 50 | // calculate the properties of static air (air accelerated to the |
| 51 | // aircraft's speed) at a given velocity. Includes |
| 52 | // compressibility, but not shock effects. |
| 53 | static void calcStaticAir(float p0, float t0, float d0, float v, |
| 54 | float* pOut, float* tOut, float* dOut); |
| 55 | void calcStaticAir(float v, float* pOut, float* tOut, float* dOut); |
| 56 | |
| 57 | static int maxTableIndex(); |
| 58 | |
| 59 | private: |
| 60 | static float getRecord(float alt, Atmosphere::Column recNum); |
| 61 | static float data[][numColumns]; |
| 62 | |
| 63 | float _temperature = 288.11f; |
| 64 | float _pressure = 101325.0f; |
| 65 | float _density = 1.22500f; |
| 66 | }; |
| 67 | |
| 68 | }; // namespace yasim |
| 69 | #endif // _ATMOSPHERE_HPP |