JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
FGEngine.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGEngine.h
4  Author: Jon S. Berndt
5  Date started: 01/21/99
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 details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA.
21 
22  Further information about the GNU Lesser General Public License can also be found on
23  the world wide web at http://www.gnu.org.
24 
25 FUNCTIONAL DESCRIPTION
26 --------------------------------------------------------------------------------
27 
28 Based on Flightgear code, which is based on LaRCSim. This class simulates
29 a generic engine.
30 
31 HISTORY
32 --------------------------------------------------------------------------------
33 01/21/99 JSB Created
34 
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 SENTRY
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 
39 #ifndef FGENGINE_H
40 #define FGENGINE_H
41 
42 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 INCLUDES
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 
46 #include <vector>
47 #include <string>
48 
49 #include "math/FGModelFunctions.h"
50 #include "math/FGColumnVector3.h"
51 
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 FORWARD DECLARATIONS
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 
56 namespace JSBSim {
57 
58 class FGFDMExec;
59 class FGThruster;
60 class Element;
61 class FGPropertyManager;
62 
63 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 CLASS DOCUMENTATION
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 CLASS DECLARATION
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102 
104 {
105 public:
106  struct Inputs {
107  double Pressure;
108  double PressureRatio;
109  double Temperature;
110  double Density;
111  double DensityRatio;
112  double Soundspeed;
113  double TotalPressure;
114  double TAT_c;
115  double Vt;
116  double Vc;
117  double qbar;
118  double alpha;
119  double beta;
120  double H_agl;
121  FGColumnVector3 AeroUVW;
122  FGColumnVector3 AeroPQR;
123  FGColumnVector3 PQRi;
124  std::vector <double> ThrottleCmd;
125  std::vector <double> MixtureCmd;
126  std::vector <double> ThrottlePos;
127  std::vector <double> MixturePos;
128  std::vector <double> PropAdvance;
129  std::vector <bool> PropFeather;
130  double TotalDeltaT;
131  };
132 
133  FGEngine(int engine_number, struct Inputs& input);
134  ~FGEngine() override;
135 
136  enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric};
137 
138  EngineType GetType(void) const { return Type; }
139  virtual const std::string& GetName(void) const { return Name; }
140 
141  // Engine controls
142  virtual double GetThrottleMin(void) const { return MinThrottle; }
143  virtual double GetThrottleMax(void) const { return MaxThrottle; }
144  virtual bool GetStarter(void) const { return Starter; }
145 
146  virtual double getFuelFlow_gph () const {return FuelFlow_gph;}
147  virtual double getFuelFlow_pph () const {return FuelFlow_pph;}
148  virtual double GetFuelFlowRate(void) const {return FuelFlowRate;}
149  virtual double GetFuelFlowRateGPH(void) const {return FuelFlowRate*3600/FuelDensity;}
150  virtual double GetFuelUsedLbs(void) const {return FuelUsedLbs;}
151  virtual bool GetStarved(void) const { return Starved; }
152  virtual bool GetRunning(void) const { return Running; }
153  virtual bool GetCranking(void) const { return Cranking; }
154 
155  virtual void SetStarved(bool tt) { Starved = tt; }
156  virtual void SetStarved(void) { Starved = true; }
157 
158  virtual void SetRunning(bool bb) { Running=bb; }
159  virtual void SetName(const std::string& name) { Name = name; }
160  virtual void SetFuelFreeze(bool f) { FuelFreeze = f; }
161  virtual void SetFuelDensity(double d) { FuelDensity = d; }
162 
163  virtual void SetStarter(bool s) { Starter = s; }
164 
165  virtual int InitRunning(void){ return 1; }
166 
168  virtual void ResetToIC(void);
169 
171  virtual void Calculate(void) = 0;
172 
173  virtual double GetThrust(void) const;
174 
179  virtual double CalcFuelNeed(void);
180 
181  virtual double CalcOxidizerNeed(void) {return 0.0;}
182 
183  virtual double GetPowerAvailable(void) {return 0.0;};
184 
185  virtual const FGColumnVector3& GetBodyForces(void);
186  virtual const FGColumnVector3& GetMoments(void);
187 
188  void LoadThruster(FGFDMExec* exec, Element *el);
189  FGThruster* GetThruster(void) const {return Thruster;}
190 
191  unsigned int GetSourceTank(unsigned int i) const;
192  size_t GetNumSourceTanks() const {return SourceTanks.size();}
193 
194  virtual std::string GetEngineLabels(const std::string& delimiter) = 0;
195  virtual std::string GetEngineValues(const std::string& delimiter) = 0;
196 
197  struct Inputs& in;
198  void LoadThrusterInputs();
199 
200 protected:
201 
202  std::string Name;
203  const int EngineNumber;
204  EngineType Type;
205  double SLFuelFlowMax;
206  double MaxThrottle;
207  double MinThrottle;
208 
209  double FuelExpended;
210  double FuelFlowRate;
211  double PctPower;
212  bool Starter;
213  bool Starved;
214  bool Running;
215  bool Cranking;
216  bool FuelFreeze;
217 
218  double FuelFlow_gph;
219  double FuelFlow_pph;
220  double FuelUsedLbs;
221  double FuelDensity;
222 
223  FGThruster* Thruster;
224 
225  std::vector <int> SourceTanks;
226 
227  bool Load(FGFDMExec *exec, Element *el);
228  void Debug(int from);
229 };
230 }
231 
232 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 #endif
This class implements a 3 element column vector.
Base class for all engines.
Definition: FGEngine.h:104
virtual void ResetToIC(void)
Resets the Engine parameters to the initial conditions.
Definition: FGEngine.cpp:77
virtual double CalcFuelNeed(void)
The fuel need is calculated based on power levels and flow rate for that power level.
Definition: FGEngine.cpp:93
virtual void Calculate(void)=0
Calculates the thrust of the engine, and other engine functions.
The model functions class provides the capability for loading, storing, and executing arbitrary funct...