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.29 2010/08/31 04:01:32 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 void FGTurbine::Calculate(void)
122 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
123 double qbar = Auxiliary->Getqbar();
124 dt = FDMExec->GetDeltaT() * Propulsion->GetRate();
125 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
126 if (ThrottlePos > 1.0) {
127 AugmentCmd = ThrottlePos - 1.0;
128 ThrottlePos -= AugmentCmd;
133 // When trimming is finished check if user wants engine OFF or RUNNING
134 if ((phase == tpTrim) && (dt > 0)) {
135 if (Running && !Starved) {
137 N2 = IdleN2 + ThrottlePos * N2_factor;
138 N1 = IdleN1 + ThrottlePos * N1_factor;
139 OilTemp_degK = 366.0;
149 if (!Running && Cutoff && Starter) {
150 if (phase == tpOff) phase = tpSpinUp;
154 if ((Starter == true) || (qbar > 30.0)) {
155 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
158 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
159 if (dt == 0) phase = tpTrim;
160 if (Starved) phase = tpOff;
161 if (Stalled) phase = tpStall;
162 if (Seized) phase = tpSeize;
165 case tpOff: thrust = Off(); break;
166 case tpRun: thrust = Run(); break;
167 case tpSpinUp: thrust = SpinUp(); break;
168 case tpStart: thrust = Start(); break;
169 case tpStall: thrust = Stall(); break;
170 case tpSeize: thrust = Seize(); break;
171 case tpTrim: thrust = Trim(); break;
172 default: thrust = Off();
175 Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
180 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182 double FGTurbine::Off(void)
184 double qbar = Auxiliary->Getqbar();
186 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
187 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
188 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
189 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
190 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
191 OilPressure_psi = N2 * 0.62;
192 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
193 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
194 Augmentation = false;
199 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 double FGTurbine::Run()
203 double idlethrust, milthrust, thrust;
204 double spoolup; // acceleration in pct/sec
205 double sigma = Atmosphere->GetDensityRatio();
206 double T = Atmosphere->GetTemperature();
208 idlethrust = MilThrust * IdleThrustLookup->GetValue();
209 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
214 // adjust acceleration for N2 and atmospheric density
215 double n = N2norm + 0.1;
217 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
219 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
220 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
221 N2norm = (N2 - IdleN2) / N2_factor;
222 thrust = idlethrust + (milthrust * N2norm * N2norm);
223 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
224 OilPressure_psi = N2 * 0.62;
225 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
228 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
229 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 10000.0);
230 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
231 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
232 thrust = thrust * (1.0 - BleedDemand);
233 EPR = 1.0 + thrust/MilThrust;
236 if (AugMethod == 1) {
237 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
238 else {Augmentation = false;}
241 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
242 thrust = MaxThrustLookup->GetValue() * MaxThrust;
243 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
244 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
247 if (AugMethod == 2) {
248 if (AugmentCmd > 0.0) {
250 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
251 thrust += (tdiff * AugmentCmd);
252 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
253 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
255 Augmentation = false;
259 if ((Injected == 1) && Injection) {
260 InjectionTimer += dt;
261 if (InjectionTimer < InjectionTime) {
262 thrust = thrust * InjectionLookup->GetValue();
269 if (Cutoff) phase = tpOff;
270 if (Starved) phase = tpOff;
275 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277 double FGTurbine::SpinUp(void)
281 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
282 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
283 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
284 OilPressure_psi = N2 * 0.62;
285 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
287 NozzlePosition = 1.0;
288 if (Starter == false) phase = tpOff;
292 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 double FGTurbine::Start(void)
296 double qbar = Auxiliary->Getqbar();
297 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
298 Cranking = true; // provided for sound effects signal
300 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
301 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
302 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
303 FuelFlow_pph = IdleFF * N2 / IdleN2;
304 OilPressure_psi = N2 * 0.62;
306 if ((Starter == false) && (qbar < 30.0)) phase = tpOff; // aborted start
315 else { // no start if N2 < 15%
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 double FGTurbine::Stall(void)
327 double qbar = Auxiliary->Getqbar();
328 EGT_degC = TAT + 903.14;
329 FuelFlow_pph = IdleFF;
330 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
331 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
333 if (ThrottlePos < 0.01) {
334 phase = tpRun; // clear the stall with throttle to idle
340 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342 double FGTurbine::Seize(void)
344 double qbar = Auxiliary->Getqbar();
346 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
347 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
349 OilPressure_psi = 0.0;
350 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
355 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 double FGTurbine::Trim()
359 double idlethrust, milthrust, thrust, tdiff;
360 idlethrust = MilThrust * IdleThrustLookup->GetValue();
361 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
362 N2 = IdleN2 + ThrottlePos * N2_factor;
363 N2norm = (N2 - IdleN2) / N2_factor;
364 thrust = (idlethrust + (milthrust * N2norm * N2norm))
365 * (1.0 - BleedDemand);
367 if (AugMethod == 1) {
368 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
369 else {Augmentation = false;}
372 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
373 thrust = MaxThrust * MaxThrustLookup->GetValue();
376 if (AugMethod == 2) {
377 if (AugmentCmd > 0.0) {
378 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
379 thrust += (tdiff * AugmentCmd);
383 if ((Injected == 1) && Injection) {
384 thrust = thrust * InjectionLookup->GetValue();
390 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 double FGTurbine::CalcFuelNeed(void)
394 double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
395 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
396 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
400 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 double FGTurbine::GetPowerAvailable(void) {
403 if( ThrottlePos <= 0.77 )
404 return 64.94*ThrottlePos;
406 return 217.38*ThrottlePos - 117.38;
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
415 if (v < target) v = target;
416 } else if (v < target) {
418 if (v > target) v = target;
423 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
425 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
427 string property_name, property_prefix;
428 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
430 if (el->FindElement("milthrust"))
431 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
432 if (el->FindElement("maxthrust"))
433 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
434 if (el->FindElement("bypassratio"))
435 BypassRatio = el->FindElementValueAsNumber("bypassratio");
436 if (el->FindElement("bleed"))
437 BleedDemand = el->FindElementValueAsNumber("bleed");
438 if (el->FindElement("tsfc"))
439 TSFC = el->FindElementValueAsNumber("tsfc");
440 if (el->FindElement("atsfc"))
441 ATSFC = el->FindElementValueAsNumber("atsfc");
442 if (el->FindElement("idlen1"))
443 IdleN1 = el->FindElementValueAsNumber("idlen1");
444 if (el->FindElement("idlen2"))
445 IdleN2 = el->FindElementValueAsNumber("idlen2");
446 if (el->FindElement("maxn1"))
447 MaxN1 = el->FindElementValueAsNumber("maxn1");
448 if (el->FindElement("maxn2"))
449 MaxN2 = el->FindElementValueAsNumber("maxn2");
450 if (el->FindElement("n1spinup"))
451 N1_spinup = el->FindElementValueAsNumber("n1spinup");
452 if (el->FindElement("n2spinup"))
453 N2_spinup = el->FindElementValueAsNumber("n2spinup");
454 if (el->FindElement("augmented"))
455 Augmented = (int)el->FindElementValueAsNumber("augmented");
456 if (el->FindElement("augmethod"))
457 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
458 if (el->FindElement("injected"))
459 Injected = (int)el->FindElementValueAsNumber("injected");
460 if (el->FindElement("injection-time"))
461 InjectionTime = el->FindElementValueAsNumber("injection-time");
463 Element *function_element;
465 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
468 function_element = el->FindNextElement("function");
469 if (!function_element) break;
470 name = function_element->GetAttributeValue("name");
471 if (name == "IdleThrust") {
472 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
473 } else if (name == "MilThrust") {
474 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
475 } else if (name == "AugThrust") {
476 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
477 } else if (name == "Injection") {
478 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
482 // Pre-calculations and initializations
484 delay = 90.0 / (BypassRatio + 3.0);
485 N1_factor = MaxN1 - IdleN1;
486 N2_factor = MaxN2 - IdleN2;
487 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
488 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
494 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
496 string FGTurbine::GetEngineLabels(const string& delimiter)
498 std::ostringstream buf;
500 buf << Name << "_N1[" << EngineNumber << "]" << delimiter
501 << Name << "_N2[" << EngineNumber << "]" << delimiter
502 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
507 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 string FGTurbine::GetEngineValues(const string& delimiter)
511 std::ostringstream buf;
513 buf << N1 << delimiter
515 << Thruster->GetThrusterValues(EngineNumber, delimiter);
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
522 void FGTurbine::bindmodel()
524 string property_name, base_property_name;
525 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
526 property_name = base_property_name + "/n1";
527 PropertyManager->Tie( property_name.c_str(), &N1);
528 property_name = base_property_name + "/n2";
529 PropertyManager->Tie( property_name.c_str(), &N2);
530 property_name = base_property_name + "/injection_cmd";
531 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
532 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
533 property_name = base_property_name + "/seized";
534 PropertyManager->Tie( property_name.c_str(), &Seized);
535 property_name = base_property_name + "/stalled";
536 PropertyManager->Tie( property_name.c_str(), &Stalled);
539 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 int FGTurbine::InitRunning(void) {
542 FDMExec->SuspendIntegration();
547 FDMExec->ResumeIntegration();
551 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
552 // The bitmasked value choices are as follows:
553 // unset: In this case (the default) JSBSim would only print
554 // out the normally expected messages, essentially echoing
555 // the config files as they are read. If the environment
556 // variable is not set, debug_lvl is set to 1 internally
557 // 0: This requests JSBSim not to output any messages
559 // 1: This value explicity requests the normal JSBSim
561 // 2: This value asks for a message to be printed out when
562 // a class is instantiated
563 // 4: When this value is set, a message is displayed when a
564 // FGModel object executes its Run() method
565 // 8: When this value is set, various runtime state variables
566 // are printed out periodically
567 // 16: When set various parameters are sanity checked and
568 // a message is printed out when they go out of bounds
570 void FGTurbine::Debug(int from)
572 if (debug_lvl <= 0) return;
574 if (debug_lvl & 1) { // Standard console startup message output
575 if (from == 0) { // Constructor
578 if (from == 2) { // called from Load()
579 cout << "\n Engine Name: " << Name << endl;
580 cout << " MilThrust: " << MilThrust << endl;
581 cout << " MaxThrust: " << MaxThrust << endl;
582 cout << " BypassRatio: " << BypassRatio << endl;
583 cout << " TSFC: " << TSFC << endl;
584 cout << " ATSFC: " << ATSFC << endl;
585 cout << " IdleN1: " << IdleN1 << endl;
586 cout << " IdleN2: " << IdleN2 << endl;
587 cout << " MaxN1: " << MaxN1 << endl;
588 cout << " MaxN2: " << MaxN2 << endl;
589 cout << " Augmented: " << Augmented << endl;
590 cout << " AugMethod: " << AugMethod << endl;
591 cout << " Injected: " << Injected << endl;
592 cout << " MinThrottle: " << MinThrottle << endl;
597 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
598 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
599 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
601 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
603 if (debug_lvl & 8 ) { // Runtime state variables
605 if (debug_lvl & 16) { // Sanity checking
607 if (debug_lvl & 64) {
608 if (from == 0) { // Constructor
609 cout << IdSrc << endl;
610 cout << IdHdr << endl;