]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGPropulsion.h
sync with JSBSim CVS
[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 <iosfwd>
43
44 #include "FGModel.h"
45 #include "math/FGMatrix33.h"
46 #include "input_output/FGXMLFileRead.h"
47
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 DEFINITIONS
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52 #define ID_PROPULSION "$Id: FGPropulsion.h,v 1.27 2011/05/20 03:18:36 jberndt Exp $"
53
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 FORWARD DECLARATIONS
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
58 namespace JSBSim {
59
60 class FGTank;
61 class FGEngine;
62
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66
67 /** Propulsion management class.
68     The Propulsion class is the container for the entire propulsion system, which is
69     comprised of engines, and tanks. Once the Propulsion class gets the config file,
70     it reads in the \<propulsion> section. Then:
71
72     -# The appropriate engine type instance is created
73     -# At least one tank object is created, and is linked to an engine.
74
75     At Run time each engine's Calculate() method is called.
76
77     <h3>Configuration File Format:</h3>
78
79   @code
80     <propulsion>
81         <engine file="{string}">
82           ... see FGEngine, FGThruster, and class for engine type ...
83         </engine>
84         ... more engines ...
85         <tank type="{FUEL | OXIDIZER}"> 
86           ... see FGTank ...
87         </tank>
88         ... more tanks ...
89         <dump-rate unit="{LBS/MIN | KG/MIN}"> {number} </dump-rate>
90     </propulsion>
91   @endcode
92
93     @author Jon S. Berndt
94     @version $Id: FGPropulsion.h,v 1.27 2011/05/20 03:18:36 jberndt Exp $
95     @see
96     FGEngine
97     FGTank
98 */
99
100 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 CLASS DECLARATION
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
103
104 class FGPropulsion : public FGModel, public FGXMLFileRead
105 {
106 public:
107   /// Constructor
108   FGPropulsion(FGFDMExec*);
109   /// Destructor
110   ~FGPropulsion();
111
112   /** Executes the propulsion model.
113       The initial plan for the FGPropulsion class calls for Run() to be executed,
114       calculating the power available from the engine.
115       Can pass in a value indicating if the executive is directing the simulation to Hold.
116       @param Holding if true, the executive has been directed to hold the sim from 
117                      advancing time. Some models may ignore this flag, such as the Input
118                      model, which may need to be active to listen on a socket for the
119                      "Resume" command to be given.
120       @return false if no error */
121   bool Run(bool Holding);
122
123   bool InitModel(void);
124
125   /** Loads the propulsion system (engine[s] and tank[s]).
126       Characteristics of the propulsion system are read in from the config file.
127       @param el pointer to an XML element that contains the engine information.
128       @return true if successfully loaded, otherwise false */
129   bool Load(Element* el);
130
131   /// Retrieves the number of engines defined for the aircraft.
132   unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
133
134   /** Retrieves an engine object pointer from the list of engines.
135       @param index the engine index within the vector container
136       @return the address of the specific engine, or zero if no such engine is
137               available */
138   FGEngine* GetEngine(unsigned int index) const {
139                       if (index < Engines.size()) return Engines[index];
140                       else                        return 0L;      }
141
142   /// Retrieves the number of tanks defined for the aircraft.
143   unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
144
145   /** Retrieves a tank object pointer from the list of tanks.
146       @param index the tank index within the vector container
147       @return the address of the specific tank, or zero if no such tank is
148               available */
149   FGTank* GetTank(unsigned int index) const {
150                       if (index < Tanks.size()) return Tanks[index];
151                       else                      return 0L;        }
152
153   /** Returns the number of fuel tanks currently actively supplying fuel */
154   int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
155
156   /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
157   int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
158
159   /** Loops the engines until thrust output steady (used for trimming) */
160   bool GetSteadyState(void);
161
162   /** Sets up the engines as running */
163   void InitRunning(int n);
164
165   std::string GetPropulsionStrings(const std::string& delimiter) const;
166   std::string GetPropulsionValues(const std::string& delimiter) const;
167
168   const FGColumnVector3& GetForces(void) const {return vForces; }
169   double GetForces(int n) const { return vForces(n);}
170   const FGColumnVector3& GetMoments(void) const {return vMoments;}
171   double GetMoments(int n) const {return vMoments(n);}
172
173   bool GetRefuel(void) const {return refuel;}
174   void SetRefuel(bool setting) {refuel = setting;}
175   bool GetFuelDump(void) const {return dump;}
176   void SetFuelDump(bool setting) {dump = setting;}
177   double Transfer(int source, int target, double amount);
178   void DoRefuel(double time_slice);
179   void DumpFuel(double time_slice);
180
181   FGColumnVector3& GetTanksMoment(void);
182   double GetTanksWeight(void);
183
184   std::ifstream* FindEngineFile(const std::string& filename);
185   std::string FindEngineFullPathname(const std::string& engine_filename);
186   inline int GetActiveEngine(void) const {return ActiveEngine;}
187   inline bool GetFuelFreeze(void) {return fuel_freeze;}
188   double GetTotalFuelQuantity(void) const {return TotalFuelQuantity;}
189
190   void SetMagnetos(int setting);
191   void SetStarter(int setting);
192   void SetCutoff(int setting=0);
193   void SetActiveEngine(int engine);
194   void SetFuelFreeze(bool f);
195   FGMatrix33& CalculateTankInertias(void);
196
197 private:
198   std::vector <FGEngine*>   Engines;
199   std::vector <FGTank*>     Tanks;
200   unsigned int numSelectedFuelTanks;
201   unsigned int numSelectedOxiTanks;
202   unsigned int numFuelTanks;
203   unsigned int numOxiTanks;
204   unsigned int numEngines;
205   unsigned int numTanks;
206   int ActiveEngine;
207   FGColumnVector3 vForces;
208   FGColumnVector3 vMoments;
209   FGColumnVector3 vTankXYZ;
210   FGColumnVector3 vXYZtank_arm;
211   FGMatrix33 tankJ;
212   bool refuel;
213   bool dump;
214   bool fuel_freeze;
215   double TotalFuelQuantity;
216   double DumpRate;
217   bool IsBound;
218   bool HavePistonEngine;
219   bool HaveTurbineEngine;
220   bool HaveTurboPropEngine;
221   bool HaveRocketEngine;
222   bool HaveElectricEngine;
223
224   int InitializedEngines;
225   bool HasInitializedEngines;
226
227   void bind();
228   void Debug(int from);
229 };
230 }
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232 #endif
233