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.31 2011/03/03 12:16:26 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;
85 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 FGTurbine::~FGTurbine()
89 delete IdleThrustLookup;
90 delete MilThrustLookup;
91 delete MaxThrustLookup;
92 delete InjectionLookup;
96 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 void FGTurbine::ResetToIC(void)
101 FGEngine::ResetToIC();
105 correctedTSFC = TSFC;
106 ThrottlePos = AugmentCmd = 0.0;
107 InletPosition = NozzlePosition = 1.0;
108 Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
111 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
113 OilTemp_degK = TAT + 273.0;
116 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 // The main purpose of Calculate() is to determine what phase the engine should
118 // be in, then call the corresponding function.
120 void FGTurbine::Calculate(void)
126 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
127 double qbar = Auxiliary->Getqbar();
128 dt = FDMExec->GetDeltaT() * Propulsion->GetRate();
129 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
130 if (ThrottlePos > 1.0) {
131 AugmentCmd = ThrottlePos - 1.0;
132 ThrottlePos -= AugmentCmd;
137 // When trimming is finished check if user wants engine OFF or RUNNING
138 if ((phase == tpTrim) && (dt > 0)) {
139 if (Running && !Starved) {
141 N2 = IdleN2 + ThrottlePos * N2_factor;
142 N1 = IdleN1 + ThrottlePos * N1_factor;
143 OilTemp_degK = 366.0;
153 if (!Running && Cutoff && Starter) {
154 if (phase == tpOff) phase = tpSpinUp;
158 if ((Starter == true) || (qbar > 30.0)) {
159 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
162 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
163 if (dt == 0) phase = tpTrim;
164 if (Starved) phase = tpOff;
165 if (Stalled) phase = tpStall;
166 if (Seized) phase = tpSeize;
169 case tpOff: thrust = Off(); break;
170 case tpRun: thrust = Run(); break;
171 case tpSpinUp: thrust = SpinUp(); break;
172 case tpStart: thrust = Start(); break;
173 case tpStall: thrust = Stall(); break;
174 case tpSeize: thrust = Seize(); break;
175 case tpTrim: thrust = Trim(); break;
176 default: thrust = Off();
179 Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
184 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 double FGTurbine::Off(void)
188 double qbar = Auxiliary->Getqbar();
190 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
191 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
192 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
193 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
194 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
195 OilPressure_psi = N2 * 0.62;
196 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
197 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
198 Augmentation = false;
203 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
205 double FGTurbine::Run()
207 double idlethrust, milthrust, thrust;
208 double spoolup; // acceleration in pct/sec
209 double sigma = Atmosphere->GetDensityRatio();
210 double T = Atmosphere->GetTemperature();
212 idlethrust = MilThrust * IdleThrustLookup->GetValue();
213 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
218 // adjust acceleration for N2 and atmospheric density
219 double n = N2norm + 0.1;
221 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
223 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
224 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
225 N2norm = (N2 - IdleN2) / N2_factor;
226 thrust = idlethrust + (milthrust * N2norm * N2norm);
227 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
228 OilPressure_psi = N2 * 0.62;
229 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
232 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
233 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 10000.0);
234 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
235 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
236 thrust = thrust * (1.0 - BleedDemand);
237 EPR = 1.0 + thrust/MilThrust;
240 if (AugMethod == 1) {
241 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
242 else {Augmentation = false;}
245 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
246 thrust = MaxThrustLookup->GetValue() * MaxThrust;
247 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
248 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
251 if (AugMethod == 2) {
252 if (AugmentCmd > 0.0) {
254 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
255 thrust += (tdiff * AugmentCmd);
256 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
257 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
259 Augmentation = false;
263 if ((Injected == 1) && Injection) {
264 InjectionTimer += dt;
265 if (InjectionTimer < InjectionTime) {
266 thrust = thrust * InjectionLookup->GetValue();
273 if (Cutoff) phase = tpOff;
274 if (Starved) phase = tpOff;
279 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281 double FGTurbine::SpinUp(void)
285 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
286 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
287 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
288 OilPressure_psi = N2 * 0.62;
289 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
291 NozzlePosition = 1.0;
292 if (Starter == false) phase = tpOff;
296 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 double FGTurbine::Start(void)
300 double qbar = Auxiliary->Getqbar();
301 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
302 Cranking = true; // provided for sound effects signal
304 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
305 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
306 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
307 FuelFlow_pph = IdleFF * N2 / IdleN2;
308 OilPressure_psi = N2 * 0.62;
310 if ((Starter == false) && (qbar < 30.0)) phase = tpOff; // aborted start
319 else { // no start if N2 < 15%
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 double FGTurbine::Stall(void)
331 double qbar = Auxiliary->Getqbar();
332 EGT_degC = TAT + 903.14;
333 FuelFlow_pph = IdleFF;
334 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
335 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
337 if (ThrottlePos < 0.01) {
338 phase = tpRun; // clear the stall with throttle to idle
344 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346 double FGTurbine::Seize(void)
348 double qbar = Auxiliary->Getqbar();
350 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
351 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
353 OilPressure_psi = 0.0;
354 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
359 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 double FGTurbine::Trim()
363 double idlethrust, milthrust, thrust, tdiff;
364 idlethrust = MilThrust * IdleThrustLookup->GetValue();
365 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
366 N2 = IdleN2 + ThrottlePos * N2_factor;
367 N2norm = (N2 - IdleN2) / N2_factor;
368 thrust = (idlethrust + (milthrust * N2norm * N2norm))
369 * (1.0 - BleedDemand);
371 if (AugMethod == 1) {
372 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
373 else {Augmentation = false;}
376 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
377 thrust = MaxThrust * MaxThrustLookup->GetValue();
380 if (AugMethod == 2) {
381 if (AugmentCmd > 0.0) {
382 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
383 thrust += (tdiff * AugmentCmd);
387 if ((Injected == 1) && Injection) {
388 thrust = thrust * InjectionLookup->GetValue();
394 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 double FGTurbine::CalcFuelNeed(void)
398 double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
399 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
400 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
404 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 double FGTurbine::GetPowerAvailable(void) {
407 if( ThrottlePos <= 0.77 )
408 return 64.94*ThrottlePos;
410 return 217.38*ThrottlePos - 117.38;
413 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
419 if (v < target) v = target;
420 } else if (v < target) {
422 if (v > target) v = target;
427 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
431 string property_name, property_prefix;
432 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
434 if (el->FindElement("milthrust"))
435 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
436 if (el->FindElement("maxthrust"))
437 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
438 if (el->FindElement("bypassratio"))
439 BypassRatio = el->FindElementValueAsNumber("bypassratio");
440 if (el->FindElement("bleed"))
441 BleedDemand = el->FindElementValueAsNumber("bleed");
442 if (el->FindElement("tsfc"))
443 TSFC = el->FindElementValueAsNumber("tsfc");
444 if (el->FindElement("atsfc"))
445 ATSFC = el->FindElementValueAsNumber("atsfc");
446 if (el->FindElement("idlen1"))
447 IdleN1 = el->FindElementValueAsNumber("idlen1");
448 if (el->FindElement("idlen2"))
449 IdleN2 = el->FindElementValueAsNumber("idlen2");
450 if (el->FindElement("maxn1"))
451 MaxN1 = el->FindElementValueAsNumber("maxn1");
452 if (el->FindElement("maxn2"))
453 MaxN2 = el->FindElementValueAsNumber("maxn2");
454 if (el->FindElement("n1spinup"))
455 N1_spinup = el->FindElementValueAsNumber("n1spinup");
456 if (el->FindElement("n2spinup"))
457 N2_spinup = el->FindElementValueAsNumber("n2spinup");
458 if (el->FindElement("augmented"))
459 Augmented = (int)el->FindElementValueAsNumber("augmented");
460 if (el->FindElement("augmethod"))
461 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
462 if (el->FindElement("injected"))
463 Injected = (int)el->FindElementValueAsNumber("injected");
464 if (el->FindElement("injection-time"))
465 InjectionTime = el->FindElementValueAsNumber("injection-time");
467 Element *function_element;
469 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
472 function_element = el->FindNextElement("function");
473 if (!function_element) break;
474 name = function_element->GetAttributeValue("name");
475 if (name == "IdleThrust") {
476 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
477 } else if (name == "MilThrust") {
478 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
479 } else if (name == "AugThrust") {
480 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
481 } else if (name == "Injection") {
482 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
486 // Pre-calculations and initializations
488 delay = 90.0 / (BypassRatio + 3.0);
489 N1_factor = MaxN1 - IdleN1;
490 N2_factor = MaxN2 - IdleN2;
491 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
492 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
498 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 string FGTurbine::GetEngineLabels(const string& delimiter)
502 std::ostringstream buf;
504 buf << Name << "_N1[" << EngineNumber << "]" << delimiter
505 << Name << "_N2[" << EngineNumber << "]" << delimiter
506 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
511 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
513 string FGTurbine::GetEngineValues(const string& delimiter)
515 std::ostringstream buf;
517 buf << N1 << delimiter
519 << Thruster->GetThrusterValues(EngineNumber, delimiter);
524 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
526 void FGTurbine::bindmodel()
528 string property_name, base_property_name;
529 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
530 property_name = base_property_name + "/n1";
531 PropertyManager->Tie( property_name.c_str(), &N1);
532 property_name = base_property_name + "/n2";
533 PropertyManager->Tie( property_name.c_str(), &N2);
534 property_name = base_property_name + "/injection_cmd";
535 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
536 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
537 property_name = base_property_name + "/seized";
538 PropertyManager->Tie( property_name.c_str(), &Seized);
539 property_name = base_property_name + "/stalled";
540 PropertyManager->Tie( property_name.c_str(), &Stalled);
541 property_name = base_property_name + "/bleed-factor";
542 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this, &FGTurbine::GetBleedDemand, &FGTurbine::SetBleedDemand);
545 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 int FGTurbine::InitRunning(void) {
548 FDMExec->SuspendIntegration();
553 FDMExec->ResumeIntegration();
557 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
558 // The bitmasked value choices are as follows:
559 // unset: In this case (the default) JSBSim would only print
560 // out the normally expected messages, essentially echoing
561 // the config files as they are read. If the environment
562 // variable is not set, debug_lvl is set to 1 internally
563 // 0: This requests JSBSim not to output any messages
565 // 1: This value explicity requests the normal JSBSim
567 // 2: This value asks for a message to be printed out when
568 // a class is instantiated
569 // 4: When this value is set, a message is displayed when a
570 // FGModel object executes its Run() method
571 // 8: When this value is set, various runtime state variables
572 // are printed out periodically
573 // 16: When set various parameters are sanity checked and
574 // a message is printed out when they go out of bounds
576 void FGTurbine::Debug(int from)
578 if (debug_lvl <= 0) return;
580 if (debug_lvl & 1) { // Standard console startup message output
581 if (from == 0) { // Constructor
584 if (from == 2) { // called from Load()
585 cout << "\n Engine Name: " << Name << endl;
586 cout << " MilThrust: " << MilThrust << endl;
587 cout << " MaxThrust: " << MaxThrust << endl;
588 cout << " BypassRatio: " << BypassRatio << endl;
589 cout << " TSFC: " << TSFC << endl;
590 cout << " ATSFC: " << ATSFC << endl;
591 cout << " IdleN1: " << IdleN1 << endl;
592 cout << " IdleN2: " << IdleN2 << endl;
593 cout << " MaxN1: " << MaxN1 << endl;
594 cout << " MaxN2: " << MaxN2 << endl;
595 cout << " Augmented: " << Augmented << endl;
596 cout << " AugMethod: " << AugMethod << endl;
597 cout << " Injected: " << Injected << endl;
598 cout << " MinThrottle: " << MinThrottle << endl;
603 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
604 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
605 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
607 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
609 if (debug_lvl & 8 ) { // Runtime state variables
611 if (debug_lvl & 16) { // Sanity checking
613 if (debug_lvl & 64) {
614 if (from == 0) { // Constructor
615 cout << IdSrc << endl;
616 cout << IdHdr << endl;