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)
58 FGEngine::Type=etSimTurbine;
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) {
86 OilTemp_degK = TAT + 10;
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);
137 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 double FGSimTurbine::Run(void)
141 double idlethrust, milthrust, thrust;
142 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
143 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
144 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
149 N2 = Seek(&N2, IdleN2 + ThrottleCmd * N2_factor, delay, delay * 3.0);
150 N1 = Seek(&N1, IdleN1 + ThrottleCmd * N1_factor, delay, delay * 2.4);
151 N2norm = (N2 - IdleN2) / N2_factor;
152 thrust = idlethrust + (milthrust * N2norm * N2norm);
153 thrust = thrust * (1.0 - BleedDemand);
154 EGT_degC = TAT + 363.1 + ThrottleCmd * 357.1;
155 OilPressure_psi = N2 * 0.62;
156 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
157 EPR = 1.0 + thrust/MilThrust;
159 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * TSFC, 1000.0, 100000);
160 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
161 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
163 if (Reversed) thrust = thrust * -0.2;
165 if (AugMethod == 1) {
166 if ((ThrottleCmd > 0.99) && (N2 > 97.0)) {Augmentation = true;}
167 else {Augmentation = false;}
170 if ((Augmented == 1) && Augmentation) {
171 thrust = MaxThrust * ThrustTables[2]->TotalValue();
172 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
173 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
176 if ((Injected == 1) && Injection)
177 thrust = thrust * ThrustTables[3]->TotalValue();
180 if (Cutoff) phase = tpOff;
181 if (Starved) phase = tpOff;
185 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 double FGSimTurbine::SpinUp(void)
191 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
192 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
193 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
194 OilPressure_psi = N2 * 0.62;
195 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
197 NozzlePosition = 1.0;
201 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 double FGSimTurbine::Start(void)
205 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
206 Cranking = true; // provided for sound effects signal
208 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
209 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
210 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
211 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
212 OilPressure_psi = N2 * 0.62;
221 else { // no start if N2 < 15%
228 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 double FGSimTurbine::Stall(void)
232 double qbar = Translation->Getqbar();
233 EGT_degC = TAT + 903.14;
234 FuelFlow_pph = IdleFF;
235 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
236 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
237 if (ThrottleCmd == 0) phase = tpRun; // clear the stall with throttle
241 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243 double FGSimTurbine::Seize(void)
245 double qbar = Translation->Getqbar();
247 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
248 FuelFlow_pph = IdleFF;
249 OilPressure_psi = 0.0;
250 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
255 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257 double FGSimTurbine::Trim(void)
259 double idlethrust, milthrust, thrust;
260 idlethrust = MilThrust * ThrustTables[0]->TotalValue();
261 milthrust = (MilThrust - idlethrust) * ThrustTables[1]->TotalValue();
262 thrust = idlethrust + (milthrust * ThrottleCmd * ThrottleCmd);
266 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268 double FGSimTurbine::CalcFuelNeed(void)
270 return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 double FGSimTurbine::GetPowerAvailable(void) {
276 if( ThrottleCmd <= 0.77 )
277 return 64.94*ThrottleCmd;
279 return 217.38*ThrottleCmd - 117.38;
282 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 double FGSimTurbine::Seek(double *var, double target, double accel, double decel) {
288 if (v < target) v = target;
289 } else if (v < target) {
291 if (v > target) v = target;
296 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298 void FGSimTurbine::SetDefaults(void)
300 Name = "None_Defined";
316 NozzlePosition = 1.0;
317 Augmentation = false;
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 bool FGSimTurbine::Load(FGConfigFile *Eng_cfg)
333 Name = Eng_cfg->GetValue("NAME");
334 cout << Name << endl;
335 Eng_cfg->GetNextConfigLine();
336 *Eng_cfg >> token >> MilThrust;
337 *Eng_cfg >> token >> MaxThrust;
338 *Eng_cfg >> token >> BypassRatio;
339 *Eng_cfg >> token >> TSFC;
340 *Eng_cfg >> token >> ATSFC;
341 *Eng_cfg >> token >> IdleN1;
342 *Eng_cfg >> token >> IdleN2;
343 *Eng_cfg >> token >> MaxN1;
344 *Eng_cfg >> token >> MaxN2;
345 *Eng_cfg >> token >> Augmented;
346 *Eng_cfg >> token >> AugMethod;
347 *Eng_cfg >> token >> Injected;
349 while( Eng_cfg->GetValue() != string("/FG_SIMTURBINE") && i < 10){
350 ThrustTables.push_back( new FGCoefficient(FDMExec) );
351 ThrustTables.back()->Load(Eng_cfg);
355 // pre-calculations and initializations
356 delay= 60.0 / (BypassRatio + 3.0);
357 N1_factor = MaxN1 - IdleN1;
358 N2_factor = MaxN2 - IdleN2;
359 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
360 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
365 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
366 // The bitmasked value choices are as follows:
367 // unset: In this case (the default) JSBSim would only print
368 // out the normally expected messages, essentially echoing
369 // the config files as they are read. If the environment
370 // variable is not set, debug_lvl is set to 1 internally
371 // 0: This requests JSBSim not to output any messages
373 // 1: This value explicity requests the normal JSBSim
375 // 2: This value asks for a message to be printed out when
376 // a class is instantiated
377 // 4: When this value is set, a message is displayed when a
378 // FGModel object executes its Run() method
379 // 8: When this value is set, various runtime state variables
380 // are printed out periodically
381 // 16: When set various parameters are sanity checked and
382 // a message is printed out when they go out of bounds
384 void FGSimTurbine::Debug(int from)
386 if (debug_lvl <= 0) return;
388 if (debug_lvl & 1) { // Standard console startup message output
389 if (from == 0) { // Constructor
393 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
394 if (from == 0) cout << "Instantiated: FGSimTurbine" << endl;
395 if (from == 1) cout << "Destroyed: FGSimTurbine" << endl;
397 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
399 if (debug_lvl & 8 ) { // Runtime state variables
401 if (debug_lvl & 16) { // Sanity checking
403 if (debug_lvl & 64) {
404 if (from == 0) { // Constructor
405 cout << IdSrc << endl;
406 cout << IdHdr << endl;