1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
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
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.
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.
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.
25 FUNCTIONAL DESCRIPTION
26 --------------------------------------------------------------------------------
28 Based on Flightgear code, which is based on LaRCSim. This class simulates
32 --------------------------------------------------------------------------------
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
49 #include "math/FGModelFunctions.h"
50 #include "input_output/FGXMLFileRead.h"
51 #include "input_output/FGXMLElement.h"
52 #include "math/FGColumnVector3.h"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 #define ID_ENGINE "$Id: FGEngine.h,v 1.29 2011/11/10 12:06:14 jberndt Exp $"
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 class FGPropertyManager;
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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.
79 <h3>Configuration File Format:</h3>
81 <engine file="{string}">
82 <location unit="{IN | M}">
87 <!-- optional orientation definition -->
88 <orient unit="{RAD | DEG}">
89 <roll> {number} </roll>
90 <pitch> {number} </pitch>
93 <feed> {integer} </feed>
94 ... optional more feed tank index numbers ...
95 <thruster file="{string}">
96 <location unit="{IN | M}">
101 <orient unit="{RAD | DEG}">
102 <roll> {number} </roll>
103 <pitch> {number} </pitch>
104 <yaw> {number} </yaw>
112 Not all thruster types can be matched with a given engine type. See the class
113 documentation for engine and thruster classes.
115 @author Jon S. Berndt
116 @version $Id: FGEngine.h,v 1.29 2011/11/10 12:06:14 jberndt Exp $
119 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
123 class FGEngine : public FGModelFunctions, public FGXMLFileRead
129 double PressureRatio;
134 double TotalPressure;
135 double TotalTempearture;
143 FGColumnVector3 AeroUVW;
144 FGColumnVector3 AeroPQR;
146 vector <double> ThrottleCmd;
147 vector <double> MixtureCmd;
148 vector <double> ThrottlePos;
149 vector <double> MixturePos;
150 vector <double> PropAdvance;
151 vector <bool> PropFeather;
155 FGEngine(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input);
158 enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
160 EngineType GetType(void) const { return Type; }
161 virtual const string& GetName(void) const { return Name; }
164 virtual double GetThrottleMin(void) const { return MinThrottle; }
165 virtual double GetThrottleMax(void) const { return MaxThrottle; }
166 virtual bool GetStarter(void) const { return Starter; }
168 virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
169 virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
170 virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
171 virtual double GetFuelFlowRateGPH(void) const {return FuelFlowRate*3600/6.02;}
172 virtual double GetFuelUsedLbs(void) const {return FuelUsedLbs;}
173 virtual bool GetStarved(void) const { return Starved; }
174 virtual bool GetRunning(void) const { return Running; }
175 virtual bool GetCranking(void) const { return Cranking; }
177 virtual void SetStarved(bool tt) { Starved = tt; }
178 virtual void SetStarved(void) { Starved = true; }
180 virtual void SetRunning(bool bb) { Running=bb; }
181 virtual void SetName(const string& name) { Name = name; }
182 virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
184 virtual void SetStarter(bool s) { Starter = s; }
186 virtual int InitRunning(void){ return 1; }
188 /** Resets the Engine parameters to the initial conditions */
189 void ResetToIC(void);
191 /** Calculates the thrust of the engine, and other engine functions. */
192 virtual void Calculate(void) = 0;
194 virtual double GetThrust(void) const;
196 /// Sets engine placement information
197 virtual void SetPlacement(const FGColumnVector3& location, const FGColumnVector3& orientation);
199 /** The fuel need is calculated based on power levels and flow rate for that
200 power level. It is also turned from a rate into an actual amount (pounds)
201 by multiplying it by the delta T and the rate.
202 @return Total fuel requirement for this engine in pounds. */
203 virtual double CalcFuelNeed(void);
205 virtual double CalcOxidizerNeed(void) {return 0.0;}
207 virtual double GetPowerAvailable(void) {return 0.0;};
209 virtual const FGColumnVector3& GetBodyForces(void);
210 virtual const FGColumnVector3& GetMoments(void);
212 bool LoadThruster(Element *el);
213 FGThruster* GetThruster(void) const {return Thruster;}
215 unsigned int GetSourceTank(unsigned int i) const;
216 unsigned int GetNumSourceTanks() const {return SourceTanks.size();}
218 virtual std::string GetEngineLabels(const std::string& delimiter) = 0;
219 virtual std::string GetEngineValues(const std::string& delimiter) = 0;
222 void LoadThrusterInputs();
225 /** Reduces the fuel in the active tanks by the amount required.
226 This function should be called from within the
227 derived class' Calculate() function before any other calculations are
228 done. This base class method removes fuel from the fuel tanks as
229 appropriate, and sets the starved flag if necessary. * /
230 virtual void ConsumeFuel(void); */
232 FGPropertyManager* PropertyManager;
234 const int EngineNumber;
239 double SLFuelFlowMax;
257 FGThruster* Thruster;
259 std::vector <int> SourceTanks;
261 void Debug(int from);
265 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%