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 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 General Public License for more
20 You should have received a copy of the GNU 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 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, FGConfigFile* cfg, int engine_number)
58 : FGEngine(exec, engine_number)
66 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 FGTurbine::~FGTurbine()
74 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 // The main purpose of Calculate() is to determine what phase the engine should
76 // be in, then call the corresponding function.
78 double FGTurbine::Calculate(void)
80 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
81 dt = State->Getdt() * Propulsion->GetRate();
82 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
83 if (ThrottlePos > 1.0) {
84 AugmentCmd = ThrottlePos - 1.0;
85 ThrottlePos -= AugmentCmd;
90 // When trimming is finished check if user wants engine OFF or RUNNING
91 if ((phase == tpTrim) && (dt > 0)) {
92 if (Running && !Starved) {
94 N2 = IdleN2 + ThrottlePos * N2_factor;
95 N1 = IdleN1 + ThrottlePos * N1_factor;
106 if (!Running && Cutoff && Starter) {
107 if (phase == tpOff) phase = tpSpinUp;
109 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
110 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
111 if (dt == 0) phase = tpTrim;
112 if (Starved) phase = tpOff;
113 if (Stalled) phase = tpStall;
114 if (Seized) phase = tpSeize;
117 case tpOff: Thrust = Off(); break;
118 case tpRun: Thrust = Run(); break;
119 case tpSpinUp: Thrust = SpinUp(); break;
120 case tpStart: Thrust = Start(); break;
121 case tpStall: Thrust = Stall(); break;
122 case tpSeize: Thrust = Seize(); break;
123 case tpTrim: Thrust = Trim(); break;
124 default: Thrust = Off();
127 // The thruster can modify the thrust, eg. thrust reverser
128 return Thrust = Thruster->Calculate(Thrust);
131 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133 double FGTurbine::Off(void)
135 double qbar = Auxiliary->Getqbar();
137 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
138 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
139 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
140 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
141 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
142 OilPressure_psi = N2 * 0.62;
143 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
144 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
145 Augmentation = false;
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 double FGTurbine::Run(void)
153 double idlethrust, milthrust, thrust;
154 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
155 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
156 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
161 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, delay, delay * 3.0);
162 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, delay, delay * 2.4);
163 N2norm = (N2 - IdleN2) / N2_factor;
164 thrust = idlethrust + (milthrust * N2norm * N2norm);
165 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
166 OilPressure_psi = N2 * 0.62;
167 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
170 double correctedTSFC = TSFC * (0.84 + (1-N2norm)*(1-N2norm));
171 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
172 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
173 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
174 thrust = thrust * (1.0 - BleedDemand);
175 EPR = 1.0 + thrust/MilThrust;
178 if (AugMethod == 1) {
179 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
180 else {Augmentation = false;}
183 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
184 thrust = MaxThrust * ThrustTables[2]->TotalValue();
185 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
186 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
189 if (AugMethod == 2) {
190 if (AugmentCmd > 0.0) {
192 double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
193 thrust += (tdiff * AugmentCmd);
194 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
195 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
197 Augmentation = false;
201 if ((Injected == 1) && Injection) {
202 thrust = thrust * ThrustTables[3]->TotalValue();
206 if (Cutoff) phase = tpOff;
207 if (Starved) phase = tpOff;
212 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 double FGTurbine::SpinUp(void)
218 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
219 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
220 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
221 OilPressure_psi = N2 * 0.62;
222 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
224 NozzlePosition = 1.0;
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 double FGTurbine::Start(void)
232 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
233 Cranking = true; // provided for sound effects signal
235 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
236 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
237 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
238 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
239 OilPressure_psi = N2 * 0.62;
249 else { // no start if N2 < 15%
257 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
259 double FGTurbine::Stall(void)
261 double qbar = Auxiliary->Getqbar();
262 EGT_degC = TAT + 903.14;
263 FuelFlow_pph = IdleFF;
264 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
265 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
267 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
272 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274 double FGTurbine::Seize(void)
276 double qbar = Auxiliary->Getqbar();
278 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
279 FuelFlow_pph = IdleFF;
281 OilPressure_psi = 0.0;
282 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
287 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 double FGTurbine::Trim(void)
291 double idlethrust, milthrust, thrust, tdiff;
292 idlethrust = MilThrust * ThrustTables[0]->TotalValue();;
293 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
294 thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos))
295 * (1.0 - BleedDemand);
296 if (AugmentCmd > 0.0) {
297 tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
298 thrust += (tdiff * AugmentCmd);
304 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 double FGTurbine::CalcFuelNeed(void)
308 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
311 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 double FGTurbine::GetPowerAvailable(void) {
314 if( ThrottlePos <= 0.77 )
315 return 64.94*ThrottlePos;
317 return 217.38*ThrottlePos - 117.38;
320 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
326 if (v < target) v = target;
327 } else if (v < target) {
329 if (v > target) v = target;
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 void FGTurbine::SetDefaults(void)
338 Name = "Not defined";
357 NozzlePosition = 1.0;
358 Augmentation = false;
370 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372 bool FGTurbine::Load(FGConfigFile *Eng_cfg)
376 Name = Eng_cfg->GetValue("NAME");
377 Eng_cfg->GetNextConfigLine();
380 while ( ((token = Eng_cfg->GetValue()) != string("/FG_TURBINE")) &&
381 (token != string("/FG_SIMTURBINE")) ) {
384 if (token[0] == '<') token.erase(0,1); // Tables are read "<TABLE"
386 if (token == "MILTHRUST") *Eng_cfg >> MilThrust;
387 else if (token == "MAXTHRUST") *Eng_cfg >> MaxThrust;
388 else if (token == "BYPASSRATIO") *Eng_cfg >> BypassRatio;
389 else if (token == "BLEED") *Eng_cfg >> BleedDemand;
390 else if (token == "TSFC") *Eng_cfg >> TSFC;
391 else if (token == "ATSFC") *Eng_cfg >> ATSFC;
392 else if (token == "IDLEN1") *Eng_cfg >> IdleN1;
393 else if (token == "IDLEN2") *Eng_cfg >> IdleN2;
394 else if (token == "MAXN1") *Eng_cfg >> MaxN1;
395 else if (token == "MAXN2") *Eng_cfg >> MaxN2;
396 else if (token == "AUGMENTED") *Eng_cfg >> Augmented;
397 else if (token == "AUGMETHOD") *Eng_cfg >> AugMethod;
398 else if (token == "INJECTED") *Eng_cfg >> Injected;
399 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
400 else if (token == "TABLE") {
401 if (counter++ == 0) Debug(2); // print engine specs prior to table read
402 ThrustTables.push_back( new FGCoefficient(FDMExec) );
403 ThrustTables.back()->Load(Eng_cfg);
405 else cerr << "Unhandled token in Engine config file: " << token << endl;
406 if (token == "EOF") return false;
409 // Pre-calculations and initializations
411 delay = 60.0 / (BypassRatio + 3.0);
412 N1_factor = MaxN1 - IdleN1;
413 N2_factor = MaxN2 - IdleN2;
414 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
415 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 string FGTurbine::GetEngineLabels(string delimeter)
425 std::ostringstream buf;
427 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
428 << Name << "_N2[" << EngineNumber << "]" << delimeter
429 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
434 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436 string FGTurbine::GetEngineValues(string delimeter)
438 std::ostringstream buf;
440 buf << N1 << delimeter
442 << Thruster->GetThrusterValues(EngineNumber, delimeter);
447 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
449 void FGTurbine::bindmodel()
451 char property_name[80];
453 snprintf(property_name, 80, "propulsion/engine[%u]/n1", EngineNumber);
454 PropertyManager->Tie( property_name, &N1);
455 snprintf(property_name, 80, "propulsion/engine[%u]/n2", EngineNumber);
456 PropertyManager->Tie( property_name, &N2);
457 snprintf(property_name, 80, "propulsion/engine[%u]/fuel-flow", EngineNumber);
458 PropertyManager->Tie( property_name, &FuelFlow_pph);
461 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463 void FGTurbine::unbind()
465 char property_name[80];
467 snprintf(property_name, 80, "propulsion/engine[%u]/n1", EngineNumber);
468 PropertyManager->Untie(property_name);
469 snprintf(property_name, 80, "propulsion/engine[%u]/n2", EngineNumber);
470 PropertyManager->Untie(property_name);
471 snprintf(property_name, 80, "propulsion/engine[%u]/fuel-flow", EngineNumber);
472 PropertyManager->Untie( property_name);
475 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476 // The bitmasked value choices are as follows:
477 // unset: In this case (the default) JSBSim would only print
478 // out the normally expected messages, essentially echoing
479 // the config files as they are read. If the environment
480 // variable is not set, debug_lvl is set to 1 internally
481 // 0: This requests JSBSim not to output any messages
483 // 1: This value explicity requests the normal JSBSim
485 // 2: This value asks for a message to be printed out when
486 // a class is instantiated
487 // 4: When this value is set, a message is displayed when a
488 // FGModel object executes its Run() method
489 // 8: When this value is set, various runtime state variables
490 // are printed out periodically
491 // 16: When set various parameters are sanity checked and
492 // a message is printed out when they go out of bounds
494 void FGTurbine::Debug(int from)
496 if (debug_lvl <= 0) return;
498 if (debug_lvl & 1) { // Standard console startup message output
499 if (from == 0) { // Constructor
502 if (from == 2) { // called from Load()
503 cout << "\n Engine Name: " << Name << endl;
504 cout << " MilThrust: " << MilThrust << endl;
505 cout << " MaxThrust: " << MaxThrust << endl;
506 cout << " BypassRatio: " << BypassRatio << endl;
507 cout << " TSFC: " << TSFC << endl;
508 cout << " ATSFC: " << ATSFC << endl;
509 cout << " IdleN1: " << IdleN1 << endl;
510 cout << " IdleN2: " << IdleN2 << endl;
511 cout << " MaxN1: " << MaxN1 << endl;
512 cout << " MaxN2: " << MaxN2 << endl;
513 cout << " Augmented: " << Augmented << endl;
514 cout << " AugMethod: " << AugMethod << endl;
515 cout << " Injected: " << Injected << endl;
516 cout << " MinThrottle: " << MinThrottle << endl;
521 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
522 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
523 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
525 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
527 if (debug_lvl & 8 ) { // Runtime state variables
529 if (debug_lvl & 16) { // Sanity checking
531 if (debug_lvl & 64) {
532 if (from == 0) { // Constructor
533 cout << IdSrc << endl;
534 cout << IdHdr << endl;