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 dt = State->Getdt() * Propulsion->GetRate();
117 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
118 if (ThrottlePos > 1.0) {
119 AugmentCmd = ThrottlePos - 1.0;
120 ThrottlePos -= AugmentCmd;
125 // When trimming is finished check if user wants engine OFF or RUNNING
126 if ((phase == tpTrim) && (dt > 0)) {
127 if (Running && !Starved) {
129 N2 = IdleN2 + ThrottlePos * N2_factor;
130 N1 = IdleN1 + ThrottlePos * N1_factor;
131 OilTemp_degK = 366.0;
141 if (!Running && Cutoff && Starter) {
142 if (phase == tpOff) phase = tpSpinUp;
144 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
145 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
146 if (dt == 0) phase = tpTrim;
147 if (Starved) phase = tpOff;
148 if (Stalled) phase = tpStall;
149 if (Seized) phase = tpSeize;
152 case tpOff: thrust = Off(); break;
153 case tpRun: thrust = Run(); break;
154 case tpSpinUp: thrust = SpinUp(); break;
155 case tpStart: thrust = Start(); break;
156 case tpStall: thrust = Stall(); break;
157 case tpSeize: thrust = Seize(); break;
158 case tpTrim: thrust = Trim(); break;
159 default: thrust = Off();
162 thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
167 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 double FGTurbine::Off(void)
171 double qbar = Auxiliary->Getqbar();
173 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
174 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
175 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
176 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
177 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
178 OilPressure_psi = N2 * 0.62;
179 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
180 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
181 Augmentation = false;
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188 double FGTurbine::Run()
190 double idlethrust, milthrust, thrust;
191 double spoolup; // acceleration in pct/sec
192 double sigma = Atmosphere->GetDensityRatio();
193 double T = Atmosphere->GetTemperature();
195 idlethrust = MilThrust * IdleThrustLookup->GetValue();
196 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
201 // adjust acceleration for N2 and atmospheric density
202 double n = N2norm + 0.1;
204 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
206 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
207 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
208 N2norm = (N2 - IdleN2) / N2_factor;
209 thrust = idlethrust + (milthrust * N2norm * N2norm);
210 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
211 OilPressure_psi = N2 * 0.62;
212 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
215 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
216 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
217 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
218 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
219 thrust = thrust * (1.0 - BleedDemand);
220 EPR = 1.0 + thrust/MilThrust;
223 if (AugMethod == 1) {
224 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
225 else {Augmentation = false;}
228 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
229 thrust = MaxThrustLookup->GetValue() * MaxThrust;
230 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
231 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
234 if (AugMethod == 2) {
235 if (AugmentCmd > 0.0) {
237 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
238 thrust += (tdiff * AugmentCmd);
239 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
240 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
242 Augmentation = false;
246 if ((Injected == 1) && Injection) {
247 InjectionTimer += dt;
248 if (InjectionTimer < InjectionTime) {
249 thrust = thrust * InjectionLookup->GetValue();
256 if (Cutoff) phase = tpOff;
257 if (Starved) phase = tpOff;
262 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264 double FGTurbine::SpinUp(void)
268 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
269 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
270 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
271 OilPressure_psi = N2 * 0.62;
272 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
274 NozzlePosition = 1.0;
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 double FGTurbine::Start(void)
282 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
283 Cranking = true; // provided for sound effects signal
285 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
286 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
287 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
288 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
289 OilPressure_psi = N2 * 0.62;
299 else { // no start if N2 < 15%
307 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 double FGTurbine::Stall(void)
311 double qbar = Auxiliary->Getqbar();
312 EGT_degC = TAT + 903.14;
313 FuelFlow_pph = IdleFF;
314 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
315 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
317 if (ThrottlePos < 0.01) {
318 phase = tpRun; // clear the stall with throttle to idle
324 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
326 double FGTurbine::Seize(void)
328 double qbar = Auxiliary->Getqbar();
330 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
331 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
333 OilPressure_psi = 0.0;
334 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
339 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 double FGTurbine::Trim()
343 double idlethrust, milthrust, thrust, tdiff;
344 idlethrust = MilThrust * IdleThrustLookup->GetValue();
345 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
346 N2 = IdleN2 + ThrottlePos * N2_factor;
347 N2norm = (N2 - IdleN2) / N2_factor;
348 thrust = (idlethrust + (milthrust * N2norm * N2norm))
349 * (1.0 - BleedDemand);
351 if (AugMethod == 1) {
352 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
353 else {Augmentation = false;}
356 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
357 thrust = MaxThrust * MaxThrustLookup->GetValue();
360 if (AugMethod == 2) {
361 if (AugmentCmd > 0.0) {
362 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
363 thrust += (tdiff * AugmentCmd);
367 if ((Injected == 1) && Injection) {
368 thrust = thrust * InjectionLookup->GetValue();
374 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376 double FGTurbine::CalcFuelNeed(void)
378 double dT = State->Getdt() * Propulsion->GetRate();
379 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
380 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
384 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
386 double FGTurbine::GetPowerAvailable(void) {
387 if( ThrottlePos <= 0.77 )
388 return 64.94*ThrottlePos;
390 return 217.38*ThrottlePos - 117.38;
393 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
399 if (v < target) v = target;
400 } else if (v < target) {
402 if (v > target) v = target;
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
411 string property_name, property_prefix;
412 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
414 if (el->FindElement("milthrust"))
415 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
416 if (el->FindElement("maxthrust"))
417 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
418 if (el->FindElement("bypassratio"))
419 BypassRatio = el->FindElementValueAsNumber("bypassratio");
420 if (el->FindElement("bleed"))
421 BleedDemand = el->FindElementValueAsNumber("bleed");
422 if (el->FindElement("tsfc"))
423 TSFC = el->FindElementValueAsNumber("tsfc");
424 if (el->FindElement("atsfc"))
425 ATSFC = el->FindElementValueAsNumber("atsfc");
426 if (el->FindElement("idlen1"))
427 IdleN1 = el->FindElementValueAsNumber("idlen1");
428 if (el->FindElement("idlen2"))
429 IdleN2 = el->FindElementValueAsNumber("idlen2");
430 if (el->FindElement("maxn1"))
431 MaxN1 = el->FindElementValueAsNumber("maxn1");
432 if (el->FindElement("maxn2"))
433 MaxN2 = el->FindElementValueAsNumber("maxn2");
434 if (el->FindElement("n1spinup"))
435 N1_spinup = el->FindElementValueAsNumber("n1spinup");
436 if (el->FindElement("n2spinup"))
437 N2_spinup = el->FindElementValueAsNumber("n2spinup");
438 if (el->FindElement("augmented"))
439 Augmented = (int)el->FindElementValueAsNumber("augmented");
440 if (el->FindElement("augmethod"))
441 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
442 if (el->FindElement("injected"))
443 Injected = (int)el->FindElementValueAsNumber("injected");
444 if (el->FindElement("injection-time"))
445 InjectionTime = el->FindElementValueAsNumber("injection-time");
447 Element *function_element;
449 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
452 function_element = el->FindNextElement("function");
453 if (!function_element) break;
454 name = function_element->GetAttributeValue("name");
455 if (name == "IdleThrust") {
456 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
457 } else if (name == "MilThrust") {
458 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
459 } else if (name == "AugThrust") {
460 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
461 } else if (name == "Injection") {
462 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
464 cerr << "Unknown function type: " << name << " in turbine definition." <<
469 // Pre-calculations and initializations
471 delay = 90.0 / (BypassRatio + 3.0);
472 N1_factor = MaxN1 - IdleN1;
473 N2_factor = MaxN2 - IdleN2;
474 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
475 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
481 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
483 string FGTurbine::GetEngineLabels(string delimeter)
485 std::ostringstream buf;
487 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
488 << Name << "_N2[" << EngineNumber << "]" << delimeter
489 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
494 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
496 string FGTurbine::GetEngineValues(string delimeter)
498 std::ostringstream buf;
500 buf << N1 << delimeter
502 << Thruster->GetThrusterValues(EngineNumber, delimeter);
507 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 void FGTurbine::bindmodel()
511 string property_name, base_property_name;
512 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
513 property_name = base_property_name + "/n1";
514 PropertyManager->Tie( property_name.c_str(), &N1);
515 property_name = base_property_name + "/n2";
516 PropertyManager->Tie( property_name.c_str(), &N2);
517 property_name = base_property_name + "/injection_cmd";
518 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
519 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
520 property_name = base_property_name + "/seized";
521 PropertyManager->Tie( property_name.c_str(), &Seized);
522 property_name = base_property_name + "/stalled";
523 PropertyManager->Tie( property_name.c_str(), &Stalled);
526 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
528 int FGTurbine::InitRunning(void) {
529 State->SuspendIntegration();
534 State->ResumeIntegration();
538 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 // The bitmasked value choices are as follows:
540 // unset: In this case (the default) JSBSim would only print
541 // out the normally expected messages, essentially echoing
542 // the config files as they are read. If the environment
543 // variable is not set, debug_lvl is set to 1 internally
544 // 0: This requests JSBSim not to output any messages
546 // 1: This value explicity requests the normal JSBSim
548 // 2: This value asks for a message to be printed out when
549 // a class is instantiated
550 // 4: When this value is set, a message is displayed when a
551 // FGModel object executes its Run() method
552 // 8: When this value is set, various runtime state variables
553 // are printed out periodically
554 // 16: When set various parameters are sanity checked and
555 // a message is printed out when they go out of bounds
557 void FGTurbine::Debug(int from)
559 if (debug_lvl <= 0) return;
561 if (debug_lvl & 1) { // Standard console startup message output
562 if (from == 0) { // Constructor
565 if (from == 2) { // called from Load()
566 cout << "\n Engine Name: " << Name << endl;
567 cout << " MilThrust: " << MilThrust << endl;
568 cout << " MaxThrust: " << MaxThrust << endl;
569 cout << " BypassRatio: " << BypassRatio << endl;
570 cout << " TSFC: " << TSFC << endl;
571 cout << " ATSFC: " << ATSFC << endl;
572 cout << " IdleN1: " << IdleN1 << endl;
573 cout << " IdleN2: " << IdleN2 << endl;
574 cout << " MaxN1: " << MaxN1 << endl;
575 cout << " MaxN2: " << MaxN2 << endl;
576 cout << " Augmented: " << Augmented << endl;
577 cout << " AugMethod: " << AugMethod << endl;
578 cout << " Injected: " << Injected << endl;
579 cout << " MinThrottle: " << MinThrottle << endl;
584 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
585 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
586 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
588 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
590 if (debug_lvl & 8 ) { // Runtime state variables
592 if (debug_lvl & 16) { // Sanity checking
594 if (debug_lvl & 64) {
595 if (from == 0) { // Constructor
596 cout << IdSrc << endl;
597 cout << IdHdr << endl;