]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGPropulsion.h
71351477e721b0b6b9d1033d67fb102b73a63ea3
[flightgear.git] / src / FDM / JSBSim / models / FGPropulsion.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGPropulsion.h
4  Author:       Jon S. Berndt
5  Date started: 08/20/00
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8
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
12  version.
13
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
17  details.
18
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.
22
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.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 08/20/00   JSB   Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGPROPULSION_H
35 #define FGPROPULSION_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #ifdef FGFS
42 #  include <simgear/compiler.h>
43 #  ifdef SG_HAVE_STD_INCLUDES
44 #    include <vector>
45 #    include <fstream>
46 #  else
47 #    include <vector.h>
48 #    include <fstream.h>
49 #  endif
50 #else
51 #  include <vector>
52 #  include <fstream>
53 #endif
54
55 #include "FGModel.h"
56 #include <models/propulsion/FGEngine.h>
57 #include <models/propulsion/FGTank.h>
58 #include <math/FGMatrix33.h>
59 #include <input_output/FGXMLFileRead.h>
60
61 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 DEFINITIONS
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
64
65 #define ID_PROPULSION "$Id$"
66
67 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68 FORWARD DECLARATIONS
69 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
70
71 namespace JSBSim {
72
73 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74 CLASS DOCUMENTATION
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
76
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:
81
82     -# The appropriate engine type instance is created
83     -# At least one tank object is created, and is linked to an engine.
84
85     At Run time each engine's Calculate() method is called.
86
87     <h3>Configuration File Format:</h3>
88
89   @code
90     <propulsion>
91         <engine file="{string}">
92           ... see FGEngine, FGThruster, and class for engine type ...
93         </engine>
94         ... more engines ...
95         <tank type="{FUEL | OXIDIZER}"> 
96           ... see FGTank ...
97         </tank>
98         ... more tanks ...
99         <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate>
100     </propulsion>
101   @endcode
102
103     @author Jon S. Berndt
104     @version $Id$
105     @see
106     FGEngine
107     FGTank
108 */
109
110 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
111 CLASS DECLARATION
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
113
114 class FGPropulsion : public FGModel, public FGXMLFileRead
115 {
116 public:
117   /// Constructor
118   FGPropulsion(FGFDMExec*);
119   /// Destructor
120   ~FGPropulsion();
121
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.
125
126       [Note: Should we be checking the Starved flag here?] */
127   bool Run(void);
128
129   bool InitModel(void);
130
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);
136
137   /// Retrieves the number of engines defined for the aircraft.
138   inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
139
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
143               available */
144   inline FGEngine* GetEngine(unsigned int index) {
145                       if (index <= Engines.size()-1) return Engines[index];
146                       else                           return 0L;      }
147
148   /// Retrieves the number of tanks defined for the aircraft.
149   inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
150
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
154               available */
155   inline FGTank* GetTank(unsigned int index) {
156                       if (index <= Tanks.size()-1) return Tanks[index];
157                       else                         return 0L;        }
158
159   /** Returns the number of fuel tanks currently actively supplying fuel */
160   inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
161
162   /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
163   inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
164
165   /** Loops the engines until thrust output steady (used for trimming) */
166   bool GetSteadyState(void);
167
168   /** Sets up the engines as running */
169   void InitRunning(int n);
170
171   string GetPropulsionStrings(string delimeter);
172   string GetPropulsionValues(string delimeter);
173
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);}
178
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);
186
187   FGColumnVector3& GetTanksMoment(void);
188   double GetTanksWeight(void);
189
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;}
195
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);
202
203 private:
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;
212   int ActiveEngine;
213   FGColumnVector3 vForces;
214   FGColumnVector3 vMoments;
215   FGColumnVector3 vTankXYZ;
216   FGColumnVector3 vXYZtank_arm;
217   FGMatrix33 tankJ;
218   bool refuel;
219   bool dump;
220   bool fuel_freeze;
221   double TotalFuelQuantity;
222   double DumpRate;
223   bool IsBound;
224   bool HavePistonEngine;
225   bool HaveTurbineEngine;
226   bool HaveTurboPropEngine;
227   bool HaveRocketEngine;
228   bool HaveElectricEngine;
229
230   int InitializedEngines;
231   bool HasInitializedEngines;
232
233   void bind();
234   void Debug(int from);
235 };
236 }
237 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 #endif
239