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 Lesser 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 Lesser General Public License for more
20 You should have received a copy of the GNU Lesser 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 Lesser 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, Element *el, int engine_number)
58 : FGEngine(exec, el, engine_number)
62 MilThrust = MaxThrust = 10000.0;
67 MaxN1 = MaxN2 = 100.0;
68 Augmented = AugMethod = Injected = 0;
69 BypassRatio = BleedDemand = 0.0;
70 IdleThrustLookup = MilThrustLookup = MaxThrustLookup = InjectionLookup = 0;
78 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 FGTurbine::~FGTurbine()
82 delete IdleThrustLookup;
83 delete MilThrustLookup;
84 delete MaxThrustLookup;
85 delete InjectionLookup;
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 void FGTurbine::ResetToIC(void)
95 ThrottlePos = AugmentCmd = 0.0;
96 InletPosition = NozzlePosition = 1.0;
97 Stalled = Seized = Overtemp = Fire = Augmentation = Injection = Reversed = false;
101 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
104 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 // The main purpose of Calculate() is to determine what phase the engine should
106 // be in, then call the corresponding function.
108 double FGTurbine::Calculate(void)
112 TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
113 dt = State->Getdt() * Propulsion->GetRate();
114 ThrottlePos = FCS->GetThrottlePos(EngineNumber);
115 if (ThrottlePos > 1.0) {
116 AugmentCmd = ThrottlePos - 1.0;
117 ThrottlePos -= AugmentCmd;
122 // When trimming is finished check if user wants engine OFF or RUNNING
123 if ((phase == tpTrim) && (dt > 0)) {
124 if (Running && !Starved) {
126 N2 = IdleN2 + ThrottlePos * N2_factor;
127 N1 = IdleN1 + ThrottlePos * N1_factor;
128 OilTemp_degK = 366.0;
138 if (!Running && Cutoff && Starter) {
139 if (phase == tpOff) phase = tpSpinUp;
141 if (!Running && !Cutoff && (N2 > 15.0)) phase = tpStart;
142 if (Cutoff && (phase != tpSpinUp)) phase = tpOff;
143 if (dt == 0) phase = tpTrim;
144 if (Starved) phase = tpOff;
145 if (Stalled) phase = tpStall;
146 if (Seized) phase = tpSeize;
149 case tpOff: thrust = Off(); break;
150 case tpRun: thrust = Run(); break;
151 case tpSpinUp: thrust = SpinUp(); break;
152 case tpStart: thrust = Start(); break;
153 case tpStall: thrust = Stall(); break;
154 case tpSeize: thrust = Seize(); break;
155 case tpTrim: thrust = Trim(); break;
156 default: thrust = Off();
159 thrust = Thruster->Calculate(thrust); // allow thruster to modify thrust (i.e. reversing)
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 double FGTurbine::Off(void)
168 double qbar = Auxiliary->Getqbar();
170 FuelFlow_pph = Seek(&FuelFlow_pph, 0, 1000.0, 10000.0);
171 N1 = Seek(&N1, qbar/10.0, N1/2.0, N1/2.0);
172 N2 = Seek(&N2, qbar/15.0, N2/2.0, N2/2.0);
173 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
174 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
175 OilPressure_psi = N2 * 0.62;
176 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
177 EPR = Seek(&EPR, 1.0, 0.2, 0.2);
178 Augmentation = false;
183 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185 double FGTurbine::Run()
187 double idlethrust, milthrust, thrust;
188 double N2norm; // 0.0 = idle N2, 1.0 = maximum N2
190 idlethrust = MilThrust * IdleThrustLookup->GetValue();
191 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
196 N2 = Seek(&N2, IdleN2 + ThrottlePos * N2_factor, delay, delay * 3.0);
197 N1 = Seek(&N1, IdleN1 + ThrottlePos * N1_factor, delay, delay * 2.4);
198 N2norm = (N2 - IdleN2) / N2_factor;
199 thrust = idlethrust + (milthrust * N2norm * N2norm);
200 EGT_degC = TAT + 363.1 + ThrottlePos * 357.1;
201 OilPressure_psi = N2 * 0.62;
202 OilTemp_degK = Seek(&OilTemp_degK, 366.0, 1.2, 0.1);
205 correctedTSFC = TSFC * (0.84 + (1-N2norm)*(1-N2norm));
206 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * correctedTSFC, 1000.0, 100000);
207 if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
208 NozzlePosition = Seek(&NozzlePosition, 1.0 - N2norm, 0.8, 0.8);
209 thrust = thrust * (1.0 - BleedDemand);
210 EPR = 1.0 + thrust/MilThrust;
213 if (AugMethod == 1) {
214 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
215 else {Augmentation = false;}
218 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
219 thrust = MaxThrustLookup->GetValue() * MaxThrust;
220 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
221 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
224 if (AugMethod == 2) {
225 if (AugmentCmd > 0.0) {
227 double tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
228 thrust += (tdiff * AugmentCmd);
229 FuelFlow_pph = Seek(&FuelFlow_pph, thrust * ATSFC, 5000.0, 10000.0);
230 NozzlePosition = Seek(&NozzlePosition, 1.0, 0.8, 0.8);
232 Augmentation = false;
236 if ((Injected == 1) && Injection) {
237 InjectionTimer += dt;
238 if (InjectionTimer < InjectionTime) {
239 thrust = thrust * InjectionLookup->GetValue();
246 if (Cutoff) phase = tpOff;
247 if (Starved) phase = tpOff;
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 double FGTurbine::SpinUp(void)
258 N2 = Seek(&N2, 25.18, 3.0, N2/2.0);
259 N1 = Seek(&N1, 5.21, 1.0, N1/2.0);
260 EGT_degC = Seek(&EGT_degC, TAT, 11.7, 7.3);
261 OilPressure_psi = N2 * 0.62;
262 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0.2, 0.2);
264 NozzlePosition = 1.0;
268 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 double FGTurbine::Start(void)
272 if ((N2 > 15.0) && !Starved) { // minimum 15% N2 needed for start
273 Cranking = true; // provided for sound effects signal
275 N2 = Seek(&N2, IdleN2, 2.0, N2/2.0);
276 N1 = Seek(&N1, IdleN1, 1.4, N1/2.0);
277 EGT_degC = Seek(&EGT_degC, TAT + 363.1, 21.3, 7.3);
278 FuelFlow_pph = Seek(&FuelFlow_pph, IdleFF, 103.7, 103.7);
279 OilPressure_psi = N2 * 0.62;
289 else { // no start if N2 < 15%
297 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299 double FGTurbine::Stall(void)
301 double qbar = Auxiliary->Getqbar();
302 EGT_degC = TAT + 903.14;
303 FuelFlow_pph = IdleFF;
304 N1 = Seek(&N1, qbar/10.0, 0, N1/10.0);
305 N2 = Seek(&N2, qbar/15.0, 0, N2/10.0);
307 if (ThrottlePos < 0.01) phase = tpRun; // clear the stall with throttle
312 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314 double FGTurbine::Seize(void)
316 double qbar = Auxiliary->Getqbar();
318 N1 = Seek(&N1, qbar/20.0, 0, N1/15.0);
319 FuelFlow_pph = IdleFF;
321 OilPressure_psi = 0.0;
322 OilTemp_degK = Seek(&OilTemp_degK, TAT + 273.0, 0, 0.2);
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329 double FGTurbine::Trim()
331 double idlethrust, milthrust, thrust, tdiff, N2norm;
332 idlethrust = MilThrust * IdleThrustLookup->GetValue();
333 milthrust = (MilThrust - idlethrust) * MilThrustLookup->GetValue();
334 N2 = IdleN2 + ThrottlePos * N2_factor;
335 N2norm = (N2 - IdleN2) / N2_factor;
336 thrust = (idlethrust + (milthrust * N2norm * N2norm))
337 * (1.0 - BleedDemand);
339 if (AugMethod == 1) {
340 if ((ThrottlePos > 0.99) && (N2 > 97.0)) {Augmentation = true;}
341 else {Augmentation = false;}
344 if ((Augmented == 1) && Augmentation && (AugMethod < 2)) {
345 thrust = MaxThrust * MaxThrustLookup->GetValue();
348 if (AugMethod == 2) {
349 if (AugmentCmd > 0.0) {
350 tdiff = (MaxThrust * MaxThrustLookup->GetValue()) - thrust;
351 thrust += (tdiff * AugmentCmd);
355 if ((Injected == 1) && Injection) {
356 thrust = thrust * InjectionLookup->GetValue();
362 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364 double FGTurbine::CalcFuelNeed(void)
366 double dT = State->Getdt() * Propulsion->GetRate();
367 FuelFlowRate = FuelFlow_pph / 3600.0; // Calculates flow in lbs/sec from lbs/hr
368 FuelExpended = FuelFlowRate * dT; // Calculates fuel expended in this time step
372 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374 double FGTurbine::GetPowerAvailable(void) {
375 if( ThrottlePos <= 0.77 )
376 return 64.94*ThrottlePos;
378 return 217.38*ThrottlePos - 117.38;
381 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
383 double FGTurbine::Seek(double *var, double target, double accel, double decel) {
387 if (v < target) v = target;
388 } else if (v < target) {
390 if (v > target) v = target;
395 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
397 bool FGTurbine::Load(FGFDMExec* exec, Element *el)
399 string property_name, property_prefix;
400 property_prefix = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
402 if (el->FindElement("milthrust"))
403 MilThrust = el->FindElementValueAsNumberConvertTo("milthrust","LBS");
404 if (el->FindElement("maxthrust"))
405 MaxThrust = el->FindElementValueAsNumberConvertTo("maxthrust","LBS");
406 if (el->FindElement("bypassratio"))
407 BypassRatio = el->FindElementValueAsNumber("bypassratio");
408 if (el->FindElement("bleed"))
409 BleedDemand = el->FindElementValueAsNumber("bleed");
410 if (el->FindElement("tsfc"))
411 TSFC = el->FindElementValueAsNumber("tsfc");
412 if (el->FindElement("atsfc"))
413 ATSFC = el->FindElementValueAsNumber("atsfc");
414 if (el->FindElement("idlen1"))
415 IdleN1 = el->FindElementValueAsNumber("idlen1");
416 if (el->FindElement("idlen2"))
417 IdleN2 = el->FindElementValueAsNumber("idlen2");
418 if (el->FindElement("maxn1"))
419 MaxN1 = el->FindElementValueAsNumber("maxn1");
420 if (el->FindElement("maxn2"))
421 MaxN2 = el->FindElementValueAsNumber("maxn2");
422 if (el->FindElement("augmented"))
423 Augmented = (int)el->FindElementValueAsNumber("augmented");
424 if (el->FindElement("augmethod"))
425 AugMethod = (int)el->FindElementValueAsNumber("augmethod");
426 if (el->FindElement("injected"))
427 Injected = (int)el->FindElementValueAsNumber("injected");
428 if (el->FindElement("injection-time"))
429 InjectionTime = el->FindElementValueAsNumber("injection-time");
431 Element *function_element;
433 FGPropertyManager* PropertyManager = exec->GetPropertyManager();
436 function_element = el->FindNextElement("function");
437 if (!function_element) break;
438 name = function_element->GetAttributeValue("name");
439 if (name == "IdleThrust") {
440 IdleThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
441 } else if (name == "MilThrust") {
442 MilThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
443 } else if (name == "AugThrust") {
444 MaxThrustLookup = new FGFunction(PropertyManager, function_element, property_prefix);
445 } else if (name == "Injection") {
446 InjectionLookup = new FGFunction(PropertyManager, function_element, property_prefix);
448 cerr << "Unknown function type: " << name << " in turbine definition." <<
453 // Pre-calculations and initializations
455 delay = 60.0 / (BypassRatio + 3.0);
456 N1_factor = MaxN1 - IdleN1;
457 N2_factor = MaxN2 - IdleN2;
458 OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
459 IdleFF = pow(MilThrust, 0.2) * 107.0; // just an estimate
465 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
467 string FGTurbine::GetEngineLabels(string delimeter)
469 std::ostringstream buf;
471 buf << Name << "_N1[" << EngineNumber << "]" << delimeter
472 << Name << "_N2[" << EngineNumber << "]" << delimeter
473 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
478 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
480 string FGTurbine::GetEngineValues(string delimeter)
482 std::ostringstream buf;
484 buf << N1 << delimeter
486 << Thruster->GetThrusterValues(EngineNumber, delimeter);
491 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
493 void FGTurbine::bindmodel()
495 string property_name, base_property_name;
496 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
497 property_name = base_property_name + "/n1";
498 PropertyManager->Tie( property_name.c_str(), &N1);
499 property_name = base_property_name + "/n2";
500 PropertyManager->Tie( property_name.c_str(), &N2);
501 property_name = base_property_name + "/injection_cmd";
502 PropertyManager->Tie( property_name.c_str(), (FGTurbine*)this,
503 &FGTurbine::GetInjection, &FGTurbine::SetInjection);
506 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
508 int FGTurbine::InitRunning(void) {
509 State->SuspendIntegration();
514 State->ResumeIntegration();
518 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
519 // The bitmasked value choices are as follows:
520 // unset: In this case (the default) JSBSim would only print
521 // out the normally expected messages, essentially echoing
522 // the config files as they are read. If the environment
523 // variable is not set, debug_lvl is set to 1 internally
524 // 0: This requests JSBSim not to output any messages
526 // 1: This value explicity requests the normal JSBSim
528 // 2: This value asks for a message to be printed out when
529 // a class is instantiated
530 // 4: When this value is set, a message is displayed when a
531 // FGModel object executes its Run() method
532 // 8: When this value is set, various runtime state variables
533 // are printed out periodically
534 // 16: When set various parameters are sanity checked and
535 // a message is printed out when they go out of bounds
537 void FGTurbine::Debug(int from)
539 if (debug_lvl <= 0) return;
541 if (debug_lvl & 1) { // Standard console startup message output
542 if (from == 0) { // Constructor
545 if (from == 2) { // called from Load()
546 cout << "\n Engine Name: " << Name << endl;
547 cout << " MilThrust: " << MilThrust << endl;
548 cout << " MaxThrust: " << MaxThrust << endl;
549 cout << " BypassRatio: " << BypassRatio << endl;
550 cout << " TSFC: " << TSFC << endl;
551 cout << " ATSFC: " << ATSFC << endl;
552 cout << " IdleN1: " << IdleN1 << endl;
553 cout << " IdleN2: " << IdleN2 << endl;
554 cout << " MaxN1: " << MaxN1 << endl;
555 cout << " MaxN2: " << MaxN2 << endl;
556 cout << " Augmented: " << Augmented << endl;
557 cout << " AugMethod: " << AugMethod << endl;
558 cout << " Injected: " << Injected << endl;
559 cout << " MinThrottle: " << MinThrottle << endl;
564 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
565 if (from == 0) cout << "Instantiated: FGTurbine" << endl;
566 if (from == 1) cout << "Destroyed: FGTurbine" << endl;
568 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
570 if (debug_lvl & 8 ) { // Runtime state variables
572 if (debug_lvl & 16) { // Sanity checking
574 if (debug_lvl & 64) {
575 if (from == 0) { // Constructor
576 cout << IdSrc << endl;
577 cout << IdHdr << endl;