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 return Thruster->Calculate(Thrust);
130 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 double FGTurbine::Off(void)
134 double qbar = Auxiliary->Getqbar();
136 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
137 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
138 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
139 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
140 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
141 OilPressure_psi = N2 * 0.62;
142 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
143 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
144 Augmentation = false;
148 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 double FGTurbine::Run(void)
152 double idlethrust, milthrust, thrust;
153 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
154 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
155 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
160 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, delay, delay * 3.0);
161 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, delay, delay * 2.4);
162 N2norm = (N2 - IdleN2) / N2_factor;
163 thrust = idlethrust + (milthrust * N2norm * N2norm);
164 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
165 OilPressure_psi = N2 * 0.62;
166 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
169 double correctedTSFC = TSFC + TSFC - (N2norm * TSFC);
170 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
171 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
172 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
173 thrust = thrust * (1.0 - BleedDemand);
174 EPR = 1.0 + thrust/MilThrust;
177 if (AugMethod == 1) {
178 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
179 else {Augmentation = false;}
182 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
183 thrust = MaxThrust * ThrustTables[2]->TotalValue();
184 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
185 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
188 if (AugMethod == 2) {
189 if (AugmentCmd > 0.0) {
191 double tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
192 thrust += (tdiff * AugmentCmd);
193 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
194 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
196 Augmentation = false;
200 if ((Injected == 1) && Injection)
201 thrust = thrust * ThrustTables[3]->TotalValue();
204 if (Cutoff) phase = tpOff;
205 if (Starved) phase = tpOff;
210 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 double FGTurbine::SpinUp(void)
216 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
217 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
218 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
219 OilPressure_psi = N2 * 0.62;
220 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
222 NozzlePosition = 1.0;
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 double FGTurbine::Start(void)
230 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
231 Cranking = true; // provided for sound effects signal
233 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
234 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
235 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
236 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
237 OilPressure_psi = N2 * 0.62;
246 else { // no start if N2 < 15%
254 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
256 double FGTurbine::Stall(void)
258 double qbar = Auxiliary->Getqbar();
259 EGT_degC = TAT + 903.14;
260 FuelFlow_pph = IdleFF;
261 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
262 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
263 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 double FGTurbine::Seize(void)
272 double qbar = Auxiliary->Getqbar();
274 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
275 FuelFlow_pph = IdleFF;
276 OilPressure_psi = 0.0;
277 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
282 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 double FGTurbine::Trim(void)
286 double idlethrust, milthrust, thrust, tdiff;
287 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
288 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
289 thrust = (idlethrust + (milthrust * ThrottlePos * ThrottlePos)) * (1.0 - BleedDemand);
290 if (AugmentCmd > 0.0) {
291 tdiff = (MaxThrust * ThrustTables[2]->TotalValue()) - thrust;
292 thrust += (tdiff * AugmentCmd);
297 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 double FGTurbine::CalcFuelNeed(void)
301 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
304 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306 double FGTurbine::GetPowerAvailable(void) {
307 if( ThrottlePos <= 0.77 )
308 return 64.94*ThrottlePos;
310 return 217.38*ThrottlePos - 117.38;
313 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
319 if (v < target) v = target;
320 } else if (v < target) {
322 if (v > target) v = target;
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 void FGTurbine::SetDefaults(void)
331 Name = "Not defined";
350 NozzlePosition = 1.0;
351 Augmentation = false;
363 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
365 bool FGTurbine::Load(FGConfigFile *Eng_cfg)
369 Name = Eng_cfg->GetValue("NAME");
370 Eng_cfg->GetNextConfigLine();
373 while ( ((token = Eng_cfg->GetValue()) != string("/FG_TURBINE")) &&
374 (token != string("/FG_SIMTURBINE")) ) {
377 if (token[0] == '<') token.erase(0,1); // Tables are read "<TABLE"
379 if (token == "MILTHRUST") *Eng_cfg >> MilThrust;
380 else if (token == "MAXTHRUST") *Eng_cfg >> MaxThrust;
381 else if (token == "BYPASSRATIO") *Eng_cfg >> BypassRatio;
382 else if (token == "BLEED") *Eng_cfg >> BleedDemand;
383 else if (token == "TSFC") *Eng_cfg >> TSFC;
384 else if (token == "ATSFC") *Eng_cfg >> ATSFC;
385 else if (token == "IDLEN1") *Eng_cfg >> IdleN1;
386 else if (token == "IDLEN2") *Eng_cfg >> IdleN2;
387 else if (token == "MAXN1") *Eng_cfg >> MaxN1;
388 else if (token == "MAXN2") *Eng_cfg >> MaxN2;
389 else if (token == "AUGMENTED") *Eng_cfg >> Augmented;
390 else if (token == "AUGMETHOD") *Eng_cfg >> AugMethod;
391 else if (token == "INJECTED") *Eng_cfg >> Injected;
392 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
393 else if (token == "TABLE") {
394 if (counter++ == 0) Debug(2); // print engine specs prior to table read
395 ThrustTables.push_back( new FGCoefficient(FDMExec) );
396 ThrustTables.back()->Load(Eng_cfg);
398 else cerr << "Unhandled token in Engine config file: " << token << endl;
401 // Pre-calculations and initializations
403 delay = 60.0 / (BypassRatio + 3.0);
404 N1_factor = MaxN1 - IdleN1;
405 N2_factor = MaxN2 - IdleN2;
406 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
407 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
413 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
415 string FGTurbine::GetEngineLabels(void)
417 std::ostringstream buf;
419 buf << Name << "_N1[" << EngineNumber << "], "
420 << Name << "_N2[" << EngineNumber << "], "
421 << Thruster->GetThrusterLabels(EngineNumber);
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 string FGTurbine::GetEngineValues(void)
430 std::ostringstream buf;
434 << Thruster->GetThrusterValues(EngineNumber);
439 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 void FGTurbine::bindmodel()
443 char property_name[80];
445 snprintf(property_name, 80, "propulsion/n1[%u]", EngineNumber);
446 PropertyManager->Tie( property_name, &N1);
447 snprintf(property_name, 80, "propulsion/n2[%u]", EngineNumber);
448 PropertyManager->Tie( property_name, &N2);
451 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
453 void FGTurbine::unbind()
455 char property_name[80];
457 snprintf(property_name, 80, "propulsion/n1[%u]", EngineNumber);
458 PropertyManager->Untie(property_name);
459 snprintf(property_name, 80, "propulsion/n2[%u]", EngineNumber);
460 PropertyManager->Untie(property_name);
463 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
464 // The bitmasked value choices are as follows:
465 // unset: In this case (the default) JSBSim would only print
466 // out the normally expected messages, essentially echoing
467 // the config files as they are read. If the environment
468 // variable is not set, debug_lvl is set to 1 internally
469 // 0: This requests JSBSim not to output any messages
471 // 1: This value explicity requests the normal JSBSim
473 // 2: This value asks for a message to be printed out when
474 // a class is instantiated
475 // 4: When this value is set, a message is displayed when a
476 // FGModel object executes its Run() method
477 // 8: When this value is set, various runtime state variables
478 // are printed out periodically
479 // 16: When set various parameters are sanity checked and
480 // a message is printed out when they go out of bounds
482 void FGTurbine::Debug(int from)
484 if (debug_lvl <= 0) return;
486 if (debug_lvl & 1) { // Standard console startup message output
487 if (from == 0) { // Constructor
490 if (from == 2) { // called from Load()
491 cout << "\n Engine Name: " << Name << endl;
492 cout << " MilThrust: " << MilThrust << endl;
493 cout << " MaxThrust: " << MaxThrust << endl;
494 cout << " BypassRatio: " << BypassRatio << endl;
495 cout << " TSFC: " << TSFC << endl;
496 cout << " ATSFC: " << ATSFC << endl;
497 cout << " IdleN1: " << IdleN1 << endl;
498 cout << " IdleN2: " << IdleN2 << endl;
499 cout << " MaxN1: " << MaxN1 << endl;
500 cout << " MaxN2: " << MaxN2 << endl;
501 cout << " Augmented: " << Augmented << endl;
502 cout << " AugMethod: " << AugMethod << endl;
503 cout << " Injected: " << Injected << endl;
504 cout << " MinThrottle: " << MinThrottle << endl;
509 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
510 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
511 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
513 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
515 if (debug_lvl & 8 ) { // Runtime state variables
517 if (debug_lvl & 16) { // Sanity checking
519 if (debug_lvl & 64) {
520 if (from == 0) { // Constructor
521 cout << IdSrc << endl;
522 cout << IdHdr << endl;