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)
62 MilThrust = MaxThrust = 10000.0;
67 MaxN1 = MaxN2 = 100.0;
68 Augmented = AugMethod = Injected = 0;
69 BypassRatio = BleedDemand = 0.0;
70 IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
71 N1_spinup = 1.0; N2_spinup = 3.0;
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 FGTurbine::~FGTurbine()
83 delete IdleThrustLookup;
84 delete MilThrustLookup;
85 delete MaxThrustLookup;
86 delete InjectionLookup;
90 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 void FGTurbine::ResetToIC(void)
97 ThrottlePos = AugmentCmd = 0.0;
98 InletPosition = NozzlePosition = 1.0;
99 Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
103 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
106 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 // The main purpose of Calculate() is to determine what phase the engine should
108 // be in, then call the corresponding function.
110 double FGTurbine::Calculate(void)
114 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
115 dt = State->Getdt() * Propulsion->GetRate();
116 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
117 if (ThrottlePos > 1.0) {
118 AugmentCmd = ThrottlePos - 1.0;
119 ThrottlePos -= AugmentCmd;
124 // When trimming is finished check if user wants engine OFF or RUNNING
125 if ((phase == tpTrim) && (dt > 0)) {
126 if (Running && !Starved) {
128 N2 = IdleN2 + ThrottlePos * N2_factor;
129 N1 = IdleN1 + ThrottlePos * N1_factor;
130 OilTemp_degK = 366.0;
140 if (!Running && Cutoff && Starter) {
141 if (phase == tpOff) phase = tpSpinUp;
143 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
144 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
145 if (dt == 0) phase = tpTrim;
146 if (Starved) phase = tpOff;
147 if (Stalled) phase = tpStall;
148 if (Seized) phase = tpSeize;
151 case tpOff: thrust = Off(); break;
152 case tpRun: thrust = Run(); break;
153 case tpSpinUp: thrust = SpinUp(); break;
154 case tpStart: thrust = Start(); break;
155 case tpStall: thrust = Stall(); break;
156 case tpSeize: thrust = Seize(); break;
157 case tpTrim: thrust = Trim(); break;
158 default: thrust = Off();
161 thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 double FGTurbine::Off(void)
170 double qbar = Auxiliary->Getqbar();
172 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
173 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
174 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
175 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
176 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
177 OilPressure_psi = N2 * 0.62;
178 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
179 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
180 Augmentation = false;
185 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 double FGTurbine::Run()
189 double idlethrust, milthrust, thrust;
190 double spoolup; // acceleration in pct/sec
191 double sigma = Atmosphere->GetDensityRatio();
192 double T = Atmosphere->GetTemperature();
194 idlethrust = MilThrust * IdleThrustLookup->GetValue();
195 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
200 // adjust acceleration for N2 and atmospheric density
201 double n = N2norm + 0.1;
203 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
205 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
206 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
207 N2norm = (N2 - IdleN2) / N2_factor;
208 thrust = idlethrust + (milthrust * N2norm * N2norm);
209 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
210 OilPressure_psi = N2 * 0.62;
211 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
214 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
215 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
216 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
217 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
218 thrust = thrust * (1.0 - BleedDemand);
219 EPR = 1.0 + thrust/MilThrust;
222 if (AugMethod == 1) {
223 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
224 else {Augmentation = false;}
227 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
228 thrust = MaxThrustLookup->GetValue() * MaxThrust;
229 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
230 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
233 if (AugMethod == 2) {
234 if (AugmentCmd > 0.0) {
236 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
237 thrust += (tdiff * AugmentCmd);
238 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
239 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
241 Augmentation = false;
245 if ((Injected == 1) && Injection) {
246 InjectionTimer += dt;
247 if (InjectionTimer < InjectionTime) {
248 thrust = thrust * InjectionLookup->GetValue();
255 if (Cutoff) phase = tpOff;
256 if (Starved) phase = tpOff;
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 double FGTurbine::SpinUp(void)
267 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
268 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
269 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
270 OilPressure_psi = N2 * 0.62;
271 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
273 NozzlePosition = 1.0;
277 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 double FGTurbine::Start(void)
281 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
282 Cranking = true; // provided for sound effects signal
284 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
285 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
286 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
287 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
288 OilPressure_psi = N2 * 0.62;
298 else { // no start if N2 < 15%
306 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308 double FGTurbine::Stall(void)
310 double qbar = Auxiliary->Getqbar();
311 EGT_degC = TAT + 903.14;
312 FuelFlow_pph = IdleFF;
313 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
314 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
316 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 double FGTurbine::Seize(void)
325 double qbar = Auxiliary->Getqbar();
327 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
328 FuelFlow_pph = IdleFF;
330 OilPressure_psi = 0.0;
331 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
336 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 double FGTurbine::Trim()
340 double idlethrust, milthrust, thrust, tdiff;
341 idlethrust = MilThrust * IdleThrustLookup->GetValue();
342 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
343 N2 = IdleN2 + ThrottlePos * N2_factor;
344 N2norm = (N2 - IdleN2) / N2_factor;
345 thrust = (idlethrust + (milthrust * N2norm * N2norm))
346 * (1.0 - BleedDemand);
348 if (AugMethod == 1) {
349 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
350 else {Augmentation = false;}
353 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
354 thrust = MaxThrust * MaxThrustLookup->GetValue();
357 if (AugMethod == 2) {
358 if (AugmentCmd > 0.0) {
359 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
360 thrust += (tdiff * AugmentCmd);
364 if ((Injected == 1) && Injection) {
365 thrust = thrust * InjectionLookup->GetValue();
371 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
373 double FGTurbine::CalcFuelNeed(void)
375 double dT = State->Getdt() * Propulsion->GetRate();
376 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
377 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
381 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 double FGTurbine::GetPowerAvailable(void) {
384 if( ThrottlePos <= 0.77 )
385 return 64.94*ThrottlePos;
387 return 217.38*ThrottlePos - 117.38;
390 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
396 if (v < target) v = target;
397 } else if (v < target) {
399 if (v > target) v = target;
404 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
406 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
408 string property_name, property_prefix;
409 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
411 if (el->FindElement("milthrust"))
412 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
413 if (el->FindElement("maxthrust"))
414 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
415 if (el->FindElement("bypassratio"))
416 BypassRatio = el->FindElementValueAsNumber("bypassratio");
417 if (el->FindElement("bleed"))
418 BleedDemand = el->FindElementValueAsNumber("bleed");
419 if (el->FindElement("tsfc"))
420 TSFC = el->FindElementValueAsNumber("tsfc");
421 if (el->FindElement("atsfc"))
422 ATSFC = el->FindElementValueAsNumber("atsfc");
423 if (el->FindElement("idlen1"))
424 IdleN1 = el->FindElementValueAsNumber("idlen1");
425 if (el->FindElement("idlen2"))
426 IdleN2 = el->FindElementValueAsNumber("idlen2");
427 if (el->FindElement("maxn1"))
428 MaxN1 = el->FindElementValueAsNumber("maxn1");
429 if (el->FindElement("maxn2"))
430 MaxN2 = el->FindElementValueAsNumber("maxn2");
431 if (el->FindElement("n1spinup"))
432 N1_spinup = el->FindElementValueAsNumber("n1spinup");
433 if (el->FindElement("n2spinup"))
434 N2_spinup = el->FindElementValueAsNumber("n2spinup");
435 if (el->FindElement("augmented"))
436 Augmented = (int)el->FindElementValueAsNumber("augmented");
437 if (el->FindElement("augmethod"))
438 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
439 if (el->FindElement("injected"))
440 Injected = (int)el->FindElementValueAsNumber("injected");
441 if (el->FindElement("injection-time"))
442 InjectionTime = el->FindElementValueAsNumber("injection-time");
444 Element *function_element;
446 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
449 function_element = el->FindNextElement("function");
450 if (!function_element) break;
451 name = function_element->GetAttributeValue("name");
452 if (name == "IdleThrust") {
453 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
454 } else if (name == "MilThrust") {
455 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
456 } else if (name == "AugThrust") {
457 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
458 } else if (name == "Injection") {
459 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
461 cerr << "Unknown function type: " << name << " in turbine definition." <<
466 // Pre-calculations and initializations
468 delay = 90.0 / (BypassRatio + 3.0);
469 N1_factor = MaxN1 - IdleN1;
470 N2_factor = MaxN2 - IdleN2;
471 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
472 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
478 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 string FGTurbine::GetEngineLabels(string delimeter)
482 std::ostringstream buf;
484 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
485 << Name << "_N2[" << EngineNumber << "]" << delimeter
486 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
491 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493 string FGTurbine::GetEngineValues(string delimeter)
495 std::ostringstream buf;
497 buf << N1 << delimeter
499 << Thruster->GetThrusterValues(EngineNumber, delimeter);
504 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
506 void FGTurbine::bindmodel()
508 string property_name, base_property_name;
509 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
510 property_name = base_property_name + "/n1";
511 PropertyManager->Tie( property_name.c_str(), &N1);
512 property_name = base_property_name + "/n2";
513 PropertyManager->Tie( property_name.c_str(), &N2);
514 property_name = base_property_name + "/injection_cmd";
515 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
516 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
519 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521 int FGTurbine::InitRunning(void) {
522 State->SuspendIntegration();
527 State->ResumeIntegration();
531 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 // The bitmasked value choices are as follows:
533 // unset: In this case (the default) JSBSim would only print
534 // out the normally expected messages, essentially echoing
535 // the config files as they are read. If the environment
536 // variable is not set, debug_lvl is set to 1 internally
537 // 0: This requests JSBSim not to output any messages
539 // 1: This value explicity requests the normal JSBSim
541 // 2: This value asks for a message to be printed out when
542 // a class is instantiated
543 // 4: When this value is set, a message is displayed when a
544 // FGModel object executes its Run() method
545 // 8: When this value is set, various runtime state variables
546 // are printed out periodically
547 // 16: When set various parameters are sanity checked and
548 // a message is printed out when they go out of bounds
550 void FGTurbine::Debug(int from)
552 if (debug_lvl <= 0) return;
554 if (debug_lvl & 1) { // Standard console startup message output
555 if (from == 0) { // Constructor
558 if (from == 2) { // called from Load()
559 cout << "\n Engine Name: " << Name << endl;
560 cout << " MilThrust: " << MilThrust << endl;
561 cout << " MaxThrust: " << MaxThrust << endl;
562 cout << " BypassRatio: " << BypassRatio << endl;
563 cout << " TSFC: " << TSFC << endl;
564 cout << " ATSFC: " << ATSFC << endl;
565 cout << " IdleN1: " << IdleN1 << endl;
566 cout << " IdleN2: " << IdleN2 << endl;
567 cout << " MaxN1: " << MaxN1 << endl;
568 cout << " MaxN2: " << MaxN2 << endl;
569 cout << " Augmented: " << Augmented << endl;
570 cout << " AugMethod: " << AugMethod << endl;
571 cout << " Injected: " << Injected << endl;
572 cout << " MinThrottle: " << MinThrottle << endl;
577 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
578 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
579 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
581 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
583 if (debug_lvl & 8 ) { // Runtime state variables
585 if (debug_lvl & 16) { // Sanity checking
587 if (debug_lvl & 64) {
588 if (from == 0) { // Constructor
589 cout << IdSrc << endl;
590 cout << IdHdr << endl;