]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Atmosphere.cpp
Moved JSBSim.hxx to src/FDM/JSBSim/
[flightgear.git] / src / FDM / YASim / Atmosphere.cpp
index 7e532dd654a7b87d519ab9d0ecb9a01f47ddcce2..0ace3869fa2a3d59ae7776787187a0b879a5de29 100644 (file)
@@ -31,6 +31,13 @@ float Atmosphere::data[][4] = {{ 0,     288.20, 101325, 1.22500 },
                               { 18000, 216.66,   7565, 0.12165 },
                               { 18900, 216.66,   6570, 0.10564 }};
 
+// Universal gas constant for air, in SI units.  P = R * rho * T.
+// P in pascals (N/m^2), rho is kg/m^3, T in kelvin.
+const float R = 287.1;
+
+// Specific heat ratio for air, at "low" temperatures.  
+const float GAMMA = 1.4;
+
 float Atmosphere::getStdTemperature(float alt)
 {
     return getRecord(alt, 1);
@@ -48,7 +55,9 @@ float Atmosphere::getStdDensity(float alt)
 
 float Atmosphere::calcVEAS(float spd, float pressure, float temp)
 {
-    return 0; //FIXME
+    static float rho0 = getStdDensity(0);
+    float densityRatio = calcDensity(pressure, temp) / rho0;
+    return spd * Math::sqrt(densityRatio);
 }
 
 float Atmosphere::calcVCAS(float spd, float pressure, float temp)
@@ -84,13 +93,23 @@ float Atmosphere::calcVCAS(float spd, float pressure, float temp)
 
 float Atmosphere::calcDensity(float pressure, float temp)
 {
-    // P = rho*R*T, R == 287 kPa*m^3 per kg*kelvin for air
-    return pressure / (287 * temp);
+    return pressure / (R * temp);
 }
 
 float Atmosphere::calcMach(float spd, float temp)
 {
-    return spd / Math::sqrt(1.4 * 287 * temp);
+    return spd / Math::sqrt(GAMMA * R * temp);
+}
+
+void Atmosphere::calcStaticAir(float p0, float t0, float d0, float v,
+                               float* pOut, float* tOut, float* dOut)
+{
+    const static float C0 = ((GAMMA-1)/(2*R*GAMMA));
+    const static float C1 = 1/(GAMMA-1);
+
+    *tOut = t0 + (v*v) * C0;
+    *dOut = d0 * Math::pow(*tOut / t0, C1);
+    *pOut = (*dOut) * R * (*tOut);
 }
 
 float Atmosphere::getRecord(float alt, int recNum)