]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/propulsion/FGTurbine.cpp
Sync. w. JSBSim cvs
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGTurbine.cpp
index 9554e553faf072f105130b55a04126bd250a8b21..d751654a03e7ba68a4f231e78bdc853321878456 100644 (file)
@@ -8,20 +8,20 @@
  ------------- Copyright (C) 2003  David Culp (davidculp2@comcast.net) ---------
 
  This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
+ the terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.
 
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
  details.
 
- You should have received a copy of the GNU General Public License along with
+ You should have received a copy of the GNU Lesser General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place - Suite 330, Boston, MA  02111-1307, USA.
 
- Further information about the GNU General Public License can also be found on
+ Further information about the GNU Lesser General Public License can also be found on
  the world wide web at http://www.gnu.org.
 
 FUNCTIONAL DESCRIPTION
@@ -57,7 +57,20 @@ CLASS IMPLEMENTATION
 FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number)
   : FGEngine(exec, el, engine_number)
 {
-  SetDefaults();
+  Type = etTurbine;
+
+  MilThrust = MaxThrust = 10000.0;
+  TSFC = 0.8;
+  ATSFC = 1.7;
+  IdleN1 = 30.0;
+  IdleN2 = 60.0;
+  MaxN1 = MaxN2 = 100.0;
+  Augmented = AugMethod = Injected = 0;
+  BypassRatio = BleedDemand = 0.0;
+  IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
+  N1_spinup = 1.0; N2_spinup = 3.0; 
+
+  ResetToIC();
 
   Load(exec, el);
   Debug(0);
@@ -67,20 +80,36 @@ FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number)
 
 FGTurbine::~FGTurbine()
 {
-  if (IdleThrustLookup) delete IdleThrustLookup;
-  if (MilThrustLookup) delete MilThrustLookup;
-  if (MaxThrustLookup) delete MaxThrustLookup;
-  if (InjectionLookup) delete InjectionLookup;
-  unbind();
+  delete IdleThrustLookup;
+  delete MilThrustLookup;
+  delete MaxThrustLookup;
+  delete InjectionLookup;
   Debug(1);
 }
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGTurbine::ResetToIC(void)
+{
+  N1 = N2 = 0.0;
+  correctedTSFC = TSFC;
+  ThrottlePos = AugmentCmd = 0.0;
+  InletPosition = NozzlePosition = 1.0;
+  Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
+  Cutoff = true;
+  phase = tpOff;
+  EGT_degC = 0.0;
+  OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
+}
+
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 // The main purpose of Calculate() is to determine what phase the engine should
 // be in, then call the corresponding function.
 
 double FGTurbine::Calculate(void)
 {
+  double thrust;
+
   TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
   dt = State->Getdt() * Propulsion->GetRate();
   ThrottlePos = FCS->GetThrottlePos(EngineNumber);
@@ -118,19 +147,19 @@ double FGTurbine::Calculate(void)
   if (Seized) phase = tpSeize;
 
   switch (phase) {
-    case tpOff:    Thrust = Off(); break;
-    case tpRun:    Thrust = Run(); break;
-    case tpSpinUp: Thrust = SpinUp(); break;
-    case tpStart:  Thrust = Start(); break;
-    case tpStall:  Thrust = Stall(); break;
-    case tpSeize:  Thrust = Seize(); break;
-    case tpTrim:   Thrust = Trim(); break;
-    default: Thrust = Off();
+    case tpOff:    thrust = Off(); break;
+    case tpRun:    thrust = Run(); break;
+    case tpSpinUp: thrust = SpinUp(); break;
+    case tpStart:  thrust = Start(); break;
+    case tpStall:  thrust = Stall(); break;
+    case tpSeize:  thrust = Seize(); break;
+    case tpTrim:   thrust = Trim(); break;
+    default: thrust = Off();
   }
 
-  Thrust = Thruster->Calculate(Thrust); // allow thruster to modify thrust (i.e. reversing)
+  thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
 
-  return Thrust;
+  return thrust;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -148,6 +177,7 @@ double FGTurbine::Off(void)
   NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
   EPR = Seek(&EPR, 1.0, 0.2, 0.2);
   Augmentation = false;
+  ConsumeFuel();  
   return 0.0;
 }
 
@@ -205,7 +235,12 @@ double FGTurbine::Run()
   }
 
   if ((Injected == 1) && Injection) {
-    thrust = thrust * InjectionLookup->GetValue();
+    InjectionTimer += dt;
+    if (InjectionTimer < InjectionTime) {
+       thrust = thrust * InjectionLookup->GetValue();
+    } else {
+       Injection = false;
+    }
   }
 
   ConsumeFuel();
@@ -221,8 +256,8 @@ double FGTurbine::SpinUp(void)
 {
   Running = false;
   FuelFlow_pph = 0.0;
-  N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
-  N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
+  N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
+  N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
   EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
   OilPressure_psi = N2 * 0.62;
   OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
@@ -294,10 +329,12 @@ double FGTurbine::Seize(void)
 
 double FGTurbine::Trim()
 {
-    double idlethrust, milthrust, thrust, tdiff;
+    double idlethrust, milthrust, thrust, tdiff, N2norm;
     idlethrust = MilThrust * IdleThrustLookup->GetValue();
     milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
-    thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos))
+    N2 = IdleN2 + ThrottlePos * N2_factor;
+    N2norm = (N2 - IdleN2) / N2_factor;
+    thrust = (idlethrust + (milthrust * N2norm * N2norm))
           * (1.0 - BleedDemand);
 
     if (AugMethod == 1) {
@@ -327,7 +364,10 @@ double FGTurbine::Trim()
 
 double FGTurbine::CalcFuelNeed(void)
 {
-  return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
+  double dT = State->Getdt() * Propulsion->GetRate();
+  FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
+  FuelExpended = FuelFlowRate * dT;     // Calculates fuel expended in this time step
+  return FuelExpended;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -355,47 +395,10 @@ double FGTurbine::Seek(double *var, double target, double accel, double decel) {
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-void FGTurbine::SetDefaults(void)
-{
-  N1 = N2 = 0.0;
-  Type = etTurbine;
-  MilThrust = 10000.0;
-  MaxThrust = 10000.0;
-  BypassRatio = 0.0;
-  TSFC = 0.8;
-  correctedTSFC = TSFC;
-  ATSFC = 1.7;
-  IdleN1 = 30.0;
-  IdleN2 = 60.0;
-  MaxN1 = 100.0;
-  MaxN2 = 100.0;
-  Augmented = 0;
-  AugMethod = 0;
-  Injected = 0;
-  BleedDemand = 0.0;
-  ThrottlePos = 0.0;
-  AugmentCmd = 0.0;
-  InletPosition = 1.0;
-  NozzlePosition = 1.0;
-  Augmentation = false;
-  Injection = false;
-  Reversed = false;
-  Cutoff = true;
-  phase = tpOff;
-  Stalled = false;
-  Seized = false;
-  Overtemp = false;
-  Fire = false;
-  EGT_degC = 0.0;
-  IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
 {
-  char property_prefix[80];
-  snprintf(property_prefix, 80, "propulsion/engine[%u]/", EngineNumber);
+  string property_name, property_prefix;
+  property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
 
   if (el->FindElement("milthrust"))
     MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
@@ -417,12 +420,18 @@ bool FGTurbine::Load(FGFDMExec* exec, Element *el)
     MaxN1 = el->FindElementValueAsNumber("maxn1");
   if (el->FindElement("maxn2"))
     MaxN2 = el->FindElementValueAsNumber("maxn2");
+  if (el->FindElement("n1spinup"))
+    N1_spinup = el->FindElementValueAsNumber("n1spinup");
+  if (el->FindElement("n2spinup"))
+    N2_spinup = el->FindElementValueAsNumber("n2spinup");
   if (el->FindElement("augmented"))
     Augmented = (int)el->FindElementValueAsNumber("augmented");
   if (el->FindElement("augmethod"))
     AugMethod = (int)el->FindElementValueAsNumber("augmethod");
   if (el->FindElement("injected"))
     Injected = (int)el->FindElementValueAsNumber("injected");
+  if (el->FindElement("injection-time"))
+    InjectionTime = el->FindElementValueAsNumber("injection-time");
 
   Element *function_element;
   string name;
@@ -488,28 +497,27 @@ string FGTurbine::GetEngineValues(string delimeter)
 
 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]/thrust", EngineNumber);
-  PropertyManager->Tie( property_name, this, &FGTurbine::GetThrust);
+  string property_name, base_property_name;
+  base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
+  property_name = base_property_name + "/n1";
+  PropertyManager->Tie( property_name.c_str(), &N1);
+  property_name = base_property_name + "/n2";
+  PropertyManager->Tie( property_name.c_str(), &N2);
+  property_name = base_property_name + "/injection_cmd";
+  PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this, 
+                        &FGTurbine::GetInjection, &FGTurbine::SetInjection);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-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]/thrust", EngineNumber);
-  PropertyManager->Untie(property_name);
+int FGTurbine::InitRunning(void) {
+  State->SuspendIntegration();
+  Cutoff=false;
+  Running=true;  
+  N2=16.0;
+  Calculate();
+  State->ResumeIntegration();
+  return phase==tpRun;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%