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