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
49 # include <iterator.h>
59 #include <models/propulsion/FGEngine.h>
60 #include <models/propulsion/FGTank.h>
61 #include <math/FGMatrix33.h>
62 #include <input_output/FGXMLFileRead.h>
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 #define ID_PROPULSION "$Id$"
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
80 /** Propulsion management class.
81 The Propulsion class is the container for the entire propulsion system, which is
82 comprised of engines, and tanks. Once the Propulsion class gets the config file,
83 it reads in information which is specific to a type of engine. Then:
85 -# The appropriate engine type instance is created
86 -# At least one tank object is created, and is linked to an engine.
88 At Run time each engines Calculate() method is called.
96 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
100 class FGPropulsion : public FGModel, public FGXMLFileRead
104 FGPropulsion(FGFDMExec*);
108 /** Executes the propulsion model.
109 The initial plan for the FGPropulsion class calls for Run() to be executed,
110 calculating the power available from the engine.
112 [Note: Should we be checking the Starved flag here?] */
115 /** Loads the propulsion system (engine[s] and tank[s]).
116 Characteristics of the propulsion system are read in from the config file.
117 @param el pointer to an XML element that contains the engine information.
118 @return true if successfully loaded, otherwise false */
119 bool Load(Element* el);
121 /// Retrieves the number of engines defined for the aircraft.
122 inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
124 /** Retrieves an engine object pointer from the list of engines.
125 @param index the engine index within the vector container
126 @return the address of the specific engine, or zero if no such engine is
128 inline FGEngine* GetEngine(unsigned int index) {
129 if (index <= Engines.size()-1) return Engines[index];
132 /// Retrieves the number of tanks defined for the aircraft.
133 inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
135 /** Retrieves a tank object pointer from the list of tanks.
136 @param index the tank index within the vector container
137 @return the address of the specific tank, or zero if no such tank is
139 inline FGTank* GetTank(unsigned int index) {
140 if (index <= Tanks.size()-1) return Tanks[index];
143 /** Returns the number of fuel tanks currently actively supplying fuel */
144 inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
146 /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
147 inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
149 /** Loops the engines until thrust output steady (used for trimming) */
150 bool GetSteadyState(void);
152 /** starts the engines in IC mode (dt=0). All engine-specific setup must
153 be done before calling this (i.e. magnetos, starter engage, etc.) */
154 bool ICEngineStart(void);
156 std::string GetPropulsionStrings(std::string delimeter);
157 std::string GetPropulsionValues(std::string delimeter);
159 inline FGColumnVector3& GetForces(void) {return vForces; }
160 inline double GetForces(int n) const { return vForces(n);}
161 inline FGColumnVector3& GetMoments(void) {return vMoments;}
162 inline double GetMoments(int n) const {return vMoments(n);}
164 inline bool GetRefuel(void) {return refuel;}
165 inline void SetRefuel(bool setting) {refuel = setting;}
166 double Transfer(int source, int target, double amount);
167 void DoRefuel(double time_slice);
169 FGColumnVector3& GetTanksMoment(void);
170 double GetTanksWeight(void);
172 std::ifstream* FindEngineFile(std::string filename);
173 std::string FindEngineFullPathname(std::string engine_filename);
174 inline int GetActiveEngine(void) const {return ActiveEngine;}
175 inline bool GetFuelFreeze(void) {return fuel_freeze;}
176 double GetTotalFuelQuantity(void) const {return TotalFuelQuantity;}
178 void SetMagnetos(int setting);
179 void SetStarter(int setting);
180 void SetCutoff(int setting=0);
181 void SetActiveEngine(int engine);
182 void SetFuelFreeze(bool f);
183 FGMatrix33& CalculateTankInertias(void);
189 std::vector <FGEngine*> Engines;
190 std::vector <FGTank*> Tanks;
191 std::vector <FGTank*>::iterator iTank;
192 unsigned int numSelectedFuelTanks;
193 unsigned int numSelectedOxiTanks;
194 unsigned int numFuelTanks;
195 unsigned int numOxiTanks;
196 unsigned int numEngines;
197 unsigned int numTanks;
199 FGColumnVector3 vForces;
200 FGColumnVector3 vMoments;
201 FGColumnVector3 vTankXYZ;
202 FGColumnVector3 vXYZtank_arm;
206 double TotalFuelQuantity;
208 bool HavePistonEngine;
209 bool HaveTurbineEngine;
210 bool HaveTurboPropEngine;
211 bool HaveRocketEngine;
212 bool HaveElectricEngine;
214 void Debug(int from);
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%