1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.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 <models/propulsion/FGEngine.h>
46 #include <models/propulsion/FGTank.h>
47 #include <math/FGMatrix33.h>
48 #include <input_output/FGXMLFileRead.h>
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 #define ID_PROPULSION "$Id$"
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /** Propulsion management class.
67 The Propulsion class is the container for the entire propulsion system, which is
68 comprised of engines, and tanks. Once the Propulsion class gets the config file,
69 it reads in the \<propulsion> section. Then:
71 -# The appropriate engine type instance is created
72 -# At least one tank object is created, and is linked to an engine.
74 At Run time each engine's Calculate() method is called.
76 <h3>Configuration File Format:</h3>
80 <engine file="{string}">
81 ... see FGEngine, FGThruster, and class for engine type ...
84 <tank type="{FUEL | OXIDIZER}">
88 <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate>
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
103 class FGPropulsion : public FGModel, public FGXMLFileRead
107 FGPropulsion(FGFDMExec*);
111 /** Executes the propulsion model.
112 The initial plan for the FGPropulsion class calls for Run() to be executed,
113 calculating the power available from the engine.
115 [Note: Should we be checking the Starved flag here?] */
118 bool InitModel(void);
120 /** Loads the propulsion system (engine[s] and tank[s]).
121 Characteristics of the propulsion system are read in from the config file.
122 @param el pointer to an XML element that contains the engine information.
123 @return true if successfully loaded, otherwise false */
124 bool Load(Element* el);
126 /// Retrieves the number of engines defined for the aircraft.
127 inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
129 /** Retrieves an engine object pointer from the list of engines.
130 @param index the engine index within the vector container
131 @return the address of the specific engine, or zero if no such engine is
133 inline FGEngine* GetEngine(unsigned int index) {
134 if (index <= Engines.size()-1) return Engines[index];
137 /// Retrieves the number of tanks defined for the aircraft.
138 inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
140 /** Retrieves a tank object pointer from the list of tanks.
141 @param index the tank index within the vector container
142 @return the address of the specific tank, or zero if no such tank is
144 inline FGTank* GetTank(unsigned int index) {
145 if (index <= Tanks.size()-1) return Tanks[index];
148 /** Returns the number of fuel tanks currently actively supplying fuel */
149 inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
151 /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
152 inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
154 /** Loops the engines until thrust output steady (used for trimming) */
155 bool GetSteadyState(void);
157 /** Sets up the engines as running */
158 void InitRunning(int n);
160 string GetPropulsionStrings(string delimeter);
161 string GetPropulsionValues(string delimeter);
163 inline FGColumnVector3& GetForces(void) {return vForces; }
164 inline double GetForces(int n) const { return vForces(n);}
165 inline FGColumnVector3& GetMoments(void) {return vMoments;}
166 inline double GetMoments(int n) const {return vMoments(n);}
168 inline bool GetRefuel(void) const {return refuel;}
169 inline void SetRefuel(bool setting) {refuel = setting;}
170 inline bool GetFuelDump(void) const {return dump;}
171 inline void SetFuelDump(bool setting) {dump = setting;}
172 double Transfer(int source, int target, double amount);
173 void DoRefuel(double time_slice);
174 void DumpFuel(double time_slice);
176 FGColumnVector3& GetTanksMoment(void);
177 double GetTanksWeight(void);
179 ifstream* FindEngineFile(string filename);
180 string FindEngineFullPathname(string engine_filename);
181 inline int GetActiveEngine(void) const {return ActiveEngine;}
182 inline bool GetFuelFreeze(void) {return fuel_freeze;}
183 double GetTotalFuelQuantity(void) const {return TotalFuelQuantity;}
185 void SetMagnetos(int setting);
186 void SetStarter(int setting);
187 void SetCutoff(int setting=0);
188 void SetActiveEngine(int engine);
189 void SetFuelFreeze(bool f);
190 FGMatrix33& CalculateTankInertias(void);
193 vector <FGEngine*> Engines;
194 vector <FGTank*> Tanks;
195 unsigned int numSelectedFuelTanks;
196 unsigned int numSelectedOxiTanks;
197 unsigned int numFuelTanks;
198 unsigned int numOxiTanks;
199 unsigned int numEngines;
200 unsigned int numTanks;
202 FGColumnVector3 vForces;
203 FGColumnVector3 vMoments;
204 FGColumnVector3 vTankXYZ;
205 FGColumnVector3 vXYZtank_arm;
210 double TotalFuelQuantity;
213 bool HavePistonEngine;
214 bool HaveTurbineEngine;
215 bool HaveTurboPropEngine;
216 bool HaveRocketEngine;
217 bool HaveElectricEngine;
219 int InitializedEngines;
220 bool HasInitializedEngines;
223 void Debug(int from);
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%