]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGPropulsion.h
Sync with JSBSim CVS again
[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 (jon@jsbsim.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 #include <vector>
42 #include <fstream>
43
44 #include "FGModel.h"
45 #include <models/propulsion/FGEngine.h>
46 #include <models/propulsion/FGTank.h>
47 #include <math/FGMatrix33.h>
48 #include <input_output/FGXMLFileRead.h>
49
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51 DEFINITIONS
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54 #define ID_PROPULSION "$Id$"
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 FORWARD DECLARATIONS
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 namespace JSBSim {
61
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 CLASS DOCUMENTATION
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
65
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:
70
71     -# The appropriate engine type instance is created
72     -# At least one tank object is created, and is linked to an engine.
73
74     At Run time each engine's Calculate() method is called.
75
76     <h3>Configuration File Format:</h3>
77
78   @code
79     <propulsion>
80         <engine file="{string}">
81           ... see FGEngine, FGThruster, and class for engine type ...
82         </engine>
83         ... more engines ...
84         <tank type="{FUEL | OXIDIZER}"> 
85           ... see FGTank ...
86         </tank>
87         ... more tanks ...
88         <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate>
89     </propulsion>
90   @endcode
91
92     @author Jon S. Berndt
93     @version $Id$
94     @see
95     FGEngine
96     FGTank
97 */
98
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 CLASS DECLARATION
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102
103 class FGPropulsion : public FGModel, public FGXMLFileRead
104 {
105 public:
106   /// Constructor
107   FGPropulsion(FGFDMExec*);
108   /// Destructor
109   ~FGPropulsion();
110
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.
114
115       [Note: Should we be checking the Starved flag here?] */
116   bool Run(void);
117
118   bool InitModel(void);
119
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);
125
126   /// Retrieves the number of engines defined for the aircraft.
127   inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
128
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
132               available */
133   inline FGEngine* GetEngine(unsigned int index) {
134                       if (index <= Engines.size()-1) return Engines[index];
135                       else                           return 0L;      }
136
137   /// Retrieves the number of tanks defined for the aircraft.
138   inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
139
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
143               available */
144   inline FGTank* GetTank(unsigned int index) {
145                       if (index <= Tanks.size()-1) return Tanks[index];
146                       else                         return 0L;        }
147
148   /** Returns the number of fuel tanks currently actively supplying fuel */
149   inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
150
151   /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
152   inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
153
154   /** Loops the engines until thrust output steady (used for trimming) */
155   bool GetSteadyState(void);
156
157   /** Sets up the engines as running */
158   void InitRunning(int n);
159
160   string GetPropulsionStrings(string delimeter);
161   string GetPropulsionValues(string delimeter);
162
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);}
167
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);
175
176   FGColumnVector3& GetTanksMoment(void);
177   double GetTanksWeight(void);
178
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;}
184
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);
191
192 private:
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;
201   int ActiveEngine;
202   FGColumnVector3 vForces;
203   FGColumnVector3 vMoments;
204   FGColumnVector3 vTankXYZ;
205   FGColumnVector3 vXYZtank_arm;
206   FGMatrix33 tankJ;
207   bool refuel;
208   bool dump;
209   bool fuel_freeze;
210   double TotalFuelQuantity;
211   double DumpRate;
212   bool IsBound;
213   bool HavePistonEngine;
214   bool HaveTurbineEngine;
215   bool HaveTurboPropEngine;
216   bool HaveRocketEngine;
217   bool HaveElectricEngine;
218
219   int InitializedEngines;
220   bool HasInitializedEngines;
221
222   void bind();
223   void Debug(int from);
224 };
225 }
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 #endif
228