]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/FGPropulsion.h
Sync. w. JSB CVS as of 15/01/2007
[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 <iterator>
46 #    include <fstream>
47 #  else
48 #    include <vector.h>
49 #    include <iterator.h>
50 #    include <fstream.h>
51 #  endif
52 #else
53 #  include <vector>
54 #  include <iterator>
55 #  include <fstream>
56 #endif
57
58 #include "FGModel.h"
59 #include <models/propulsion/FGEngine.h>
60 #include <models/propulsion/FGTank.h>
61 #include <math/FGMatrix33.h>
62 #include <input_output/FGXMLElement.h>
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 DEFINITIONS
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 #define ID_PROPULSION "$Id$"
69
70 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 FORWARD DECLARATIONS
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
73
74 namespace JSBSim {
75
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 CLASS DOCUMENTATION
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79
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:
84
85     -# The appropriate engine type instance is created
86     -# At least one tank object is created, and is linked to an engine.
87
88     At Run time each engines Calculate() method is called.
89     @author Jon S. Berndt
90     @version $Id$
91     @see
92     FGEngine
93     FGTank
94 */
95
96 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97 CLASS DECLARATION
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
99
100 class FGPropulsion : public FGModel
101 {
102 public:
103   /// Constructor
104   FGPropulsion(FGFDMExec*);
105   /// Destructor
106   ~FGPropulsion();
107
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.
111
112       [Note: Should we be checking the Starved flag here?] */
113   bool Run(void);
114
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);
120
121   /// Retrieves the number of engines defined for the aircraft.
122   inline unsigned int GetNumEngines(void) const {return (unsigned int)Engines.size();}
123
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
127               available */
128   inline FGEngine* GetEngine(unsigned int index) {
129                       if (index <= Engines.size()-1) return Engines[index];
130                       else                           return 0L;      }
131
132   /// Retrieves the number of tanks defined for the aircraft.
133   inline unsigned int GetNumTanks(void) const {return (unsigned int)Tanks.size();}
134
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
138               available */
139   inline FGTank* GetTank(unsigned int index) {
140                       if (index <= Tanks.size()-1) return Tanks[index];
141                       else                         return 0L;        }
142
143   /** Returns the number of fuel tanks currently actively supplying fuel */
144   inline int GetnumSelectedFuelTanks(void) const {return numSelectedFuelTanks;}
145
146   /** Returns the number of oxidizer tanks currently actively supplying oxidizer */
147   inline int GetnumSelectedOxiTanks(void) const {return numSelectedOxiTanks;}
148
149   /** Loops the engines until thrust output steady (used for trimming) */
150   bool GetSteadyState(void);
151
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);
155
156   string GetPropulsionStrings(string delimeter);
157   string GetPropulsionValues(string delimeter);
158
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);}
163
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);
168
169   FGColumnVector3& GetTanksMoment(void);
170   double GetTanksWeight(void);
171
172   ifstream* FindEngineFile(string filename);
173   string FindEngineFullPathname(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;}
177
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);
184
185   void bind();
186   void unbind();
187
188 private:
189   vector <FGEngine*>   Engines;
190   vector <FGTank*>     Tanks;
191   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;
198   int ActiveEngine;
199   FGColumnVector3 vForces;
200   FGColumnVector3 vMoments;
201   FGColumnVector3 vTankXYZ;
202   FGColumnVector3 vXYZtank_arm;
203   FGMatrix33 tankJ;
204   bool refuel;
205   bool fuel_freeze;
206   double TotalFuelQuantity;
207   bool IsBound;
208   bool HavePistonEngine;
209   bool HaveTurbineEngine;
210   bool HaveTurboPropEngine;
211   bool HaveRocketEngine;
212   bool HaveElectricEngine;
213
214   void Debug(int from);
215 };
216 }
217 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
218 #endif
219