]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGEngine.h
Better fix for a compilation problem with MSVC 2012
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGEngine.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGEngine.h
4  Author:       Jon S. Berndt
5  Date started: 01/21/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser 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 Lesser General Public License for more details.
17
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA  02111-1307, USA.
21
22  Further information about the GNU Lesser General Public License can also be found on
23  the world wide web at http://www.gnu.org.
24
25 FUNCTIONAL DESCRIPTION
26 --------------------------------------------------------------------------------
27
28 Based on Flightgear code, which is based on LaRCSim. This class simulates
29 a generic engine.
30
31 HISTORY
32 --------------------------------------------------------------------------------
33 01/21/99   JSB   Created
34
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 SENTRY
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #ifndef FGENGINE_H
40 #define FGENGINE_H
41
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 INCLUDES
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45
46 #include <vector>
47 #include <string>
48
49 #include "math/FGModelFunctions.h"
50 #include "input_output/FGXMLFileRead.h"
51 #include "input_output/FGXMLElement.h"
52 #include "math/FGColumnVector3.h"
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 DEFINITIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 #define ID_ENGINE "$Id: FGEngine.h,v 1.35 2012/04/14 18:10:44 bcoconni Exp $"
59
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 FORWARD DECLARATIONS
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63
64 namespace JSBSim {
65
66 class FGFDMExec;
67 class FGThruster;
68 class Element;
69 class FGPropertyManager;
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 CLASS DOCUMENTATION
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 /** Base class for all engines.
76     This base class contains methods and members common to all engines, such as
77     logic to drain fuel from the appropriate tank, etc. 
78     <br>
79     <h3>Configuration File Format:</h3>
80 @code
81         <engine file="{string}">
82             <location unit="{IN | M}">
83                 <x> {number} </x>
84                 <y> {number} </y>
85                 <z> {number} </z>
86             </location>
87             <!-- optional orientation definition -->
88             <orient unit="{RAD | DEG}">
89                 <roll>  {number} </roll>
90                 <pitch> {number} </pitch>
91                 <yaw> {number} </yaw>
92             </orient>
93             <feed> {integer} </feed>
94             ... optional more feed tank index numbers ... 
95             <thruster file="{string}">
96                 <location unit="{IN | M}">
97                     <x> {number} </x>
98                     <y> {number} </y>
99                     <z> {number} </z>
100                 </location>
101                 <orient unit="{RAD | DEG}">
102                     <roll> {number} </roll>
103                     <pitch> {number} </pitch>
104                     <yaw> {number} </yaw>
105                 </orient>
106             </thruster>
107         </engine>
108 @endcode
109 <pre>
110     NOTES:
111
112   Not all thruster types can be matched with a given engine type.  See the class
113   documentation for engine and thruster classes.
114 </pre>     
115     @author Jon S. Berndt
116     @version $Id: FGEngine.h,v 1.35 2012/04/14 18:10:44 bcoconni Exp $
117 */
118
119 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120 CLASS DECLARATION
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
122
123 class FGEngine : public FGModelFunctions, public FGXMLFileRead
124 {
125 public:
126   struct Inputs {
127     double SLPressure;
128     double Pressure;
129     double PressureRatio;
130     double Temperature;
131     double Density;
132     double DensityRatio;
133     double Soundspeed;
134     double TotalPressure;
135     double TotalTempearture;
136     double TAT_c;
137     double Vt;
138     double Vc;
139     double qbar;
140     double alpha;
141     double beta;
142     double H_agl;
143     FGColumnVector3 AeroUVW;
144     FGColumnVector3 AeroPQR;
145     FGColumnVector3 PQR;
146     vector <double> ThrottleCmd;
147     vector <double> MixtureCmd;
148     vector <double> ThrottlePos;
149     vector <double> MixturePos;
150     vector <double> PropAdvance;
151     vector <bool> PropFeather;
152     FGColumnVector3 vXYZcg; // CG coordinates expressed in the structural frame
153     double TotalDeltaT;
154   };
155
156   FGEngine(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input);
157   virtual ~FGEngine();
158
159   enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
160
161   EngineType             GetType(void) const { return Type; }
162   virtual const string&  GetName(void) const { return Name; }
163
164   // Engine controls
165   virtual double  GetThrottleMin(void) const { return MinThrottle; }
166   virtual double  GetThrottleMax(void) const { return MaxThrottle; }
167   virtual bool    GetStarter(void) const     { return Starter; }
168
169   virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
170   virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
171   virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
172   virtual double GetFuelFlowRateGPH(void) const {return FuelFlowRate*3600/6.02;}
173   virtual double GetFuelUsedLbs(void) const {return FuelUsedLbs;}
174   virtual bool   GetStarved(void) const { return Starved; }
175   virtual bool   GetRunning(void) const { return Running; }
176   virtual bool   GetCranking(void) const { return Cranking; }
177
178   virtual void SetStarved(bool tt) { Starved = tt; }
179   virtual void SetStarved(void)    { Starved = true; }
180
181   virtual void SetRunning(bool bb) { Running=bb; }
182   virtual void SetName(const string& name) { Name = name; }
183   virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
184
185   virtual void SetStarter(bool s) { Starter = s; }
186
187   virtual int InitRunning(void){ return 1; }
188
189   /** Resets the Engine parameters to the initial conditions */
190   void ResetToIC(void);
191
192   /** Calculates the thrust of the engine, and other engine functions. */
193   virtual void Calculate(void) = 0;
194
195   virtual double GetThrust(void) const;
196     
197   /// Sets engine placement information
198   virtual void SetPlacement(const FGColumnVector3& location, const FGColumnVector3& orientation);
199
200   /** The fuel need is calculated based on power levels and flow rate for that
201       power level. It is also turned from a rate into an actual amount (pounds)
202       by multiplying it by the delta T and the rate.
203       @return Total fuel requirement for this engine in pounds. */
204   virtual double CalcFuelNeed(void);
205
206   virtual double CalcOxidizerNeed(void) {return 0.0;}
207
208   virtual double GetPowerAvailable(void) {return 0.0;};
209
210   virtual const FGColumnVector3& GetBodyForces(void);
211   virtual const FGColumnVector3& GetMoments(void);
212
213   bool LoadThruster(Element *el);
214   FGThruster* GetThruster(void) const {return Thruster;}
215
216   unsigned int GetSourceTank(unsigned int i) const;
217   unsigned int GetNumSourceTanks() const {return SourceTanks.size();}
218
219   virtual std::string GetEngineLabels(const std::string& delimiter) = 0;
220   virtual std::string GetEngineValues(const std::string& delimiter) = 0;
221
222   struct Inputs& in;
223   void LoadThrusterInputs();
224
225 protected:
226   /** Reduces the fuel in the active tanks by the amount required.
227       This function should be called from within the
228       derived class' Calculate() function before any other calculations are
229       done. This base class method removes fuel from the fuel tanks as
230       appropriate, and sets the starved flag if necessary. * /
231   virtual void ConsumeFuel(void); */
232
233   FGPropertyManager* PropertyManager;
234   std::string Name;
235   const int   EngineNumber;
236   EngineType Type;
237   double X, Y, Z;
238   double EnginePitch;
239   double EngineYaw;
240   double SLFuelFlowMax;
241   double MaxThrottle;
242   double MinThrottle;
243
244   double FuelExpended;
245   double FuelFlowRate;
246   double PctPower;
247   bool  Starter;
248   bool  Starved;
249   bool  Running;
250   bool  Cranking;
251   bool  FuelFreeze;
252
253   double FuelFlow_gph;
254   double FuelFlow_pph;
255   double FuelUsedLbs;
256
257   FGFDMExec*      FDMExec;
258   FGThruster*     Thruster;
259
260   std::vector <int> SourceTanks;
261
262   void Debug(int from);
263 };
264 }
265
266 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 #endif
268