]> git.mxchange.org Git - flightgear.git/commitdiff
Vivian Meazza:
authorehofman <ehofman>
Wed, 22 Sep 2004 19:11:36 +0000 (19:11 +0000)
committerehofman <ehofman>
Wed, 22 Sep 2004 19:11:36 +0000 (19:11 +0000)
The value of rho (air density) varies with height. (Including the upper
stratosphere, ust in case someone wants to model ICBMs.) The standard
atmosphere is used (based on a sea-level temperature of 15 deg C.).

Erik Hofman:
I moved this code over the AIBase::update() so all AIModels can make
use of rho, temperature, pressure, etc.

src/AIModel/AIBallistic.cxx
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/AIModel/AIManager.cxx
src/AIModel/AIManager.hxx
src/AIModel/AIStorm.cxx

index d3ea25a1be4828b187902b1b96105e3f3e666923..590177c310921136e0101ffe5ab83da794bc148c 100644 (file)
@@ -27,7 +27,6 @@
 #include "AIBallistic.hxx"
 
 
-
 FGAIBallistic::FGAIBallistic(FGAIManager* mgr) {
     manager = mgr;
     _type_str = "ballistic";
@@ -122,6 +121,7 @@ void FGAIBallistic::setWeight(double w) {
 }
 
 void FGAIBallistic::Run(double dt) {
+
    life_timer += dt;
    if (life_timer > life) setDie(true); 
 
@@ -130,7 +130,7 @@ void FGAIBallistic::Run(double dt) {
    double wind_speed_from_north_deg_sec;
    double wind_speed_from_east_deg_sec;
    double mass;
-      
+   
    // the drag calculations below assume sea-level density,
    // rho = 0.023780  slugs/ft3
    // calculate mass
@@ -153,7 +153,7 @@ void FGAIBallistic::Run(double dt) {
    speed_east_deg_sec  = sin(hdg / SG_RADIANS_TO_DEGREES) * hs / ft_per_deg_lon;
    
    // if wind not required, set to zero
-   if (!wind){
+   if (!wind) {
       wind_from_north = 0;
       wind_from_east = 0;
    }
index 057f3bc84791f022a6502c3a0b232ebe40074ad5..f082f5176e4e8c8bbf7e637c7d7c582aa6f1f781 100644 (file)
@@ -44,7 +44,7 @@
 #include "AIManager.hxx"
 
 
-const double FGAIBase::rho = 0.023780;  // sea level air density slugs/ft3
+const double FGAIBase::e = 2.71828183;
 const double FGAIBase::lbs_to_slugs = 0.031080950172;   //conversion factor
 
 
@@ -80,6 +80,24 @@ FGAIBase::~FGAIBase() {
 void FGAIBase::update(double dt) {
     ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.lat()/SG_RADIANS_TO_DEGREES);
     ft_per_deg_lon = 365228.16 * cos(pos.lat() / SG_RADIANS_TO_DEGREES);
+
+    // Calculate rho at altitude, using standard atmosphere
+    // For the temperature T and the pressure p,
+
+    if (altitude < 36152) {            // curve fits for the troposphere
+      T = 59 - 0.00356 * altitude;
+      p = 2116 * pow( ((T + 459.7) / 518.6) , 5.256);
+
+    } else if ( 36152 < altitude < 82345 ) {    // lower stratosphere
+      T = -70;
+      p = 473.1 * pow( e , 1.73 - (0.000048 * altitude) );
+
+    } else {                                    //  upper stratosphere
+      T = -205.05 + (0.00164 * altitude);
+      p = 51.97 * pow( ((T + 459.7) / 389.98) , -11.388);
+    }
+
+    rho = p / (1718 * (T + 459.7));
 }
 
 
index 89c7981528b7d49c0a6b173d5d79db615b092305..6b71e2c861e0485b67c4c413083e9b4cce777fd3 100644 (file)
@@ -179,7 +179,10 @@ public:
     double _getY_shift() const;
     double _getRotation() const;
 
-    static const double rho;
+    double rho;
+    double T;                             // temperature, degs farenheit
+    double p;                             // pressure lbs/sq ft
+    static const double e;
     static const double lbs_to_slugs;
 
     int _getID() const;
index 3c25f276e99bfacca2b297a3b9cf5fe89910432a..d6839cf854112fde3dd2392e534d5521b4a9828d 100644 (file)
@@ -90,7 +90,7 @@ void FGAIManager::update(double dt) {
         if (!enabled)
             return;
 
-        _dt = dt;      
+        _dt = dt;
 
         ai_list_itr = ai_list.begin();
         while(ai_list_itr != ai_list.end()) {
@@ -203,8 +203,8 @@ FGAIManager::createBallistic( FGAIModelEntity *entity ) {
         ai_ballistic->setWind_from_north(entity->wind_from_north);
         ai_ballistic->setWind(entity->wind);
         ai_ballistic->setRoll(entity->roll);
-               ai_ballistic->setCd(entity->cd);
-               ai_ballistic->setWeight(entity->weight);
+        ai_ballistic->setCd(entity->cd);
+        ai_ballistic->setWeight(entity->weight);
         ai_ballistic->init();
         ai_ballistic->bind();
         return ai_ballistic;
@@ -214,7 +214,6 @@ void*
 FGAIManager::createStorm( FGAIModelEntity *entity ) {
 
         FGAIStorm* ai_storm = new FGAIStorm(this);
-        ai_list.push_back(ai_storm);
         ++numObjects[0];
         ++numObjects[FGAIBase::otStorm];
         ai_storm->setHeading(entity->heading);
@@ -225,6 +224,7 @@ FGAIManager::createStorm( FGAIModelEntity *entity ) {
         ai_storm->setLatitude(entity->latitude);
         ai_storm->init();
         ai_storm->bind();
+        ai_list.push_back(ai_storm);
         return ai_storm;
 }
 
@@ -232,7 +232,6 @@ void*
 FGAIManager::createThermal( FGAIModelEntity *entity ) {
 
         FGAIThermal* ai_thermal = new FGAIThermal(this);
-        ai_list.push_back(ai_thermal);
         ++numObjects[0];
         ++numObjects[FGAIBase::otThermal];
         ai_thermal->setLongitude(entity->longitude);
@@ -241,6 +240,7 @@ FGAIManager::createThermal( FGAIModelEntity *entity ) {
         ai_thermal->setDiameter(entity->diameter / 6076.11549);
         ai_thermal->init();
         ai_thermal->bind();
+        ai_list.push_back(ai_thermal);
         return ai_thermal;
 }
 
index fd3357f5bb23ac8bf099614ea463777fff897e9f..1e430e8195133ebe4f0d290350a2eea85cbc96f3 100644 (file)
@@ -78,7 +78,9 @@ public:
     inline double get_user_yaw() { return user_yaw; }
     inline double get_user_speed() {return user_speed; }
 
-    inline int getNum( FGAIBase::object_type ot ) { return numObjects[ot]; }
+    inline int getNum( FGAIBase::object_type ot ) {
+      return (0 < ot < FGAIBase::MAX_OBJECTS) ? numObjects[ot] : numObjects[0];
+    }
 
     void processScenario( string filename );
 
index edba9038dc7720b24d4ea6e2a6cde15bf246de97..896253614e5360a8ce9361d0f801dff1af2a0b60 100644 (file)
@@ -36,7 +36,7 @@ SG_USING_STD(string);
 
 FGAIStorm::FGAIStorm(FGAIManager* mgr) {
    manager = mgr;   
-   _type_str = "thunderstorm";
+   _type_str = "storm";
    _otype = otStorm;
 }