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) : FGEngine(exec)
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 FGTurbine::~FGTurbine()
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 // The main purpose of Calculate() is to determine what phase the engine should
74 // be in, then call the corresponding function.
76 double FGTurbine::Calculate(void)
78 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
79 dt = State->Getdt() * Propulsion->GetRate();
80 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
81 if (ThrottlePos > 1.0) {
82 AugmentCmd = ThrottlePos - 1.0;
83 ThrottlePos -= AugmentCmd;
88 // When trimming is finished check if user wants engine OFF or RUNNING
89 if ((phase == tpTrim) && (dt > 0)) {
90 if (Running && !Starved) {
92 N2 = IdleN2 + ThrottlePos * N2_factor;
93 N1 = IdleN1 + ThrottlePos * N1_factor;
104 if (!Running && Cutoff && Starter) {
105 if (phase == tpOff) phase = tpSpinUp;
107 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
108 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
109 if (dt == 0) phase = tpTrim;
110 if (Starved) phase = tpOff;
111 if (Stalled) phase = tpStall;
112 if (Seized) phase = tpSeize;
115 case tpOff: Thrust = Off(); break;
116 case tpRun: Thrust = Run(); break;
117 case tpSpinUp: Thrust = SpinUp(); break;
118 case tpStart: Thrust = Start(); break;
119 case tpStall: Thrust = Stall(); break;
120 case tpSeize: Thrust = Seize(); break;
121 case tpTrim: Thrust = Trim(); break;
122 default: Thrust = Off();
125 return Thruster->Calculate(Thrust);
128 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 double FGTurbine::Off(void)
132 double qbar = Auxiliary->Getqbar();
134 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
135 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
136 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
137 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
138 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
139 OilPressure_psi = N2 * 0.62;
140 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
141 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
142 Augmentation = false;
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 double FGTurbine::Run(void)
150 double idlethrust, milthrust, thrust;
151 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
152 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
153 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
158 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, delay, delay * 3.0);
159 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, delay, delay * 2.4);
160 N2norm = (N2 - IdleN2) / N2_factor;
161 thrust = idlethrust + (milthrust * N2norm * N2norm);
162 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
163 OilPressure_psi = N2 * 0.62;
164 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
167 double correctedTSFC = TSFC + TSFC - (N2norm * TSFC);
168 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
169 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
170 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
171 thrust = thrust * (1.0 - BleedDemand);
172 EPR = 1.0 + thrust/MilThrust;
175 if (AugMethod == 1) {
176 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
177 else {Augmentation = false;}
180 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
181 thrust = MaxThrust * ThrustTables[2]->TotalValue();
182 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
183 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
186 if ((AugmentCmd > 0.0) && (AugMethod == 2)) {
188 double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
189 thrust += (tdiff * AugmentCmd);
190 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
191 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
193 Augmentation = false;
196 if ((Injected == 1) && Injection)
197 thrust = thrust * ThrustTables[3]->TotalValue();
200 if (Cutoff) phase = tpOff;
201 if (Starved) phase = tpOff;
206 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 double FGTurbine::SpinUp(void)
212 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
213 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
214 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
215 OilPressure_psi = N2 * 0.62;
216 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
218 NozzlePosition = 1.0;
222 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 double FGTurbine::Start(void)
226 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
227 Cranking = true; // provided for sound effects signal
229 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
230 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
231 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
232 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
233 OilPressure_psi = N2 * 0.62;
242 else { // no start if N2 < 15%
250 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 double FGTurbine::Stall(void)
254 double qbar = Auxiliary->Getqbar();
255 EGT_degC = TAT + 903.14;
256 FuelFlow_pph = IdleFF;
257 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
258 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
259 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
264 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266 double FGTurbine::Seize(void)
268 double qbar = Auxiliary->Getqbar();
270 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
271 FuelFlow_pph = IdleFF;
272 OilPressure_psi = 0.0;
273 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 double FGTurbine::Trim(void)
282 double idlethrust, milthrust, thrust, tdiff;
283 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
284 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
285 thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos)) * (1.0 - BleedDemand);
286 if (AugmentCmd > 0.0) {
287 tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
288 thrust += (tdiff * AugmentCmd);
293 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295 double FGTurbine::CalcFuelNeed(void)
297 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
300 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302 double FGTurbine::GetPowerAvailable(void) {
303 if( ThrottlePos <= 0.77 )
304 return 64.94*ThrottlePos;
306 return 217.38*ThrottlePos - 117.38;
309 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
315 if (v < target) v = target;
316 } else if (v < target) {
318 if (v > target) v = target;
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 void FGTurbine::SetDefaults(void)
327 Name = "Not defined";
346 NozzlePosition = 1.0;
347 Augmentation = false;
359 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 bool FGTurbine::Load(FGConfigFile *Eng_cfg)
365 Name = Eng_cfg->GetValue("NAME");
366 Eng_cfg->GetNextConfigLine();
369 while ( ((token = Eng_cfg->GetValue()) != string("/FG_TURBINE")) &&
370 (token != string("/FG_SIMTURBINE")) ) {
373 if (token[0] == '<') token.erase(0,1); // Tables are read "<TABLE"
375 if (token == "MILTHRUST") *Eng_cfg >> MilThrust;
376 else if (token == "MAXTHRUST") *Eng_cfg >> MaxThrust;
377 else if (token == "BYPASSRATIO") *Eng_cfg >> BypassRatio;
378 else if (token == "BLEED") *Eng_cfg >> BleedDemand;
379 else if (token == "TSFC") *Eng_cfg >> TSFC;
380 else if (token == "ATSFC") *Eng_cfg >> ATSFC;
381 else if (token == "IDLEN1") *Eng_cfg >> IdleN1;
382 else if (token == "IDLEN2") *Eng_cfg >> IdleN2;
383 else if (token == "MAXN1") *Eng_cfg >> MaxN1;
384 else if (token == "MAXN2") *Eng_cfg >> MaxN2;
385 else if (token == "AUGMENTED") *Eng_cfg >> Augmented;
386 else if (token == "AUGMETHOD") *Eng_cfg >> AugMethod;
387 else if (token == "INJECTED") *Eng_cfg >> Injected;
388 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
389 else if (token == "TABLE") {
390 if (counter++ == 0) Debug(2); // print engine specs prior to table read
391 ThrustTables.push_back( new FGCoefficient(FDMExec) );
392 ThrustTables.back()->Load(Eng_cfg);
394 else cerr << "Unhandled token in Engine config file: " << token << endl;
397 // Pre-calculations and initializations
399 delay = 60.0 / (BypassRatio + 3.0);
400 N1_factor = MaxN1 - IdleN1;
401 N2_factor = MaxN2 - IdleN2;
402 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
403 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
408 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410 string FGTurbine::GetEngineLabels(void)
412 std::ostringstream buf;
414 buf << Name << "_N1[" << EngineNumber << "], "
415 << Name << "_N2[" << EngineNumber << "], "
416 << Thruster->GetThrusterLabels(EngineNumber);
421 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423 string FGTurbine::GetEngineValues(void)
425 std::ostringstream buf;
429 << Thruster->GetThrusterValues(EngineNumber);
434 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 // The bitmasked value choices are as follows:
436 // unset: In this case (the default) JSBSim would only print
437 // out the normally expected messages, essentially echoing
438 // the config files as they are read. If the environment
439 // variable is not set, debug_lvl is set to 1 internally
440 // 0: This requests JSBSim not to output any messages
442 // 1: This value explicity requests the normal JSBSim
444 // 2: This value asks for a message to be printed out when
445 // a class is instantiated
446 // 4: When this value is set, a message is displayed when a
447 // FGModel object executes its Run() method
448 // 8: When this value is set, various runtime state variables
449 // are printed out periodically
450 // 16: When set various parameters are sanity checked and
451 // a message is printed out when they go out of bounds
453 void FGTurbine::Debug(int from)
455 if (debug_lvl <= 0) return;
457 if (debug_lvl & 1) { // Standard console startup message output
458 if (from == 0) { // Constructor
461 if (from == 2) { // called from Load()
462 cout << "\n Engine Name: " << Name << endl;
463 cout << " MilThrust: " << MilThrust << endl;
464 cout << " MaxThrust: " << MaxThrust << endl;
465 cout << " BypassRatio: " << BypassRatio << endl;
466 cout << " TSFC: " << TSFC << endl;
467 cout << " ATSFC: " << ATSFC << endl;
468 cout << " IdleN1: " << IdleN1 << endl;
469 cout << " IdleN2: " << IdleN2 << endl;
470 cout << " MaxN1: " << MaxN1 << endl;
471 cout << " MaxN2: " << MaxN2 << endl;
472 cout << " Augmented: " << Augmented << endl;
473 cout << " AugMethod: " << AugMethod << endl;
474 cout << " Injected: " << Injected << endl;
475 cout << " MinThrottle: " << MinThrottle << endl;
480 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
481 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
482 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
484 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
486 if (debug_lvl & 8 ) { // Runtime state variables
488 if (debug_lvl & 16) { // Sanity checking
490 if (debug_lvl & 64) {
491 if (from == 0) { // Constructor
492 cout << IdSrc << endl;
493 cout << IdHdr << endl;