]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGSimTurbine.h
Fix a potention buffer overflow
[flightgear.git] / src / FDM / JSBSim / FGSimTurbine.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGSimTurbine.h
4  Author:       David Culp
5  Date started: 03/11/2003
6
7  ------------- Copyright (C) 2003  David Culp (davidculp2@comcast.net)----------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 03/11/2003  DPC  Created, based on FGTurbine
29 09/22/2003  DPC  Added starting, stopping, new framework 
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 COMMENTS, REFERENCES,  and NOTES
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 SENTRY
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #ifndef FGSIMTURBINE_H
40 #define FGSIMTURBINE_H
41
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 INCLUDES
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45
46 #include <vector>
47 #include "FGEngine.h"
48 #include "FGConfigFile.h"
49 #include "FGCoefficient.h"
50
51 #define ID_SIMTURBINE "$Id$"
52
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FORWARD DECLARATIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
57 namespace JSBSim {
58
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 CLASS DOCUMENTATION
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62
63 /** This class models a turbine engine.  Based on Jon Berndt's FGTurbine module.
64     Here the term "phase" signifies the engine's mode of operation.  At any given
65     time the engine is in only one phase.  At simulator startup the engine will be
66     placed in the Trim phase in order to provide a simplified thrust value without
67     throttle lag.  When trimming is complete the engine will go to the Off phase,
68     unless the value FGEngine::Running has been previously set to true, in which
69     case the engine will go to the Run phase.  Once an engine is in the Off phase
70     the full starting procedure (or airstart) must be used to get it running.
71 <P>
72     -STARTING (on ground):
73       -#  Set the control FGEngine::Starter to true.  The engine will spin up to
74           a maximum of about %25 N2 (%5.2 N1).  This simulates the action of a
75           pneumatic starter.
76       -#  After reaching %15 N2 set the control FGEngine::Cutoff to false. If fuel
77           is available the engine will now accelerate to idle.  The starter will
78           automatically be set to false after the start cycle.
79 <P>
80     -STARTING (in air):
81       -#  Increase speed to obtain a minimum of %15 N2.  If this is not possible,
82           the starter may be used to assist.
83       -#  Place the control FGEngine::Cutoff to false.
84 <P>
85     Ignition is assumed to be on anytime the Cutoff control is set to false, 
86     therefore a seperate ignition system is not modeled.
87
88     @author David P. Culp
89     @version $Id$
90 */
91
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 CLASS DECLARATION
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95
96 class FGSimTurbine : public FGEngine
97 {
98 public:
99   /** Constructor
100       @param exec pointer to executive structure
101       @param Eng_Cfg pointer to engine config file instance */
102   FGSimTurbine(FGFDMExec* exec, FGConfigFile* Eng_cfg);
103   /// Destructor
104   ~FGSimTurbine();
105
106   enum phaseType { tpOff, tpRun, tpSpinUp, tpStart, tpStall, tpSeize, tpTrim };
107
108   double Calculate(double);
109   double CalcFuelNeed(void);
110   double GetPowerAvailable(void);
111   double Seek(double* var, double target, double accel, double decel);
112
113   virtual phaseType GetPhase(void) { return phase; }
114   virtual void SetPhase( phaseType p ) { phase = p; } 
115
116   virtual bool GetOvertemp(void) { return Overtemp; }
117   virtual bool GetFire(void) { return Fire; }
118   
119 private:
120
121   typedef vector<FGCoefficient*> CoeffArray;
122   CoeffArray ThrustTables;
123
124   phaseType phase;         ///< Operating mode, or "phase"
125   double MilThrust;        ///< Maximum Unaugmented Thrust, static @ S.L. (lbf)
126   double MaxThrust;        ///< Maximum Augmented Thrust, static @ S.L. (lbf)
127   double BypassRatio;      ///< Bypass Ratio
128   double TSFC;             ///< Thrust Specific Fuel Consumption (lbm/hr/lbf)
129   double ATSFC;            ///< Augmented TSFC (lbm/hr/lbf)
130   double IdleN1;           ///< Idle N1
131   double IdleN2;           ///< Idle N2
132   double MaxN1;            ///< N1 at 100% throttle
133   double MaxN2;            ///< N2 at 100% throttle
134   double IdleFF;           ///< Idle Fuel Flow (lbm/hr)
135   double delay;            ///< Inverse spool-up time from idle to 100% (seconds)
136   double dt;               ///< Simulator time slice
137   double N1_factor;        ///< factor to tie N1 and throttle
138   double N2_factor;        ///< factor to tie N2 and throttle
139   double ThrottleCmd;      ///< FCS-supplied throttle position
140   double TAT;              ///< total air temperature (deg C)
141   bool Stalled;            ///< true if engine is compressor-stalled
142   bool Seized;             ///< true if inner spool is seized
143   bool Overtemp;           ///< true if EGT exceeds limits
144   bool Fire;               ///< true if engine fire detected
145   int Augmented;           ///< = 1 if augmentation installed
146   int Injected;            ///< = 1 if water injection installed
147   int AugMethod;           ///< = 0 if using property /engine[n]/augmentation
148                            ///< = 1 if using last 1% of throttle movement
149
150   double Off(void);
151   double Run(void);
152   double SpinUp(void);
153   double Start(void);
154   double Stall(void);
155   double Seize(void);
156   double Trim(void);
157
158   void SetDefaults(void);
159   bool Load(FGConfigFile *ENG_cfg);
160   void Debug(int from);
161
162 };
163 }
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 #endif
166