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
19 You should have received a copy of the GNU Lesser 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.
23 Further information about the GNU Lesser General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 #ifndef FGPROPULSION_H
35 #define FGPROPULSION_H
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 #include "math/FGMatrix33.h"
46 #include "input_output/FGXMLFileRead.h"
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 #define ID_PROPULSION "$Id$"
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67 /** Propulsion management class.
68 The Propulsion class is the container for the entire propulsion system, which is
69 comprised of engines, and tanks. Once the Propulsion class gets the config file,
70 it reads in the \<propulsion> section. Then:
72 -# The appropriate engine type instance is created
73 -# At least one tank object is created, and is linked to an engine.
75 At Run time each engine's Calculate() method is called.
77 <h3>Configuration File Format:</h3>
81 <engine file="{string}">
82 ... see FGEngine, FGThruster, and class for engine type ...
85 <tank type="{FUEL | OXIDIZER}">
89 <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate>
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
104 class FGPropulsion : public FGModel, public FGXMLFileRead
108 FGPropulsion(FGFDMExec*);
112 /** Executes the propulsion model.
113 The initial plan for the FGPropulsion class calls for Run() to be executed,
114 calculating the power available from the engine.
116 [Note: Should we be checking the Starved flag here?] */
119 bool InitModel(void);
121 /** Loads the propulsion system (engine[s] and tank[s]).
122 Characteristics of the propulsion system are read in from the config file.
123 @param el pointer to an XML element that contains the engine information.
124 @return true if successfully loaded, otherwise false */
125 bool Load(Element* el);
127 /// Retrieves the number of engines defined for the aircraft.
128 inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
130 /** Retrieves an engine object pointer from the list of engines.
131 @param index the engine index within the vector container
132 @return the address of the specific engine, or zero if no such engine is
134 inline FGEngine* GetEngine(unsigned int index) {
135 if (index <= Engines.size()-1) return Engines[index];
138 /// Retrieves the number of tanks defined for the aircraft.
139 inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
141 /** Retrieves a tank object pointer from the list of tanks.
142 @param index the tank index within the vector container
143 @return the address of the specific tank, or zero if no such tank is
145 inline FGTank* GetTank(unsigned int index) {
146 if (index <= Tanks.size()-1) return Tanks[index];
149 /** Returns the number of fuel tanks currently actively supplying fuel */
150 inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
152 /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
153 inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
155 /** Loops the engines until thrust output steady (used for trimming) */
156 bool GetSteadyState(void);
158 /** Sets up the engines as running */
159 void InitRunning(int n);
161 std::string GetPropulsionStrings(const std::string& delimiter);
162 std::string GetPropulsionValues(const std::string& delimiter);
164 inline FGColumnVector3& GetForces(void) {return vForces; }
165 inline double GetForces(int n) const { return vForces(n);}
166 inline FGColumnVector3& GetMoments(void) {return vMoments;}
167 inline double GetMoments(int n) const {return vMoments(n);}
169 inline bool GetRefuel(void) const {return refuel;}
170 inline void SetRefuel(bool setting) {refuel = setting;}
171 inline bool GetFuelDump(void) const {return dump;}
172 inline void SetFuelDump(bool setting) {dump = setting;}
173 double Transfer(int source, int target, double amount);
174 void DoRefuel(double time_slice);
175 void DumpFuel(double time_slice);
177 FGColumnVector3& GetTanksMoment(void);
178 double GetTanksWeight(void);
180 std::ifstream* FindEngineFile(const std::string& filename);
181 std::string FindEngineFullPathname(const std::string& engine_filename);
182 inline int GetActiveEngine(void) const {return ActiveEngine;}
183 inline bool GetFuelFreeze(void) {return fuel_freeze;}
184 double GetTotalFuelQuantity(void) const {return TotalFuelQuantity;}
186 void SetMagnetos(int setting);
187 void SetStarter(int setting);
188 void SetCutoff(int setting=0);
189 void SetActiveEngine(int engine);
190 void SetFuelFreeze(bool f);
191 FGMatrix33& CalculateTankInertias(void);
194 std::vector <FGEngine*> Engines;
195 std::vector <FGTank*> Tanks;
196 unsigned int numSelectedFuelTanks;
197 unsigned int numSelectedOxiTanks;
198 unsigned int numFuelTanks;
199 unsigned int numOxiTanks;
200 unsigned int numEngines;
201 unsigned int numTanks;
203 FGColumnVector3 vForces;
204 FGColumnVector3 vMoments;
205 FGColumnVector3 vTankXYZ;
206 FGColumnVector3 vXYZtank_arm;
211 double TotalFuelQuantity;
214 bool HavePistonEngine;
215 bool HaveTurbineEngine;
216 bool HaveTurboPropEngine;
217 bool HaveRocketEngine;
218 bool HaveElectricEngine;
220 int InitializedEngines;
221 bool HasInitializedEngines;
224 void Debug(int from);
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%