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