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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 #include "FGTurbine.h"
46 #include "models/FGPropulsion.h"
47 #include "FGThruster.h"
53 static const char *IdSrc = "$Id$";
54 static const char *IdHdr = ID_TURBINE;
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number)
62 : FGEngine(exec, el, engine_number)
66 MilThrust = MaxThrust = 10000.0;
71 MaxN1 = MaxN2 = 100.0;
72 Augmented = AugMethod = Injected = 0;
73 BypassRatio = BleedDemand = 0.0;
74 IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
75 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)
100 correctedTSFC = TSFC;
101 ThrottlePos = AugmentCmd = 0.0;
102 InletPosition = NozzlePosition = 1.0;
103 Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
106 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
108 OilTemp_degK = TAT + 273.0;
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 // The main purpose of Calculate() is to determine what phase the engine should
113 // be in, then call the corresponding function.
115 double FGTurbine::Calculate(void)
119 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
120 double qbar = Auxiliary->Getqbar();
121 dt = State->Getdt() * Propulsion->GetRate();
122 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
123 if (ThrottlePos > 1.0) {
124 AugmentCmd = ThrottlePos - 1.0;
125 ThrottlePos -= AugmentCmd;
130 // When trimming is finished check if user wants engine OFF or RUNNING
131 if ((phase == tpTrim) && (dt > 0)) {
132 if (Running && !Starved) {
134 N2 = IdleN2 + ThrottlePos * N2_factor;
135 N1 = IdleN1 + ThrottlePos * N1_factor;
136 OilTemp_degK = 366.0;
146 if (!Running && Cutoff && Starter) {
147 if (phase == tpOff) phase = tpSpinUp;
151 if ((Starter == true) || (qbar > 30.0)) {
152 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
155 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
156 if (dt == 0) phase = tpTrim;
157 if (Starved) phase = tpOff;
158 if (Stalled) phase = tpStall;
159 if (Seized) phase = tpSeize;
162 case tpOff: thrust = Off(); break;
163 case tpRun: thrust = Run(); break;
164 case tpSpinUp: thrust = SpinUp(); break;
165 case tpStart: thrust = Start(); break;
166 case tpStall: thrust = Stall(); break;
167 case tpSeize: thrust = Seize(); break;
168 case tpTrim: thrust = Trim(); break;
169 default: thrust = Off();
172 thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
177 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 double FGTurbine::Off(void)
181 double qbar = Auxiliary->Getqbar();
183 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
184 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
185 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
186 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
187 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
188 OilPressure_psi = N2 * 0.62;
189 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
190 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
191 Augmentation = false;
196 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198 double FGTurbine::Run()
200 double idlethrust, milthrust, thrust;
201 double spoolup; // acceleration in pct/sec
202 double sigma = Atmosphere->GetDensityRatio();
203 double T = Atmosphere->GetTemperature();
205 idlethrust = MilThrust * IdleThrustLookup->GetValue();
206 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
211 // adjust acceleration for N2 and atmospheric density
212 double n = N2norm + 0.1;
214 spoolup = delay / (1 + 3 * (1-n)*(1-n)*(1-n) + (1 - sigma));
216 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, spoolup, spoolup * 3.0);
217 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, spoolup, spoolup * 2.4);
218 N2norm = (N2 - IdleN2) / N2_factor;
219 thrust = idlethrust + (milthrust * N2norm * N2norm);
220 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
221 OilPressure_psi = N2 * 0.62;
222 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
225 correctedTSFC = TSFC * sqrt(T/389.7) * (0.84 + (1-N2norm)*(1-N2norm));
226 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
227 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
228 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
229 thrust = thrust * (1.0 - BleedDemand);
230 EPR = 1.0 + thrust/MilThrust;
233 if (AugMethod == 1) {
234 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
235 else {Augmentation = false;}
238 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
239 thrust = MaxThrustLookup->GetValue() * MaxThrust;
240 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
241 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
244 if (AugMethod == 2) {
245 if (AugmentCmd > 0.0) {
247 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
248 thrust += (tdiff * AugmentCmd);
249 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
250 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
252 Augmentation = false;
256 if ((Injected == 1) && Injection) {
257 InjectionTimer += dt;
258 if (InjectionTimer < InjectionTime) {
259 thrust = thrust * InjectionLookup->GetValue();
266 if (Cutoff) phase = tpOff;
267 if (Starved) phase = tpOff;
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 double FGTurbine::SpinUp(void)
278 N2 = Seek(&N2, 25.18, N2_spinup, N2/2.0);
279 N1 = Seek(&N1, 5.21, N1_spinup, N1/2.0);
280 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
281 OilPressure_psi = N2 * 0.62;
282 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
284 NozzlePosition = 1.0;
285 if (Starter == false) phase = tpOff;
289 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
291 double FGTurbine::Start(void)
293 double qbar = Auxiliary->Getqbar();
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;
303 if ((Starter == false) && (qbar < 30.0)) phase = tpOff; // aborted start
312 else { // no start if N2 < 15%
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 double FGTurbine::Stall(void)
324 double qbar = Auxiliary->Getqbar();
325 EGT_degC = TAT + 903.14;
326 FuelFlow_pph = IdleFF;
327 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
328 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
330 if (ThrottlePos < 0.01) {
331 phase = tpRun; // clear the stall with throttle to idle
337 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
339 double FGTurbine::Seize(void)
341 double qbar = Auxiliary->Getqbar();
343 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
344 FuelFlow_pph = Cutoff ? 0.0 : IdleFF;
346 OilPressure_psi = 0.0;
347 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
352 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 double FGTurbine::Trim()
356 double idlethrust, milthrust, thrust, tdiff;
357 idlethrust = MilThrust * IdleThrustLookup->GetValue();
358 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
359 N2 = IdleN2 + ThrottlePos * N2_factor;
360 N2norm = (N2 - IdleN2) / N2_factor;
361 thrust = (idlethrust + (milthrust * N2norm * N2norm))
362 * (1.0 - BleedDemand);
364 if (AugMethod == 1) {
365 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
366 else {Augmentation = false;}
369 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
370 thrust = MaxThrust * MaxThrustLookup->GetValue();
373 if (AugMethod == 2) {
374 if (AugmentCmd > 0.0) {
375 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
376 thrust += (tdiff * AugmentCmd);
380 if ((Injected == 1) && Injection) {
381 thrust = thrust * InjectionLookup->GetValue();
387 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389 double FGTurbine::CalcFuelNeed(void)
391 double dT = State->Getdt() * Propulsion->GetRate();
392 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
393 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
397 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
399 double FGTurbine::GetPowerAvailable(void) {
400 if( ThrottlePos <= 0.77 )
401 return 64.94*ThrottlePos;
403 return 217.38*ThrottlePos - 117.38;
406 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
412 if (v < target) v = target;
413 } else if (v < target) {
415 if (v > target) v = target;
420 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
422 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
424 string property_name, property_prefix;
425 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
427 if (el->FindElement("milthrust"))
428 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
429 if (el->FindElement("maxthrust"))
430 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
431 if (el->FindElement("bypassratio"))
432 BypassRatio = el->FindElementValueAsNumber("bypassratio");
433 if (el->FindElement("bleed"))
434 BleedDemand = el->FindElementValueAsNumber("bleed");
435 if (el->FindElement("tsfc"))
436 TSFC = el->FindElementValueAsNumber("tsfc");
437 if (el->FindElement("atsfc"))
438 ATSFC = el->FindElementValueAsNumber("atsfc");
439 if (el->FindElement("idlen1"))
440 IdleN1 = el->FindElementValueAsNumber("idlen1");
441 if (el->FindElement("idlen2"))
442 IdleN2 = el->FindElementValueAsNumber("idlen2");
443 if (el->FindElement("maxn1"))
444 MaxN1 = el->FindElementValueAsNumber("maxn1");
445 if (el->FindElement("maxn2"))
446 MaxN2 = el->FindElementValueAsNumber("maxn2");
447 if (el->FindElement("n1spinup"))
448 N1_spinup = el->FindElementValueAsNumber("n1spinup");
449 if (el->FindElement("n2spinup"))
450 N2_spinup = el->FindElementValueAsNumber("n2spinup");
451 if (el->FindElement("augmented"))
452 Augmented = (int)el->FindElementValueAsNumber("augmented");
453 if (el->FindElement("augmethod"))
454 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
455 if (el->FindElement("injected"))
456 Injected = (int)el->FindElementValueAsNumber("injected");
457 if (el->FindElement("injection-time"))
458 InjectionTime = el->FindElementValueAsNumber("injection-time");
460 Element *function_element;
462 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
465 function_element = el->FindNextElement("function");
466 if (!function_element) break;
467 name = function_element->GetAttributeValue("name");
468 if (name == "IdleThrust") {
469 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
470 } else if (name == "MilThrust") {
471 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
472 } else if (name == "AugThrust") {
473 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
474 } else if (name == "Injection") {
475 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
477 cerr << "Unknown function type: " << name << " in turbine definition." <<
482 // Pre-calculations and initializations
484 delay = 90.0 / (BypassRatio + 3.0);
485 N1_factor = MaxN1 - IdleN1;
486 N2_factor = MaxN2 - IdleN2;
487 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
488 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
494 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
496 string FGTurbine::GetEngineLabels(const string& delimiter)
498 std::ostringstream buf;
500 buf << Name << "_N1[" << EngineNumber << "]" << delimiter
501 << Name << "_N2[" << EngineNumber << "]" << delimiter
502 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
507 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
509 string FGTurbine::GetEngineValues(const string& delimiter)
511 std::ostringstream buf;
513 buf << N1 << delimiter
515 << Thruster->GetThrusterValues(EngineNumber, delimiter);
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
522 void FGTurbine::bindmodel()
524 string property_name, base_property_name;
525 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
526 property_name = base_property_name + "/n1";
527 PropertyManager->Tie( property_name.c_str(), &N1);
528 property_name = base_property_name + "/n2";
529 PropertyManager->Tie( property_name.c_str(), &N2);
530 property_name = base_property_name + "/injection_cmd";
531 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
532 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
533 property_name = base_property_name + "/seized";
534 PropertyManager->Tie( property_name.c_str(), &Seized);
535 property_name = base_property_name + "/stalled";
536 PropertyManager->Tie( property_name.c_str(), &Stalled);
539 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 int FGTurbine::InitRunning(void) {
542 State->SuspendIntegration();
547 State->ResumeIntegration();
551 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
552 // The bitmasked value choices are as follows:
553 // unset: In this case (the default) JSBSim would only print
554 // out the normally expected messages, essentially echoing
555 // the config files as they are read. If the environment
556 // variable is not set, debug_lvl is set to 1 internally
557 // 0: This requests JSBSim not to output any messages
559 // 1: This value explicity requests the normal JSBSim
561 // 2: This value asks for a message to be printed out when
562 // a class is instantiated
563 // 4: When this value is set, a message is displayed when a
564 // FGModel object executes its Run() method
565 // 8: When this value is set, various runtime state variables
566 // are printed out periodically
567 // 16: When set various parameters are sanity checked and
568 // a message is printed out when they go out of bounds
570 void FGTurbine::Debug(int from)
572 if (debug_lvl <= 0) return;
574 if (debug_lvl & 1) { // Standard console startup message output
575 if (from == 0) { // Constructor
578 if (from == 2) { // called from Load()
579 cout << "\n Engine Name: " << Name << endl;
580 cout << " MilThrust: " << MilThrust << endl;
581 cout << " MaxThrust: " << MaxThrust << endl;
582 cout << " BypassRatio: " << BypassRatio << endl;
583 cout << " TSFC: " << TSFC << endl;
584 cout << " ATSFC: " << ATSFC << endl;
585 cout << " IdleN1: " << IdleN1 << endl;
586 cout << " IdleN2: " << IdleN2 << endl;
587 cout << " MaxN1: " << MaxN1 << endl;
588 cout << " MaxN2: " << MaxN2 << endl;
589 cout << " Augmented: " << Augmented << endl;
590 cout << " AugMethod: " << AugMethod << endl;
591 cout << " Injected: " << Injected << endl;
592 cout << " MinThrottle: " << MinThrottle << endl;
597 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
598 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
599 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
601 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
603 if (debug_lvl & 8 ) { // Runtime state variables
605 if (debug_lvl & 16) { // Sanity checking
607 if (debug_lvl & 64) {
608 if (from == 0) { // Constructor
609 cout << IdSrc << endl;
610 cout << IdHdr << endl;