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.35 2012/04/14 18:10:44 bcoconni 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.35 2012/04/14 18:10:44 bcoconni 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;
152 FGColumnVector3 vXYZcg; // CG coordinates expressed in the structural frame
156 FGEngine(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input);
159 enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
161 EngineType GetType(void) const { return Type; }
162 virtual const string& GetName(void) const { return Name; }
165 virtual double GetThrottleMin(void) const { return MinThrottle; }
166 virtual double GetThrottleMax(void) const { return MaxThrottle; }
167 virtual bool GetStarter(void) const { return Starter; }
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; }
178 virtual void SetStarved(bool tt) { Starved = tt; }
179 virtual void SetStarved(void) { Starved = true; }
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; }
185 virtual void SetStarter(bool s) { Starter = s; }
187 virtual int InitRunning(void){ return 1; }
189 /** Resets the Engine parameters to the initial conditions */
190 void ResetToIC(void);
192 /** Calculates the thrust of the engine, and other engine functions. */
193 virtual void Calculate(void) = 0;
195 virtual double GetThrust(void) const;
197 /// Sets engine placement information
198 virtual void SetPlacement(const FGColumnVector3& location, const FGColumnVector3& orientation);
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);
206 virtual double CalcOxidizerNeed(void) {return 0.0;}
208 virtual double GetPowerAvailable(void) {return 0.0;};
210 virtual const FGColumnVector3& GetBodyForces(void);
211 virtual const FGColumnVector3& GetMoments(void);
213 bool LoadThruster(Element *el);
214 FGThruster* GetThruster(void) const {return Thruster;}
216 unsigned int GetSourceTank(unsigned int i) const;
217 unsigned int GetNumSourceTanks() const {return SourceTanks.size();}
219 virtual std::string GetEngineLabels(const std::string& delimiter) = 0;
220 virtual std::string GetEngineValues(const std::string& delimiter) = 0;
223 void LoadThrusterInputs();
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); */
233 FGPropertyManager* PropertyManager;
235 const int EngineNumber;
240 double SLFuelFlowMax;
258 FGThruster* Thruster;
260 std::vector <int> SourceTanks;
262 void Debug(int from);
266 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%