]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGSimTurbine.cpp
David Culp:
[flightgear.git] / src / FDM / JSBSim / FGSimTurbine.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGSimTurbine.cpp
4  Author:       David Culp
5  Date started: 03/11/2003
6  Purpose:      This module models a turbine engine.
7
8  ------------- Copyright (C) 2003  David Culp (davidculp2@comcast.net) ---------
9
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
13  version.
14
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
18  details.
19
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.
23
24  Further information about the GNU General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29
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
32
33 HISTORY
34 --------------------------------------------------------------------------------
35 03/11/2003  DPC  Created
36 09/08/2003  DPC  Changed Calculate() and added engine phases 
37
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include <vector>
43 #include "FGSimTurbine.h"
44
45 namespace JSBSim {
46
47 static const char *IdSrc = "$Id$";
48 static const char *IdHdr = ID_SIMTURBINE;
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 CLASS IMPLEMENTATION
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54
55 FGSimTurbine::FGSimTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
56 {
57   SetDefaults();
58   FGEngine::Type=etSimTurbine;
59   Load(cfg);
60   Debug(0);
61 }
62
63 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
65 FGSimTurbine::~FGSimTurbine()
66 {
67   Debug(1);
68 }
69
70 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 // The main purpose of Calculate() is to determine what phase the engine should
72 // be in, then call the corresponding function. 
73
74 double FGSimTurbine::Calculate(double dummy)
75 {
76   TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
77   dt = State->Getdt() * Propulsion->GetRate();
78   ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
79
80   // When trimming is finished check if user wants engine OFF or RUNNING
81   if ((phase == tpTrim) && (dt > 0)) {
82     if (Running && !Starved) {
83       phase = tpRun;
84       N2 = IdleN2;
85       N1 = IdleN1;
86       OilTemp_degK = TAT + 10;  
87       Cutoff = false;
88       }
89     else {
90       phase = tpOff;
91       Cutoff = true;
92       EGT_degC = TAT; 
93       }
94     }
95   
96   if (!Running && Cutoff && Starter) {
97      if (phase == tpOff) phase = tpSpinUp;
98      }
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;
105   
106   switch (phase) {
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();
115   }   
116
117   return Thrust;  
118 }
119
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122 double FGSimTurbine::Off(void)
123 {
124     double qbar = Translation->Getqbar();
125     Running = false;
126     FuelFlow_pph = 0.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     EPR = 1.0;
133     return 0.0; 
134 }
135
136 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137
138 double FGSimTurbine::Run(void)
139 {
140     double idlethrust, milthrust, thrust;
141     double N2norm;   // 0.0 = idle N2, 1.0 = maximum N2
142     idlethrust = MaxMilThrust * ThrustTables[0]->TotalValue();
143     milthrust = (MaxMilThrust - idlethrust) * ThrustTables[1]->TotalValue();
144  
145     Running = true;
146     Starter = false;
147    
148     N2 = Seek(&N2, IdleN2 + ThrottleCmd * N2_factor, delay, delay * 3.0);
149     N1 = Seek(&N1, IdleN1 + ThrottleCmd * N1_factor, delay, delay * 2.4);
150     N2norm = (N2 - IdleN2) / N2_factor;
151     thrust = idlethrust + (milthrust * N2norm * N2norm); 
152     FuelFlow_pph = thrust * TSFC;
153     thrust = thrust * (1.0 - BleedDemand);
154     if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
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);
158     EPR = 1.0 + thrust/MaxMilThrust;
159     NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
160     if (Reversed) thrust = thrust * -0.2;
161
162     if (AugMethod == 1) {
163       if ((ThrottleCmd > 0.99) && (N2 > 97.0)) {Augmentation = true;} 
164         else {Augmentation = false;}
165       }
166
167     if ((Augmented == 1) && Augmentation) {
168       thrust = thrust * ThrustTables[2]->TotalValue();
169       FuelFlow_pph = thrust * ATSFC;
170       NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0);
171       }
172
173     if ((Injected == 1) && Injection)
174       thrust = thrust * ThrustTables[3]->TotalValue(); 
175
176     ConsumeFuel();
177     if (Cutoff) phase = tpOff;
178     if (Starved) phase = tpOff;
179     return thrust;
180 }
181         
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184 double FGSimTurbine::SpinUp(void)
185 {
186     Running = false;
187     FuelFlow_pph = 0.0;
188     N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
189     N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
190     EGT_degC = TAT;
191     OilPressure_psi = N2 * 0.62;
192     OilTemp_degK = TAT + 273.0;
193     EPR = 1.0;
194     NozzlePosition = 1.0;
195     return 0.0;
196 }
197
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199
200 double FGSimTurbine::Start(void)
201 {
202     if ((N2 > 15.0) && !Starved) {       // minimum 15% N2 needed for start
203       Cranking = true;
204       if (N2 < IdleN2) {
205         N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
206         N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
207         EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
208         FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
209         OilPressure_psi = N2 * 0.62;
210         }
211       else {
212         phase = tpRun;
213         Running = true;
214         Starter = false;
215         Cranking = false;
216         } 
217       }
218     else {                 // no start if N2 < 15%
219       phase = tpOff;
220       Starter = false;
221       }
222     return 0.0; 
223 }
224
225 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226
227 double FGSimTurbine::Stall(void)
228 {
229     double qbar = Translation->Getqbar();
230     EGT_degC = TAT + 903.14;
231     FuelFlow_pph = IdleFF;
232     N1 = Seek(&N1, qbar/10.0, 0, N1/10.0); 
233     N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
234     if (ThrottleCmd == 0) phase = tpRun;        // clear the stall with throttle
235     return 0.0; 
236 }
237
238 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239
240 double FGSimTurbine::Seize(void)
241 {
242     double qbar = Translation->Getqbar();
243     N2 = 0.0;
244     N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
245     FuelFlow_pph = IdleFF;
246     OilPressure_psi = 0.0;
247     OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
248     Running = false;
249     return 0.0; 
250 }
251
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
253
254 double FGSimTurbine::Trim(void)
255 {
256     double idlethrust, milthrust, thrust;
257     idlethrust = MaxMilThrust * ThrustTables[0]->TotalValue();
258     milthrust = (MaxMilThrust - idlethrust) * ThrustTables[1]->TotalValue();
259     thrust = idlethrust + (milthrust * ThrottleCmd * ThrottleCmd);
260     return thrust; 
261 }
262
263 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264
265 double FGSimTurbine::CalcFuelNeed(void)
266 {
267   return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
268 }
269
270 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271
272 double FGSimTurbine::GetPowerAvailable(void) {
273   if( ThrottleCmd <= 0.77 )
274     return 64.94*ThrottleCmd;
275   else
276     return 217.38*ThrottleCmd - 117.38;
277 }
278
279 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280
281 double FGSimTurbine::Seek(double *var, double target, double accel, double decel) {
282   double v = *var;
283   if (v > target) {
284     v -= dt * decel;
285     if (v < target) v = target;
286   } else if (v < target) {
287     v += dt * accel;
288     if (v > target) v = target;
289   }
290   return v;
291 }
292
293 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294
295 void FGSimTurbine::SetDefaults(void)
296 {
297   Name = "None_Defined";
298   MaxMilThrust = 10000.0;
299   BypassRatio = 0.0;
300   TSFC = 0.8;
301   ATSFC = 1.7;
302   IdleN1 = 30.0;
303   IdleN2 = 60.0;
304   MaxN1 = 100.0;
305   MaxN2 = 100.0;
306   Augmented = 0;
307   AugMethod = 0;
308   Injected = 0;
309   BleedDemand = 0.0;
310   ThrottleCmd = 0.0;
311   InletPosition = 1.0;
312   NozzlePosition = 1.0;
313   Augmentation = false;
314   Injection = false;
315   Reversed = false;
316   phase = tpOff;
317   Stalled = false;
318   Seized = false;
319   Overtemp = false;
320   Fire = false;
321 }
322
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324
325 bool FGSimTurbine::Load(FGConfigFile *Eng_cfg)
326 {
327   int i;
328   string token;
329   Name = Eng_cfg->GetValue("NAME");
330   cout << Name << endl;
331   Eng_cfg->GetNextConfigLine();
332   *Eng_cfg >> token >> MaxMilThrust;
333   *Eng_cfg >> token >> BypassRatio;
334   *Eng_cfg >> token >> TSFC;
335   *Eng_cfg >> token >> ATSFC;
336   *Eng_cfg >> token >> IdleN1;
337   *Eng_cfg >> token >> IdleN2;
338   *Eng_cfg >> token >> MaxN1;
339   *Eng_cfg >> token >> MaxN2;
340   *Eng_cfg >> token >> Augmented;
341   *Eng_cfg >> token >> AugMethod;
342   *Eng_cfg >> token >> Injected;
343   i=0;
344   while( Eng_cfg->GetValue() != string("/FG_SIMTURBINE") && i < 10){
345     ThrustTables.push_back( new FGCoefficient(FDMExec) );
346     ThrustTables.back()->Load(Eng_cfg);
347     i++;
348   }
349   
350   // pre-calculations and initializations
351   delay= 60.0 / (BypassRatio + 3.0);
352   N1_factor = MaxN1 - IdleN1;
353   N2_factor = MaxN2 - IdleN2;
354   OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
355   IdleFF = pow(MaxMilThrust, 0.2) * 107.0;  // just an estimate
356   return true;
357 }
358
359
360 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 //    The bitmasked value choices are as follows:
362 //    unset: In this case (the default) JSBSim would only print
363 //       out the normally expected messages, essentially echoing
364 //       the config files as they are read. If the environment
365 //       variable is not set, debug_lvl is set to 1 internally
366 //    0: This requests JSBSim not to output any messages
367 //       whatsoever.
368 //    1: This value explicity requests the normal JSBSim
369 //       startup messages
370 //    2: This value asks for a message to be printed out when
371 //       a class is instantiated
372 //    4: When this value is set, a message is displayed when a
373 //       FGModel object executes its Run() method
374 //    8: When this value is set, various runtime state variables
375 //       are printed out periodically
376 //    16: When set various parameters are sanity checked and
377 //       a message is printed out when they go out of bounds
378
379 void FGSimTurbine::Debug(int from)
380 {
381   if (debug_lvl <= 0) return;
382
383   if (debug_lvl & 1) { // Standard console startup message output
384     if (from == 0) { // Constructor
385
386     }
387   }
388   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
389     if (from == 0) cout << "Instantiated: FGSimTurbine" << endl;
390     if (from == 1) cout << "Destroyed:    FGSimTurbine" << endl;
391   }
392   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
393   }
394   if (debug_lvl & 8 ) { // Runtime state variables
395   }
396   if (debug_lvl & 16) { // Sanity checking
397   }
398   if (debug_lvl & 64) {
399     if (from == 0) { // Constructor
400       cout << IdSrc << endl;
401       cout << IdHdr << endl;
402     }
403   }
404 }
405 }