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"
49 static const char *IdSrc = "$Id$";
50 static const char *IdHdr = ID_TURBINE;
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number)
58 : FGEngine(exec, el, engine_number)
66 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 FGTurbine::~FGTurbine()
70 delete IdleThrustLookup;
71 delete MilThrustLookup;
72 delete MaxThrustLookup;
73 delete InjectionLookup;
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 // The main purpose of Calculate() is to determine what phase the engine should
80 // be in, then call the corresponding function.
82 double FGTurbine::Calculate(void)
84 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
85 dt = State->Getdt() * Propulsion->GetRate();
86 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
87 if (ThrottlePos > 1.0) {
88 AugmentCmd = ThrottlePos - 1.0;
89 ThrottlePos -= AugmentCmd;
94 // When trimming is finished check if user wants engine OFF or RUNNING
95 if ((phase == tpTrim) && (dt > 0)) {
96 if (Running && !Starved) {
98 N2 = IdleN2 + ThrottlePos * N2_factor;
99 N1 = IdleN1 + ThrottlePos * N1_factor;
100 OilTemp_degK = 366.0;
110 if (!Running && Cutoff && Starter) {
111 if (phase == tpOff) phase = tpSpinUp;
113 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
114 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
115 if (dt == 0) phase = tpTrim;
116 if (Starved) phase = tpOff;
117 if (Stalled) phase = tpStall;
118 if (Seized) phase = tpSeize;
121 case tpOff: Thrust = Off(); break;
122 case tpRun: Thrust = Run(); break;
123 case tpSpinUp: Thrust = SpinUp(); break;
124 case tpStart: Thrust = Start(); break;
125 case tpStall: Thrust = Stall(); break;
126 case tpSeize: Thrust = Seize(); break;
127 case tpTrim: Thrust = Trim(); break;
128 default: Thrust = Off();
131 Thrust = Thruster->Calculate(Thrust); // allow thruster to modify thrust (i.e. reversing)
136 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 double FGTurbine::Off(void)
140 double qbar = Auxiliary->Getqbar();
142 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
143 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
144 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
145 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
146 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
147 OilPressure_psi = N2 * 0.62;
148 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
149 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
150 Augmentation = false;
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 double FGTurbine::Run()
158 double idlethrust, milthrust, thrust;
159 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
161 idlethrust = MilThrust * IdleThrustLookup->GetValue();
162 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
167 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, delay, delay * 3.0);
168 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, delay, delay * 2.4);
169 N2norm = (N2 - IdleN2) / N2_factor;
170 thrust = idlethrust + (milthrust * N2norm * N2norm);
171 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
172 OilPressure_psi = N2 * 0.62;
173 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
176 correctedTSFC = TSFC * (0.84 + (1-N2norm)*(1-N2norm));
177 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
178 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
179 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
180 thrust = thrust * (1.0 - BleedDemand);
181 EPR = 1.0 + thrust/MilThrust;
184 if (AugMethod == 1) {
185 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
186 else {Augmentation = false;}
189 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
190 thrust = MaxThrustLookup->GetValue() * MaxThrust;
191 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
192 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
195 if (AugMethod == 2) {
196 if (AugmentCmd > 0.0) {
198 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
199 thrust += (tdiff * AugmentCmd);
200 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
201 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
203 Augmentation = false;
207 if ((Injected == 1) && Injection) {
208 thrust = thrust * InjectionLookup->GetValue();
212 if (Cutoff) phase = tpOff;
213 if (Starved) phase = tpOff;
218 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 double FGTurbine::SpinUp(void)
224 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
225 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
226 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
227 OilPressure_psi = N2 * 0.62;
228 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
230 NozzlePosition = 1.0;
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 double FGTurbine::Start(void)
238 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
239 Cranking = true; // provided for sound effects signal
241 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
242 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
243 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
244 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
245 OilPressure_psi = N2 * 0.62;
255 else { // no start if N2 < 15%
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 double FGTurbine::Stall(void)
267 double qbar = Auxiliary->Getqbar();
268 EGT_degC = TAT + 903.14;
269 FuelFlow_pph = IdleFF;
270 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
271 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
273 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 double FGTurbine::Seize(void)
282 double qbar = Auxiliary->Getqbar();
284 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
285 FuelFlow_pph = IdleFF;
287 OilPressure_psi = 0.0;
288 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
293 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 double FGTurbine::Trim()
297 double idlethrust, milthrust, thrust, tdiff;
298 idlethrust = MilThrust * IdleThrustLookup->GetValue();
299 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
300 thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos))
301 * (1.0 - BleedDemand);
303 if (AugMethod == 1) {
304 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
305 else {Augmentation = false;}
308 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
309 thrust = MaxThrust * MaxThrustLookup->GetValue();
312 if (AugMethod == 2) {
313 if (AugmentCmd > 0.0) {
314 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
315 thrust += (tdiff * AugmentCmd);
319 if ((Injected == 1) && Injection) {
320 thrust = thrust * InjectionLookup->GetValue();
326 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 double FGTurbine::CalcFuelNeed(void)
330 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
333 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 double FGTurbine::GetPowerAvailable(void) {
336 if( ThrottlePos <= 0.77 )
337 return 64.94*ThrottlePos;
339 return 217.38*ThrottlePos - 117.38;
342 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
348 if (v < target) v = target;
349 } else if (v < target) {
351 if (v > target) v = target;
356 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 void FGTurbine::SetDefaults(void)
366 correctedTSFC = TSFC;
379 NozzlePosition = 1.0;
380 Augmentation = false;
390 IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
397 char property_prefix[80];
398 snprintf(property_prefix, 80, "propulsion/engine[%u]/", EngineNumber);
400 if (el->FindElement("milthrust"))
401 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
402 if (el->FindElement("maxthrust"))
403 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
404 if (el->FindElement("bypassratio"))
405 BypassRatio = el->FindElementValueAsNumber("bypassratio");
406 if (el->FindElement("bleed"))
407 BleedDemand = el->FindElementValueAsNumber("bleed");
408 if (el->FindElement("tsfc"))
409 TSFC = el->FindElementValueAsNumber("tsfc");
410 if (el->FindElement("atsfc"))
411 ATSFC = el->FindElementValueAsNumber("atsfc");
412 if (el->FindElement("idlen1"))
413 IdleN1 = el->FindElementValueAsNumber("idlen1");
414 if (el->FindElement("idlen2"))
415 IdleN2 = el->FindElementValueAsNumber("idlen2");
416 if (el->FindElement("maxn1"))
417 MaxN1 = el->FindElementValueAsNumber("maxn1");
418 if (el->FindElement("maxn2"))
419 MaxN2 = el->FindElementValueAsNumber("maxn2");
420 if (el->FindElement("augmented"))
421 Augmented = (int)el->FindElementValueAsNumber("augmented");
422 if (el->FindElement("augmethod"))
423 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
424 if (el->FindElement("injected"))
425 Injected = (int)el->FindElementValueAsNumber("injected");
427 Element *function_element;
429 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
432 function_element = el->FindNextElement("function");
433 if (!function_element) break;
434 name = function_element->GetAttributeValue("name");
435 if (name == "IdleThrust") {
436 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
437 } else if (name == "MilThrust") {
438 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
439 } else if (name == "AugThrust") {
440 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
441 } else if (name == "Injection") {
442 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
444 cerr << "Unknown function type: " << name << " in turbine definition." <<
449 // Pre-calculations and initializations
451 delay = 60.0 / (BypassRatio + 3.0);
452 N1_factor = MaxN1 - IdleN1;
453 N2_factor = MaxN2 - IdleN2;
454 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
455 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
461 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463 string FGTurbine::GetEngineLabels(string delimeter)
465 std::ostringstream buf;
467 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
468 << Name << "_N2[" << EngineNumber << "]" << delimeter
469 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
474 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476 string FGTurbine::GetEngineValues(string delimeter)
478 std::ostringstream buf;
480 buf << N1 << delimeter
482 << Thruster->GetThrusterValues(EngineNumber, delimeter);
487 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489 void FGTurbine::bindmodel()
491 char property_name[80];
493 snprintf(property_name, 80, "propulsion/engine[%u]/n1", EngineNumber);
494 PropertyManager->Tie( property_name, &N1);
495 snprintf(property_name, 80, "propulsion/engine[%u]/n2", EngineNumber);
496 PropertyManager->Tie( property_name, &N2);
497 snprintf(property_name, 80, "propulsion/engine[%u]/thrust", EngineNumber);
498 PropertyManager->Tie( property_name, this, &FGTurbine::GetThrust);
501 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503 void FGTurbine::unbind()
505 char property_name[80];
507 snprintf(property_name, 80, "propulsion/engine[%u]/n1", EngineNumber);
508 PropertyManager->Untie(property_name);
509 snprintf(property_name, 80, "propulsion/engine[%u]/n2", EngineNumber);
510 PropertyManager->Untie(property_name);
511 snprintf(property_name, 80, "propulsion/engine[%u]/thrust", EngineNumber);
512 PropertyManager->Untie(property_name);
515 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
516 // The bitmasked value choices are as follows:
517 // unset: In this case (the default) JSBSim would only print
518 // out the normally expected messages, essentially echoing
519 // the config files as they are read. If the environment
520 // variable is not set, debug_lvl is set to 1 internally
521 // 0: This requests JSBSim not to output any messages
523 // 1: This value explicity requests the normal JSBSim
525 // 2: This value asks for a message to be printed out when
526 // a class is instantiated
527 // 4: When this value is set, a message is displayed when a
528 // FGModel object executes its Run() method
529 // 8: When this value is set, various runtime state variables
530 // are printed out periodically
531 // 16: When set various parameters are sanity checked and
532 // a message is printed out when they go out of bounds
534 void FGTurbine::Debug(int from)
536 if (debug_lvl <= 0) return;
538 if (debug_lvl & 1) { // Standard console startup message output
539 if (from == 0) { // Constructor
542 if (from == 2) { // called from Load()
543 cout << "\n Engine Name: " << Name << endl;
544 cout << " MilThrust: " << MilThrust << endl;
545 cout << " MaxThrust: " << MaxThrust << endl;
546 cout << " BypassRatio: " << BypassRatio << endl;
547 cout << " TSFC: " << TSFC << endl;
548 cout << " ATSFC: " << ATSFC << endl;
549 cout << " IdleN1: " << IdleN1 << endl;
550 cout << " IdleN2: " << IdleN2 << endl;
551 cout << " MaxN1: " << MaxN1 << endl;
552 cout << " MaxN2: " << MaxN2 << endl;
553 cout << " Augmented: " << Augmented << endl;
554 cout << " AugMethod: " << AugMethod << endl;
555 cout << " Injected: " << Injected << endl;
556 cout << " MinThrottle: " << MinThrottle << endl;
561 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
562 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
563 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
565 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
567 if (debug_lvl & 8 ) { // Runtime state variables
569 if (debug_lvl & 16) { // Sanity checking
571 if (debug_lvl & 64) {
572 if (from == 0) { // Constructor
573 cout << IdSrc << endl;
574 cout << IdHdr << endl;