]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/models/propulsion/FGPiston.cpp
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / models / propulsion / FGPiston.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGPiston.cpp
4  Author:       Jon S. Berndt, JSBSim framework
5                Dave Luff, Piston engine model
6                Ronald Jensen, Piston engine model
7  Date started: 09/12/2000
8  Purpose:      This module models a Piston engine
9
10  ------------- Copyright (C) 2000  Jon S. Berndt (jon@jsbsim.org) --------------
11
12  This program is free software; you can redistribute it and/or modify it under
13  the terms of the GNU Lesser General Public License as published by the Free Software
14  Foundation; either version 2 of the License, or (at your option) any later
15  version.
16
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
20  details.
21
22  You should have received a copy of the GNU Lesser General Public License along with
23  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24  Place - Suite 330, Boston, MA  02111-1307, USA.
25
26  Further information about the GNU Lesser General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31
32 This class descends from the FGEngine class and models a Piston engine based on
33 parameters given in the engine config file for this class
34
35 HISTORY
36 --------------------------------------------------------------------------------
37 09/12/2000  JSB  Created
38
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 INCLUDES
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
42
43 #include <iostream>
44 #include <sstream>
45
46 #include "FGPiston.h"
47 #include "FGPropeller.h"
48
49 using namespace std;
50
51 namespace JSBSim {
52
53 static const char *IdSrc = "$Id: FGPiston.cpp,v 1.71 2012/04/07 01:50:54 jentron Exp $";
54 static const char *IdHdr = ID_PISTON;
55
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 CLASS IMPLEMENTATION
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59
60 FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input)
61   : FGEngine(exec, el, engine_number, input),
62   R_air(287.3),                  // Gas constant for air J/Kg/K
63   rho_fuel(800),                 // estimate
64   calorific_value_fuel(47.3e6),  // J/Kg
65   Cp_air(1005),                  // Specific heat (constant pressure) J/Kg/K
66   Cp_fuel(1700),
67   standard_pressure(101320.73)
68 {
69   Element *table_element;
70   string token;
71   string name="";
72
73   // Defaults and initializations
74
75   Type = etPiston;
76
77   // These items are read from the configuration file
78   // Defaults are from a Lycoming O-360, more or less
79
80   Cycles = 4;
81   IdleRPM = 600;
82   MaxRPM = 2800;
83   Displacement = 360;
84   SparkFailDrop = 1.0;
85   MaxHP = 200;
86   MinManifoldPressure_inHg = 6.5;
87   MaxManifoldPressure_inHg = 28.5;
88   ManifoldPressureLag=1.0;
89   ISFC = -1;
90   volumetric_efficiency = 0.85;
91   Bore = 5.125;
92   Stroke = 4.375;
93   Cylinders = 4;
94   CylinderHeadMass = 2; //kg
95   CompressionRatio = 8.5;
96   Z_airbox = -999;
97   Ram_Air_Factor = 1;
98   PeakMeanPistonSpeed_fps = 100;
99   FMEPDynamic= 18400;
100   FMEPStatic = 46500;
101   Cooling_Factor = 0.5144444;
102   StaticFriction_HP = 1.5;
103   StarterGain = 1.;
104   StarterTorque = -1.;
105   StarterRPM = -1.;
106
107   // These are internal program variables
108
109   Lookup_Combustion_Efficiency = 0;
110   Mixture_Efficiency_Correlation = 0;
111   crank_counter = 0;
112   Magnetos = 0;
113   minMAP = 21950;
114   maxMAP = 96250;
115
116   ResetToIC();
117
118   // Supercharging
119   BoostSpeeds = 0;  // Default to no supercharging
120   BoostSpeed = 0;
121   Boosted = false;
122   BoostOverride = 0;
123   BoostManual = 0;
124   bBoostOverride = false;
125   bTakeoffBoost = false;
126   TakeoffBoost = 0.0;   // Default to no extra takeoff-boost
127   BoostLossFactor = 0.0;   // Default to free boost
128   
129   int i;
130   for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
131     RatedBoost[i] = 0.0;
132     RatedPower[i] = 0.0;
133     RatedAltitude[i] = 0.0;
134     BoostMul[i] = 1.0;
135     RatedMAP[i] = 100000;
136     RatedRPM[i] = 2500;
137     TakeoffMAP[i] = 100000;
138   }
139   for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
140     BoostSwitchAltitude[i] = 0.0;
141     BoostSwitchPressure[i] = 0.0;
142   }
143
144   // Read inputs from engine data file where present.
145
146   if (el->FindElement("minmp")) 
147     MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
148   if (el->FindElement("maxmp"))
149     MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
150   if (el->FindElement("man-press-lag"))
151     ManifoldPressureLag = el->FindElementValueAsNumber("man-press-lag");
152   if (el->FindElement("displacement"))
153     Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
154   if (el->FindElement("maxhp"))
155     MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
156   if (el->FindElement("static-friction"))
157     StaticFriction_HP = el->FindElementValueAsNumberConvertTo("static-friction","HP");
158   if (el->FindElement("sparkfaildrop"))
159     SparkFailDrop = Constrain(0, 1 - el->FindElementValueAsNumber("sparkfaildrop"), 1);
160   if (el->FindElement("cycles"))
161     Cycles = el->FindElementValueAsNumber("cycles");
162   if (el->FindElement("idlerpm"))
163     IdleRPM = el->FindElementValueAsNumber("idlerpm");
164   if (el->FindElement("maxrpm"))
165     MaxRPM = el->FindElementValueAsNumber("maxrpm");
166   if (el->FindElement("maxthrottle"))
167     MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
168   if (el->FindElement("minthrottle"))
169     MinThrottle = el->FindElementValueAsNumber("minthrottle");
170   if (el->FindElement("bsfc"))
171     ISFC = el->FindElementValueAsNumberConvertTo("bsfc", "LBS/HP*HR");
172   if (el->FindElement("volumetric-efficiency"))
173     volumetric_efficiency = el->FindElementValueAsNumber("volumetric-efficiency");
174   if (el->FindElement("compression-ratio"))
175     CompressionRatio = el->FindElementValueAsNumber("compression-ratio");
176   if (el->FindElement("bore"))
177     Bore = el->FindElementValueAsNumberConvertTo("bore","IN");
178   if (el->FindElement("stroke"))
179     Stroke = el->FindElementValueAsNumberConvertTo("stroke","IN");
180   if (el->FindElement("cylinders"))
181     Cylinders = el->FindElementValueAsNumber("cylinders");
182   if (el->FindElement("cylinder-head-mass"))
183     CylinderHeadMass = el->FindElementValueAsNumberConvertTo("cylinder-head-mass","KG");
184   if (el->FindElement("air-intake-impedance-factor"))
185     Z_airbox = el->FindElementValueAsNumber("air-intake-impedance-factor");
186   if (el->FindElement("ram-air-factor"))
187     Ram_Air_Factor  = el->FindElementValueAsNumber("ram-air-factor");
188   if (el->FindElement("cooling-factor"))
189     Cooling_Factor  = el->FindElementValueAsNumber("cooling-factor");
190   if (el->FindElement("starter-rpm"))
191     StarterRPM  = el->FindElementValueAsNumber("starter-rpm");
192   if (el->FindElement("starter-torque"))
193     StarterTorque  = el->FindElementValueAsNumber("starter-torque");
194   if (el->FindElement("dynamic-fmep"))
195     FMEPDynamic= el->FindElementValueAsNumberConvertTo("dynamic-fmep","PA");
196   if (el->FindElement("static-fmep"))
197     FMEPStatic = el->FindElementValueAsNumberConvertTo("static-fmep","PA");
198   if (el->FindElement("peak-piston-speed"))
199     PeakMeanPistonSpeed_fps  = el->FindElementValueAsNumber("peak-piston-speed");
200   if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
201     BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
202     if (el->FindElement("boostoverride"))
203       BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
204     if (el->FindElement("boostmanual"))
205       BoostManual = (int)el->FindElementValueAsNumber("boostmanual");
206     if (el->FindElement("takeoffboost"))
207       TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI");
208     if (el->FindElement("boost-loss-factor"))
209       BoostLossFactor = el->FindElementValueAsNumber("boost-loss-factor");
210     if (el->FindElement("ratedboost1"))
211       RatedBoost[0] = el->FindElementValueAsNumberConvertTo("ratedboost1", "PSI");
212     if (el->FindElement("ratedboost2"))
213       RatedBoost[1] = el->FindElementValueAsNumberConvertTo("ratedboost2", "PSI");
214     if (el->FindElement("ratedboost3"))
215       RatedBoost[2] = el->FindElementValueAsNumberConvertTo("ratedboost3", "PSI");
216     if (el->FindElement("ratedpower1"))
217       RatedPower[0] = el->FindElementValueAsNumberConvertTo("ratedpower1", "HP");
218     if (el->FindElement("ratedpower2"))
219       RatedPower[1] = el->FindElementValueAsNumberConvertTo("ratedpower2", "HP");
220     if (el->FindElement("ratedpower3"))
221       RatedPower[2] = el->FindElementValueAsNumberConvertTo("ratedpower3", "HP");
222     if (el->FindElement("ratedrpm1"))
223       RatedRPM[0] = el->FindElementValueAsNumber("ratedrpm1");
224     if (el->FindElement("ratedrpm2"))
225       RatedRPM[1] = el->FindElementValueAsNumber("ratedrpm2");
226     if (el->FindElement("ratedrpm3"))
227       RatedRPM[2] = el->FindElementValueAsNumber("ratedrpm3");
228     if (el->FindElement("ratedaltitude1"))
229       RatedAltitude[0] = el->FindElementValueAsNumberConvertTo("ratedaltitude1", "FT");
230     if (el->FindElement("ratedaltitude2"))
231       RatedAltitude[1] = el->FindElementValueAsNumberConvertTo("ratedaltitude2", "FT");
232     if (el->FindElement("ratedaltitude3"))
233       RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT");
234   }
235
236   while((table_element = el->FindNextElement("table")) != 0) {
237     name = table_element->GetAttributeValue("name");
238     try {
239       if (name == "COMBUSTION") {
240         Lookup_Combustion_Efficiency = new FGTable(PropertyManager, table_element);
241       } else if (name == "MIXTURE") {
242         Mixture_Efficiency_Correlation = new FGTable(PropertyManager, table_element);
243       } else {
244         cerr << "Unknown table type: " << name << " in piston engine definition." << endl;
245       }
246     } catch (std::string str) {
247       throw("Error loading piston engine table:" + name + ". " + str);
248     }
249   }
250
251
252   volumetric_efficiency_reduced = volumetric_efficiency;
253
254   if(StarterRPM < 0.) StarterRPM = 2*IdleRPM;
255   if(StarterTorque < 0)
256     StarterTorque = (MaxHP)*0.4; //just a wag.
257
258   displacement_SI = Displacement * in3tom3;
259   RatedMeanPistonSpeed_fps =  ( MaxRPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
260
261   // Create IFSC to match the engine if not provided
262   if (ISFC < 0) {
263       double pmep = 29.92 - MaxManifoldPressure_inHg;
264       pmep *= inhgtopa  * volumetric_efficiency;
265       double fmep = (FMEPDynamic * RatedMeanPistonSpeed_fps * fttom + FMEPStatic);
266       double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371);
267       ISFC = ( 1.1*Displacement * MaxRPM * volumetric_efficiency *(MaxManifoldPressure_inHg / 29.92) ) / (9411 * (MaxHP+hp_loss-StaticFriction_HP));
268 // cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " <<hp_loss <<endl;
269   }
270   if ( MaxManifoldPressure_inHg > 29.9 ) {   // Don't allow boosting with a bogus number
271       MaxManifoldPressure_inHg = 29.9;
272   }
273   minMAP = MinManifoldPressure_inHg * inhgtopa;  // inHg to Pa
274   maxMAP = MaxManifoldPressure_inHg * inhgtopa;
275
276 // For throttle
277 /*
278  * Pm = ( Ze / ( Ze + Zi + Zt ) ) * Pa
279  * Where:
280  * Pm = Manifold Pressure
281  * Pa = Ambient Pressre
282  * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed
283  * Zi = airbox impedance
284  * Zt = throttle impedance
285  *
286  * For the calculation below throttle is fully open or Zt = 0
287  *
288  *
289  *
290  */
291   if(Z_airbox < 0.0){
292     double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence
293     Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox
294   }
295   // Constant for Throttle impedence
296   Z_throttle=(PeakMeanPistonSpeed_fps/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox; 
297   //  Z_throttle=(MaxRPM/IdleRPM )*(standard_pressure/minMAP+2); // Constant for Throttle impedence
298
299 // Default tables if not provided in the configuration file
300   if(Lookup_Combustion_Efficiency == 0) {
301     // First column is thi, second is neta (combustion efficiency)
302     Lookup_Combustion_Efficiency = new FGTable(12);
303     *Lookup_Combustion_Efficiency << 0.00 << 0.980;
304     *Lookup_Combustion_Efficiency << 0.90 << 0.980;
305     *Lookup_Combustion_Efficiency << 1.00 << 0.970;
306     *Lookup_Combustion_Efficiency << 1.05 << 0.950;
307     *Lookup_Combustion_Efficiency << 1.10 << 0.900;
308     *Lookup_Combustion_Efficiency << 1.15 << 0.850;
309     *Lookup_Combustion_Efficiency << 1.20 << 0.790;
310     *Lookup_Combustion_Efficiency << 1.30 << 0.700;
311     *Lookup_Combustion_Efficiency << 1.40 << 0.630;
312     *Lookup_Combustion_Efficiency << 1.50 << 0.570;
313     *Lookup_Combustion_Efficiency << 1.60 << 0.525;
314     *Lookup_Combustion_Efficiency << 2.00 << 0.345;
315   }
316
317     // First column is Fuel/Air Ratio, second is neta (mixture efficiency)
318   if( Mixture_Efficiency_Correlation == 0) {
319     Mixture_Efficiency_Correlation = new FGTable(15);
320     *Mixture_Efficiency_Correlation << 0.05000 << 0.00000;
321     *Mixture_Efficiency_Correlation << 0.05137 << 0.00862;
322     *Mixture_Efficiency_Correlation << 0.05179 << 0.21552;
323     *Mixture_Efficiency_Correlation << 0.05430 << 0.48276;
324     *Mixture_Efficiency_Correlation << 0.05842 << 0.70690;
325     *Mixture_Efficiency_Correlation << 0.06312 << 0.83621;
326     *Mixture_Efficiency_Correlation << 0.06942 << 0.93103;
327     *Mixture_Efficiency_Correlation << 0.07786 << 1.00000;
328     *Mixture_Efficiency_Correlation << 0.08845 << 1.00000;
329     *Mixture_Efficiency_Correlation << 0.09270 << 0.98276;
330     *Mixture_Efficiency_Correlation << 0.10120 << 0.93103;
331     *Mixture_Efficiency_Correlation << 0.11455 << 0.72414;
332     *Mixture_Efficiency_Correlation << 0.12158 << 0.45690;
333     *Mixture_Efficiency_Correlation << 0.12435 << 0.23276;
334     *Mixture_Efficiency_Correlation << 0.12500 << 0.00000;
335   }
336
337   string property_name, base_property_name;
338   base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
339   property_name = base_property_name + "/power-hp";
340   PropertyManager->Tie(property_name, &HP);
341   property_name = base_property_name + "/friction-hp";
342   PropertyManager->Tie(property_name, &StaticFriction_HP);
343   property_name = base_property_name + "/bsfc-lbs_hphr";
344   PropertyManager->Tie(property_name, &ISFC);
345   property_name = base_property_name + "/starter-norm";
346   PropertyManager->Tie(property_name, &StarterGain);
347   property_name = base_property_name + "/volumetric-efficiency";
348   PropertyManager->Tie(property_name, &volumetric_efficiency);
349   property_name = base_property_name + "/map-pa";
350   PropertyManager->Tie(property_name, &MAP);
351   property_name = base_property_name + "/map-inhg";
352   PropertyManager->Tie(property_name, &ManifoldPressure_inHg);
353   property_name = base_property_name + "/air-intake-impedance-factor";
354   PropertyManager->Tie(property_name, &Z_airbox);
355   property_name = base_property_name + "/ram-air-factor";
356   PropertyManager->Tie(property_name, &Ram_Air_Factor);
357   property_name = base_property_name + "/cooling-factor";
358   PropertyManager->Tie(property_name, &Cooling_Factor);
359   property_name = base_property_name + "/boost-speed";
360   PropertyManager->Tie(property_name, &BoostSpeed);
361   property_name = base_property_name + "/cht-degF";
362   PropertyManager->Tie(property_name, this, &FGPiston::getCylinderHeadTemp_degF);
363   property_name = base_property_name + "/oil-temperature-degF";
364   PropertyManager->Tie(property_name, this, &FGPiston::getOilTemp_degF);
365   property_name = base_property_name + "/oil-pressure-psi";
366   PropertyManager->Tie(property_name, this, &FGPiston::getOilPressure_psi);
367   property_name = base_property_name + "/egt-degF";
368   PropertyManager->Tie(property_name, this, &FGPiston::getExhaustGasTemp_degF);
369   if(BoostLossFactor > 0.0) {
370     property_name = base_property_name + "/boostloss-factor";
371     PropertyManager->Tie(property_name, &BoostLossFactor);
372     property_name = base_property_name + "/boostloss-hp";
373     PropertyManager->Tie(property_name, &BoostLossHP);
374   }
375
376   // Set up and sanity-check the turbo/supercharging configuration based on the input values.
377   if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
378   for (i=0; i<BoostSpeeds; ++i) {
379     bool bad = false;
380     if (RatedBoost[i] <= 0.0) bad = true;
381     if (RatedPower[i] <= 0.0) bad = true;
382     if (RatedAltitude[i] < 0.0) bad = true;  // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
383     if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
384     if (bad) {
385       // We can't recover from the above - don't use this supercharger speed.
386       BoostSpeeds--;
387       // TODO - put out a massive error message!
388       break;
389     }
390     // Now sanity-check stuff that is recoverable.
391     if (i < BoostSpeeds - 1) {
392       if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
393         // TODO - put out an error message
394         // But we can also make a reasonable estimate, as below.
395         BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
396       }
397       BoostSwitchPressure[i] = GetStdPressure100K(BoostSwitchAltitude[i]) * psftopa;
398       //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
399       // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
400       BoostSwitchHysteresis = 1000;
401     }
402     // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
403     RatedMAP[i] = standard_pressure + RatedBoost[i] * 6895;  // psi*6895 = Pa.
404     // Sometimes a separate BCV setting for takeoff or extra power is fitted.
405     if (TakeoffBoost > RatedBoost[0]) {
406       // Assume that the effect on the BCV is the same whichever speed is in use.
407       TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
408       bTakeoffBoost = true;
409     } else {
410       TakeoffMAP[i] = RatedMAP[i];
411       bTakeoffBoost = false;
412     }
413     BoostMul[i] = RatedMAP[i] / (GetStdPressure100K(RatedAltitude[i]) * psftopa);
414
415   }
416
417   if (BoostSpeeds > 0) {
418     Boosted = true;
419     BoostSpeed = 0;
420   }
421   bBoostOverride = (BoostOverride == 1 ? true : false);
422   bBoostManual   = (BoostManual   == 1 ? true : false);
423   Debug(0); // Call Debug() routine from constructor if needed
424 }
425
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427
428 FGPiston::~FGPiston()
429 {
430   delete Lookup_Combustion_Efficiency;
431   delete Mixture_Efficiency_Correlation;
432   Debug(1); // Call Debug() routine from constructor if needed
433 }
434
435 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
436
437 void FGPiston::ResetToIC(void)
438 {
439   FGEngine::ResetToIC();
440
441   ManifoldPressure_inHg = in.Pressure * psftoinhg; // psf to in Hg
442   MAP = in.Pressure * psftopa;
443   TMAP = MAP;
444   double airTemperature_degK = RankineToKelvin(in.Temperature);
445   OilTemp_degK = airTemperature_degK;
446   CylinderHeadTemp_degK = airTemperature_degK;
447   ExhaustGasTemp_degK = airTemperature_degK;
448   EGT_degC = ExhaustGasTemp_degK - 273;
449   Thruster->SetRPM(0.0);
450   RPM = 0.0;
451   OilPressure_psi = 0.0;
452   BoostLossHP = 0.;
453 }
454
455 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456
457 void FGPiston::Calculate(void)
458 {
459   // Input values.
460
461   p_amb = in.Pressure * psftopa;
462   double p = in.TotalPressure * psftopa;
463   p_ram = (p - p_amb) * Ram_Air_Factor + p_amb;
464   T_amb = RankineToKelvin(in.Temperature);
465
466   RunPreFunctions();
467
468   TotalDeltaT = ( in.TotalDeltaT < 1e-9 ) ? 1.0 : in.TotalDeltaT;
469
470 /* The thruster controls the engine RPM because it encapsulates the gear ratio and other transmission variables */
471   RPM = Thruster->GetEngineRPM();
472
473   MeanPistonSpeed_fps =  ( RPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
474
475   IAS = in.Vc;
476
477   doEngineStartup();
478   if (Boosted) doBoostControl();
479   doMAP();
480   doAirFlow();
481   doFuelFlow();
482
483   //Now that the fuel flow is done check if the mixture is too lean to run the engine
484   //Assume lean limit at 22 AFR for now - thats a thi of 0.668
485   //This might be a bit generous, but since there's currently no audiable warning of impending
486   //cutout in the form of misfiring and/or rough running its probably reasonable for now.
487
488   //  if (equivalence_ratio < 0.668)
489   //    Running = false;
490
491   doEnginePower();
492   if (IndicatedHorsePower < 0.1250) Running = false;
493
494   doEGT();
495   doCHT();
496   doOilTemperature();
497   doOilPressure();
498
499   if (Thruster->GetType() == FGThruster::ttPropeller) {
500     ((FGPropeller*)Thruster)->SetAdvance(in.PropAdvance[EngineNumber]);
501     ((FGPropeller*)Thruster)->SetFeather(in.PropFeather[EngineNumber]);
502   }
503
504   LoadThrusterInputs();
505   Thruster->Calculate(HP * hptoftlbssec);
506
507   RunPostFunctions();
508 }
509
510 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
511
512 double FGPiston::CalcFuelNeed(void)
513 {
514   FuelExpended = FuelFlowRate * in.TotalDeltaT;
515   if (!Starved) FuelUsedLbs += FuelExpended; 
516   return FuelExpended;
517 }
518
519 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520
521 int FGPiston::InitRunning(void)
522 {
523   Magnetos=3;
524   in.MixtureCmd[EngineNumber] = in.PressureRatio*1.3;
525   in.MixturePos[EngineNumber] = in.PressureRatio*1.3;
526   Thruster->SetRPM( 2.0*IdleRPM/Thruster->GetGearRatio() );
527   Running = true;
528   return 1;
529 }
530
531 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
532 /**
533  * Start or stop the engine.
534  */
535
536 void FGPiston::doEngineStartup(void)
537 {
538   // Check parameters that may alter the operating state of the engine.
539   // (spark, fuel, starter motor etc)
540   bool spark;
541   bool fuel;
542   // Check for spark
543   Magneto_Left = false;
544   Magneto_Right = false;
545   // Magneto positions:
546   // 0 -> off
547   // 1 -> left only
548   // 2 -> right only
549   // 3 -> both
550   if (Magnetos != 0) {
551     spark = true;
552   } else {
553     spark = false;
554   }  // neglects battery voltage, master on switch, etc for now.
555
556   if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
557   if (Magnetos > 1)  Magneto_Right = true;
558
559 // We will 'run' with any fuel flow. If there is not enough fuel to make power it will show in doEnginePower
560   fuel = FuelFlowRate > 0.0 ? 1 : 0;
561
562   // Check if we are turning the starter motor
563   if (Cranking != Starter) {
564     // This check saves .../cranking from getting updated every loop - they
565     // only update when changed.
566     Cranking = Starter;
567   }
568
569
570   // Cut the engine *power* - Note: the engine will continue to
571   // spin depending on prop Ixx and freestream velocity
572
573   if ( Running ) {
574     if (!spark || !fuel)    Running = false;
575     if (RPM < IdleRPM*0.8 ) Running = false;
576   } else { // !Running  
577     if ( spark && fuel) {     // start the engine if revs high enough
578       if (RPM > IdleRPM*0.8)  // This allows us to in-air start
579         Running = true;       // when windmilling
580     }
581   }
582
583 }
584
585 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
586
587 /**
588  * Calculate the Current Boost Speed
589  *
590  * This function calculates the current turbo/supercharger boost speed
591  * based on altitude and the (automatic) boost-speed control valve configuration.
592  *
593  * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
594  *
595  * Outputs: BoostSpeed
596  */
597
598 void FGPiston::doBoostControl(void)
599 {
600   if(bBoostManual) {
601     if(BoostSpeed > BoostSpeeds-1) BoostSpeed = BoostSpeeds-1;
602     if(BoostSpeed < 0) BoostSpeed = 0;
603   } else {
604     if(BoostSpeed < BoostSpeeds - 1) {
605       // Check if we need to change to a higher boost speed
606       if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
607         BoostSpeed++;
608       }
609     } if(BoostSpeed > 0) {
610       // Check if we need to change to a lower boost speed
611       if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
612         BoostSpeed--;
613       }
614     }
615   }
616 }
617
618 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
619
620 /**
621  * Calculate the manifold absolute pressure (MAP) in inches hg
622  *
623  * This function calculates manifold absolute pressure (MAP)
624  * from the throttle position, turbo/supercharger boost control
625  * system, engine speed and local ambient air density.
626  *
627  * Inputs: p_amb, Throttle,
628  *         MeanPistonSpeed_fps, dt
629  *
630  * Outputs: MAP, ManifoldPressure_inHg, TMAP, BoostLossHP
631  */
632
633 void FGPiston::doMAP(void)
634 {
635   double Zt = (1 - in.ThrottlePos[EngineNumber])*(1 - in.ThrottlePos[EngineNumber])*Z_throttle; // throttle impedence
636   double Ze= MeanPistonSpeed_fps > 0 ? PeakMeanPistonSpeed_fps/MeanPistonSpeed_fps : 999999; // engine impedence
637
638   double map_coefficient = Ze/(Ze+Z_airbox+Zt);
639
640   // Add a variable lag to manifold pressure changes
641   double dMAP=(TMAP - p_ram * map_coefficient);
642   if (ManifoldPressureLag > TotalDeltaT) dMAP *= TotalDeltaT/ManifoldPressureLag;
643
644   TMAP -=dMAP;
645
646   // Find the mean effective pressure required to achieve this manifold pressure
647   // Fixme: determine the HP consumed by the supercharger
648
649   PMEP = (TMAP - p_amb) * volumetric_efficiency; // Fixme: p_amb should be exhaust manifold pressure
650
651   if (Boosted) {
652     // If takeoff boost is fitted, we currently assume the following throttle map:
653     // (In throttle % - actual input is 0 -> 1)
654     // 99 / 100 - Takeoff boost
655     // In real life, most planes would be fitted with a mechanical 'gate' between
656     // the rated boost and takeoff boost positions.
657
658     bool bTakeoffPos = false;
659     if (bTakeoffBoost) {
660       if (in.ThrottlePos[EngineNumber] > 0.98) {
661         bTakeoffPos = true;
662       }
663     }
664     // Boost the manifold pressure.
665     double boost_factor = (( BoostMul[BoostSpeed] - 1 ) / RatedRPM[BoostSpeed] ) * RPM + 1;
666     MAP = TMAP * boost_factor;
667     // Now clip the manifold pressure to BCV or Wastegate setting.
668     if(!bBoostOverride) {
669       if (bTakeoffPos) {
670         if (MAP > TakeoffMAP[BoostSpeed]) MAP = TakeoffMAP[BoostSpeed];
671       } else {
672         if (MAP > RatedMAP[BoostSpeed]) MAP = RatedMAP[BoostSpeed];
673       }
674     }
675   } else {
676       MAP = TMAP;
677   }
678
679   if( BoostLossFactor > 0.0 )
680   {
681       double gamma = 1.414; // specific heat constants
682       double Nstage = 1; // Nstage is the number of boost stages.
683       BoostLossHP = ((Nstage * TMAP * v_dot_air * gamma) / (gamma - 1)) * (pow((MAP/TMAP),((gamma-1)/(Nstage * gamma))) - 1) * BoostLossFactor / 745.7 ; // 745.7 convert watt to hp
684   } else {
685       BoostLossHP = 0;
686   }
687   
688   // And set the value in American units as well
689   ManifoldPressure_inHg = MAP / inhgtopa;
690 }
691
692 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
693 /**
694  * Calculate the air flow through the engine.
695  * Also calculates ambient air density
696  * (used in CHT calculation for air-cooled engines).
697  *
698  * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
699  *   RPM, volumetric_efficiency,
700  *
701  * TODO: Model inlet manifold air temperature.
702  *
703  * Outputs: rho_air, m_dot_air, volumetric_efficiency_reduced
704  */
705
706 void FGPiston::doAirFlow(void)
707 {
708   double gamma = 1.3; // specific heat constants
709 // loss of volumentric efficiency due to difference between MAP and exhaust pressure
710 // Eq 6-10 from The Internal Combustion Engine - Charles Taylor Vol 1
711   double mratio = MAP < 1. ? CompressionRatio : p_amb/MAP;
712   if (mratio > CompressionRatio) mratio = CompressionRatio;
713   double ve =((gamma-1)/gamma) +( CompressionRatio -(mratio))/(gamma*( CompressionRatio - 1));
714
715   rho_air = p_amb / (R_air * T_amb);
716   double swept_volume = (displacement_SI * (RPM/60)) / 2;
717   volumetric_efficiency_reduced = volumetric_efficiency *ve;
718   v_dot_air = swept_volume * volumetric_efficiency_reduced;
719
720   double rho_air_manifold = MAP / (R_air * T_amb);
721   m_dot_air = v_dot_air * rho_air_manifold;
722
723 }
724
725 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726 /**
727  * Calculate the fuel flow into the engine.
728  *
729  * Inputs: Mixture, thi_sea_level, p_amb, m_dot_air
730  *
731  * Outputs: equivalence_ratio, m_dot_fuel
732  */
733
734 void FGPiston::doFuelFlow(void)
735 {
736   double thi_sea_level = 1.3 * in.MixturePos[EngineNumber]; // Allows an AFR of infinity:1 to 11.3075:1
737   equivalence_ratio = thi_sea_level * 101325.0 / p_amb;
738 //  double AFR = 10+(12*(1-in.Mixture[EngineNumber]));// mixture 10:1 to 22:1
739 //  m_dot_fuel = m_dot_air / AFR;
740   m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;
741   FuelFlowRate =  m_dot_fuel * 2.2046;  // kg to lb
742   if(Starved) // There is no fuel, so zero out the flows we've calculated so far
743   {
744     equivalence_ratio = 0.0;
745     FuelFlowRate = 0.0;
746     m_dot_fuel = 0.0;
747   }
748   FuelFlow_pph = FuelFlowRate  * 3600;  // seconds to hours
749   FuelFlow_gph = FuelFlow_pph / 6.0;    // Assumes 6 lbs / gallon
750 }
751
752 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
753 /**
754  * Calculate the power produced by the engine.
755  *
756  * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, ISFC,
757  *   Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
758  *   MeanPistonSpeed_fps
759  *
760  * Outputs: PctPower, HP, FMEP, IndicatedHorsePower
761  */
762
763 void FGPiston::doEnginePower(void)
764 {
765   IndicatedHorsePower = -StaticFriction_HP;
766   FMEP = 0;
767   if (Running) {
768     double ME, power;  // Convienience term for use in the calculations
769     ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
770
771 // Guestimate engine friction losses from Figure 4.4 of "Engines: An Introduction", John Lumley
772     FMEP = (-FMEPDynamic * MeanPistonSpeed_fps * fttom - FMEPStatic);
773
774     power = 1;
775
776     if ( Magnetos != 3 ) power *= SparkFailDrop;
777
778
779     IndicatedHorsePower = (FuelFlow_pph / ISFC )* ME * power - StaticFriction_HP; //FIXME static friction should depend on oil temp and configuration;
780
781   } else {
782     // Power output when the engine is not running
783     double torque, k_torque, rpm;  // Convienience term for use in the calculations
784     
785     rpm = RPM < 1.0 ? 1.0 : RPM;
786     if (Cranking) {
787       if(RPM<StarterRPM) k_torque = 1.0-RPM/(StarterRPM);
788       else k_torque = 0;
789       torque = StarterTorque*k_torque*StarterGain;
790       IndicatedHorsePower = torque * rpm / 5252;
791      } 
792   }
793
794   // Constant is (1/2) * 60 * 745.7
795   // (1/2) convert cycles, 60 minutes to seconds, 745.7 watts to hp.
796   double pumping_hp = ((PMEP + FMEP) * displacement_SI * RPM)/(Cycles*22371);
797
798 HP = IndicatedHorsePower + pumping_hp - BoostLossHP;
799 //  cout << "pumping_hp " <<pumping_hp << FMEP << PMEP <<endl;
800   PctPower = HP / MaxHP ;
801 //  cout << "Power = " << HP << "  RPM = " << RPM << "  Running = " << Running << "  Cranking = " << Cranking << endl;
802 }
803
804 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805 /**
806  * Calculate the exhaust gas temperature.
807  *
808  * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
809  *   Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, PctPower
810  *
811  * Outputs: combustion_efficiency, ExhaustGasTemp_degK
812  */
813
814 void FGPiston::doEGT(void)
815 {
816   double delta_T_exhaust;
817   double enthalpy_exhaust;
818   double heat_capacity_exhaust;
819   double dEGTdt;
820
821   if ((Running) && (m_dot_air > 0.0)) {  // do the energy balance
822     combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
823     enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
824                               combustion_efficiency * 0.30;
825     heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
826     delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
827     ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
828   } else {  // Drop towards ambient - guess an appropriate time constant for now
829     combustion_efficiency = 0;
830     dEGTdt = (RankineToKelvin(in.Temperature) - ExhaustGasTemp_degK) / 100.0;
831     delta_T_exhaust = dEGTdt * TotalDeltaT;
832
833     ExhaustGasTemp_degK += delta_T_exhaust;
834   }
835 }
836
837 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838 /**
839  * Calculate the cylinder head temperature.
840  *
841  * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
842  *   combustion_efficiency, RPM, MaxRPM, Displacement, Cylinders
843  *
844  * Outputs: CylinderHeadTemp_degK
845  */
846
847 void FGPiston::doCHT(void)
848 {
849   double h1 = -95.0;
850   double h2 = -3.95;
851   double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
852
853   double arbitary_area = Displacement/360.0;
854   double CpCylinderHead = 800.0;
855   double MassCylinderHead = CylinderHeadMass * Cylinders;
856
857   double temperature_difference = CylinderHeadTemp_degK - T_amb;
858   double v_apparent = IAS * Cooling_Factor;
859   double v_dot_cooling_air = arbitary_area * v_apparent;
860   double m_dot_cooling_air = v_dot_cooling_air * rho_air;
861   double dqdt_from_combustion =
862     m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
863   double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
864     (h3 * RPM * temperature_difference / MaxRPM);
865   double dqdt_free = h1 * temperature_difference * arbitary_area;
866   double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
867
868   double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
869
870   CylinderHeadTemp_degK +=
871     (dqdt_cylinder_head / HeatCapacityCylinderHead) * TotalDeltaT;
872
873 }
874
875 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
876 /**
877  * Calculate the oil temperature.
878  *
879  * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
880  *
881  * Outputs: OilTemp_degK
882  */
883
884 void FGPiston::doOilTemperature(void)
885 {
886   double target_oil_temp;        // Steady state oil temp at the current engine conditions
887   double time_constant;          // The time constant for the differential equation
888   double efficiency = 0.667;     // The aproximate oil cooling system efficiency // FIXME: may vary by engine
889
890 //  Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature
891 //  target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;
892   target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;
893
894   if (OilPressure_psi > 5.0 ) {
895     time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
896                                             // The higher the pressure the faster it reaches
897                                             // target temperature.  Oil pressure should be about
898                                             // 60 PSI yielding a TC of about 80.
899   } else {
900     time_constant = 1000;  // Time constant for engine-off; reflects the fact
901                            // that oil is no longer getting circulated
902   }
903
904   double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
905
906   OilTemp_degK += (dOilTempdt * TotalDeltaT);
907 }
908
909 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
910 /**
911  * Calculate the oil pressure.
912  *
913  * Inputs: RPM, MaxRPM, OilTemp_degK
914  *
915  * Outputs: OilPressure_psi
916  */
917
918 void FGPiston::doOilPressure(void)
919 {
920   double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
921   double Oil_Press_RPM_Max = MaxRPM * 0.75;    // 75% of max rpm FIXME: may vary by engine
922   double Design_Oil_Temp = 358;          // degK; FIXME: may vary by engine
923   double Oil_Viscosity_Index = 0.25;
924
925   OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
926
927   if (OilPressure_psi >= Oil_Press_Relief_Valve) {
928     OilPressure_psi = Oil_Press_Relief_Valve;
929   }
930
931   OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
932 }
933
934 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 //
936 // This is a local copy of the same function in FGStandardAtmosphere.
937
938 double FGPiston::GetStdPressure100K(double altitude) const
939 {
940   // Limit this equation to input altitudes of 100000 ft.
941   if (altitude > 100000.0) altitude = 100000.0;
942
943   double alt[5];
944   const double coef[5] = {  2116.217,
945                           -7.648932746E-2,
946                            1.0925498604E-6,
947                           -7.1135726027E-12,
948                            1.7470331356E-17 };
949
950   alt[0] = 1;
951   for (int pwr=1; pwr<=4; pwr++) alt[pwr] = alt[pwr-1]*altitude;
952
953   double press = 0.0;
954   for (int ctr=0; ctr<=4; ctr++) press += coef[ctr]*alt[ctr];
955   return press;
956 }
957
958 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
959
960 string FGPiston::GetEngineLabels(const string& delimiter)
961 {
962   std::ostringstream buf;
963
964   buf << Name << " Power Available (engine " << EngineNumber << " in ft-lbs/sec)" << delimiter
965       << Name << " HP (engine " << EngineNumber << ")" << delimiter
966       << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimiter
967       << Name << " MAP (engine " << EngineNumber << " in inHg)" << delimiter
968       << Thruster->GetThrusterLabels(EngineNumber, delimiter);
969
970   return buf.str();
971 }
972
973 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974
975 string FGPiston::GetEngineValues(const string& delimiter)
976 {
977   std::ostringstream buf;
978
979   buf << (HP * hptoftlbssec) << delimiter << HP << delimiter
980       << equivalence_ratio << delimiter << ManifoldPressure_inHg << delimiter
981       << Thruster->GetThrusterValues(EngineNumber, delimiter);
982
983   return buf.str();
984 }
985
986 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
987 //
988 //    The bitmasked value choices are as follows:
989 //    unset: In this case (the default) JSBSim would only print
990 //       out the normally expected messages, essentially echoing
991 //       the config files as they are read. If the environment
992 //       variable is not set, debug_lvl is set to 1 internally
993 //    0: This requests JSBSim not to output any messages
994 //       whatsoever.
995 //    1: This value explicity requests the normal JSBSim
996 //       startup messages
997 //    2: This value asks for a message to be printed out when
998 //       a class is instantiated
999 //    4: When this value is set, a message is displayed when a
1000 //       FGModel object executes its Run() method
1001 //    8: When this value is set, various runtime state variables
1002 //       are printed out periodically
1003 //    16: When set various parameters are sanity checked and
1004 //       a message is printed out when they go out of bounds
1005
1006 void FGPiston::Debug(int from)
1007 {
1008   if (debug_lvl <= 0) return;
1009
1010   if (debug_lvl & 1) { // Standard console startup message output
1011     if (from == 0) { // Constructor
1012
1013       cout << "\n    Engine Name: "         << Name << endl;
1014       cout << "      MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
1015       cout << "      MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
1016       cout << "      MinMaP (Pa):         " << minMAP << endl;
1017       cout << "      MaxMaP (Pa):         " << maxMAP << endl;
1018       cout << "      Displacement: "        << Displacement             << endl;
1019       cout << "      Bore: "                << Bore                     << endl;
1020       cout << "      Stroke: "              << Stroke                   << endl;
1021       cout << "      Cylinders: "           << Cylinders                << endl;
1022       cout << "      Cylinders Head Mass: " << CylinderHeadMass         << endl;
1023       cout << "      Compression Ratio: "   << CompressionRatio         << endl;
1024       cout << "      MaxHP: "               << MaxHP                    << endl;
1025       cout << "      Cycles: "              << Cycles                   << endl;
1026       cout << "      IdleRPM: "             << IdleRPM                  << endl;
1027       cout << "      MaxRPM: "              << MaxRPM                   << endl;
1028       cout << "      Throttle Constant: "   << Z_throttle               << endl;
1029       cout << "      ISFC: "                << ISFC                     << endl;
1030       cout << "      Volumetric Efficiency: " << volumetric_efficiency    << endl;
1031       cout << "      PeakMeanPistonSpeed_fps: " << PeakMeanPistonSpeed_fps << endl;
1032       cout << "      Intake Impedance Factor: " << Z_airbox << endl;
1033       cout << "      Dynamic FMEP Factor: " << FMEPDynamic << endl;
1034       cout << "      Static FMEP Factor: " << FMEPStatic << endl;
1035
1036       cout << "      Starter Motor Torque: " << StarterTorque << endl;
1037       cout << "      Starter Motor RPM:    " << StarterRPM << endl;
1038
1039       cout << endl;
1040       cout << "      Combustion Efficiency table:" << endl;
1041       Lookup_Combustion_Efficiency->Print();
1042       cout << endl;
1043
1044       cout << endl;
1045       cout << "      Mixture Efficiency Correlation table:" << endl;
1046       Mixture_Efficiency_Correlation->Print();
1047       cout << endl;
1048
1049     }
1050   }
1051   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1052     if (from == 0) cout << "Instantiated: FGPiston" << endl;
1053     if (from == 1) cout << "Destroyed:    FGPiston" << endl;
1054   }
1055   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1056   }
1057   if (debug_lvl & 8 ) { // Runtime state variables
1058   }
1059   if (debug_lvl & 16) { // Sanity checking
1060   }
1061   if (debug_lvl & 64) {
1062     if (from == 0) { // Constructor
1063       cout << IdSrc << endl;
1064       cout << IdHdr << endl;
1065     }
1066   }
1067 }
1068 } // namespace JSBSim