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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 #include "FGTurbine.h"
46 #include "FGThruster.h"
52 static const char *IdSrc = "$Id: FGTurbine.cpp,v 1.36 2011/09/25 23:56:11 jentron Exp $";
53 static const char *IdHdr = ID_TURBINE;
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input)
61 : FGEngine(exec, el, engine_number, input)
65 MilThrust = MaxThrust = 10000.0;
70 MaxN1 = MaxN2 = 100.0;
71 Augmented = AugMethod = Injected = 0;
72 BypassRatio = BleedDemand = 0.0;
73 IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
74 N1_spinup = 1.0; N2_spinup = 3.0;
83 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 FGTurbine::~FGTurbine()
87 delete IdleThrustLookup;
88 delete MilThrustLookup;
89 delete MaxThrustLookup;
90 delete InjectionLookup;
94 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 void FGTurbine::ResetToIC(void)
99 FGEngine::ResetToIC();
103 correctedTSFC = TSFC;
105 InletPosition = NozzlePosition = 1.0;
106 Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
109 TAT = (in.TotalTempearture - 491.69) * 0.5555556;
111 OilTemp_degK = TAT + 273.0;
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 // The main purpose of Calculate() is to determine what phase the engine should
116 // be in, then call the corresponding function.
118 void FGTurbine::Calculate(void)
124 ThrottlePos = in.ThrottlePos[EngineNumber];
126 TAT = (in.TotalTempearture - 491.69) * 0.5555556;
127 if (ThrottlePos > 1.0) {
128 AugmentCmd = ThrottlePos - 1.0;
129 ThrottlePos -= AugmentCmd;
134 // When trimming is finished check if user wants engine OFF or RUNNING
135 if ((phase == tpTrim) && (in.TotalDeltaT > 0)) {
136 if (Running && !Starved) {
138 N2 = IdleN2 + ThrottlePos * N2_factor;
139 N1 = IdleN1 + ThrottlePos * N1_factor;
140 OilTemp_degK = 366.0;
150 if (!Running && Cutoff && Starter) {
151 if (phase == tpOff) phase = tpSpinUp;
155 if ((Starter == true) || (in.qbar > 30.0)) {
156 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
159 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
160 if (in.TotalDeltaT == 0) phase = tpTrim;
161 if (Starved) phase = tpOff;
162 if (Stalled) phase = tpStall;
163 if (Seized) phase = tpSeize;
166 case tpOff: thrust = Off(); break;
167 case tpRun: thrust = Run(); break;
168 case tpSpinUp: thrust = SpinUp(); break;
169 case tpStart: thrust = Start(); break;
170 case tpStall: thrust = Stall(); break;
171 case tpSeize: thrust = Seize(); break;
172 case tpTrim: thrust = Trim(); break;
173 default: thrust = Off();
176 Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
181 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 double FGTurbine::Off(void)
186 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
187 N1 = Seek(&N1, in.qbar/10.0, N1/2.0, N1/2.0);
188 N2 = Seek(&N2, in.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;
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 double FGTurbine::Run()
202 double idlethrust, milthrust, thrust;
203 double spoolup; // acceleration in pct/sec
204 double sigma = in.DensityRatio;
205 double T = in.Temperature;
207 idlethrust = MilThrust * IdleThrustLookup->GetValue();
208 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
213 // adjust acceleration for N2 and atmospheric density
214 double n = N2norm + 0.1;
216 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
218 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
219 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
220 N2norm = (N2 - IdleN2) / N2_factor;
221 thrust = idlethrust + (milthrust * N2norm * N2norm);
222 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
223 OilPressure_psi = N2 * 0.62;
224 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
227 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
228 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 10000.0);
229 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
230 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
231 thrust = thrust * (1.0 - BleedDemand);
232 EPR = 1.0 + thrust/MilThrust;
235 if (AugMethod == 1) {
236 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
237 else {Augmentation = false;}
240 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
241 thrust = MaxThrustLookup->GetValue() * MaxThrust;
242 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
243 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
246 if (AugMethod == 2) {
247 if (AugmentCmd > 0.0) {
249 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
250 thrust += (tdiff * AugmentCmd);
251 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
252 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
254 Augmentation = false;
258 if ((Injected == 1) && Injection) {
259 InjectionTimer += in.TotalDeltaT;
260 if (InjectionTimer < InjectionTime) {
261 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 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
295 Cranking = true; // provided for sound effects signal
297 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
298 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
299 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
300 FuelFlow_pph = IdleFF * N2 / IdleN2;
301 OilPressure_psi = N2 * 0.62;
302 if ((Starter == false) && (in.qbar < 30.0)) phase = tpOff; // aborted start
311 else { // no start if N2 < 15%
319 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 double FGTurbine::Stall(void)
323 EGT_degC = TAT + 903.14;
324 FuelFlow_pph = IdleFF;
325 N1 = Seek(&N1, in.qbar/10.0, 0, N1/10.0);
326 N2 = Seek(&N2, in.qbar/15.0, 0, N2/10.0);
327 if (ThrottlePos < 0.01) {
328 phase = tpRun; // clear the stall with throttle to idle
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 double FGTurbine::Seize(void)
339 N1 = Seek(&N1, in.qbar/20.0, 0, N1/15.0);
340 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
341 OilPressure_psi = 0.0;
342 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
347 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 double FGTurbine::Trim()
351 double idlethrust, milthrust, thrust, tdiff, N2, N2norm;
352 idlethrust = MilThrust * IdleThrustLookup->GetValue();
353 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
354 N2 = IdleN2 + ThrottlePos * N2_factor;
355 N2norm = (N2 - IdleN2) / N2_factor;
356 thrust = (idlethrust + (milthrust * N2norm * N2norm))
357 * (1.0 - BleedDemand);
359 if (AugMethod == 1) {
360 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
361 else {Augmentation = false;}
364 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
365 thrust = MaxThrust * MaxThrustLookup->GetValue();
368 if (AugMethod == 2) {
369 if (AugmentCmd > 0.0) {
370 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
371 thrust += (tdiff * AugmentCmd);
375 if ((Injected == 1) && Injection) {
376 thrust = thrust * InjectionLookup->GetValue();
382 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384 double FGTurbine::CalcFuelNeed(void)
386 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
387 FuelExpended = FuelFlowRate * in.TotalDeltaT; // Calculates fuel expended in this time step
388 if (!Starved) FuelUsedLbs += FuelExpended;
392 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394 double FGTurbine::GetPowerAvailable(void) {
395 if( ThrottlePos <= 0.77 )
396 return 64.94*ThrottlePos;
398 return 217.38*ThrottlePos - 117.38;
401 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
403 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
406 v -= in.TotalDeltaT * decel;
407 if (v < target) v = target;
408 } else if (v < target) {
409 v += in.TotalDeltaT * accel;
410 if (v > target) v = target;
415 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
417 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
419 string property_name, property_prefix;
420 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
422 if (el->FindElement("milthrust"))
423 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
424 if (el->FindElement("maxthrust"))
425 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
426 if (el->FindElement("bypassratio"))
427 BypassRatio = el->FindElementValueAsNumber("bypassratio");
428 if (el->FindElement("bleed"))
429 BleedDemand = el->FindElementValueAsNumber("bleed");
430 if (el->FindElement("tsfc"))
431 TSFC = el->FindElementValueAsNumber("tsfc");
432 if (el->FindElement("atsfc"))
433 ATSFC = el->FindElementValueAsNumber("atsfc");
434 if (el->FindElement("idlen1"))
435 IdleN1 = el->FindElementValueAsNumber("idlen1");
436 if (el->FindElement("idlen2"))
437 IdleN2 = el->FindElementValueAsNumber("idlen2");
438 if (el->FindElement("maxn1"))
439 MaxN1 = el->FindElementValueAsNumber("maxn1");
440 if (el->FindElement("maxn2"))
441 MaxN2 = el->FindElementValueAsNumber("maxn2");
442 if (el->FindElement("n1spinup"))
443 N1_spinup = el->FindElementValueAsNumber("n1spinup");
444 if (el->FindElement("n2spinup"))
445 N2_spinup = el->FindElementValueAsNumber("n2spinup");
446 if (el->FindElement("augmented"))
447 Augmented = (int)el->FindElementValueAsNumber("augmented");
448 if (el->FindElement("augmethod"))
449 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
450 if (el->FindElement("injected"))
451 Injected = (int)el->FindElementValueAsNumber("injected");
452 if (el->FindElement("injection-time"))
453 InjectionTime = el->FindElementValueAsNumber("injection-time");
455 Element *function_element;
457 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
460 function_element = el->FindNextElement("function");
461 if (!function_element) break;
462 name = function_element->GetAttributeValue("name");
463 if (name == "IdleThrust") {
464 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
465 } else if (name == "MilThrust") {
466 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
467 } else if (name == "AugThrust") {
468 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
469 } else if (name == "Injection") {
470 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
474 // Pre-calculations and initializations
476 delay = 90.0 / (BypassRatio + 3.0);
477 N1_factor = MaxN1 - IdleN1;
478 N2_factor = MaxN2 - IdleN2;
479 OilTemp_degK = (in.TotalTempearture - 491.69) * 0.5555556 + 273.0;
480 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
486 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
488 string FGTurbine::GetEngineLabels(const string& delimiter)
490 std::ostringstream buf;
492 buf << Name << "_N1[" << EngineNumber << "]" << delimiter
493 << Name << "_N2[" << EngineNumber << "]" << delimiter
494 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
499 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
501 string FGTurbine::GetEngineValues(const string& delimiter)
503 std::ostringstream buf;
505 buf << N1 << delimiter
507 << Thruster->GetThrusterValues(EngineNumber, delimiter);
512 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
514 void FGTurbine::bindmodel()
516 string property_name, base_property_name;
517 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
518 property_name = base_property_name + "/n1";
519 PropertyManager->Tie( property_name.c_str(), &N1);
520 property_name = base_property_name + "/n2";
521 PropertyManager->Tie( property_name.c_str(), &N2);
522 property_name = base_property_name + "/injection_cmd";
523 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
524 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
525 property_name = base_property_name + "/seized";
526 PropertyManager->Tie( property_name.c_str(), &Seized);
527 property_name = base_property_name + "/stalled";
528 PropertyManager->Tie( property_name.c_str(), &Stalled);
529 property_name = base_property_name + "/bleed-factor";
530 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this, &FGTurbine::GetBleedDemand, &FGTurbine::SetBleedDemand);
533 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535 int FGTurbine::InitRunning(void)
537 FDMExec->SuspendIntegration();
542 FDMExec->ResumeIntegration();
546 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547 // The bitmasked value choices are as follows:
548 // unset: In this case (the default) JSBSim would only print
549 // out the normally expected messages, essentially echoing
550 // the config files as they are read. If the environment
551 // variable is not set, debug_lvl is set to 1 internally
552 // 0: This requests JSBSim not to output any messages
554 // 1: This value explicity requests the normal JSBSim
556 // 2: This value asks for a message to be printed out when
557 // a class is instantiated
558 // 4: When this value is set, a message is displayed when a
559 // FGModel object executes its Run() method
560 // 8: When this value is set, various runtime state variables
561 // are printed out periodically
562 // 16: When set various parameters are sanity checked and
563 // a message is printed out when they go out of bounds
565 void FGTurbine::Debug(int from)
567 if (debug_lvl <= 0) return;
569 if (debug_lvl & 1) { // Standard console startup message output
570 if (from == 0) { // Constructor
573 if (from == 2) { // called from Load()
574 cout << "\n Engine Name: " << Name << endl;
575 cout << " MilThrust: " << MilThrust << endl;
576 cout << " MaxThrust: " << MaxThrust << endl;
577 cout << " BypassRatio: " << BypassRatio << endl;
578 cout << " TSFC: " << TSFC << endl;
579 cout << " ATSFC: " << ATSFC << endl;
580 cout << " IdleN1: " << IdleN1 << endl;
581 cout << " IdleN2: " << IdleN2 << endl;
582 cout << " MaxN1: " << MaxN1 << endl;
583 cout << " MaxN2: " << MaxN2 << endl;
584 cout << " Augmented: " << Augmented << endl;
585 cout << " AugMethod: " << AugMethod << endl;
586 cout << " Injected: " << Injected << endl;
587 cout << " MinThrottle: " << MinThrottle << endl;
592 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
593 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
594 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
596 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
598 if (debug_lvl & 8 ) { // Runtime state variables
600 if (debug_lvl & 16) { // Sanity checking
602 if (debug_lvl & 64) {
603 if (from == 0) { // Constructor
604 cout << IdSrc << endl;
605 cout << IdHdr << endl;