1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
10 ------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) --------------
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
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
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.
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.
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
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
36 --------------------------------------------------------------------------------
37 09/12/2000 JSB Created
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #include "models/FGAtmosphere.h"
47 #include "models/FGAuxiliary.h"
48 #include "models/FGPropulsion.h"
49 #include "FGPropeller.h"
56 static const char *IdSrc = "$Id: FGPiston.cpp,v 1.58 2011/06/13 15:23:09 jentron Exp $";
57 static const char *IdHdr = ID_PISTON;
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number)
64 : FGEngine(exec, el, engine_number),
65 R_air(287.3), // Gas constant for air J/Kg/K
66 rho_fuel(800), // estimate
67 calorific_value_fuel(47.3e6), // J/Kg
68 Cp_air(1005), // Specific heat (constant pressure) J/Kg/K
70 standard_pressure(101320.73)
74 // Defaults and initializations
77 dt = FDMExec->GetDeltaT();
79 // These items are read from the configuration file
80 // Defaults are from a Lycoming O-360, more or less
88 MinManifoldPressure_inHg = 6.5;
89 MaxManifoldPressure_inHg = 28.5;
91 volumetric_efficiency = 0.85;
95 CylinderHeadMass = 2; //kg
96 CompressionRatio = 8.5;
99 PeakMeanPistonSpeed_fps = 100;
102 Cooling_Factor = 0.5144444;
103 StaticFriction_HP = 1.5;
105 // These are internal program variables
115 BoostSpeeds = 0; // Default to no supercharging
120 bBoostOverride = false;
121 bTakeoffBoost = false;
122 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
124 for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
127 RatedAltitude[i] = 0.0;
129 RatedMAP[i] = 100000;
131 TakeoffMAP[i] = 100000;
133 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
134 BoostSwitchAltitude[i] = 0.0;
135 BoostSwitchPressure[i] = 0.0;
138 // First column is thi, second is neta (combustion efficiency)
139 Lookup_Combustion_Efficiency = new FGTable(12);
140 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
141 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
142 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
143 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
144 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
145 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
146 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
147 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
148 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
149 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
150 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
151 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
153 Mixture_Efficiency_Correlation = new FGTable(15);
154 *Mixture_Efficiency_Correlation << 0.05000 << 0.00000;
155 *Mixture_Efficiency_Correlation << 0.05137 << 0.00862;
156 *Mixture_Efficiency_Correlation << 0.05179 << 0.21552;
157 *Mixture_Efficiency_Correlation << 0.05430 << 0.48276;
158 *Mixture_Efficiency_Correlation << 0.05842 << 0.70690;
159 *Mixture_Efficiency_Correlation << 0.06312 << 0.83621;
160 *Mixture_Efficiency_Correlation << 0.06942 << 0.93103;
161 *Mixture_Efficiency_Correlation << 0.07786 << 1.00000;
162 *Mixture_Efficiency_Correlation << 0.08845 << 1.00000;
163 *Mixture_Efficiency_Correlation << 0.09270 << 0.98276;
164 *Mixture_Efficiency_Correlation << 0.10120 << 0.93103;
165 *Mixture_Efficiency_Correlation << 0.11455 << 0.72414;
166 *Mixture_Efficiency_Correlation << 0.12158 << 0.45690;
167 *Mixture_Efficiency_Correlation << 0.12435 << 0.23276;
168 *Mixture_Efficiency_Correlation << 0.12500 << 0.00000;
171 // Read inputs from engine data file where present.
173 if (el->FindElement("minmp")) // Should have ELSE statement telling default value used?
174 MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
175 if (el->FindElement("maxmp"))
176 MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
177 if (el->FindElement("displacement"))
178 Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
179 if (el->FindElement("maxhp"))
180 MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
181 if (el->FindElement("static-friction"))
182 StaticFriction_HP = el->FindElementValueAsNumberConvertTo("static-friction","HP");
183 if (el->FindElement("sparkfaildrop"))
184 SparkFailDrop = Constrain(0, 1 - el->FindElementValueAsNumber("sparkfaildrop"), 1);
185 if (el->FindElement("cycles"))
186 Cycles = el->FindElementValueAsNumber("cycles");
187 if (el->FindElement("idlerpm"))
188 IdleRPM = el->FindElementValueAsNumber("idlerpm");
189 if (el->FindElement("maxrpm"))
190 MaxRPM = el->FindElementValueAsNumber("maxrpm");
191 if (el->FindElement("maxthrottle"))
192 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
193 if (el->FindElement("minthrottle"))
194 MinThrottle = el->FindElementValueAsNumber("minthrottle");
195 if (el->FindElement("bsfc"))
196 ISFC = el->FindElementValueAsNumberConvertTo("bsfc", "LBS/HP*HR");
197 if (el->FindElement("volumetric-efficiency"))
198 volumetric_efficiency = el->FindElementValueAsNumber("volumetric-efficiency");
199 if (el->FindElement("compression-ratio"))
200 CompressionRatio = el->FindElementValueAsNumber("compression-ratio");
201 if (el->FindElement("bore"))
202 Bore = el->FindElementValueAsNumberConvertTo("bore","IN");
203 if (el->FindElement("stroke"))
204 Stroke = el->FindElementValueAsNumberConvertTo("stroke","IN");
205 if (el->FindElement("cylinders"))
206 Cylinders = el->FindElementValueAsNumber("cylinders");
207 if (el->FindElement("cylinder-head-mass"))
208 CylinderHeadMass = el->FindElementValueAsNumberConvertTo("cylinder-head-mass","KG");
209 if (el->FindElement("air-intake-impedance-factor"))
210 Z_airbox = el->FindElementValueAsNumber("air-intake-impedance-factor");
211 if (el->FindElement("ram-air-factor"))
212 Ram_Air_Factor = el->FindElementValueAsNumber("ram-air-factor");
213 if (el->FindElement("cooling-factor"))
214 Cooling_Factor = el->FindElementValueAsNumber("cooling-factor");
215 if (el->FindElement("dynamic-fmep"))
216 FMEPDynamic= el->FindElementValueAsNumberConvertTo("dynamic-fmep","PA");
217 if (el->FindElement("static-fmep"))
218 FMEPStatic = el->FindElementValueAsNumberConvertTo("static-fmep","PA");
219 if (el->FindElement("peak-piston-speed"))
220 PeakMeanPistonSpeed_fps = el->FindElementValueAsNumber("peak-piston-speed");
221 if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
222 BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
223 if (el->FindElement("boostoverride"))
224 BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
225 if (el->FindElement("boostmanual"))
226 BoostManual = (int)el->FindElementValueAsNumber("boostmanual");
227 if (el->FindElement("takeoffboost"))
228 TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI");
229 if (el->FindElement("ratedboost1"))
230 RatedBoost[0] = el->FindElementValueAsNumberConvertTo("ratedboost1", "PSI");
231 if (el->FindElement("ratedboost2"))
232 RatedBoost[1] = el->FindElementValueAsNumberConvertTo("ratedboost2", "PSI");
233 if (el->FindElement("ratedboost3"))
234 RatedBoost[2] = el->FindElementValueAsNumberConvertTo("ratedboost3", "PSI");
235 if (el->FindElement("ratedpower1"))
236 RatedPower[0] = el->FindElementValueAsNumberConvertTo("ratedpower1", "HP");
237 if (el->FindElement("ratedpower2"))
238 RatedPower[1] = el->FindElementValueAsNumberConvertTo("ratedpower2", "HP");
239 if (el->FindElement("ratedpower3"))
240 RatedPower[2] = el->FindElementValueAsNumberConvertTo("ratedpower3", "HP");
241 if (el->FindElement("ratedrpm1"))
242 RatedRPM[0] = el->FindElementValueAsNumber("ratedrpm1");
243 if (el->FindElement("ratedrpm2"))
244 RatedRPM[1] = el->FindElementValueAsNumber("ratedrpm2");
245 if (el->FindElement("ratedrpm3"))
246 RatedRPM[2] = el->FindElementValueAsNumber("ratedrpm3");
247 if (el->FindElement("ratedaltitude1"))
248 RatedAltitude[0] = el->FindElementValueAsNumberConvertTo("ratedaltitude1", "FT");
249 if (el->FindElement("ratedaltitude2"))
250 RatedAltitude[1] = el->FindElementValueAsNumberConvertTo("ratedaltitude2", "FT");
251 if (el->FindElement("ratedaltitude3"))
252 RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT");
255 StarterHP = sqrt(MaxHP) * 0.4;
256 displacement_SI = Displacement * in3tom3;
257 RatedMeanPistonSpeed_fps = ( MaxRPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
259 // Create IFSC to match the engine if not provided
261 double pmep = 29.92 - MaxManifoldPressure_inHg;
262 pmep *= inhgtopa * volumetric_efficiency;
263 double fmep = (FMEPDynamic * RatedMeanPistonSpeed_fps * fttom + FMEPStatic);
264 double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371);
265 ISFC = ( 1.1*Displacement * MaxRPM * volumetric_efficiency *(MaxManifoldPressure_inHg / 29.92) ) / (9411 * (MaxHP+hp_loss-StaticFriction_HP));
266 // cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " <<hp_loss <<endl;
268 if ( MaxManifoldPressure_inHg > 29.9 ) { // Don't allow boosting with a bogus number
269 MaxManifoldPressure_inHg = 29.9;
271 minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa
272 maxMAP = MaxManifoldPressure_inHg * inhgtopa;
276 * Pm = ( Ze / ( Ze + Zi + Zt ) ) * Pa
278 * Pm = Manifold Pressure
279 * Pa = Ambient Pressre
280 * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed
281 * Zi = airbox impedance
282 * Zt = throttle impedance
284 * For the calculation below throttle is fully open or Zt = 0
291 double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence
292 Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox
294 // Constant for Throttle impedence
295 Z_throttle=(PeakMeanPistonSpeed_fps/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox;
296 // Z_throttle=(MaxRPM/IdleRPM )*(standard_pressure/minMAP+2); // Constant for Throttle impedence
298 string property_name, base_property_name;
299 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
300 property_name = base_property_name + "/power-hp";
301 PropertyManager->Tie(property_name, &HP);
302 property_name = base_property_name + "/bsfc-lbs_hphr";
303 PropertyManager->Tie(property_name, &ISFC);
304 property_name = base_property_name + "/volumetric-efficiency";
305 PropertyManager->Tie(property_name, &volumetric_efficiency);
306 property_name = base_property_name + "/map-pa";
307 PropertyManager->Tie(property_name, &MAP);
308 property_name = base_property_name + "/map-inhg";
309 PropertyManager->Tie(property_name, &ManifoldPressure_inHg);
310 property_name = base_property_name + "/air-intake-impedance-factor";
311 PropertyManager->Tie(property_name, &Z_airbox);
312 property_name = base_property_name + "/ram-air-factor";
313 PropertyManager->Tie(property_name, &Ram_Air_Factor);
314 property_name = base_property_name + "/cooling-factor";
315 PropertyManager->Tie(property_name, &Cooling_Factor);
316 property_name = base_property_name + "/boost-speed";
317 PropertyManager->Tie(property_name, &BoostSpeed);
318 property_name = base_property_name + "/cht-degF";
319 PropertyManager->Tie(property_name, this, &FGPiston::getCylinderHeadTemp_degF);
320 property_name = base_property_name + "/engine-rpm";
321 PropertyManager->Tie(property_name, this, &FGPiston::getRPM);
322 property_name = base_property_name + "/oil-temperature-degF";
323 PropertyManager->Tie(property_name, this, &FGPiston::getOilTemp_degF);
324 property_name = base_property_name + "/oil-pressure-psi";
325 PropertyManager->Tie(property_name, this, &FGPiston::getOilPressure_psi);
326 property_name = base_property_name + "/egt-degF";
327 PropertyManager->Tie(property_name, this, &FGPiston::getExhaustGasTemp_degF);
329 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
330 if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
331 for (i=0; i<BoostSpeeds; ++i) {
333 if (RatedBoost[i] <= 0.0) bad = true;
334 if (RatedPower[i] <= 0.0) bad = true;
335 if (RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
336 if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
338 // We can't recover from the above - don't use this supercharger speed.
340 // TODO - put out a massive error message!
343 // Now sanity-check stuff that is recoverable.
344 if (i < BoostSpeeds - 1) {
345 if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
346 // TODO - put out an error message
347 // But we can also make a reasonable estimate, as below.
348 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
350 BoostSwitchPressure[i] = Atmosphere->GetPressure(BoostSwitchAltitude[i]) * psftopa;
351 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
352 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
353 BoostSwitchHysteresis = 1000;
355 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
356 RatedMAP[i] = Atmosphere->GetPressureSL() * psftopa + RatedBoost[i] * 6895; // psi*6895 = Pa.
357 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
358 if (TakeoffBoost > RatedBoost[0]) {
359 // Assume that the effect on the BCV is the same whichever speed is in use.
360 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
361 bTakeoffBoost = true;
363 TakeoffMAP[i] = RatedMAP[i];
364 bTakeoffBoost = false;
366 BoostMul[i] = RatedMAP[i] / (Atmosphere->GetPressure(RatedAltitude[i]) * psftopa);
370 if (BoostSpeeds > 0) {
374 bBoostOverride = (BoostOverride == 1 ? true : false);
375 bBoostManual = (BoostManual == 1 ? true : false);
376 Debug(0); // Call Debug() routine from constructor if needed
379 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381 FGPiston::~FGPiston()
383 delete Lookup_Combustion_Efficiency;
384 delete Mixture_Efficiency_Correlation;
385 Debug(1); // Call Debug() routine from constructor if needed
388 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 void FGPiston::ResetToIC(void)
392 FGEngine::ResetToIC();
394 ManifoldPressure_inHg = Atmosphere->GetPressure() * psftoinhg; // psf to in Hg
395 MAP = Atmosphere->GetPressure() * psftopa;
397 double airTemperature_degK = RankineToKelvin(Atmosphere->GetTemperature());
398 OilTemp_degK = airTemperature_degK;
399 CylinderHeadTemp_degK = airTemperature_degK;
400 ExhaustGasTemp_degK = airTemperature_degK;
401 EGT_degC = ExhaustGasTemp_degK - 273;
402 Thruster->SetRPM(0.0);
404 OilPressure_psi = 0.0;
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 void FGPiston::Calculate(void)
412 if (FuelFlow_gph > 0.0) ConsumeFuel();
414 Throttle = FCS->GetThrottlePos(EngineNumber);
415 Mixture = FCS->GetMixturePos(EngineNumber);
419 p_amb = Atmosphere->GetPressure() * psftopa;
420 double p = Auxiliary->GetTotalPressure() * psftopa;
421 p_ram = (p - p_amb) * Ram_Air_Factor + p_amb;
422 T_amb = RankineToKelvin(Atmosphere->GetTemperature());
424 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
425 MeanPistonSpeed_fps = ( RPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
427 IAS = Auxiliary->GetVcalibratedKTS();
430 if (Boosted) doBoostControl();
435 //Now that the fuel flow is done check if the mixture is too lean to run the engine
436 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
437 //This might be a bit generous, but since there's currently no audiable warning of impending
438 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
440 // if (equivalence_ratio < 0.668)
444 if (IndicatedHorsePower < 0.1250) Running = false;
451 if (Thruster->GetType() == FGThruster::ttPropeller) {
452 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
453 ((FGPropeller*)Thruster)->SetFeather(FCS->GetPropFeather(EngineNumber));
456 Thruster->Calculate(HP * hptoftlbssec);
461 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
463 double FGPiston::CalcFuelNeed(void)
465 double dT = FDMExec->GetDeltaT() * Propulsion->GetRate();
466 FuelExpended = FuelFlowRate * dT;
470 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
472 int FGPiston::InitRunning(void) {
474 p_amb = Atmosphere->GetPressure() * psftopa;
475 double mix= p_amb / (101325.0*1.3);
476 FCS->SetMixturePos(EngineNumber, mix);
477 Thruster->SetRPM( 2.*IdleRPM/Thruster->GetGearRatio() );
478 //Thruster->SetRPM( 1000 );
480 // cout <<"Set Running in FGPiston. RPM:" << Thruster->GetRPM()*Thruster->GetGearRatio() <<" Pressure:"<<p_amb<<" Mixture:"<< mix <<endl;
484 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
486 * Start or stop the engine.
489 void FGPiston::doEngineStartup(void)
491 // Check parameters that may alter the operating state of the engine.
492 // (spark, fuel, starter motor etc)
496 Magneto_Left = false;
497 Magneto_Right = false;
498 // Magneto positions:
507 } // neglects battery voltage, master on switch, etc for now.
509 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
510 if (Magnetos > 1) Magneto_Right = true;
512 // Assume we have fuel for now
515 // Check if we are turning the starter motor
516 if (Cranking != Starter) {
517 // This check saves .../cranking from getting updated every loop - they
518 // only update when changed.
523 if (Cranking) crank_counter++; //Check mode of engine operation
525 if (!Running && spark && fuel) { // start the engine if revs high enough
527 if ((RPM > IdleRPM*0.8) && (crank_counter > 175)) // Add a little delay to startup
528 Running = true; // on the starter
530 if (RPM > IdleRPM*0.8) // This allows us to in-air start
531 Running = true; // when windmilling
535 // Cut the engine *power* - Note: the engine may continue to
536 // spin if the prop is in a moving airstream
538 if ( Running && (!spark || !fuel) ) Running = false;
540 // Check for stalling (RPM = 0).
544 } else if ((RPM <= IdleRPM *0.8 ) && (Cranking)) {
550 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
553 * Calculate the Current Boost Speed
555 * This function calculates the current turbo/supercharger boost speed
556 * based on altitude and the (automatic) boost-speed control valve configuration.
558 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
560 * Outputs: BoostSpeed
563 void FGPiston::doBoostControl(void)
566 if(BoostSpeed > BoostSpeeds-1) BoostSpeed = BoostSpeeds-1;
567 if(BoostSpeed < 0) BoostSpeed = 0;
569 if(BoostSpeed < BoostSpeeds - 1) {
570 // Check if we need to change to a higher boost speed
571 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
574 } if(BoostSpeed > 0) {
575 // Check if we need to change to a lower boost speed
576 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
583 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
586 * Calculate the manifold absolute pressure (MAP) in inches hg
588 * This function calculates manifold absolute pressure (MAP)
589 * from the throttle position, turbo/supercharger boost control
590 * system, engine speed and local ambient air density.
592 * Inputs: p_amb, Throttle,
593 * MeanPistonSpeed_fps, dt
595 * Outputs: MAP, ManifoldPressure_inHg, TMAP
598 void FGPiston::doMAP(void)
600 double Zt = (1-Throttle)*(1-Throttle)*Z_throttle; // throttle impedence
601 double Ze= MeanPistonSpeed_fps > 0 ? PeakMeanPistonSpeed_fps/MeanPistonSpeed_fps : 999999; // engine impedence
603 double map_coefficient = Ze/(Ze+Z_airbox+Zt);
605 // Add a one second lag to manifold pressure changes
606 double dMAP = (TMAP - p_ram * map_coefficient) * dt;
609 // Find the mean effective pressure required to achieve this manifold pressure
610 // Fixme: determine the HP consumed by the supercharger
612 PMEP = (TMAP - p_amb) * volumetric_efficiency; // Fixme: p_amb should be exhaust manifold pressure
615 // If takeoff boost is fitted, we currently assume the following throttle map:
616 // (In throttle % - actual input is 0 -> 1)
617 // 99 / 100 - Takeoff boost
618 // In real life, most planes would be fitted with a mechanical 'gate' between
619 // the rated boost and takeoff boost positions.
621 bool bTakeoffPos = false;
623 if (Throttle > 0.98) {
627 // Boost the manifold pressure.
628 double boost_factor = (( BoostMul[BoostSpeed] - 1 ) / RatedRPM[BoostSpeed] ) * RPM + 1;
629 MAP = TMAP * boost_factor;
630 // Now clip the manifold pressure to BCV or Wastegate setting.
632 if (MAP > TakeoffMAP[BoostSpeed]) MAP = TakeoffMAP[BoostSpeed];
634 if (MAP > RatedMAP[BoostSpeed]) MAP = RatedMAP[BoostSpeed];
640 // And set the value in American units as well
641 ManifoldPressure_inHg = MAP / inhgtopa;
644 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
646 * Calculate the air flow through the engine.
647 * Also calculates ambient air density
648 * (used in CHT calculation for air-cooled engines).
650 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
651 * RPM, volumetric_efficiency,
653 * TODO: Model inlet manifold air temperature.
655 * Outputs: rho_air, m_dot_air
658 void FGPiston::doAirFlow(void)
660 double gamma = 1.3; // specific heat constants
661 // loss of volumentric efficiency due to difference between MAP and exhaust pressure
662 // Eq 6-10 from The Internal Combustion Engine - Charles Taylor Vol 1
663 double ve =((gamma-1)/gamma) +( CompressionRatio -(p_amb/MAP))/(gamma*( CompressionRatio - 1));
664 // FGAtmosphere::GetDensity() * FGJSBBase::m3toft3 / FGJSBBase::kgtoslug;
665 rho_air = p_amb / (R_air * T_amb);
666 double swept_volume = (displacement_SI * (RPM/60)) / 2;
667 double v_dot_air = swept_volume * volumetric_efficiency *ve;
669 double rho_air_manifold = MAP / (R_air * T_amb);
670 m_dot_air = v_dot_air * rho_air_manifold;
674 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676 * Calculate the fuel flow into the engine.
678 * Inputs: Mixture, thi_sea_level, p_amb, m_dot_air
680 * Outputs: equivalence_ratio, m_dot_fuel
683 void FGPiston::doFuelFlow(void)
685 double thi_sea_level = 1.3 * Mixture; // Allows an AFR of infinity:1 to 11.3075:1
686 equivalence_ratio = thi_sea_level * 101325.0 / p_amb;
687 // double AFR = 10+(12*(1-Mixture));// mixture 10:1 to 22:1
688 // m_dot_fuel = m_dot_air / AFR;
689 m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;
690 FuelFlowRate = m_dot_fuel * 2.2046; // kg to lb
691 FuelFlow_pph = FuelFlowRate * 3600; // seconds to hours
692 FuelFlow_gph = FuelFlow_pph / 6.0; // Assumes 6 lbs / gallon
695 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
697 * Calculate the power produced by the engine.
699 * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, ISFC,
700 * Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
701 * MeanPistonSpeed_fps
703 * Outputs: PctPower, HP, FMEP, IndicatedHorsePower
706 void FGPiston::doEnginePower(void)
708 IndicatedHorsePower = 0;
711 // FIXME: this needs to be generalized
712 double ME, percent_RPM, power; // Convienience term for use in the calculations
713 ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
715 percent_RPM = RPM/MaxRPM;
716 // Guestimate engine friction losses from Figure 4.4 of "Engines: An Introduction", John Lumley
717 FMEP = (-FMEPDynamic * MeanPistonSpeed_fps * fttom - FMEPStatic);
721 if ( Magnetos != 3 ) power *= SparkFailDrop;
724 IndicatedHorsePower = (FuelFlow_pph / ISFC )* ME * power;
727 // Power output when the engine is not running
730 IndicatedHorsePower = StarterHP;
731 } else if (RPM < IdleRPM*0.8) {
732 IndicatedHorsePower = StarterHP + ((IdleRPM*0.8 - RPM) / 8.0);
733 // This is a guess - would be nice to find a proper starter moter torque curve
735 IndicatedHorsePower = StarterHP;
740 // Constant is (1/2) * 60 * 745.7
741 // (1/2) convert cycles, 60 minutes to seconds, 745.7 watts to hp.
742 double pumping_hp = ((PMEP + FMEP) * displacement_SI * RPM)/(Cycles*22371);
744 HP = IndicatedHorsePower + pumping_hp - StaticFriction_HP; //FIXME static friction should depend on oil temp and configuration
745 // cout << "pumping_hp " <<pumping_hp << FMEP << PMEP <<endl;
746 PctPower = HP / MaxHP ;
747 // cout << "Power = " << HP << " RPM = " << RPM << " Running = " << Running << " Cranking = " << Cranking << endl;
750 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
752 * Calculate the exhaust gas temperature.
754 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
755 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, PctPower
757 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
760 void FGPiston::doEGT(void)
762 double delta_T_exhaust;
763 double enthalpy_exhaust;
764 double heat_capacity_exhaust;
767 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
768 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
769 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
770 combustion_efficiency * 0.30;
771 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
772 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
773 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
774 } else { // Drop towards ambient - guess an appropriate time constant for now
775 combustion_efficiency = 0;
776 dEGTdt = (RankineToKelvin(Atmosphere->GetTemperature()) - ExhaustGasTemp_degK) / 100.0;
777 delta_T_exhaust = dEGTdt * dt;
778 ExhaustGasTemp_degK += delta_T_exhaust;
782 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 * Calculate the cylinder head temperature.
786 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
787 * combustion_efficiency, RPM, MaxRPM, Displacement, Cylinders
789 * Outputs: CylinderHeadTemp_degK
792 void FGPiston::doCHT(void)
796 double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
798 double arbitary_area = Displacement/360.0;
799 double CpCylinderHead = 800.0;
800 double MassCylinderHead = CylinderHeadMass * Cylinders;
802 double temperature_difference = CylinderHeadTemp_degK - T_amb;
803 double v_apparent = IAS * Cooling_Factor;
804 double v_dot_cooling_air = arbitary_area * v_apparent;
805 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
806 double dqdt_from_combustion =
807 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
808 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
809 (h3 * RPM * temperature_difference / MaxRPM);
810 double dqdt_free = h1 * temperature_difference * arbitary_area;
811 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
813 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
815 CylinderHeadTemp_degK +=
816 (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;
819 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
821 * Calculate the oil temperature.
823 * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
825 * Outputs: OilTemp_degK
828 void FGPiston::doOilTemperature(void)
830 double target_oil_temp; // Steady state oil temp at the current engine conditions
831 double time_constant; // The time constant for the differential equation
832 double efficiency = 0.667; // The aproximate oil cooling system efficiency // FIXME: may vary by engine
834 // Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature
835 // target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;
836 target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;
838 if (OilPressure_psi > 5.0 ) {
839 time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
840 // The higher the pressure the faster it reaches
841 // target temperature. Oil pressure should be about
842 // 60 PSI yielding a TC of about 80.
844 time_constant = 1000; // Time constant for engine-off; reflects the fact
845 // that oil is no longer getting circulated
848 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
850 OilTemp_degK += (dOilTempdt * dt);
853 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
855 * Calculate the oil pressure.
857 * Inputs: RPM, MaxRPM, OilTemp_degK
859 * Outputs: OilPressure_psi
862 void FGPiston::doOilPressure(void)
864 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
865 double Oil_Press_RPM_Max = MaxRPM * 0.75; // 75% of max rpm FIXME: may vary by engine
866 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
867 double Oil_Viscosity_Index = 0.25;
869 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
871 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
872 OilPressure_psi = Oil_Press_Relief_Valve;
875 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
878 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
880 string FGPiston::GetEngineLabels(const string& delimiter)
882 std::ostringstream buf;
884 buf << Name << " Power Available (engine " << EngineNumber << " in ft-lbs/sec)" << delimiter
885 << Name << " HP (engine " << EngineNumber << ")" << delimiter
886 << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimiter
887 << Name << " MAP (engine " << EngineNumber << " in inHg)" << delimiter
888 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
893 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895 string FGPiston::GetEngineValues(const string& delimiter)
897 std::ostringstream buf;
899 buf << (HP * hptoftlbssec) << delimiter << HP << delimiter
900 << equivalence_ratio << delimiter << ManifoldPressure_inHg << delimiter
901 << Thruster->GetThrusterValues(EngineNumber, delimiter);
906 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
908 // The bitmasked value choices are as follows:
909 // unset: In this case (the default) JSBSim would only print
910 // out the normally expected messages, essentially echoing
911 // the config files as they are read. If the environment
912 // variable is not set, debug_lvl is set to 1 internally
913 // 0: This requests JSBSim not to output any messages
915 // 1: This value explicity requests the normal JSBSim
917 // 2: This value asks for a message to be printed out when
918 // a class is instantiated
919 // 4: When this value is set, a message is displayed when a
920 // FGModel object executes its Run() method
921 // 8: When this value is set, various runtime state variables
922 // are printed out periodically
923 // 16: When set various parameters are sanity checked and
924 // a message is printed out when they go out of bounds
926 void FGPiston::Debug(int from)
928 if (debug_lvl <= 0) return;
930 if (debug_lvl & 1) { // Standard console startup message output
931 if (from == 0) { // Constructor
933 cout << "\n Engine Name: " << Name << endl;
934 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
935 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
936 cout << " MinMaP (Pa): " << minMAP << endl;
937 cout << " MaxMaP (Pa): " << maxMAP << endl;
938 cout << " Displacement: " << Displacement << endl;
939 cout << " Bore: " << Bore << endl;
940 cout << " Stroke: " << Stroke << endl;
941 cout << " Cylinders: " << Cylinders << endl;
942 cout << " Cylinders Head Mass: " <<CylinderHeadMass << endl;
943 cout << " Compression Ratio: " << CompressionRatio << endl;
944 cout << " MaxHP: " << MaxHP << endl;
945 cout << " Cycles: " << Cycles << endl;
946 cout << " IdleRPM: " << IdleRPM << endl;
947 cout << " MaxRPM: " << MaxRPM << endl;
948 cout << " Throttle Constant: " << Z_throttle << endl;
949 cout << " ISFC: " << ISFC << endl;
950 cout << " Volumetric Efficiency: " << volumetric_efficiency << endl;
951 cout << " PeakMeanPistonSpeed_fps: " << PeakMeanPistonSpeed_fps << endl;
952 cout << " Intake Impedance Factor: " << Z_airbox << endl;
953 cout << " Dynamic FMEP Factor: " << FMEPDynamic << endl;
954 cout << " Static FMEP Factor: " << FMEPStatic << endl;
957 cout << " Combustion Efficiency table:" << endl;
958 Lookup_Combustion_Efficiency->Print();
962 cout << " Mixture Efficiency Correlation table:" << endl;
963 Mixture_Efficiency_Correlation->Print();
968 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
969 if (from == 0) cout << "Instantiated: FGPiston" << endl;
970 if (from == 1) cout << "Destroyed: FGPiston" << endl;
972 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
974 if (debug_lvl & 8 ) { // Runtime state variables
976 if (debug_lvl & 16) { // Sanity checking
978 if (debug_lvl & 64) {
979 if (from == 0) { // Constructor
980 cout << IdSrc << endl;
981 cout << IdHdr << endl;
985 } // namespace JSBSim