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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 #include "FGPropeller.h"
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;
56 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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
67 standard_pressure(101320.73)
69 Element *table_element;
73 // Defaults and initializations
77 // These items are read from the configuration file
78 // Defaults are from a Lycoming O-360, more or less
86 MinManifoldPressure_inHg = 6.5;
87 MaxManifoldPressure_inHg = 28.5;
88 ManifoldPressureLag=1.0;
90 volumetric_efficiency = 0.85;
94 CylinderHeadMass = 2; //kg
95 CompressionRatio = 8.5;
98 PeakMeanPistonSpeed_fps = 100;
101 Cooling_Factor = 0.5144444;
102 StaticFriction_HP = 1.5;
107 // These are internal program variables
109 Lookup_Combustion_Efficiency = 0;
110 Mixture_Efficiency_Correlation = 0;
119 BoostSpeeds = 0; // Default to no supercharging
124 bBoostOverride = false;
125 bTakeoffBoost = false;
126 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
127 BoostLossFactor = 0.0; // Default to free boost
130 for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
133 RatedAltitude[i] = 0.0;
135 RatedMAP[i] = 100000;
137 TakeoffMAP[i] = 100000;
139 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
140 BoostSwitchAltitude[i] = 0.0;
141 BoostSwitchPressure[i] = 0.0;
144 // Read inputs from engine data file where present.
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");
236 while((table_element = el->FindNextElement("table")) != 0) {
237 name = table_element->GetAttributeValue("name");
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);
244 cerr << "Unknown table type: " << name << " in piston engine definition." << endl;
246 } catch (std::string str) {
247 throw("Error loading piston engine table:" + name + ". " + str);
252 volumetric_efficiency_reduced = volumetric_efficiency;
254 if(StarterRPM < 0.) StarterRPM = 2*IdleRPM;
255 if(StarterTorque < 0)
256 StarterTorque = (MaxHP)*0.4; //just a wag.
258 displacement_SI = Displacement * in3tom3;
259 RatedMeanPistonSpeed_fps = ( MaxRPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
261 // Create IFSC to match the engine if not provided
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;
270 if ( MaxManifoldPressure_inHg > 29.9 ) { // Don't allow boosting with a bogus number
271 MaxManifoldPressure_inHg = 29.9;
273 minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa
274 maxMAP = MaxManifoldPressure_inHg * inhgtopa;
278 * Pm = ( Ze / ( Ze + Zi + Zt ) ) * Pa
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
286 * For the calculation below throttle is fully open or Zt = 0
292 double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence
293 Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox
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
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;
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;
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);
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) {
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;
385 // We can't recover from the above - don't use this supercharger speed.
387 // TODO - put out a massive error message!
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;
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;
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;
410 TakeoffMAP[i] = RatedMAP[i];
411 bTakeoffBoost = false;
413 BoostMul[i] = RatedMAP[i] / (GetStdPressure100K(RatedAltitude[i]) * psftopa);
417 if (BoostSpeeds > 0) {
421 bBoostOverride = (BoostOverride == 1 ? true : false);
422 bBoostManual = (BoostManual == 1 ? true : false);
423 Debug(0); // Call Debug() routine from constructor if needed
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 FGPiston::~FGPiston()
430 delete Lookup_Combustion_Efficiency;
431 delete Mixture_Efficiency_Correlation;
432 Debug(1); // Call Debug() routine from constructor if needed
435 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
437 void FGPiston::ResetToIC(void)
439 FGEngine::ResetToIC();
441 ManifoldPressure_inHg = in.Pressure * psftoinhg; // psf to in Hg
442 MAP = in.Pressure * psftopa;
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);
451 OilPressure_psi = 0.0;
455 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
457 void FGPiston::Calculate(void)
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);
468 TotalDeltaT = ( in.TotalDeltaT < 1e-9 ) ? 1.0 : in.TotalDeltaT;
470 /* The thruster controls the engine RPM because it encapsulates the gear ratio and other transmission variables */
471 RPM = Thruster->GetEngineRPM();
473 MeanPistonSpeed_fps = ( RPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
478 if (Boosted) doBoostControl();
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.
488 // if (equivalence_ratio < 0.668)
492 if (IndicatedHorsePower < 0.1250) Running = false;
499 if (Thruster->GetType() == FGThruster::ttPropeller) {
500 ((FGPropeller*)Thruster)->SetAdvance(in.PropAdvance[EngineNumber]);
501 ((FGPropeller*)Thruster)->SetFeather(in.PropFeather[EngineNumber]);
504 LoadThrusterInputs();
505 Thruster->Calculate(HP * hptoftlbssec);
510 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512 double FGPiston::CalcFuelNeed(void)
514 FuelExpended = FuelFlowRate * in.TotalDeltaT;
515 if (!Starved) FuelUsedLbs += FuelExpended;
519 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521 int FGPiston::InitRunning(void)
524 in.MixtureCmd[EngineNumber] = in.PressureRatio*1.3;
525 in.MixturePos[EngineNumber] = in.PressureRatio*1.3;
526 Thruster->SetRPM( 2.0*IdleRPM/Thruster->GetGearRatio() );
531 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533 * Start or stop the engine.
536 void FGPiston::doEngineStartup(void)
538 // Check parameters that may alter the operating state of the engine.
539 // (spark, fuel, starter motor etc)
543 Magneto_Left = false;
544 Magneto_Right = false;
545 // Magneto positions:
554 } // neglects battery voltage, master on switch, etc for now.
556 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
557 if (Magnetos > 1) Magneto_Right = true;
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;
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.
570 // Cut the engine *power* - Note: the engine will continue to
571 // spin depending on prop Ixx and freestream velocity
574 if (!spark || !fuel) Running = false;
575 if (RPM < IdleRPM*0.8 ) Running = false;
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
585 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
588 * Calculate the Current Boost Speed
590 * This function calculates the current turbo/supercharger boost speed
591 * based on altitude and the (automatic) boost-speed control valve configuration.
593 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
595 * Outputs: BoostSpeed
598 void FGPiston::doBoostControl(void)
601 if(BoostSpeed > BoostSpeeds-1) BoostSpeed = BoostSpeeds-1;
602 if(BoostSpeed < 0) BoostSpeed = 0;
604 if(BoostSpeed < BoostSpeeds - 1) {
605 // Check if we need to change to a higher boost speed
606 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
609 } if(BoostSpeed > 0) {
610 // Check if we need to change to a lower boost speed
611 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
618 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621 * Calculate the manifold absolute pressure (MAP) in inches hg
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.
627 * Inputs: p_amb, Throttle,
628 * MeanPistonSpeed_fps, dt
630 * Outputs: MAP, ManifoldPressure_inHg, TMAP, BoostLossHP
633 void FGPiston::doMAP(void)
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
638 double map_coefficient = Ze/(Ze+Z_airbox+Zt);
640 // Add a variable lag to manifold pressure changes
641 double dMAP=(TMAP - p_ram * map_coefficient);
642 if (ManifoldPressureLag > TotalDeltaT) dMAP *= TotalDeltaT/ManifoldPressureLag;
646 // Find the mean effective pressure required to achieve this manifold pressure
647 // Fixme: determine the HP consumed by the supercharger
649 PMEP = (TMAP - p_amb) * volumetric_efficiency; // Fixme: p_amb should be exhaust manifold pressure
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.
658 bool bTakeoffPos = false;
660 if (in.ThrottlePos[EngineNumber] > 0.98) {
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) {
670 if (MAP > TakeoffMAP[BoostSpeed]) MAP = TakeoffMAP[BoostSpeed];
672 if (MAP > RatedMAP[BoostSpeed]) MAP = RatedMAP[BoostSpeed];
679 if( BoostLossFactor > 0.0 )
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
688 // And set the value in American units as well
689 ManifoldPressure_inHg = MAP / inhgtopa;
692 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694 * Calculate the air flow through the engine.
695 * Also calculates ambient air density
696 * (used in CHT calculation for air-cooled engines).
698 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
699 * RPM, volumetric_efficiency,
701 * TODO: Model inlet manifold air temperature.
703 * Outputs: rho_air, m_dot_air, volumetric_efficiency_reduced
706 void FGPiston::doAirFlow(void)
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));
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;
720 double rho_air_manifold = MAP / (R_air * T_amb);
721 m_dot_air = v_dot_air * rho_air_manifold;
725 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727 * Calculate the fuel flow into the engine.
729 * Inputs: Mixture, thi_sea_level, p_amb, m_dot_air
731 * Outputs: equivalence_ratio, m_dot_fuel
734 void FGPiston::doFuelFlow(void)
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
744 equivalence_ratio = 0.0;
748 FuelFlow_pph = FuelFlowRate * 3600; // seconds to hours
749 FuelFlow_gph = FuelFlow_pph / 6.0; // Assumes 6 lbs / gallon
752 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
754 * Calculate the power produced by the engine.
756 * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, ISFC,
757 * Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
758 * MeanPistonSpeed_fps
760 * Outputs: PctPower, HP, FMEP, IndicatedHorsePower
763 void FGPiston::doEnginePower(void)
765 IndicatedHorsePower = -StaticFriction_HP;
768 double ME, power; // Convienience term for use in the calculations
769 ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
771 // Guestimate engine friction losses from Figure 4.4 of "Engines: An Introduction", John Lumley
772 FMEP = (-FMEPDynamic * MeanPistonSpeed_fps * fttom - FMEPStatic);
776 if ( Magnetos != 3 ) power *= SparkFailDrop;
779 IndicatedHorsePower = (FuelFlow_pph / ISFC )* ME * power - StaticFriction_HP; //FIXME static friction should depend on oil temp and configuration;
782 // Power output when the engine is not running
783 double torque, k_torque, rpm; // Convienience term for use in the calculations
785 rpm = RPM < 1.0 ? 1.0 : RPM;
787 if(RPM<StarterRPM) k_torque = 1.0-RPM/(StarterRPM);
789 torque = StarterTorque*k_torque*StarterGain;
790 IndicatedHorsePower = torque * rpm / 5252;
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);
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;
804 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
806 * Calculate the exhaust gas temperature.
808 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
809 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, PctPower
811 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
814 void FGPiston::doEGT(void)
816 double delta_T_exhaust;
817 double enthalpy_exhaust;
818 double heat_capacity_exhaust;
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;
833 ExhaustGasTemp_degK += delta_T_exhaust;
837 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
839 * Calculate the cylinder head temperature.
841 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
842 * combustion_efficiency, RPM, MaxRPM, Displacement, Cylinders
844 * Outputs: CylinderHeadTemp_degK
847 void FGPiston::doCHT(void)
851 double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
853 double arbitary_area = Displacement/360.0;
854 double CpCylinderHead = 800.0;
855 double MassCylinderHead = CylinderHeadMass * Cylinders;
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;
868 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
870 CylinderHeadTemp_degK +=
871 (dqdt_cylinder_head / HeatCapacityCylinderHead) * TotalDeltaT;
875 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877 * Calculate the oil temperature.
879 * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
881 * Outputs: OilTemp_degK
884 void FGPiston::doOilTemperature(void)
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
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) ;
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.
900 time_constant = 1000; // Time constant for engine-off; reflects the fact
901 // that oil is no longer getting circulated
904 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
906 OilTemp_degK += (dOilTempdt * TotalDeltaT);
909 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
911 * Calculate the oil pressure.
913 * Inputs: RPM, MaxRPM, OilTemp_degK
915 * Outputs: OilPressure_psi
918 void FGPiston::doOilPressure(void)
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;
925 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
927 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
928 OilPressure_psi = Oil_Press_Relief_Valve;
931 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
934 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
936 // This is a local copy of the same function in FGStandardAtmosphere.
938 double FGPiston::GetStdPressure100K(double altitude) const
940 // Limit this equation to input altitudes of 100000 ft.
941 if (altitude > 100000.0) altitude = 100000.0;
944 const double coef[5] = { 2116.217,
951 for (int pwr=1; pwr<=4; pwr++) alt[pwr] = alt[pwr-1]*altitude;
954 for (int ctr=0; ctr<=4; ctr++) press += coef[ctr]*alt[ctr];
958 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
960 string FGPiston::GetEngineLabels(const string& delimiter)
962 std::ostringstream buf;
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);
973 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
975 string FGPiston::GetEngineValues(const string& delimiter)
977 std::ostringstream buf;
979 buf << (HP * hptoftlbssec) << delimiter << HP << delimiter
980 << equivalence_ratio << delimiter << ManifoldPressure_inHg << delimiter
981 << Thruster->GetThrusterValues(EngineNumber, delimiter);
986 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
995 // 1: This value explicity requests the normal JSBSim
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
1006 void FGPiston::Debug(int from)
1008 if (debug_lvl <= 0) return;
1010 if (debug_lvl & 1) { // Standard console startup message output
1011 if (from == 0) { // Constructor
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;
1036 cout << " Starter Motor Torque: " << StarterTorque << endl;
1037 cout << " Starter Motor RPM: " << StarterRPM << endl;
1040 cout << " Combustion Efficiency table:" << endl;
1041 Lookup_Combustion_Efficiency->Print();
1045 cout << " Mixture Efficiency Correlation table:" << endl;
1046 Mixture_Efficiency_Correlation->Print();
1051 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1052 if (from == 0) cout << "Instantiated: FGPiston" << endl;
1053 if (from == 1) cout << "Destroyed: FGPiston" << endl;
1055 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1057 if (debug_lvl & 8 ) { // Runtime state variables
1059 if (debug_lvl & 16) { // Sanity checking
1061 if (debug_lvl & 64) {
1062 if (from == 0) { // Constructor
1063 cout << IdSrc << endl;
1064 cout << IdHdr << endl;
1068 } // namespace JSBSim