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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42 # include <simgear/compiler.h>
43 # ifdef SG_HAVE_STD_INCLUDES
56 #include <models/propulsion/FGEngine.h>
57 #include <models/propulsion/FGTank.h>
58 #include <math/FGMatrix33.h>
59 #include <input_output/FGXMLFileRead.h>
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65 #define ID_PROPULSION "$Id$"
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77 /** Propulsion management class.
78 The Propulsion class is the container for the entire propulsion system, which is
79 comprised of engines, and tanks. Once the Propulsion class gets the config file,
80 it reads in the \<propulsion> section. Then:
82 -# The appropriate engine type instance is created
83 -# At least one tank object is created, and is linked to an engine.
85 At Run time each engine's Calculate() method is called.
87 <h3>Configuration File Format:</h3>
91 <engine file="{string}">
92 ... see FGEngine, FGThruster, and class for engine type ...
95 <tank type="{FUEL | OXIDIZER}">
99 <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate>
103 @author Jon S. Berndt
110 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
114 class FGPropulsion : public FGModel, public FGXMLFileRead
118 FGPropulsion(FGFDMExec*);
122 /** Executes the propulsion model.
123 The initial plan for the FGPropulsion class calls for Run() to be executed,
124 calculating the power available from the engine.
126 [Note: Should we be checking the Starved flag here?] */
129 bool InitModel(void);
131 /** Loads the propulsion system (engine[s] and tank[s]).
132 Characteristics of the propulsion system are read in from the config file.
133 @param el pointer to an XML element that contains the engine information.
134 @return true if successfully loaded, otherwise false */
135 bool Load(Element* el);
137 /// Retrieves the number of engines defined for the aircraft.
138 inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
140 /** Retrieves an engine object pointer from the list of engines.
141 @param index the engine index within the vector container
142 @return the address of the specific engine, or zero if no such engine is
144 inline FGEngine* GetEngine(unsigned int index) {
145 if (index <= Engines.size()-1) return Engines[index];
148 /// Retrieves the number of tanks defined for the aircraft.
149 inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
151 /** Retrieves a tank object pointer from the list of tanks.
152 @param index the tank index within the vector container
153 @return the address of the specific tank, or zero if no such tank is
155 inline FGTank* GetTank(unsigned int index) {
156 if (index <= Tanks.size()-1) return Tanks[index];
159 /** Returns the number of fuel tanks currently actively supplying fuel */
160 inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
162 /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
163 inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
165 /** Loops the engines until thrust output steady (used for trimming) */
166 bool GetSteadyState(void);
168 /** Sets up the engines as running */
169 void InitRunning(int n);
171 string GetPropulsionStrings(string delimeter);
172 string GetPropulsionValues(string delimeter);
174 inline FGColumnVector3& GetForces(void) {return vForces; }
175 inline double GetForces(int n) const { return vForces(n);}
176 inline FGColumnVector3& GetMoments(void) {return vMoments;}
177 inline double GetMoments(int n) const {return vMoments(n);}
179 inline bool GetRefuel(void) const {return refuel;}
180 inline void SetRefuel(bool setting) {refuel = setting;}
181 inline bool GetFuelDump(void) const {return dump;}
182 inline void SetFuelDump(bool setting) {dump = setting;}
183 double Transfer(int source, int target, double amount);
184 void DoRefuel(double time_slice);
185 void DumpFuel(double time_slice);
187 FGColumnVector3& GetTanksMoment(void);
188 double GetTanksWeight(void);
190 ifstream* FindEngineFile(string filename);
191 string FindEngineFullPathname(string engine_filename);
192 inline int GetActiveEngine(void) const {return ActiveEngine;}
193 inline bool GetFuelFreeze(void) {return fuel_freeze;}
194 double GetTotalFuelQuantity(void) const {return TotalFuelQuantity;}
196 void SetMagnetos(int setting);
197 void SetStarter(int setting);
198 void SetCutoff(int setting=0);
199 void SetActiveEngine(int engine);
200 void SetFuelFreeze(bool f);
201 FGMatrix33& CalculateTankInertias(void);
204 vector <FGEngine*> Engines;
205 vector <FGTank*> Tanks;
206 unsigned int numSelectedFuelTanks;
207 unsigned int numSelectedOxiTanks;
208 unsigned int numFuelTanks;
209 unsigned int numOxiTanks;
210 unsigned int numEngines;
211 unsigned int numTanks;
213 FGColumnVector3 vForces;
214 FGColumnVector3 vMoments;
215 FGColumnVector3 vTankXYZ;
216 FGColumnVector3 vXYZtank_arm;
221 double TotalFuelQuantity;
224 bool HavePistonEngine;
225 bool HaveTurbineEngine;
226 bool HaveTurboPropEngine;
227 bool HaveRocketEngine;
228 bool HaveElectricEngine;
230 int InitializedEngines;
231 bool HasInitializedEngines;
234 void Debug(int from);
237 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%