1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 Date started: 03/11/2003
6 Purpose: This module models a turbine engine.
8 ------------- Copyright (C) 2003 David Culp (davidculp2@comcast.net) ---------
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
20 You should have received a copy of the GNU Lesser General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
30 This class descends from the FGEngine class and models a turbine engine based
31 on parameters given in the engine config file for this class
34 --------------------------------------------------------------------------------
35 03/11/2003 DPC Created
36 09/08/2003 DPC Changed Calculate() and added engine phases
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGTurbine.h"
45 #include "FGThruster.h"
46 #include "models/FGPropulsion.h"
47 #include "models/FGAuxiliary.h"
48 #include "models/FGAtmosphere.h"
54 static const char *IdSrc = "$Id: FGTurbine.cpp,v 1.27 2010/05/24 11:26:37 jberndt Exp $";
55 static const char *IdHdr = ID_TURBINE;
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number)
63 : FGEngine(exec, el, engine_number)
67 MilThrust = MaxThrust = 10000.0;
72 MaxN1 = MaxN2 = 100.0;
73 Augmented = AugMethod = Injected = 0;
74 BypassRatio = BleedDemand = 0.0;
75 IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
76 N1_spinup = 1.0; N2_spinup = 3.0;
84 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 FGTurbine::~FGTurbine()
88 delete IdleThrustLookup;
89 delete MilThrustLookup;
90 delete MaxThrustLookup;
91 delete InjectionLookup;
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 void FGTurbine::ResetToIC(void)
101 correctedTSFC = TSFC;
102 ThrottlePos = AugmentCmd = 0.0;
103 InletPosition = NozzlePosition = 1.0;
104 Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
107 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
109 OilTemp_degK = TAT + 273.0;
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 // The main purpose of Calculate() is to determine what phase the engine should
114 // be in, then call the corresponding function.
116 double FGTurbine::Calculate(void)
120 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
121 double qbar = Auxiliary->Getqbar();
122 dt = FDMExec->GetDeltaT() * Propulsion->GetRate();
123 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
124 if (ThrottlePos > 1.0) {
125 AugmentCmd = ThrottlePos - 1.0;
126 ThrottlePos -= AugmentCmd;
131 // When trimming is finished check if user wants engine OFF or RUNNING
132 if ((phase == tpTrim) && (dt > 0)) {
133 if (Running && !Starved) {
135 N2 = IdleN2 + ThrottlePos * N2_factor;
136 N1 = IdleN1 + ThrottlePos * N1_factor;
137 OilTemp_degK = 366.0;
147 if (!Running && Cutoff && Starter) {
148 if (phase == tpOff) phase = tpSpinUp;
152 if ((Starter == true) || (qbar > 30.0)) {
153 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
156 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
157 if (dt == 0) phase = tpTrim;
158 if (Starved) phase = tpOff;
159 if (Stalled) phase = tpStall;
160 if (Seized) phase = tpSeize;
163 case tpOff: thrust = Off(); break;
164 case tpRun: thrust = Run(); break;
165 case tpSpinUp: thrust = SpinUp(); break;
166 case tpStart: thrust = Start(); break;
167 case tpStall: thrust = Stall(); break;
168 case tpSeize: thrust = Seize(); break;
169 case tpTrim: thrust = Trim(); break;
170 default: thrust = Off();
173 thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
178 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180 double FGTurbine::Off(void)
182 double qbar = Auxiliary->Getqbar();
184 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
185 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
186 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
187 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
188 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
189 OilPressure_psi = N2 * 0.62;
190 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
191 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
192 Augmentation = false;
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 double FGTurbine::Run()
201 double idlethrust, milthrust, thrust;
202 double spoolup; // acceleration in pct/sec
203 double sigma = Atmosphere->GetDensityRatio();
204 double T = Atmosphere->GetTemperature();
206 idlethrust = MilThrust * IdleThrustLookup->GetValue();
207 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
212 // adjust acceleration for N2 and atmospheric density
213 double n = N2norm + 0.1;
215 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
217 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
218 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
219 N2norm = (N2 - IdleN2) / N2_factor;
220 thrust = idlethrust + (milthrust * N2norm * N2norm);
221 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
222 OilPressure_psi = N2 * 0.62;
223 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
226 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
227 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 10000.0);
228 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
229 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
230 thrust = thrust * (1.0 - BleedDemand);
231 EPR = 1.0 + thrust/MilThrust;
234 if (AugMethod == 1) {
235 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
236 else {Augmentation = false;}
239 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
240 thrust = MaxThrustLookup->GetValue() * MaxThrust;
241 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
242 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
245 if (AugMethod == 2) {
246 if (AugmentCmd > 0.0) {
248 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
249 thrust += (tdiff * AugmentCmd);
250 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
251 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
253 Augmentation = false;
257 if ((Injected == 1) && Injection) {
258 InjectionTimer += dt;
259 if (InjectionTimer < InjectionTime) {
260 thrust = thrust * InjectionLookup->GetValue();
267 if (Cutoff) phase = tpOff;
268 if (Starved) phase = tpOff;
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 double FGTurbine::SpinUp(void)
279 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
280 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
281 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
282 OilPressure_psi = N2 * 0.62;
283 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
285 NozzlePosition = 1.0;
286 if (Starter == false) phase = tpOff;
290 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 double FGTurbine::Start(void)
294 double qbar = Auxiliary->Getqbar();
295 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
296 Cranking = true; // provided for sound effects signal
298 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
299 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
300 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
301 FuelFlow_pph = IdleFF * N2 / IdleN2;
302 OilPressure_psi = N2 * 0.62;
304 if ((Starter == false) && (qbar < 30.0)) phase = tpOff; // aborted start
313 else { // no start if N2 < 15%
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 double FGTurbine::Stall(void)
325 double qbar = Auxiliary->Getqbar();
326 EGT_degC = TAT + 903.14;
327 FuelFlow_pph = IdleFF;
328 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
329 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
331 if (ThrottlePos < 0.01) {
332 phase = tpRun; // clear the stall with throttle to idle
338 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 double FGTurbine::Seize(void)
342 double qbar = Auxiliary->Getqbar();
344 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
345 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
347 OilPressure_psi = 0.0;
348 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
353 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355 double FGTurbine::Trim()
357 double idlethrust, milthrust, thrust, tdiff;
358 idlethrust = MilThrust * IdleThrustLookup->GetValue();
359 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
360 N2 = IdleN2 + ThrottlePos * N2_factor;
361 N2norm = (N2 - IdleN2) / N2_factor;
362 thrust = (idlethrust + (milthrust * N2norm * N2norm))
363 * (1.0 - BleedDemand);
365 if (AugMethod == 1) {
366 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
367 else {Augmentation = false;}
370 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
371 thrust = MaxThrust * MaxThrustLookup->GetValue();
374 if (AugMethod == 2) {
375 if (AugmentCmd > 0.0) {
376 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
377 thrust += (tdiff * AugmentCmd);
381 if ((Injected == 1) && Injection) {
382 thrust = thrust * InjectionLookup->GetValue();
388 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 double FGTurbine::CalcFuelNeed(void)
392 double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
393 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
394 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
398 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400 double FGTurbine::GetPowerAvailable(void) {
401 if( ThrottlePos <= 0.77 )
402 return 64.94*ThrottlePos;
404 return 217.38*ThrottlePos - 117.38;
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
413 if (v < target) v = target;
414 } else if (v < target) {
416 if (v > target) v = target;
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
425 string property_name, property_prefix;
426 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
428 if (el->FindElement("milthrust"))
429 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
430 if (el->FindElement("maxthrust"))
431 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
432 if (el->FindElement("bypassratio"))
433 BypassRatio = el->FindElementValueAsNumber("bypassratio");
434 if (el->FindElement("bleed"))
435 BleedDemand = el->FindElementValueAsNumber("bleed");
436 if (el->FindElement("tsfc"))
437 TSFC = el->FindElementValueAsNumber("tsfc");
438 if (el->FindElement("atsfc"))
439 ATSFC = el->FindElementValueAsNumber("atsfc");
440 if (el->FindElement("idlen1"))
441 IdleN1 = el->FindElementValueAsNumber("idlen1");
442 if (el->FindElement("idlen2"))
443 IdleN2 = el->FindElementValueAsNumber("idlen2");
444 if (el->FindElement("maxn1"))
445 MaxN1 = el->FindElementValueAsNumber("maxn1");
446 if (el->FindElement("maxn2"))
447 MaxN2 = el->FindElementValueAsNumber("maxn2");
448 if (el->FindElement("n1spinup"))
449 N1_spinup = el->FindElementValueAsNumber("n1spinup");
450 if (el->FindElement("n2spinup"))
451 N2_spinup = el->FindElementValueAsNumber("n2spinup");
452 if (el->FindElement("augmented"))
453 Augmented = (int)el->FindElementValueAsNumber("augmented");
454 if (el->FindElement("augmethod"))
455 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
456 if (el->FindElement("injected"))
457 Injected = (int)el->FindElementValueAsNumber("injected");
458 if (el->FindElement("injection-time"))
459 InjectionTime = el->FindElementValueAsNumber("injection-time");
461 Element *function_element;
463 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
466 function_element = el->FindNextElement("function");
467 if (!function_element) break;
468 name = function_element->GetAttributeValue("name");
469 if (name == "IdleThrust") {
470 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
471 } else if (name == "MilThrust") {
472 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
473 } else if (name == "AugThrust") {
474 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
475 } else if (name == "Injection") {
476 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
478 cerr << "Unknown function type: " << name << " in turbine definition." <<
483 // Pre-calculations and initializations
485 delay = 90.0 / (BypassRatio + 3.0);
486 N1_factor = MaxN1 - IdleN1;
487 N2_factor = MaxN2 - IdleN2;
488 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
489 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
495 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
497 string FGTurbine::GetEngineLabels(const string& delimiter)
499 std::ostringstream buf;
501 buf << Name << "_N1[" << EngineNumber << "]" << delimiter
502 << Name << "_N2[" << EngineNumber << "]" << delimiter
503 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
508 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
510 string FGTurbine::GetEngineValues(const string& delimiter)
512 std::ostringstream buf;
514 buf << N1 << delimiter
516 << Thruster->GetThrusterValues(EngineNumber, delimiter);
521 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
523 void FGTurbine::bindmodel()
525 string property_name, base_property_name;
526 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
527 property_name = base_property_name + "/n1";
528 PropertyManager->Tie( property_name.c_str(), &N1);
529 property_name = base_property_name + "/n2";
530 PropertyManager->Tie( property_name.c_str(), &N2);
531 property_name = base_property_name + "/injection_cmd";
532 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
533 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
534 property_name = base_property_name + "/seized";
535 PropertyManager->Tie( property_name.c_str(), &Seized);
536 property_name = base_property_name + "/stalled";
537 PropertyManager->Tie( property_name.c_str(), &Stalled);
540 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
542 int FGTurbine::InitRunning(void) {
543 FDMExec->SuspendIntegration();
548 FDMExec->ResumeIntegration();
552 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 // The bitmasked value choices are as follows:
554 // unset: In this case (the default) JSBSim would only print
555 // out the normally expected messages, essentially echoing
556 // the config files as they are read. If the environment
557 // variable is not set, debug_lvl is set to 1 internally
558 // 0: This requests JSBSim not to output any messages
560 // 1: This value explicity requests the normal JSBSim
562 // 2: This value asks for a message to be printed out when
563 // a class is instantiated
564 // 4: When this value is set, a message is displayed when a
565 // FGModel object executes its Run() method
566 // 8: When this value is set, various runtime state variables
567 // are printed out periodically
568 // 16: When set various parameters are sanity checked and
569 // a message is printed out when they go out of bounds
571 void FGTurbine::Debug(int from)
573 if (debug_lvl <= 0) return;
575 if (debug_lvl & 1) { // Standard console startup message output
576 if (from == 0) { // Constructor
579 if (from == 2) { // called from Load()
580 cout << "\n Engine Name: " << Name << endl;
581 cout << " MilThrust: " << MilThrust << endl;
582 cout << " MaxThrust: " << MaxThrust << endl;
583 cout << " BypassRatio: " << BypassRatio << endl;
584 cout << " TSFC: " << TSFC << endl;
585 cout << " ATSFC: " << ATSFC << endl;
586 cout << " IdleN1: " << IdleN1 << endl;
587 cout << " IdleN2: " << IdleN2 << endl;
588 cout << " MaxN1: " << MaxN1 << endl;
589 cout << " MaxN2: " << MaxN2 << endl;
590 cout << " Augmented: " << Augmented << endl;
591 cout << " AugMethod: " << AugMethod << endl;
592 cout << " Injected: " << Injected << endl;
593 cout << " MinThrottle: " << MinThrottle << endl;
598 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
599 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
600 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
602 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
604 if (debug_lvl & 8 ) { // Runtime state variables
606 if (debug_lvl & 16) { // Sanity checking
608 if (debug_lvl & 64) {
609 if (from == 0) { // Constructor
610 cout << IdSrc << endl;
611 cout << IdHdr << endl;