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;
102 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
104 OilTemp_degK = TAT + 273.0;
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 // The main purpose of Calculate() is to determine what phase the engine should
109 // be in, then call the corresponding function.
111 double FGTurbine::Calculate(void)
115 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
116 double qbar = Auxiliary->Getqbar();
117 dt = State->Getdt() * Propulsion->GetRate();
118 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
119 if (ThrottlePos > 1.0) {
120 AugmentCmd = ThrottlePos - 1.0;
121 ThrottlePos -= AugmentCmd;
126 // When trimming is finished check if user wants engine OFF or RUNNING
127 if ((phase == tpTrim) && (dt > 0)) {
128 if (Running && !Starved) {
130 N2 = IdleN2 + ThrottlePos * N2_factor;
131 N1 = IdleN1 + ThrottlePos * N1_factor;
132 OilTemp_degK = 366.0;
142 if (!Running && Cutoff && Starter) {
143 if (phase == tpOff) phase = tpSpinUp;
147 if ((Starter == true) || (qbar > 30.0)) {
148 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
151 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
152 if (dt == 0) phase = tpTrim;
153 if (Starved) phase = tpOff;
154 if (Stalled) phase = tpStall;
155 if (Seized) phase = tpSeize;
158 case tpOff: thrust = Off(); break;
159 case tpRun: thrust = Run(); break;
160 case tpSpinUp: thrust = SpinUp(); break;
161 case tpStart: thrust = Start(); break;
162 case tpStall: thrust = Stall(); break;
163 case tpSeize: thrust = Seize(); break;
164 case tpTrim: thrust = Trim(); break;
165 default: thrust = Off();
168 thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
173 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 double FGTurbine::Off(void)
177 double qbar = Auxiliary->Getqbar();
179 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
180 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
181 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
182 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
183 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
184 OilPressure_psi = N2 * 0.62;
185 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
186 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
187 Augmentation = false;
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 double FGTurbine::Run()
196 double idlethrust, milthrust, thrust;
197 double spoolup; // acceleration in pct/sec
198 double sigma = Atmosphere->GetDensityRatio();
199 double T = Atmosphere->GetTemperature();
201 idlethrust = MilThrust * IdleThrustLookup->GetValue();
202 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
207 // adjust acceleration for N2 and atmospheric density
208 double n = N2norm + 0.1;
210 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
212 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
213 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
214 N2norm = (N2 - IdleN2) / N2_factor;
215 thrust = idlethrust + (milthrust * N2norm * N2norm);
216 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
217 OilPressure_psi = N2 * 0.62;
218 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
221 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
222 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
223 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
224 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
225 thrust = thrust * (1.0 - BleedDemand);
226 EPR = 1.0 + thrust/MilThrust;
229 if (AugMethod == 1) {
230 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
231 else {Augmentation = false;}
234 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
235 thrust = MaxThrustLookup->GetValue() * MaxThrust;
236 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
237 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
240 if (AugMethod == 2) {
241 if (AugmentCmd > 0.0) {
243 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
244 thrust += (tdiff * AugmentCmd);
245 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
246 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
248 Augmentation = false;
252 if ((Injected == 1) && Injection) {
253 InjectionTimer += dt;
254 if (InjectionTimer < InjectionTime) {
255 thrust = thrust * InjectionLookup->GetValue();
262 if (Cutoff) phase = tpOff;
263 if (Starved) phase = tpOff;
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 double FGTurbine::SpinUp(void)
274 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
275 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
276 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
277 OilPressure_psi = N2 * 0.62;
278 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
280 NozzlePosition = 1.0;
281 if (Starter == false) phase = tpOff;
285 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 double FGTurbine::Start(void)
289 double qbar = Auxiliary->Getqbar();
290 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
291 Cranking = true; // provided for sound effects signal
293 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
294 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
295 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
296 FuelFlow_pph = IdleFF * N2 / IdleN2;
297 OilPressure_psi = N2 * 0.62;
299 if ((Starter == false) && (qbar < 30.0)) phase = tpOff; // aborted start
308 else { // no start if N2 < 15%
316 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318 double FGTurbine::Stall(void)
320 double qbar = Auxiliary->Getqbar();
321 EGT_degC = TAT + 903.14;
322 FuelFlow_pph = IdleFF;
323 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
324 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
326 if (ThrottlePos < 0.01) {
327 phase = tpRun; // clear the stall with throttle to idle
333 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 double FGTurbine::Seize(void)
337 double qbar = Auxiliary->Getqbar();
339 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
340 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
342 OilPressure_psi = 0.0;
343 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
348 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350 double FGTurbine::Trim()
352 double idlethrust, milthrust, thrust, tdiff;
353 idlethrust = MilThrust * IdleThrustLookup->GetValue();
354 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
355 N2 = IdleN2 + ThrottlePos * N2_factor;
356 N2norm = (N2 - IdleN2) / N2_factor;
357 thrust = (idlethrust + (milthrust * N2norm * N2norm))
358 * (1.0 - BleedDemand);
360 if (AugMethod == 1) {
361 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
362 else {Augmentation = false;}
365 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
366 thrust = MaxThrust * MaxThrustLookup->GetValue();
369 if (AugMethod == 2) {
370 if (AugmentCmd > 0.0) {
371 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
372 thrust += (tdiff * AugmentCmd);
376 if ((Injected == 1) && Injection) {
377 thrust = thrust * InjectionLookup->GetValue();
383 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 double FGTurbine::CalcFuelNeed(void)
387 double dT = State->Getdt() * Propulsion->GetRate();
388 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
389 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 double FGTurbine::GetPowerAvailable(void) {
396 if( ThrottlePos <= 0.77 )
397 return 64.94*ThrottlePos;
399 return 217.38*ThrottlePos - 117.38;
402 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
408 if (v < target) v = target;
409 } else if (v < target) {
411 if (v > target) v = target;
416 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
420 string property_name, property_prefix;
421 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
423 if (el->FindElement("milthrust"))
424 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
425 if (el->FindElement("maxthrust"))
426 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
427 if (el->FindElement("bypassratio"))
428 BypassRatio = el->FindElementValueAsNumber("bypassratio");
429 if (el->FindElement("bleed"))
430 BleedDemand = el->FindElementValueAsNumber("bleed");
431 if (el->FindElement("tsfc"))
432 TSFC = el->FindElementValueAsNumber("tsfc");
433 if (el->FindElement("atsfc"))
434 ATSFC = el->FindElementValueAsNumber("atsfc");
435 if (el->FindElement("idlen1"))
436 IdleN1 = el->FindElementValueAsNumber("idlen1");
437 if (el->FindElement("idlen2"))
438 IdleN2 = el->FindElementValueAsNumber("idlen2");
439 if (el->FindElement("maxn1"))
440 MaxN1 = el->FindElementValueAsNumber("maxn1");
441 if (el->FindElement("maxn2"))
442 MaxN2 = el->FindElementValueAsNumber("maxn2");
443 if (el->FindElement("n1spinup"))
444 N1_spinup = el->FindElementValueAsNumber("n1spinup");
445 if (el->FindElement("n2spinup"))
446 N2_spinup = el->FindElementValueAsNumber("n2spinup");
447 if (el->FindElement("augmented"))
448 Augmented = (int)el->FindElementValueAsNumber("augmented");
449 if (el->FindElement("augmethod"))
450 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
451 if (el->FindElement("injected"))
452 Injected = (int)el->FindElementValueAsNumber("injected");
453 if (el->FindElement("injection-time"))
454 InjectionTime = el->FindElementValueAsNumber("injection-time");
456 Element *function_element;
458 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
461 function_element = el->FindNextElement("function");
462 if (!function_element) break;
463 name = function_element->GetAttributeValue("name");
464 if (name == "IdleThrust") {
465 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
466 } else if (name == "MilThrust") {
467 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
468 } else if (name == "AugThrust") {
469 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
470 } else if (name == "Injection") {
471 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
473 cerr << "Unknown function type: " << name << " in turbine definition." <<
478 // Pre-calculations and initializations
480 delay = 90.0 / (BypassRatio + 3.0);
481 N1_factor = MaxN1 - IdleN1;
482 N2_factor = MaxN2 - IdleN2;
483 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
484 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
490 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
492 string FGTurbine::GetEngineLabels(string delimeter)
494 std::ostringstream buf;
496 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
497 << Name << "_N2[" << EngineNumber << "]" << delimeter
498 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
503 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505 string FGTurbine::GetEngineValues(string delimeter)
507 std::ostringstream buf;
509 buf << N1 << delimeter
511 << Thruster->GetThrusterValues(EngineNumber, delimeter);
516 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
518 void FGTurbine::bindmodel()
520 string property_name, base_property_name;
521 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
522 property_name = base_property_name + "/n1";
523 PropertyManager->Tie( property_name.c_str(), &N1);
524 property_name = base_property_name + "/n2";
525 PropertyManager->Tie( property_name.c_str(), &N2);
526 property_name = base_property_name + "/injection_cmd";
527 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
528 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
529 property_name = base_property_name + "/seized";
530 PropertyManager->Tie( property_name.c_str(), &Seized);
531 property_name = base_property_name + "/stalled";
532 PropertyManager->Tie( property_name.c_str(), &Stalled);
535 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537 int FGTurbine::InitRunning(void) {
538 State->SuspendIntegration();
543 State->ResumeIntegration();
547 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 // The bitmasked value choices are as follows:
549 // unset: In this case (the default) JSBSim would only print
550 // out the normally expected messages, essentially echoing
551 // the config files as they are read. If the environment
552 // variable is not set, debug_lvl is set to 1 internally
553 // 0: This requests JSBSim not to output any messages
555 // 1: This value explicity requests the normal JSBSim
557 // 2: This value asks for a message to be printed out when
558 // a class is instantiated
559 // 4: When this value is set, a message is displayed when a
560 // FGModel object executes its Run() method
561 // 8: When this value is set, various runtime state variables
562 // are printed out periodically
563 // 16: When set various parameters are sanity checked and
564 // a message is printed out when they go out of bounds
566 void FGTurbine::Debug(int from)
568 if (debug_lvl <= 0) return;
570 if (debug_lvl & 1) { // Standard console startup message output
571 if (from == 0) { // Constructor
574 if (from == 2) { // called from Load()
575 cout << "\n Engine Name: " << Name << endl;
576 cout << " MilThrust: " << MilThrust << endl;
577 cout << " MaxThrust: " << MaxThrust << endl;
578 cout << " BypassRatio: " << BypassRatio << endl;
579 cout << " TSFC: " << TSFC << endl;
580 cout << " ATSFC: " << ATSFC << endl;
581 cout << " IdleN1: " << IdleN1 << endl;
582 cout << " IdleN2: " << IdleN2 << endl;
583 cout << " MaxN1: " << MaxN1 << endl;
584 cout << " MaxN2: " << MaxN2 << endl;
585 cout << " Augmented: " << Augmented << endl;
586 cout << " AugMethod: " << AugMethod << endl;
587 cout << " Injected: " << Injected << endl;
588 cout << " MinThrottle: " << MinThrottle << endl;
593 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
594 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
595 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
597 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
599 if (debug_lvl & 8 ) { // Runtime state variables
601 if (debug_lvl & 16) { // Sanity checking
603 if (debug_lvl & 64) {
604 if (from == 0) { // Constructor
605 cout << IdSrc << endl;
606 cout << IdHdr << endl;