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