JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
FGPiston.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGPiston.h
4  Author: Jon S. Berndt
5  Date started: 09/12/2000
6 
7  ------------- Copyright (C) 2000 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 09/12/2000 JSB Created
29 10/01/2001 DPM Modified to use equations from Dave Luff's piston model.
30 11/01/2008 RKJ Modified piston engine model for more general use.
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 SENTRY
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34 
35 #ifndef FGPISTON_H
36 #define FGPISTON_H
37 
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 
42 #include "FGEngine.h"
43 #include "math/FGTable.h"
44 
45 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 DEFINITIONS
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 
49 #define FG_MAX_BOOST_SPEEDS 3
50 
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 FORWARD DECLARATIONS
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 
55 namespace JSBSim {
56 
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS DOCUMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 
219 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220 CLASS DECLARATION
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
222 
223 class FGPiston : public FGEngine
224 {
225 public:
227  FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input);
229  ~FGPiston();
230 
231  std::string GetEngineLabels(const std::string& delimiter);
232  std::string GetEngineValues(const std::string& delimiter);
233 
234  void Calculate(void);
235  double GetPowerAvailable(void) const {return (HP * hptoftlbssec);}
236  double CalcFuelNeed(void);
237 
238  void ResetToIC(void);
239  void SetMagnetos(int magnetos) {Magnetos = magnetos;}
240 
241  double GetEGT(void) const { return EGT_degC; }
242  int GetMagnetos(void) const {return Magnetos;}
243 
244  double getExhaustGasTemp_degF(void) const {return KelvinToFahrenheit(ExhaustGasTemp_degK);}
245  double getManifoldPressure_inHg(void) const {return ManifoldPressure_inHg;}
246  double getCylinderHeadTemp_degF(void) const {return KelvinToFahrenheit(CylinderHeadTemp_degK);}
247  double getOilPressure_psi(void) const {return OilPressure_psi;}
248  double getOilTemp_degF (void) const {return KelvinToFahrenheit(OilTemp_degK);}
249  double getRPM(void) const {return RPM;}
250  double getAFR(void) const {return m_dot_fuel > 0.0 ? m_dot_air / m_dot_fuel : INFINITY;}
251 
252 protected:
253 
254 private:
255  int crank_counter = 0;
256 
257  double IndicatedHorsePower = 0.0;
258  //double IndicatedPower;
259  double PMEP = 0.0;
260  double FMEP = 0.0;
261  double FMEPDynamic = 0.0;
262  double FMEPStatic = 0.0;
263  //double T_Intake;
264 
265  void doEngineStartup(void);
266  void doBoostControl(void);
267  void doMAP(void);
268  void doAirFlow(void);
269  void doFuelFlow(void);
270  void doEnginePower(void);
271  void doEGT(void);
272  void doCHT(void);
273  void doOilPressure(void);
274  void doOilTemperature(void);
275  double GetStdPressure100K(double altitude) const;
276 
277  int InitRunning(void);
278 
279  //
280  // constants
281  //
282 
283  const double R_air;
284  //const double rho_fuel; // kg/m^3
285  const double calorific_value_fuel; // J/Kg (approximate)
286  const double Cp_air; // J/KgK
287  const double Cp_fuel; // J/KgK
288  const double standard_pressure; //Pa
289 
290 
291  FGTable *Lookup_Combustion_Efficiency;
292  FGTable *Mixture_Efficiency_Correlation;
293 
294  //
295  // Configuration
296  //
297  double MinManifoldPressure_inHg = 0.0; // Inches Hg
298  double MaxManifoldPressure_inHg = 0.0; // Inches Hg
299  //double MaxManifoldPressure_Percent; // MaxManifoldPressure / 29.92
300  double ManifoldPressureLag = 0.0; // Manifold Pressure delay in seconds.
301  double Displacement = 0.0; // cubic inches
302  double displacement_SI = 0.0; // cubic meters
303  double MaxHP = 0.0; // horsepower
304  double StaticFriction_HP = 0.0; // horsepower: amount subtracted from final engine power
305  double SparkFailDrop = 0.0; // drop of power due to spark failure
306  double Cycles = 0.0; // cycles/power stroke
307  double IdleRPM = 0.0; // revolutions per minute
308  double MaxRPM = 0.0; // revolutions per minute
309  double Bore = 0.0; // inches
310  double Stroke = 0.0; // inches
311  double Cylinders = 0.0; // number
312  double CylinderHeadMass = 0.0; // kilograms
313  double CompressionRatio = 0.0; // number
314  double Z_airbox = 0.0; // number representing intake impediance before the throttle
315  double Z_throttle = 0.0; // number representing slope of throttle impediance
316  double PeakMeanPistonSpeed_fps = 0.0; // ft/sec speed where intake valves begin to choke. Typically 33-50 fps
317  double RatedMeanPistonSpeed_fps = 0.0; // ft/sec derived from MaxRPM and stroke.
318  double Ram_Air_Factor = 0.0; // number
319 
320  double StarterTorque = 0.0;// Peak Torque of the starter motor
321  double StarterRPM = 0.0; // Peak RPM of the starter motor
322  double StarterGain = 0.0; // control the torque of the starter motor.
323  int BoostSpeeds = 0; // Number of super/turbocharger boost speeds - zero implies no turbo/supercharging.
324  int BoostSpeed = 0; // The current boost-speed (zero-based).
325  bool Boosted = false; // Set true for boosted engine.
326  int BoostManual = 0; // The raw value read in from the config file - should be 1 or 0 - see description below.
327  bool bBoostManual = false; // Set true if pilot must manually control the boost speed.
328  int BoostOverride = 0; // The raw value read in from the config file - should be 1 or 0 - see description below.
329  bool bBoostOverride = false; // Set true if pilot override of the boost regulator was fitted.
330  // (Typically called 'war emergency power').
331  bool bTakeoffBoost = false; // Set true if extra takeoff / emergency boost above rated boost could be attained.
332  // (Typically by extra throttle movement past a mechanical 'gate').
333  double TakeoffBoost = 0.0; // Sea-level takeoff boost in psi. (if fitted).
334  double RatedBoost[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Sea-level rated boost in psi.
335  double RatedAltitude[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Altitude at which full boost is reached (boost regulation ends)
336  // and at which power starts to fall with altitude [ft].
337  double RatedRPM[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Engine speed at which the rated power for each boost speed is delivered [rpm].
338  double RatedPower[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Power at rated throttle position at rated altitude [HP].
339  double BoostSwitchAltitude[FG_MAX_BOOST_SPEEDS - 1] = {0.0, 0.0}; // Altitude at which switchover (currently assumed automatic)
340  // from one boost speed to next occurs [ft].
341  double BoostSwitchPressure[FG_MAX_BOOST_SPEEDS - 1] = {0.0, 0.0}; // Pressure at which boost speed switchover occurs [Pa]
342  double BoostMul[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Pressure multiplier of unregulated supercharger
343  double RatedMAP[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Rated manifold absolute pressure [Pa] (BCV clamp)
344  double TakeoffMAP[FG_MAX_BOOST_SPEEDS] = {0.0, 0.0, 0.0}; // Takeoff setting manifold absolute pressure [Pa] (BCV clamp)
345  double BoostSwitchHysteresis = 0.0; // Pa.
346  double BoostLossFactor = 0.0; // multiplier for HP consumed by the supercharger
347 
348  double minMAP = 0.0; // Pa
349  double maxMAP = 0.0; // Pa
350  double MAP = 0.0; // Pa
351  double TMAP = 0.0; // Pa - throttle manifold pressure e.g. before the supercharger boost
352  double ISFC = 0.0; // Indicated specific fuel consumption [lbs/horsepower*hour
353 
354  //
355  // Inputs (in addition to those in FGEngine).
356  //
357  double p_amb = 0.0; // Pascals
358  double p_ram = 0.0; // Pascals
359  double T_amb = 0.0; // degrees Kelvin
360  double RPM = 0.0; // revolutions per minute
361  double IAS = 0.0; // knots
362  double Cooling_Factor = 0.0; // normal
363  bool Magneto_Left = false;
364  bool Magneto_Right = false;
365  int Magnetos = 0;
366 
367  double Oil_Press_Relief_Valve = 0.0;
368  double Oil_Press_RPM_Max = 0.0;
369  double Design_Oil_Temp = 0.0; // degK
370  double Oil_Viscosity_Index = 0.0;
371 
372  //
373  // Outputs (in addition to those in FGEngine).
374  //
375  double rho_air = 0.0;
376  double volumetric_efficiency = 0.0;
377  double volumetric_efficiency_reduced = 0.0;
378  //double map_coefficient;
379  double m_dot_air = 0.0;
380  double v_dot_air = 0.0;
381  double equivalence_ratio = 0.0;
382  double m_dot_fuel = 0.0;
383  double HP = 0.0;
384  double BoostLossHP = 0.0;
385  double combustion_efficiency = 0.0;
386  double ExhaustGasTemp_degK = 0.0;
387  double EGT_degC = 0.0;
388  double ManifoldPressure_inHg = 0.0;
389  double CylinderHeadTemp_degK = 0.0;
390  double OilPressure_psi = 0.0;
391  double OilTemp_degK = 0.0;
392  double MeanPistonSpeed_fps = 0.0;
393 
394  void Debug(int from);
395 };
396 }
397 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398 #endif
Base class for all engines.
Definition: FGEngine.h:104
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:184
static constexpr double KelvinToFahrenheit(double kelvin)
Converts from degrees Kelvin to degrees Fahrenheit.
Definition: FGJSBBase.h:186
Models a Supercharged Piston engine.
Definition: FGPiston.h:224
void Calculate(void)
Calculates the thrust of the engine, and other engine functions.
Definition: FGPiston.cpp:475
~FGPiston()
Destructor.
Definition: FGPiston.cpp:446
void ResetToIC(void)
Resets the Engine parameters to the initial conditions.
Definition: FGPiston.cpp:455
FGPiston(FGFDMExec *exec, Element *el, int engine_number, struct Inputs &input)
Constructor.
Definition: FGPiston.cpp:59
double CalcFuelNeed(void)
The fuel need is calculated based on power levels and flow rate for that power level.
Definition: FGPiston.cpp:531
Lookup table class.
Definition: FGTable.h:234