]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGTurbine.cpp
Fix stall widths for the "auxilliary" (reverse flow) stalls so they
[flightgear.git] / src / FDM / JSBSim / FGTurbine.cpp
index 437b04917e10ba085dcc502429972b5c546dd53b..d43031b38252f26c9e64c9b2d07439f10f57273a 100644 (file)
@@ -54,7 +54,8 @@ CLASS IMPLEMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 
-FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
+FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg, int engine_number)
+  : FGEngine(exec, engine_number)
 {
   SetDefaults();
 
@@ -66,6 +67,7 @@ FGTurbine::FGTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
 
 FGTurbine::~FGTurbine()
 {
+  unbind();
   Debug(1);
 }
 
@@ -122,7 +124,8 @@ double FGTurbine::Calculate(void)
     default: Thrust = Off();
   }
 
-  return Thruster->Calculate(Thrust);
+  // The thruster can modify the thrust, eg. thrust reverser
+  return Thrust = Thruster->Calculate(Thrust);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -164,7 +167,7 @@ double FGTurbine::Run(void)
   OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
 
   if (!Augmentation) {
-    double correctedTSFC = TSFC + TSFC - (N2norm * TSFC);
+    double correctedTSFC = TSFC * (0.84 + (1-N2norm)*(1-N2norm));
     FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
     if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
     NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
@@ -183,18 +186,21 @@ double FGTurbine::Run(void)
     NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
   }
 
-  if ((AugmentCmd > 0.0) && (AugMethod == 2)) {
-    Augmentation = true;
-    double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
-    thrust += (tdiff * AugmentCmd);
-    FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
-    NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
-  } else {
-    Augmentation = false;
+  if (AugMethod == 2) {
+    if (AugmentCmd > 0.0) {
+      Augmentation = true;
+      double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
+      thrust += (tdiff * AugmentCmd);
+      FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
+      NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
+    } else {
+      Augmentation = false;
+    }
   }
 
-  if ((Injected == 1) && Injection)
-    thrust = thrust * ThrustTables[3]->TotalValue();
+  if ((Injected == 1) && Injection) {
+     thrust = thrust * ThrustTables[3]->TotalValue();
+  }
 
   ConsumeFuel();
   if (Cutoff) phase = tpOff;
@@ -231,6 +237,7 @@ double FGTurbine::Start(void)
       EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
       FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
       OilPressure_psi = N2 * 0.62;
+      ConsumeFuel();
       }
     else {
       phase = tpRun;
@@ -256,6 +263,7 @@ double FGTurbine::Stall(void)
   FuelFlow_pph = IdleFF;
   N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
   N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
+  ConsumeFuel();
   if (ThrottlePos < 0.01) phase = tpRun;        // clear the stall with throttle
 
   return 0.0;
@@ -269,6 +277,7 @@ double FGTurbine::Seize(void)
     N2 = 0.0;
     N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
     FuelFlow_pph = IdleFF;
+    ConsumeFuel();
     OilPressure_psi = 0.0;
     OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
     Running = false;
@@ -280,13 +289,15 @@ double FGTurbine::Seize(void)
 double FGTurbine::Trim(void)
 {
     double idlethrust, milthrust, thrust, tdiff;
-    idlethrust = MilThrust * ThrustTables[0]->TotalValue();
+    idlethrust = MilThrust * ThrustTables[0]->TotalValue();;
     milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
-    thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos)) * (1.0 - BleedDemand);
+    thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos))
+          * (1.0 - BleedDemand);
     if (AugmentCmd > 0.0) {
       tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
       thrust += (tdiff * AugmentCmd);
-      }
+    } 
+
     return thrust;
 }
 
@@ -392,6 +403,7 @@ bool FGTurbine::Load(FGConfigFile *Eng_cfg)
       ThrustTables.back()->Load(Eng_cfg);
     }
     else cerr << "Unhandled token in Engine config file: " << token << endl;
+    if (token == "EOF") return false;
   }
 
   // Pre-calculations and initializations
@@ -402,35 +414,64 @@ bool FGTurbine::Load(FGConfigFile *Eng_cfg)
   OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
   IdleFF = pow(MilThrust, 0.2) * 107.0;  // just an estimate
 
+  bindmodel();
   return true;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGTurbine::GetEngineLabels(void)
+string FGTurbine::GetEngineLabels(string delimeter)
 {
   std::ostringstream buf;
 
-  buf << Name << "_N1[" << EngineNumber << "], "
-      << Name << "_N2[" << EngineNumber << "], "
-      << Thruster->GetThrusterLabels(EngineNumber);
+  buf << Name << "_N1[" << EngineNumber << "]" << delimeter
+      << Name << "_N2[" << EngineNumber << "]" << delimeter
+      << Thruster->GetThrusterLabels(EngineNumber, delimeter);
 
   return buf.str();
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGTurbine::GetEngineValues(void)
+string FGTurbine::GetEngineValues(string delimeter)
 {
   std::ostringstream buf;
 
-  buf << N1 << ", "
-      << N2 << ", "
-      << Thruster->GetThrusterValues(EngineNumber);
+  buf << N1 << delimeter
+      << N2 << delimeter
+      << Thruster->GetThrusterValues(EngineNumber, delimeter);
 
   return buf.str();
 }
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGTurbine::bindmodel()
+{
+  char property_name[80];
+
+  snprintf(property_name, 80, "propulsion/engine[%u]/n1", EngineNumber);
+  PropertyManager->Tie( property_name, &N1);
+  snprintf(property_name, 80, "propulsion/engine[%u]/n2", EngineNumber);
+  PropertyManager->Tie( property_name, &N2);
+  snprintf(property_name, 80, "propulsion/engine[%u]/fuel-flow", EngineNumber);
+  PropertyManager->Tie( property_name, &FuelFlow_pph);
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGTurbine::unbind()
+{
+  char property_name[80];
+
+  snprintf(property_name, 80, "propulsion/engine[%u]/n1", EngineNumber);
+  PropertyManager->Untie(property_name);
+  snprintf(property_name, 80, "propulsion/engine[%u]/n2", EngineNumber);
+  PropertyManager->Untie(property_name);
+  snprintf(property_name, 80, "propulsion/engine[%u]/fuel-flow", EngineNumber);
+  PropertyManager->Untie( property_name);
+}
+
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 //    The bitmasked value choices are as follows:
 //    unset: In this case (the default) JSBSim would only print