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;
118 case tpOff: Thrust = Off(); break;
119 case tpRun: Thrust = Run(CT); break;
120 case tpSpinUp: Thrust = SpinUp(); break;
121 case tpStart: Thrust = Start(); break;
122 case tpStall: Thrust = Stall(); break;
123 case tpSeize: Thrust = Seize(); break;
124 case tpTrim: Thrust = Trim(CT); break;
125 default: Thrust = Off();
128 Thruster->SetThrustCoefficient(CT);
130 return Thruster->Calculate(Thrust);
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135 double FGTurbine::Off(void)
137 double qbar = Auxiliary->Getqbar();
139 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
140 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
141 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
142 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
143 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
144 OilPressure_psi = N2 * 0.62;
145 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
146 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
147 Augmentation = false;
151 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153 double FGTurbine::Run(double &TC)
155 double idlethrust, milthrust, thrust;
156 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
158 idlethrust = ThrustTables[0]->TotalValue();
159 milthrust = (1.0 - idlethrust) * ThrustTables[1]->TotalValue();
164 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, delay, delay * 3.0);
165 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, delay, delay * 2.4);
166 N2norm = (N2 - IdleN2) / N2_factor;
167 TC = idlethrust + (milthrust * N2norm * N2norm);
168 thrust = TC * MilThrust;
169 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
170 OilPressure_psi = N2 * 0.62;
171 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
174 double correctedTSFC = TSFC + TSFC - (N2norm * TSFC);
175 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
176 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
177 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
178 TC = TC * (1.0 - BleedDemand);
182 if (AugMethod == 1) {
183 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
184 else {Augmentation = false;}
187 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
188 TC = ThrustTables[2]->TotalValue();
189 thrust = TC * MaxThrust;
190 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
191 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
194 if (AugMethod == 2) {
195 if (AugmentCmd > 0.0) {
197 double tdiff = ThrustTables[2]->TotalValue() - TC;
198 TC += (tdiff * AugmentCmd);
199 thrust = TC * MaxThrust;
200 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
201 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
203 Augmentation = false;
207 if ((Injected == 1) && Injection) {
208 TC = TC * ThrustTables[3]->TotalValue();
209 thrust = thrust * ThrustTables[3]->TotalValue();
213 if (Cutoff) phase = tpOff;
214 if (Starved) phase = tpOff;
219 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 double FGTurbine::SpinUp(void)
225 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
226 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
227 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
228 OilPressure_psi = N2 * 0.62;
229 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
231 NozzlePosition = 1.0;
235 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
237 double FGTurbine::Start(void)
239 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
240 Cranking = true; // provided for sound effects signal
242 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
243 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
244 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
245 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
246 OilPressure_psi = N2 * 0.62;
255 else { // no start if N2 < 15%
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 double FGTurbine::Stall(void)
267 double qbar = Auxiliary->Getqbar();
268 EGT_degC = TAT + 903.14;
269 FuelFlow_pph = IdleFF;
270 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
271 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
272 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
277 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 double FGTurbine::Seize(void)
281 double qbar = Auxiliary->Getqbar();
283 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
284 FuelFlow_pph = IdleFF;
285 OilPressure_psi = 0.0;
286 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 double FGTurbine::Trim(double &TC)
295 double idlethrust, milthrust, thrust, tdiff;
296 idlethrust = ThrustTables[0]->TotalValue();;
297 milthrust = (1.0 - TC) * ThrustTables[1]->TotalValue();
298 TC = (idlethrust + (milthrust * ThrottlePos * ThrottlePos))
299 * (1.0 - BleedDemand);
300 if (AugmentCmd > 0.0) {
301 tdiff = ThrustTables[2]->TotalValue() - TC;
302 TC += (tdiff * AugmentCmd);
303 thrust = TC * MaxThrust;
306 thrust = TC * MilThrust;
311 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 double FGTurbine::CalcFuelNeed(void)
315 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
318 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 double FGTurbine::GetPowerAvailable(void) {
321 if( ThrottlePos <= 0.77 )
322 return 64.94*ThrottlePos;
324 return 217.38*ThrottlePos - 117.38;
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
333 if (v < target) v = target;
334 } else if (v < target) {
336 if (v > target) v = target;
341 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 void FGTurbine::SetDefaults(void)
345 Name = "Not defined";
364 NozzlePosition = 1.0;
365 Augmentation = false;
377 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 bool FGTurbine::Load(FGConfigFile *Eng_cfg)
383 Name = Eng_cfg->GetValue("NAME");
384 Eng_cfg->GetNextConfigLine();
387 while ( ((token = Eng_cfg->GetValue()) != string("/FG_TURBINE")) &&
388 (token != string("/FG_SIMTURBINE")) ) {
391 if (token[0] == '<') token.erase(0,1); // Tables are read "<TABLE"
393 if (token == "MILTHRUST") *Eng_cfg >> MilThrust;
394 else if (token == "MAXTHRUST") *Eng_cfg >> MaxThrust;
395 else if (token == "BYPASSRATIO") *Eng_cfg >> BypassRatio;
396 else if (token == "BLEED") *Eng_cfg >> BleedDemand;
397 else if (token == "TSFC") *Eng_cfg >> TSFC;
398 else if (token == "ATSFC") *Eng_cfg >> ATSFC;
399 else if (token == "IDLEN1") *Eng_cfg >> IdleN1;
400 else if (token == "IDLEN2") *Eng_cfg >> IdleN2;
401 else if (token == "MAXN1") *Eng_cfg >> MaxN1;
402 else if (token == "MAXN2") *Eng_cfg >> MaxN2;
403 else if (token == "AUGMENTED") *Eng_cfg >> Augmented;
404 else if (token == "AUGMETHOD") *Eng_cfg >> AugMethod;
405 else if (token == "INJECTED") *Eng_cfg >> Injected;
406 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
407 else if (token == "TABLE") {
408 if (counter++ == 0) Debug(2); // print engine specs prior to table read
409 ThrustTables.push_back( new FGCoefficient(FDMExec) );
410 ThrustTables.back()->Load(Eng_cfg);
412 else cerr << "Unhandled token in Engine config file: " << token << endl;
413 if (token == "EOF") return false;
416 // Pre-calculations and initializations
418 delay = 60.0 / (BypassRatio + 3.0);
419 N1_factor = MaxN1 - IdleN1;
420 N2_factor = MaxN2 - IdleN2;
421 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
422 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
428 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
430 string FGTurbine::GetEngineLabels(void)
432 std::ostringstream buf;
434 buf << Name << "_N1[" << EngineNumber << "], "
435 << Name << "_N2[" << EngineNumber << "], "
436 << Thruster->GetThrusterLabels(EngineNumber);
441 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
443 string FGTurbine::GetEngineValues(void)
445 std::ostringstream buf;
449 << Thruster->GetThrusterValues(EngineNumber);
454 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 void FGTurbine::bindmodel()
458 char property_name[80];
460 snprintf(property_name, 80, "propulsion/n1[%u]", EngineNumber);
461 PropertyManager->Tie( property_name, &N1);
462 snprintf(property_name, 80, "propulsion/n2[%u]", EngineNumber);
463 PropertyManager->Tie( property_name, &N2);
466 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
468 void FGTurbine::unbind()
470 char property_name[80];
472 snprintf(property_name, 80, "propulsion/n1[%u]", EngineNumber);
473 PropertyManager->Untie(property_name);
474 snprintf(property_name, 80, "propulsion/n2[%u]", EngineNumber);
475 PropertyManager->Untie(property_name);
478 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 // The bitmasked value choices are as follows:
480 // unset: In this case (the default) JSBSim would only print
481 // out the normally expected messages, essentially echoing
482 // the config files as they are read. If the environment
483 // variable is not set, debug_lvl is set to 1 internally
484 // 0: This requests JSBSim not to output any messages
486 // 1: This value explicity requests the normal JSBSim
488 // 2: This value asks for a message to be printed out when
489 // a class is instantiated
490 // 4: When this value is set, a message is displayed when a
491 // FGModel object executes its Run() method
492 // 8: When this value is set, various runtime state variables
493 // are printed out periodically
494 // 16: When set various parameters are sanity checked and
495 // a message is printed out when they go out of bounds
497 void FGTurbine::Debug(int from)
499 if (debug_lvl <= 0) return;
501 if (debug_lvl & 1) { // Standard console startup message output
502 if (from == 0) { // Constructor
505 if (from == 2) { // called from Load()
506 cout << "\n Engine Name: " << Name << endl;
507 cout << " MilThrust: " << MilThrust << endl;
508 cout << " MaxThrust: " << MaxThrust << endl;
509 cout << " BypassRatio: " << BypassRatio << endl;
510 cout << " TSFC: " << TSFC << endl;
511 cout << " ATSFC: " << ATSFC << endl;
512 cout << " IdleN1: " << IdleN1 << endl;
513 cout << " IdleN2: " << IdleN2 << endl;
514 cout << " MaxN1: " << MaxN1 << endl;
515 cout << " MaxN2: " << MaxN2 << endl;
516 cout << " Augmented: " << Augmented << endl;
517 cout << " AugMethod: " << AugMethod << endl;
518 cout << " Injected: " << Injected << endl;
519 cout << " MinThrottle: " << MinThrottle << endl;
524 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
525 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
526 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
528 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
530 if (debug_lvl & 8 ) { // Runtime state variables
532 if (debug_lvl & 16) { // Sanity checking
534 if (debug_lvl & 64) {
535 if (from == 0) { // Constructor
536 cout << IdSrc << endl;
537 cout << IdHdr << endl;