1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGSimTurbine.cpp
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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGSimTurbine.h"
47 static const char *IdSrc = "$Id$";
48 static const char *IdHdr = ID_SIMTURBINE;
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 FGSimTurbine::FGSimTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 FGSimTurbine::~FGSimTurbine()
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 // The main purpose of Calculate() is to determine what phase the engine should
72 // be in, then call the corresponding function.
74 double FGSimTurbine::Calculate(double dummy)
76 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
77 dt = State->Getdt() * Propulsion->GetRate();
78 ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
80 // When trimming is finished check if user wants engine OFF or RUNNING
81 if ((phase == tpTrim) && (dt > 0)) {
82 if (Running && !Starved) {
96 if (!Running && Cutoff && Starter) {
97 if (phase == tpOff) phase = tpSpinUp;
99 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
100 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
101 if (dt == 0) phase = tpTrim;
102 if (Starved) phase = tpOff;
103 if (Stalled) phase = tpStall;
104 if (Seized) phase = tpSeize;
107 case tpOff: Thrust = Off(); break;
108 case tpRun: Thrust = Run(); break;
109 case tpSpinUp: Thrust = SpinUp(); break;
110 case tpStart: Thrust = Start(); break;
111 case tpStall: Thrust = Stall(); break;
112 case tpSeize: Thrust = Seize(); break;
113 case tpTrim: Thrust = Trim(); break;
114 default: Thrust = Off();
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 double FGSimTurbine::Off(void)
124 double qbar = Translation->Getqbar();
126 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
127 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
128 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
129 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
130 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
131 OilPressure_psi = N2 * 0.62;
132 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
133 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
134 Augmentation = false;
138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 double FGSimTurbine::Run(void)
142 double idlethrust, milthrust, thrust;
143 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
144 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
145 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
150 N2 = Seek(&N2, IdleN2 + ThrottleCmd * N2_factor, delay, delay * 3.0);
151 N1 = Seek(&N1, IdleN1 + ThrottleCmd * N1_factor, delay, delay * 2.4);
152 N2norm = (N2 - IdleN2) / N2_factor;
153 thrust = idlethrust + (milthrust * N2norm * N2norm);
154 thrust = thrust * (1.0 - BleedDemand);
155 EGT_degC = TAT + 363.1 + ThrottleCmd * 357.1;
156 OilPressure_psi = N2 * 0.62;
157 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
158 EPR = 1.0 + thrust/MilThrust;
161 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * TSFC, 1000.0, 100000);
162 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
163 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
166 if (AugMethod == 1) {
167 if ((ThrottleCmd > 0.99) && (N2 > 97.0)) {Augmentation = true;}
168 else {Augmentation = false;}
171 if ((Augmented == 1) && Augmentation) {
172 thrust = MaxThrust * ThrustTables[2]->TotalValue();
173 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
174 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
177 if ((Injected == 1) && Injection)
178 thrust = thrust * ThrustTables[3]->TotalValue();
181 if (Cutoff) phase = tpOff;
182 if (Starved) phase = tpOff;
187 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189 double FGSimTurbine::SpinUp(void)
193 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
194 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
195 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
196 OilPressure_psi = N2 * 0.62;
197 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
199 NozzlePosition = 1.0;
204 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206 double FGSimTurbine::Start(void)
208 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
209 Cranking = true; // provided for sound effects signal
211 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
212 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
213 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
214 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
215 OilPressure_psi = N2 * 0.62;
224 else { // no start if N2 < 15%
232 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234 double FGSimTurbine::Stall(void)
236 double qbar = Translation->Getqbar();
237 EGT_degC = TAT + 903.14;
238 FuelFlow_pph = IdleFF;
239 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
240 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
241 if (ThrottleCmd == 0) phase = tpRun; // clear the stall with throttle
246 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 double FGSimTurbine::Seize(void)
250 double qbar = Translation->Getqbar();
252 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
253 FuelFlow_pph = IdleFF;
254 OilPressure_psi = 0.0;
255 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
260 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 double FGSimTurbine::Trim(void)
264 double idlethrust, milthrust, thrust;
265 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
266 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
267 thrust = idlethrust + (milthrust * ThrottleCmd * ThrottleCmd);
271 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 double FGSimTurbine::CalcFuelNeed(void)
275 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
278 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280 double FGSimTurbine::GetPowerAvailable(void) {
281 if( ThrottleCmd <= 0.77 )
282 return 64.94*ThrottleCmd;
284 return 217.38*ThrottleCmd - 117.38;
287 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 double FGSimTurbine::Seek(double *var, double target, double accel, double decel) {
293 if (v < target) v = target;
294 } else if (v < target) {
296 if (v > target) v = target;
301 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
303 void FGSimTurbine::SetDefaults(void)
305 Name = "Not defined";
323 NozzlePosition = 1.0;
324 Augmentation = false;
336 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 bool FGSimTurbine::Load(FGConfigFile *Eng_cfg)
342 Name = Eng_cfg->GetValue("NAME");
343 Eng_cfg->GetNextConfigLine();
346 while (Eng_cfg->GetValue() != string("/FG_SIMTURBINE")) {
349 if (token[0] == '<') token.erase(0,1); // Tables are read "<TABLE"
351 if (token == "MILTHRUST") *Eng_cfg >> MilThrust;
352 else if (token == "MAXTHRUST") *Eng_cfg >> MaxThrust;
353 else if (token == "BYPASSRATIO") *Eng_cfg >> BypassRatio;
354 else if (token == "TSFC") *Eng_cfg >> TSFC;
355 else if (token == "ATSFC") *Eng_cfg >> ATSFC;
356 else if (token == "IDLEN1") *Eng_cfg >> IdleN1;
357 else if (token == "IDLEN2") *Eng_cfg >> IdleN2;
358 else if (token == "MAXN1") *Eng_cfg >> MaxN1;
359 else if (token == "MAXN2") *Eng_cfg >> MaxN2;
360 else if (token == "AUGMENTED") *Eng_cfg >> Augmented;
361 else if (token == "AUGMETHOD") *Eng_cfg >> AugMethod;
362 else if (token == "INJECTED") *Eng_cfg >> Injected;
363 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
364 else if (token == "TABLE") {
365 if (counter++ == 0) Debug(2); // print engine specs prior to table read
366 ThrustTables.push_back( new FGCoefficient(FDMExec) );
367 ThrustTables.back()->Load(Eng_cfg);
369 else cerr << "Unhandled token in Engine config file: " << token << endl;
372 // Pre-calculations and initializations
374 delay = 60.0 / (BypassRatio + 3.0);
375 N1_factor = MaxN1 - IdleN1;
376 N2_factor = MaxN2 - IdleN2;
377 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
378 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
384 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 // The bitmasked value choices are as follows:
386 // unset: In this case (the default) JSBSim would only print
387 // out the normally expected messages, essentially echoing
388 // the config files as they are read. If the environment
389 // variable is not set, debug_lvl is set to 1 internally
390 // 0: This requests JSBSim not to output any messages
392 // 1: This value explicity requests the normal JSBSim
394 // 2: This value asks for a message to be printed out when
395 // a class is instantiated
396 // 4: When this value is set, a message is displayed when a
397 // FGModel object executes its Run() method
398 // 8: When this value is set, various runtime state variables
399 // are printed out periodically
400 // 16: When set various parameters are sanity checked and
401 // a message is printed out when they go out of bounds
403 void FGSimTurbine::Debug(int from)
405 if (debug_lvl <= 0) return;
407 if (debug_lvl & 1) { // Standard console startup message output
408 if (from == 0) { // Constructor
411 if (from == 2) { // called from Load()
412 cout << "\n Engine Name: " << Name << endl;
413 cout << " MilThrust: " << MilThrust << endl;
414 cout << " MaxThrust: " << MaxThrust << endl;
415 cout << " BypassRatio: " << BypassRatio << endl;
416 cout << " TSFC: " << TSFC << endl;
417 cout << " ATSFC: " << ATSFC << endl;
418 cout << " IdleN1: " << IdleN1 << endl;
419 cout << " IdleN2: " << IdleN2 << endl;
420 cout << " MaxN1: " << MaxN1 << endl;
421 cout << " MaxN2: " << MaxN2 << endl;
422 cout << " Augmented: " << Augmented << endl;
423 cout << " AugMethod: " << AugMethod << endl;
424 cout << " Injected: " << Injected << endl;
425 cout << " MinThrottle: " << MinThrottle << endl;
430 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
431 if (from == 0) cout << "Instantiated: FGSimTurbine" << endl;
432 if (from == 1) cout << "Destroyed: FGSimTurbine" << endl;
434 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
436 if (debug_lvl & 8 ) { // Runtime state variables
438 if (debug_lvl & 16) { // Sanity checking
440 if (debug_lvl & 64) {
441 if (from == 0) { // Constructor
442 cout << IdSrc << endl;
443 cout << IdHdr << endl;