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"
48 #include "input_output/FGXMLElement.h"
54 static const char *IdSrc = "$Id: FGPiston.cpp,v 1.72 2013/11/24 11:40:57 bcoconni Exp $";
55 static const char *IdHdr = ID_PISTON;
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61 FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input)
62 : FGEngine(exec, el, engine_number, input),
63 R_air(287.3), // Gas constant for air J/Kg/K
64 rho_fuel(800), // estimate
65 calorific_value_fuel(47.3e6), // J/Kg
66 Cp_air(1005), // Specific heat (constant pressure) J/Kg/K
68 standard_pressure(101320.73)
70 Element *table_element;
74 // Defaults and initializations
78 // These items are read from the configuration file
79 // Defaults are from a Lycoming O-360, more or less
87 MinManifoldPressure_inHg = 6.5;
88 MaxManifoldPressure_inHg = 28.5;
89 ManifoldPressureLag=1.0;
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;
108 // These are internal program variables
110 Lookup_Combustion_Efficiency = 0;
111 Mixture_Efficiency_Correlation = 0;
120 BoostSpeeds = 0; // Default to no supercharging
125 bBoostOverride = false;
126 bTakeoffBoost = false;
127 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
128 BoostLossFactor = 0.0; // Default to free boost
131 for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
134 RatedAltitude[i] = 0.0;
136 RatedMAP[i] = 100000;
138 TakeoffMAP[i] = 100000;
140 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
141 BoostSwitchAltitude[i] = 0.0;
142 BoostSwitchPressure[i] = 0.0;
145 // Read inputs from engine data file where present.
147 if (el->FindElement("minmp"))
148 MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
149 if (el->FindElement("maxmp"))
150 MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
151 if (el->FindElement("man-press-lag"))
152 ManifoldPressureLag = el->FindElementValueAsNumber("man-press-lag");
153 if (el->FindElement("displacement"))
154 Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
155 if (el->FindElement("maxhp"))
156 MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
157 if (el->FindElement("static-friction"))
158 StaticFriction_HP = el->FindElementValueAsNumberConvertTo("static-friction","HP");
159 if (el->FindElement("sparkfaildrop"))
160 SparkFailDrop = Constrain(0, 1 - el->FindElementValueAsNumber("sparkfaildrop"), 1);
161 if (el->FindElement("cycles"))
162 Cycles = el->FindElementValueAsNumber("cycles");
163 if (el->FindElement("idlerpm"))
164 IdleRPM = el->FindElementValueAsNumber("idlerpm");
165 if (el->FindElement("maxrpm"))
166 MaxRPM = el->FindElementValueAsNumber("maxrpm");
167 if (el->FindElement("maxthrottle"))
168 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
169 if (el->FindElement("minthrottle"))
170 MinThrottle = el->FindElementValueAsNumber("minthrottle");
171 if (el->FindElement("bsfc"))
172 ISFC = el->FindElementValueAsNumberConvertTo("bsfc", "LBS/HP*HR");
173 if (el->FindElement("volumetric-efficiency"))
174 volumetric_efficiency = el->FindElementValueAsNumber("volumetric-efficiency");
175 if (el->FindElement("compression-ratio"))
176 CompressionRatio = el->FindElementValueAsNumber("compression-ratio");
177 if (el->FindElement("bore"))
178 Bore = el->FindElementValueAsNumberConvertTo("bore","IN");
179 if (el->FindElement("stroke"))
180 Stroke = el->FindElementValueAsNumberConvertTo("stroke","IN");
181 if (el->FindElement("cylinders"))
182 Cylinders = el->FindElementValueAsNumber("cylinders");
183 if (el->FindElement("cylinder-head-mass"))
184 CylinderHeadMass = el->FindElementValueAsNumberConvertTo("cylinder-head-mass","KG");
185 if (el->FindElement("air-intake-impedance-factor"))
186 Z_airbox = el->FindElementValueAsNumber("air-intake-impedance-factor");
187 if (el->FindElement("ram-air-factor"))
188 Ram_Air_Factor = el->FindElementValueAsNumber("ram-air-factor");
189 if (el->FindElement("cooling-factor"))
190 Cooling_Factor = el->FindElementValueAsNumber("cooling-factor");
191 if (el->FindElement("starter-rpm"))
192 StarterRPM = el->FindElementValueAsNumber("starter-rpm");
193 if (el->FindElement("starter-torque"))
194 StarterTorque = el->FindElementValueAsNumber("starter-torque");
195 if (el->FindElement("dynamic-fmep"))
196 FMEPDynamic= el->FindElementValueAsNumberConvertTo("dynamic-fmep","PA");
197 if (el->FindElement("static-fmep"))
198 FMEPStatic = el->FindElementValueAsNumberConvertTo("static-fmep","PA");
199 if (el->FindElement("peak-piston-speed"))
200 PeakMeanPistonSpeed_fps = el->FindElementValueAsNumber("peak-piston-speed");
201 if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
202 BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
203 if (el->FindElement("boostoverride"))
204 BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
205 if (el->FindElement("boostmanual"))
206 BoostManual = (int)el->FindElementValueAsNumber("boostmanual");
207 if (el->FindElement("takeoffboost"))
208 TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI");
209 if (el->FindElement("boost-loss-factor"))
210 BoostLossFactor = el->FindElementValueAsNumber("boost-loss-factor");
211 if (el->FindElement("ratedboost1"))
212 RatedBoost[0] = el->FindElementValueAsNumberConvertTo("ratedboost1", "PSI");
213 if (el->FindElement("ratedboost2"))
214 RatedBoost[1] = el->FindElementValueAsNumberConvertTo("ratedboost2", "PSI");
215 if (el->FindElement("ratedboost3"))
216 RatedBoost[2] = el->FindElementValueAsNumberConvertTo("ratedboost3", "PSI");
217 if (el->FindElement("ratedpower1"))
218 RatedPower[0] = el->FindElementValueAsNumberConvertTo("ratedpower1", "HP");
219 if (el->FindElement("ratedpower2"))
220 RatedPower[1] = el->FindElementValueAsNumberConvertTo("ratedpower2", "HP");
221 if (el->FindElement("ratedpower3"))
222 RatedPower[2] = el->FindElementValueAsNumberConvertTo("ratedpower3", "HP");
223 if (el->FindElement("ratedrpm1"))
224 RatedRPM[0] = el->FindElementValueAsNumber("ratedrpm1");
225 if (el->FindElement("ratedrpm2"))
226 RatedRPM[1] = el->FindElementValueAsNumber("ratedrpm2");
227 if (el->FindElement("ratedrpm3"))
228 RatedRPM[2] = el->FindElementValueAsNumber("ratedrpm3");
229 if (el->FindElement("ratedaltitude1"))
230 RatedAltitude[0] = el->FindElementValueAsNumberConvertTo("ratedaltitude1", "FT");
231 if (el->FindElement("ratedaltitude2"))
232 RatedAltitude[1] = el->FindElementValueAsNumberConvertTo("ratedaltitude2", "FT");
233 if (el->FindElement("ratedaltitude3"))
234 RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT");
237 while((table_element = el->FindNextElement("table")) != 0) {
238 name = table_element->GetAttributeValue("name");
240 if (name == "COMBUSTION") {
241 Lookup_Combustion_Efficiency = new FGTable(PropertyManager, table_element);
242 } else if (name == "MIXTURE") {
243 Mixture_Efficiency_Correlation = new FGTable(PropertyManager, table_element);
245 cerr << "Unknown table type: " << name << " in piston engine definition." << endl;
247 } catch (std::string str) {
248 throw("Error loading piston engine table:" + name + ". " + str);
253 volumetric_efficiency_reduced = volumetric_efficiency;
255 if(StarterRPM < 0.) StarterRPM = 2*IdleRPM;
256 if(StarterTorque < 0)
257 StarterTorque = (MaxHP)*0.4; //just a wag.
259 displacement_SI = Displacement * in3tom3;
260 RatedMeanPistonSpeed_fps = ( MaxRPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
262 // Create IFSC to match the engine if not provided
264 double pmep = 29.92 - MaxManifoldPressure_inHg;
265 pmep *= inhgtopa * volumetric_efficiency;
266 double fmep = (FMEPDynamic * RatedMeanPistonSpeed_fps * fttom + FMEPStatic);
267 double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371);
268 ISFC = ( 1.1*Displacement * MaxRPM * volumetric_efficiency *(MaxManifoldPressure_inHg / 29.92) ) / (9411 * (MaxHP+hp_loss-StaticFriction_HP));
269 // cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " <<hp_loss <<endl;
271 if ( MaxManifoldPressure_inHg > 29.9 ) { // Don't allow boosting with a bogus number
272 MaxManifoldPressure_inHg = 29.9;
274 minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa
275 maxMAP = MaxManifoldPressure_inHg * inhgtopa;
279 * Pm = ( Ze / ( Ze + Zi + Zt ) ) * Pa
281 * Pm = Manifold Pressure
282 * Pa = Ambient Pressre
283 * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed
284 * Zi = airbox impedance
285 * Zt = throttle impedance
287 * For the calculation below throttle is fully open or Zt = 0
293 double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence
294 Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox
296 // Constant for Throttle impedence
297 Z_throttle=(PeakMeanPistonSpeed_fps/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox;
298 // Z_throttle=(MaxRPM/IdleRPM )*(standard_pressure/minMAP+2); // Constant for Throttle impedence
300 // Default tables if not provided in the configuration file
301 if(Lookup_Combustion_Efficiency == 0) {
302 // First column is thi, second is neta (combustion efficiency)
303 Lookup_Combustion_Efficiency = new FGTable(12);
304 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
305 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
306 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
307 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
308 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
309 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
310 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
311 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
312 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
313 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
314 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
315 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
318 // First column is Fuel/Air Ratio, second is neta (mixture efficiency)
319 if( Mixture_Efficiency_Correlation == 0) {
320 Mixture_Efficiency_Correlation = new FGTable(15);
321 *Mixture_Efficiency_Correlation << 0.05000 << 0.00000;
322 *Mixture_Efficiency_Correlation << 0.05137 << 0.00862;
323 *Mixture_Efficiency_Correlation << 0.05179 << 0.21552;
324 *Mixture_Efficiency_Correlation << 0.05430 << 0.48276;
325 *Mixture_Efficiency_Correlation << 0.05842 << 0.70690;
326 *Mixture_Efficiency_Correlation << 0.06312 << 0.83621;
327 *Mixture_Efficiency_Correlation << 0.06942 << 0.93103;
328 *Mixture_Efficiency_Correlation << 0.07786 << 1.00000;
329 *Mixture_Efficiency_Correlation << 0.08845 << 1.00000;
330 *Mixture_Efficiency_Correlation << 0.09270 << 0.98276;
331 *Mixture_Efficiency_Correlation << 0.10120 << 0.93103;
332 *Mixture_Efficiency_Correlation << 0.11455 << 0.72414;
333 *Mixture_Efficiency_Correlation << 0.12158 << 0.45690;
334 *Mixture_Efficiency_Correlation << 0.12435 << 0.23276;
335 *Mixture_Efficiency_Correlation << 0.12500 << 0.00000;
338 string property_name, base_property_name;
339 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
340 property_name = base_property_name + "/power-hp";
341 PropertyManager->Tie(property_name, &HP);
342 property_name = base_property_name + "/friction-hp";
343 PropertyManager->Tie(property_name, &StaticFriction_HP);
344 property_name = base_property_name + "/bsfc-lbs_hphr";
345 PropertyManager->Tie(property_name, &ISFC);
346 property_name = base_property_name + "/starter-norm";
347 PropertyManager->Tie(property_name, &StarterGain);
348 property_name = base_property_name + "/volumetric-efficiency";
349 PropertyManager->Tie(property_name, &volumetric_efficiency);
350 property_name = base_property_name + "/map-pa";
351 PropertyManager->Tie(property_name, &MAP);
352 property_name = base_property_name + "/map-inhg";
353 PropertyManager->Tie(property_name, &ManifoldPressure_inHg);
354 property_name = base_property_name + "/air-intake-impedance-factor";
355 PropertyManager->Tie(property_name, &Z_airbox);
356 property_name = base_property_name + "/ram-air-factor";
357 PropertyManager->Tie(property_name, &Ram_Air_Factor);
358 property_name = base_property_name + "/cooling-factor";
359 PropertyManager->Tie(property_name, &Cooling_Factor);
360 property_name = base_property_name + "/boost-speed";
361 PropertyManager->Tie(property_name, &BoostSpeed);
362 property_name = base_property_name + "/cht-degF";
363 PropertyManager->Tie(property_name, this, &FGPiston::getCylinderHeadTemp_degF);
364 property_name = base_property_name + "/oil-temperature-degF";
365 PropertyManager->Tie(property_name, this, &FGPiston::getOilTemp_degF);
366 property_name = base_property_name + "/oil-pressure-psi";
367 PropertyManager->Tie(property_name, this, &FGPiston::getOilPressure_psi);
368 property_name = base_property_name + "/egt-degF";
369 PropertyManager->Tie(property_name, this, &FGPiston::getExhaustGasTemp_degF);
370 if(BoostLossFactor > 0.0) {
371 property_name = base_property_name + "/boostloss-factor";
372 PropertyManager->Tie(property_name, &BoostLossFactor);
373 property_name = base_property_name + "/boostloss-hp";
374 PropertyManager->Tie(property_name, &BoostLossHP);
377 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
378 if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
379 for (i=0; i<BoostSpeeds; ++i) {
381 if (RatedBoost[i] <= 0.0) bad = true;
382 if (RatedPower[i] <= 0.0) bad = true;
383 if (RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
384 if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
386 // We can't recover from the above - don't use this supercharger speed.
388 // TODO - put out a massive error message!
391 // Now sanity-check stuff that is recoverable.
392 if (i < BoostSpeeds - 1) {
393 if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
394 // TODO - put out an error message
395 // But we can also make a reasonable estimate, as below.
396 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
398 BoostSwitchPressure[i] = GetStdPressure100K(BoostSwitchAltitude[i]) * psftopa;
399 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
400 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
401 BoostSwitchHysteresis = 1000;
403 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
404 RatedMAP[i] = standard_pressure + RatedBoost[i] * 6895; // psi*6895 = Pa.
405 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
406 if (TakeoffBoost > RatedBoost[0]) {
407 // Assume that the effect on the BCV is the same whichever speed is in use.
408 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
409 bTakeoffBoost = true;
411 TakeoffMAP[i] = RatedMAP[i];
412 bTakeoffBoost = false;
414 BoostMul[i] = RatedMAP[i] / (GetStdPressure100K(RatedAltitude[i]) * psftopa);
418 if (BoostSpeeds > 0) {
422 bBoostOverride = (BoostOverride == 1 ? true : false);
423 bBoostManual = (BoostManual == 1 ? true : false);
424 Debug(0); // Call Debug() routine from constructor if needed
427 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
429 FGPiston::~FGPiston()
431 delete Lookup_Combustion_Efficiency;
432 delete Mixture_Efficiency_Correlation;
433 Debug(1); // Call Debug() routine from constructor if needed
436 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
438 void FGPiston::ResetToIC(void)
440 FGEngine::ResetToIC();
442 ManifoldPressure_inHg = in.Pressure * psftoinhg; // psf to in Hg
443 MAP = in.Pressure * psftopa;
445 double airTemperature_degK = RankineToKelvin(in.Temperature);
446 OilTemp_degK = airTemperature_degK;
447 CylinderHeadTemp_degK = airTemperature_degK;
448 ExhaustGasTemp_degK = airTemperature_degK;
449 EGT_degC = ExhaustGasTemp_degK - 273;
450 Thruster->SetRPM(0.0);
452 OilPressure_psi = 0.0;
456 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
458 void FGPiston::Calculate(void)
462 p_amb = in.Pressure * psftopa;
463 double p = in.TotalPressure * psftopa;
464 p_ram = (p - p_amb) * Ram_Air_Factor + p_amb;
465 T_amb = RankineToKelvin(in.Temperature);
469 TotalDeltaT = ( in.TotalDeltaT < 1e-9 ) ? 1.0 : in.TotalDeltaT;
471 /* The thruster controls the engine RPM because it encapsulates the gear ratio and other transmission variables */
472 RPM = Thruster->GetEngineRPM();
474 MeanPistonSpeed_fps = ( RPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
479 if (Boosted) doBoostControl();
484 //Now that the fuel flow is done check if the mixture is too lean to run the engine
485 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
486 //This might be a bit generous, but since there's currently no audiable warning of impending
487 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
489 // if (equivalence_ratio < 0.668)
493 if (IndicatedHorsePower < 0.1250) Running = false;
500 if (Thruster->GetType() == FGThruster::ttPropeller) {
501 ((FGPropeller*)Thruster)->SetAdvance(in.PropAdvance[EngineNumber]);
502 ((FGPropeller*)Thruster)->SetFeather(in.PropFeather[EngineNumber]);
505 LoadThrusterInputs();
506 Thruster->Calculate(HP * hptoftlbssec);
511 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
513 double FGPiston::CalcFuelNeed(void)
515 FuelExpended = FuelFlowRate * in.TotalDeltaT;
516 if (!Starved) FuelUsedLbs += FuelExpended;
520 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
522 int FGPiston::InitRunning(void)
525 in.MixtureCmd[EngineNumber] = in.PressureRatio*1.3;
526 in.MixturePos[EngineNumber] = in.PressureRatio*1.3;
527 Thruster->SetRPM( 2.0*IdleRPM/Thruster->GetGearRatio() );
532 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534 * Start or stop the engine.
537 void FGPiston::doEngineStartup(void)
539 // Check parameters that may alter the operating state of the engine.
540 // (spark, fuel, starter motor etc)
544 Magneto_Left = false;
545 Magneto_Right = false;
546 // Magneto positions:
555 } // neglects battery voltage, master on switch, etc for now.
557 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
558 if (Magnetos > 1) Magneto_Right = true;
560 // We will 'run' with any fuel flow. If there is not enough fuel to make power it will show in doEnginePower
561 fuel = FuelFlowRate > 0.0 ? 1 : 0;
563 // Check if we are turning the starter motor
564 if (Cranking != Starter) {
565 // This check saves .../cranking from getting updated every loop - they
566 // only update when changed.
571 // Cut the engine *power* - Note: the engine will continue to
572 // spin depending on prop Ixx and freestream velocity
575 if (!spark || !fuel) Running = false;
576 if (RPM < IdleRPM*0.8 ) Running = false;
578 if ( spark && fuel) { // start the engine if revs high enough
579 if (RPM > IdleRPM*0.8) // This allows us to in-air start
580 Running = true; // when windmilling
586 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
589 * Calculate the Current Boost Speed
591 * This function calculates the current turbo/supercharger boost speed
592 * based on altitude and the (automatic) boost-speed control valve configuration.
594 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
596 * Outputs: BoostSpeed
599 void FGPiston::doBoostControl(void)
602 if(BoostSpeed > BoostSpeeds-1) BoostSpeed = BoostSpeeds-1;
603 if(BoostSpeed < 0) BoostSpeed = 0;
605 if(BoostSpeed < BoostSpeeds - 1) {
606 // Check if we need to change to a higher boost speed
607 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
610 } if(BoostSpeed > 0) {
611 // Check if we need to change to a lower boost speed
612 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
619 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
622 * Calculate the manifold absolute pressure (MAP) in inches hg
624 * This function calculates manifold absolute pressure (MAP)
625 * from the throttle position, turbo/supercharger boost control
626 * system, engine speed and local ambient air density.
628 * Inputs: p_amb, Throttle,
629 * MeanPistonSpeed_fps, dt
631 * Outputs: MAP, ManifoldPressure_inHg, TMAP, BoostLossHP
634 void FGPiston::doMAP(void)
636 double Zt = (1 - in.ThrottlePos[EngineNumber])*(1 - in.ThrottlePos[EngineNumber])*Z_throttle; // throttle impedence
637 double Ze= MeanPistonSpeed_fps > 0 ? PeakMeanPistonSpeed_fps/MeanPistonSpeed_fps : 999999; // engine impedence
639 double map_coefficient = Ze/(Ze+Z_airbox+Zt);
641 // Add a variable lag to manifold pressure changes
642 double dMAP=(TMAP - p_ram * map_coefficient);
643 if (ManifoldPressureLag > TotalDeltaT) dMAP *= TotalDeltaT/ManifoldPressureLag;
647 // Find the mean effective pressure required to achieve this manifold pressure
648 // Fixme: determine the HP consumed by the supercharger
650 PMEP = (TMAP - p_amb) * volumetric_efficiency; // Fixme: p_amb should be exhaust manifold pressure
653 // If takeoff boost is fitted, we currently assume the following throttle map:
654 // (In throttle % - actual input is 0 -> 1)
655 // 99 / 100 - Takeoff boost
656 // In real life, most planes would be fitted with a mechanical 'gate' between
657 // the rated boost and takeoff boost positions.
659 bool bTakeoffPos = false;
661 if (in.ThrottlePos[EngineNumber] > 0.98) {
665 // Boost the manifold pressure.
666 double boost_factor = (( BoostMul[BoostSpeed] - 1 ) / RatedRPM[BoostSpeed] ) * RPM + 1;
667 MAP = TMAP * boost_factor;
668 // Now clip the manifold pressure to BCV or Wastegate setting.
669 if(!bBoostOverride) {
671 if (MAP > TakeoffMAP[BoostSpeed]) MAP = TakeoffMAP[BoostSpeed];
673 if (MAP > RatedMAP[BoostSpeed]) MAP = RatedMAP[BoostSpeed];
680 if( BoostLossFactor > 0.0 )
682 double gamma = 1.414; // specific heat constants
683 double Nstage = 1; // Nstage is the number of boost stages.
684 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
689 // And set the value in American units as well
690 ManifoldPressure_inHg = MAP / inhgtopa;
693 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695 * Calculate the air flow through the engine.
696 * Also calculates ambient air density
697 * (used in CHT calculation for air-cooled engines).
699 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
700 * RPM, volumetric_efficiency,
702 * TODO: Model inlet manifold air temperature.
704 * Outputs: rho_air, m_dot_air, volumetric_efficiency_reduced
707 void FGPiston::doAirFlow(void)
709 double gamma = 1.3; // specific heat constants
710 // loss of volumentric efficiency due to difference between MAP and exhaust pressure
711 // Eq 6-10 from The Internal Combustion Engine - Charles Taylor Vol 1
712 double mratio = MAP < 1. ? CompressionRatio : p_amb/MAP;
713 if (mratio > CompressionRatio) mratio = CompressionRatio;
714 double ve =((gamma-1)/gamma) +( CompressionRatio -(mratio))/(gamma*( CompressionRatio - 1));
716 rho_air = p_amb / (R_air * T_amb);
717 double swept_volume = (displacement_SI * (RPM/60)) / 2;
718 volumetric_efficiency_reduced = volumetric_efficiency *ve;
719 v_dot_air = swept_volume * volumetric_efficiency_reduced;
721 double rho_air_manifold = MAP / (R_air * T_amb);
722 m_dot_air = v_dot_air * rho_air_manifold;
726 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
728 * Calculate the fuel flow into the engine.
730 * Inputs: Mixture, thi_sea_level, p_amb, m_dot_air
732 * Outputs: equivalence_ratio, m_dot_fuel
735 void FGPiston::doFuelFlow(void)
737 double thi_sea_level = 1.3 * in.MixturePos[EngineNumber]; // Allows an AFR of infinity:1 to 11.3075:1
738 equivalence_ratio = thi_sea_level * 101325.0 / p_amb;
739 // double AFR = 10+(12*(1-in.Mixture[EngineNumber]));// mixture 10:1 to 22:1
740 // m_dot_fuel = m_dot_air / AFR;
741 m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;
742 FuelFlowRate = m_dot_fuel * 2.2046; // kg to lb
743 if(Starved) // There is no fuel, so zero out the flows we've calculated so far
745 equivalence_ratio = 0.0;
749 FuelFlow_pph = FuelFlowRate * 3600; // seconds to hours
750 FuelFlow_gph = FuelFlow_pph / 6.0; // Assumes 6 lbs / gallon
753 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755 * Calculate the power produced by the engine.
757 * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, ISFC,
758 * Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
759 * MeanPistonSpeed_fps
761 * Outputs: PctPower, HP, FMEP, IndicatedHorsePower
764 void FGPiston::doEnginePower(void)
766 IndicatedHorsePower = -StaticFriction_HP;
769 double ME, power; // Convienience term for use in the calculations
770 ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
772 // Guestimate engine friction losses from Figure 4.4 of "Engines: An Introduction", John Lumley
773 FMEP = (-FMEPDynamic * MeanPistonSpeed_fps * fttom - FMEPStatic);
777 if ( Magnetos != 3 ) power *= SparkFailDrop;
780 IndicatedHorsePower = (FuelFlow_pph / ISFC )* ME * power - StaticFriction_HP; //FIXME static friction should depend on oil temp and configuration;
783 // Power output when the engine is not running
784 double torque, k_torque, rpm; // Convienience term for use in the calculations
786 rpm = RPM < 1.0 ? 1.0 : RPM;
788 if(RPM<StarterRPM) k_torque = 1.0-RPM/(StarterRPM);
790 torque = StarterTorque*k_torque*StarterGain;
791 IndicatedHorsePower = torque * rpm / 5252;
795 // Constant is (1/2) * 60 * 745.7
796 // (1/2) convert cycles, 60 minutes to seconds, 745.7 watts to hp.
797 double pumping_hp = ((PMEP + FMEP) * displacement_SI * RPM)/(Cycles*22371);
799 HP = IndicatedHorsePower + pumping_hp - BoostLossHP;
800 // cout << "pumping_hp " <<pumping_hp << FMEP << PMEP <<endl;
801 PctPower = HP / MaxHP ;
802 // cout << "Power = " << HP << " RPM = " << RPM << " Running = " << Running << " Cranking = " << Cranking << endl;
805 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
807 * Calculate the exhaust gas temperature.
809 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
810 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, PctPower
812 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
815 void FGPiston::doEGT(void)
817 double delta_T_exhaust;
818 double enthalpy_exhaust;
819 double heat_capacity_exhaust;
822 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
823 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
824 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
825 combustion_efficiency * 0.30;
826 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
827 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
828 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
829 } else { // Drop towards ambient - guess an appropriate time constant for now
830 combustion_efficiency = 0;
831 dEGTdt = (RankineToKelvin(in.Temperature) - ExhaustGasTemp_degK) / 100.0;
832 delta_T_exhaust = dEGTdt * TotalDeltaT;
834 ExhaustGasTemp_degK += delta_T_exhaust;
838 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
840 * Calculate the cylinder head temperature.
842 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
843 * combustion_efficiency, RPM, MaxRPM, Displacement, Cylinders
845 * Outputs: CylinderHeadTemp_degK
848 void FGPiston::doCHT(void)
852 double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
854 double arbitary_area = Displacement/360.0;
855 double CpCylinderHead = 800.0;
856 double MassCylinderHead = CylinderHeadMass * Cylinders;
858 double temperature_difference = CylinderHeadTemp_degK - T_amb;
859 double v_apparent = IAS * Cooling_Factor;
860 double v_dot_cooling_air = arbitary_area * v_apparent;
861 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
862 double dqdt_from_combustion =
863 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
864 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
865 (h3 * RPM * temperature_difference / MaxRPM);
866 double dqdt_free = h1 * temperature_difference * arbitary_area;
867 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
869 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
871 CylinderHeadTemp_degK +=
872 (dqdt_cylinder_head / HeatCapacityCylinderHead) * TotalDeltaT;
876 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
878 * Calculate the oil temperature.
880 * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
882 * Outputs: OilTemp_degK
885 void FGPiston::doOilTemperature(void)
887 double target_oil_temp; // Steady state oil temp at the current engine conditions
888 double time_constant; // The time constant for the differential equation
889 double efficiency = 0.667; // The aproximate oil cooling system efficiency // FIXME: may vary by engine
891 // Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature
892 // target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;
893 target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;
895 if (OilPressure_psi > 5.0 ) {
896 time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
897 // The higher the pressure the faster it reaches
898 // target temperature. Oil pressure should be about
899 // 60 PSI yielding a TC of about 80.
901 time_constant = 1000; // Time constant for engine-off; reflects the fact
902 // that oil is no longer getting circulated
905 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
907 OilTemp_degK += (dOilTempdt * TotalDeltaT);
910 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912 * Calculate the oil pressure.
914 * Inputs: RPM, MaxRPM, OilTemp_degK
916 * Outputs: OilPressure_psi
919 void FGPiston::doOilPressure(void)
921 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
922 double Oil_Press_RPM_Max = MaxRPM * 0.75; // 75% of max rpm FIXME: may vary by engine
923 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
924 double Oil_Viscosity_Index = 0.25;
926 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
928 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
929 OilPressure_psi = Oil_Press_Relief_Valve;
932 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
935 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
937 // This is a local copy of the same function in FGStandardAtmosphere.
939 double FGPiston::GetStdPressure100K(double altitude) const
941 // Limit this equation to input altitudes of 100000 ft.
942 if (altitude > 100000.0) altitude = 100000.0;
945 const double coef[5] = { 2116.217,
952 for (int pwr=1; pwr<=4; pwr++) alt[pwr] = alt[pwr-1]*altitude;
955 for (int ctr=0; ctr<=4; ctr++) press += coef[ctr]*alt[ctr];
959 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
961 string FGPiston::GetEngineLabels(const string& delimiter)
963 std::ostringstream buf;
965 buf << Name << " Power Available (engine " << EngineNumber << " in ft-lbs/sec)" << delimiter
966 << Name << " HP (engine " << EngineNumber << ")" << delimiter
967 << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimiter
968 << Name << " MAP (engine " << EngineNumber << " in inHg)" << delimiter
969 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
974 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 string FGPiston::GetEngineValues(const string& delimiter)
978 std::ostringstream buf;
980 buf << (HP * hptoftlbssec) << delimiter << HP << delimiter
981 << equivalence_ratio << delimiter << ManifoldPressure_inHg << delimiter
982 << Thruster->GetThrusterValues(EngineNumber, delimiter);
987 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
989 // The bitmasked value choices are as follows:
990 // unset: In this case (the default) JSBSim would only print
991 // out the normally expected messages, essentially echoing
992 // the config files as they are read. If the environment
993 // variable is not set, debug_lvl is set to 1 internally
994 // 0: This requests JSBSim not to output any messages
996 // 1: This value explicity requests the normal JSBSim
998 // 2: This value asks for a message to be printed out when
999 // a class is instantiated
1000 // 4: When this value is set, a message is displayed when a
1001 // FGModel object executes its Run() method
1002 // 8: When this value is set, various runtime state variables
1003 // are printed out periodically
1004 // 16: When set various parameters are sanity checked and
1005 // a message is printed out when they go out of bounds
1007 void FGPiston::Debug(int from)
1009 if (debug_lvl <= 0) return;
1011 if (debug_lvl & 1) { // Standard console startup message output
1012 if (from == 0) { // Constructor
1014 cout << "\n Engine Name: " << Name << endl;
1015 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
1016 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
1017 cout << " MinMaP (Pa): " << minMAP << endl;
1018 cout << " MaxMaP (Pa): " << maxMAP << endl;
1019 cout << " Displacement: " << Displacement << endl;
1020 cout << " Bore: " << Bore << endl;
1021 cout << " Stroke: " << Stroke << endl;
1022 cout << " Cylinders: " << Cylinders << endl;
1023 cout << " Cylinders Head Mass: " << CylinderHeadMass << endl;
1024 cout << " Compression Ratio: " << CompressionRatio << endl;
1025 cout << " MaxHP: " << MaxHP << endl;
1026 cout << " Cycles: " << Cycles << endl;
1027 cout << " IdleRPM: " << IdleRPM << endl;
1028 cout << " MaxRPM: " << MaxRPM << endl;
1029 cout << " Throttle Constant: " << Z_throttle << endl;
1030 cout << " ISFC: " << ISFC << endl;
1031 cout << " Volumetric Efficiency: " << volumetric_efficiency << endl;
1032 cout << " PeakMeanPistonSpeed_fps: " << PeakMeanPistonSpeed_fps << endl;
1033 cout << " Intake Impedance Factor: " << Z_airbox << endl;
1034 cout << " Dynamic FMEP Factor: " << FMEPDynamic << endl;
1035 cout << " Static FMEP Factor: " << FMEPStatic << endl;
1037 cout << " Starter Motor Torque: " << StarterTorque << endl;
1038 cout << " Starter Motor RPM: " << StarterRPM << endl;
1041 cout << " Combustion Efficiency table:" << endl;
1042 Lookup_Combustion_Efficiency->Print();
1046 cout << " Mixture Efficiency Correlation table:" << endl;
1047 Mixture_Efficiency_Correlation->Print();
1052 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1053 if (from == 0) cout << "Instantiated: FGPiston" << endl;
1054 if (from == 1) cout << "Destroyed: FGPiston" << endl;
1056 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1058 if (debug_lvl & 8 ) { // Runtime state variables
1060 if (debug_lvl & 16) { // Sanity checking
1062 if (debug_lvl & 64) {
1063 if (from == 0) { // Constructor
1064 cout << IdSrc << endl;
1065 cout << IdHdr << endl;
1069 } // namespace JSBSim