]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGSimTurbine.cpp
Updates from JSBSim, including new turbine engine model from 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@attbi.com) -----------
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
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include <vector>
42 #include "FGSimTurbine.h"
43
44 namespace JSBSim {
45
46 static const char *IdSrc = "$Id$";
47 static const char *IdHdr = ID_SIMTURBINE;
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 CLASS IMPLEMENTATION
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53
54 FGSimTurbine::FGSimTurbine(FGFDMExec* exec, FGConfigFile* cfg) : FGEngine(exec)
55 {
56   SetDefaults();
57   FGEngine::Type=etSimTurbine;
58   Load(cfg);
59   Debug(0);
60 }
61
62 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
64 FGSimTurbine::~FGSimTurbine()
65 {
66   Debug(1);
67 }
68
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70
71 double FGSimTurbine::Calculate(double dummy)
72 {
73   double idlethrust, milthrust, thrust;
74   double TAT = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556;
75   dt = State->Getdt() * Propulsion->GetRate();
76
77   // calculate virtual throttle position (actual +/- lag) based on
78   // FCS Throttle value (except when trimming)
79   if (dt > 0.0) {
80     ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
81     if ( ThrottleCmd > throttle ) {
82       throttle += (dt * delay);
83       if (throttle > ThrottleCmd ) throttle = ThrottleCmd;
84       }
85     else {
86       throttle -= (dt * delay * 3.0);
87       if (throttle < ThrottleCmd ) throttle = ThrottleCmd;
88       }
89     }
90   else {
91     throttle = ThrottleCmd = FCS->GetThrottleCmd(EngineNumber);
92     }
93     
94   idlethrust = MaxMilThrust * ThrustTables[0]->TotalValue();
95   milthrust = MaxMilThrust * ThrustTables[1]->TotalValue();
96
97   if (!Starved) {
98     thrust = milthrust * throttle * throttle;
99     if (thrust < idlethrust) thrust = idlethrust;
100     FuelFlow_pph = thrust * TSFC;
101     thrust = thrust * (1.0 - BleedDemand);
102     IdleFF = pow(MaxMilThrust, 0.2) * 107.0;
103     if (FuelFlow_pph < IdleFF) FuelFlow_pph = IdleFF;
104     N1 = IdleN1 + throttle * N1_factor;
105     N2 = IdleN2 + throttle * N2_factor;
106     EGT_degC = TAT + 363.1 + ThrottleCmd * 357.1;
107     OilPressure_psi = N2 * 0.62;
108     OilTemp_degK += dt * 1.2;
109     if (OilTemp_degK > 366.0) OilTemp_degK = 366.0;
110     EPR = 1.0 + thrust/MaxMilThrust;
111     NozzlePosition = 1.0 - throttle;
112     if (Reversed) thrust = thrust * -0.2;
113     }
114   else {
115     thrust = 0.0;
116     FuelFlow_pph = 0.0;
117     N1 -= (dt * 3.0);
118     if (N1 < (Translation->Getqbar()/10.0)) N1 = Translation->Getqbar()/10.0;
119     N2 -= (dt * 3.5);
120     if (N2 < (Translation->Getqbar()/15.0)) N2 = Translation->Getqbar()/15.0;
121     EGT_degC -= (dt * 11.7);
122     if (EGT_degC < TAT) EGT_degC = TAT;
123     OilPressure_psi = N2 * 0.62;
124     OilTemp_degK -= (dt * 0.2);
125     if (OilTemp_degK < (TAT + 273.0)) OilTemp_degK = (TAT + 273.0);
126     EPR = 1.0;
127     }
128
129   if (AugMethod == 1) {
130     if (throttle > 0.99) {Augmentation = true;} 
131       else {Augmentation = false;}
132     }
133
134   if ((Augmented == 1) && Augmentation) {
135     thrust = thrust * ThrustTables[2]->TotalValue();
136     FuelFlow_pph = thrust * ATSFC;
137     NozzlePosition = 1.0;
138     }
139
140   if ((Injected == 1) && Injection)
141     thrust = thrust * ThrustTables[3]->TotalValue();  
142   
143   ConsumeFuel();
144   
145   return Thrust = thrust;
146   
147 }
148         
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
151 double FGSimTurbine::CalcFuelNeed(void)
152 {
153   return FuelFlow_pph /3600 * State->Getdt() * Propulsion->GetRate();
154 }
155
156
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158
159 void FGSimTurbine::SetDefaults(void)
160 {
161   Name = "None_Defined";
162   MaxMilThrust = 10000.0;
163   BypassRatio = 0.0;
164   TSFC = 0.8;
165   ATSFC = 1.7;
166   IdleN1 = 30.0;
167   IdleN2 = 60.0;
168   MaxN1 = 100.0;
169   MaxN2 = 100.0;
170   Augmented = 0;
171   AugMethod = 0;
172   Injected = 0;
173   BleedDemand = 0.0;
174   throttle = 0.0;
175   InletPosition = 1.0;
176   NozzlePosition = 1.0;
177   Augmentation = false;
178   Injection = false;
179   Reversed = false;
180 }
181
182 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183
184 bool FGSimTurbine::Load(FGConfigFile *Eng_cfg)
185 {
186   int i;
187   string token;
188   Name = Eng_cfg->GetValue("NAME");
189   cout << Name << endl;
190   Eng_cfg->GetNextConfigLine();
191   *Eng_cfg >> token >> MaxMilThrust;
192   *Eng_cfg >> token >> BypassRatio;
193   *Eng_cfg >> token >> TSFC;
194   *Eng_cfg >> token >> ATSFC;
195   *Eng_cfg >> token >> IdleN1;
196   *Eng_cfg >> token >> IdleN2;
197   *Eng_cfg >> token >> MaxN1;
198   *Eng_cfg >> token >> MaxN2;
199   *Eng_cfg >> token >> Augmented;
200   *Eng_cfg >> token >> AugMethod;
201   *Eng_cfg >> token >> Injected;
202   i=0;
203   while( Eng_cfg->GetValue() != string("/FG_SIMTURBINE") && i < 10){
204     ThrustTables.push_back( new FGCoefficient(FDMExec) );
205     ThrustTables.back()->Load(Eng_cfg);
206     i++;
207   }
208   
209   // pre-calculations and initializations
210   delay= 1.0 / (BypassRatio + 3.0);
211   N1_factor = MaxN1 - IdleN1;
212   N2_factor = MaxN2 - IdleN2;
213   OilTemp_degK = (Auxiliary->GetTotalTemperature() - 491.69) * 0.5555556 + 273.0;
214   IdleFF = pow(MaxMilThrust, 0.2) * 107.0;  // just an estimate
215   AddFeedTank(EngineNumber);   // engine[n] feeds from tank[n]
216   return true;
217 }
218
219
220 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 //    The bitmasked value choices are as follows:
222 //    unset: In this case (the default) JSBSim would only print
223 //       out the normally expected messages, essentially echoing
224 //       the config files as they are read. If the environment
225 //       variable is not set, debug_lvl is set to 1 internally
226 //    0: This requests JSBSim not to output any messages
227 //       whatsoever.
228 //    1: This value explicity requests the normal JSBSim
229 //       startup messages
230 //    2: This value asks for a message to be printed out when
231 //       a class is instantiated
232 //    4: When this value is set, a message is displayed when a
233 //       FGModel object executes its Run() method
234 //    8: When this value is set, various runtime state variables
235 //       are printed out periodically
236 //    16: When set various parameters are sanity checked and
237 //       a message is printed out when they go out of bounds
238
239 void FGSimTurbine::Debug(int from)
240 {
241   if (debug_lvl <= 0) return;
242
243   if (debug_lvl & 1) { // Standard console startup message output
244     if (from == 0) { // Constructor
245
246     }
247   }
248   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
249     if (from == 0) cout << "Instantiated: FGSimTurbine" << endl;
250     if (from == 1) cout << "Destroyed:    FGSimTurbine" << endl;
251   }
252   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
253   }
254   if (debug_lvl & 8 ) { // Runtime state variables
255   }
256   if (debug_lvl & 16) { // Sanity checking
257   }
258   if (debug_lvl & 64) {
259     if (from == 0) { // Constructor
260       cout << IdSrc << endl;
261       cout << IdHdr << endl;
262     }
263   }
264 }
265 }