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.64 2011/08/04 13:45:42 jberndt 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;
89 volumetric_efficiency = 0.85;
93 CylinderHeadMass = 2; //kg
94 CompressionRatio = 8.5;
97 PeakMeanPistonSpeed_fps = 100;
100 Cooling_Factor = 0.5144444;
101 StaticFriction_HP = 1.5;
103 // These are internal program variables
105 Lookup_Combustion_Efficiency = 0;
106 Mixture_Efficiency_Correlation = 0;
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 // Read inputs from engine data file where present.
140 if (el->FindElement("minmp")) // Should have ELSE statement telling default value used?
141 MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
142 if (el->FindElement("maxmp"))
143 MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
144 if (el->FindElement("displacement"))
145 Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
146 if (el->FindElement("maxhp"))
147 MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
148 if (el->FindElement("static-friction"))
149 StaticFriction_HP = el->FindElementValueAsNumberConvertTo("static-friction","HP");
150 if (el->FindElement("sparkfaildrop"))
151 SparkFailDrop = Constrain(0, 1 - el->FindElementValueAsNumber("sparkfaildrop"), 1);
152 if (el->FindElement("cycles"))
153 Cycles = el->FindElementValueAsNumber("cycles");
154 if (el->FindElement("idlerpm"))
155 IdleRPM = el->FindElementValueAsNumber("idlerpm");
156 if (el->FindElement("maxrpm"))
157 MaxRPM = el->FindElementValueAsNumber("maxrpm");
158 if (el->FindElement("maxthrottle"))
159 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
160 if (el->FindElement("minthrottle"))
161 MinThrottle = el->FindElementValueAsNumber("minthrottle");
162 if (el->FindElement("bsfc"))
163 ISFC = el->FindElementValueAsNumberConvertTo("bsfc", "LBS/HP*HR");
164 if (el->FindElement("volumetric-efficiency"))
165 volumetric_efficiency = el->FindElementValueAsNumber("volumetric-efficiency");
166 if (el->FindElement("compression-ratio"))
167 CompressionRatio = el->FindElementValueAsNumber("compression-ratio");
168 if (el->FindElement("bore"))
169 Bore = el->FindElementValueAsNumberConvertTo("bore","IN");
170 if (el->FindElement("stroke"))
171 Stroke = el->FindElementValueAsNumberConvertTo("stroke","IN");
172 if (el->FindElement("cylinders"))
173 Cylinders = el->FindElementValueAsNumber("cylinders");
174 if (el->FindElement("cylinder-head-mass"))
175 CylinderHeadMass = el->FindElementValueAsNumberConvertTo("cylinder-head-mass","KG");
176 if (el->FindElement("air-intake-impedance-factor"))
177 Z_airbox = el->FindElementValueAsNumber("air-intake-impedance-factor");
178 if (el->FindElement("ram-air-factor"))
179 Ram_Air_Factor = el->FindElementValueAsNumber("ram-air-factor");
180 if (el->FindElement("cooling-factor"))
181 Cooling_Factor = el->FindElementValueAsNumber("cooling-factor");
182 if (el->FindElement("dynamic-fmep"))
183 FMEPDynamic= el->FindElementValueAsNumberConvertTo("dynamic-fmep","PA");
184 if (el->FindElement("static-fmep"))
185 FMEPStatic = el->FindElementValueAsNumberConvertTo("static-fmep","PA");
186 if (el->FindElement("peak-piston-speed"))
187 PeakMeanPistonSpeed_fps = el->FindElementValueAsNumber("peak-piston-speed");
188 if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
189 BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
190 if (el->FindElement("boostoverride"))
191 BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
192 if (el->FindElement("boostmanual"))
193 BoostManual = (int)el->FindElementValueAsNumber("boostmanual");
194 if (el->FindElement("takeoffboost"))
195 TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI");
196 if (el->FindElement("ratedboost1"))
197 RatedBoost[0] = el->FindElementValueAsNumberConvertTo("ratedboost1", "PSI");
198 if (el->FindElement("ratedboost2"))
199 RatedBoost[1] = el->FindElementValueAsNumberConvertTo("ratedboost2", "PSI");
200 if (el->FindElement("ratedboost3"))
201 RatedBoost[2] = el->FindElementValueAsNumberConvertTo("ratedboost3", "PSI");
202 if (el->FindElement("ratedpower1"))
203 RatedPower[0] = el->FindElementValueAsNumberConvertTo("ratedpower1", "HP");
204 if (el->FindElement("ratedpower2"))
205 RatedPower[1] = el->FindElementValueAsNumberConvertTo("ratedpower2", "HP");
206 if (el->FindElement("ratedpower3"))
207 RatedPower[2] = el->FindElementValueAsNumberConvertTo("ratedpower3", "HP");
208 if (el->FindElement("ratedrpm1"))
209 RatedRPM[0] = el->FindElementValueAsNumber("ratedrpm1");
210 if (el->FindElement("ratedrpm2"))
211 RatedRPM[1] = el->FindElementValueAsNumber("ratedrpm2");
212 if (el->FindElement("ratedrpm3"))
213 RatedRPM[2] = el->FindElementValueAsNumber("ratedrpm3");
214 if (el->FindElement("ratedaltitude1"))
215 RatedAltitude[0] = el->FindElementValueAsNumberConvertTo("ratedaltitude1", "FT");
216 if (el->FindElement("ratedaltitude2"))
217 RatedAltitude[1] = el->FindElementValueAsNumberConvertTo("ratedaltitude2", "FT");
218 if (el->FindElement("ratedaltitude3"))
219 RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT");
222 while(table_element = el->FindNextElement("table")) {
223 name = table_element->GetAttributeValue("name");
225 if (name == "COMBUSTION") {
226 Lookup_Combustion_Efficiency = new FGTable(PropertyManager, table_element);
227 } else if (name == "MIXTURE") {
228 Mixture_Efficiency_Correlation = new FGTable(PropertyManager, table_element);
230 cerr << "Unknown table type: " << name << " in piston engine definition." << endl;
232 } catch (std::string str) {
233 throw("Error loading piston engine table:" + name + ". " + str);
237 StarterHP = sqrt(MaxHP) * 0.4;
238 displacement_SI = Displacement * in3tom3;
239 RatedMeanPistonSpeed_fps = ( MaxRPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
241 // Create IFSC to match the engine if not provided
243 double pmep = 29.92 - MaxManifoldPressure_inHg;
244 pmep *= inhgtopa * volumetric_efficiency;
245 double fmep = (FMEPDynamic * RatedMeanPistonSpeed_fps * fttom + FMEPStatic);
246 double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371);
247 ISFC = ( 1.1*Displacement * MaxRPM * volumetric_efficiency *(MaxManifoldPressure_inHg / 29.92) ) / (9411 * (MaxHP+hp_loss-StaticFriction_HP));
248 // cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " <<hp_loss <<endl;
250 if ( MaxManifoldPressure_inHg > 29.9 ) { // Don't allow boosting with a bogus number
251 MaxManifoldPressure_inHg = 29.9;
253 minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa
254 maxMAP = MaxManifoldPressure_inHg * inhgtopa;
258 * Pm = ( Ze / ( Ze + Zi + Zt ) ) * Pa
260 * Pm = Manifold Pressure
261 * Pa = Ambient Pressre
262 * Ze = engine impedance, Ze is effectively 1 / Mean Piston Speed
263 * Zi = airbox impedance
264 * Zt = throttle impedance
266 * For the calculation below throttle is fully open or Zt = 0
272 double Ze=PeakMeanPistonSpeed_fps/RatedMeanPistonSpeed_fps; // engine impedence
273 Z_airbox = (standard_pressure *Ze / maxMAP) - Ze; // impedence of airbox
275 // Constant for Throttle impedence
276 Z_throttle=(PeakMeanPistonSpeed_fps/((IdleRPM * Stroke) / 360))*(standard_pressure/minMAP - 1) - Z_airbox;
277 // Z_throttle=(MaxRPM/IdleRPM )*(standard_pressure/minMAP+2); // Constant for Throttle impedence
279 // Default tables if not provided in the configuration file
280 if(Lookup_Combustion_Efficiency == 0) {
281 // First column is thi, second is neta (combustion efficiency)
282 Lookup_Combustion_Efficiency = new FGTable(12);
283 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
284 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
285 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
286 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
287 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
288 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
289 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
290 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
291 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
292 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
293 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
294 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
297 // First column is Fuel/Air Ratio, second is neta (mixture efficiency)
298 if( Mixture_Efficiency_Correlation == 0) {
299 Mixture_Efficiency_Correlation = new FGTable(15);
300 *Mixture_Efficiency_Correlation << 0.05000 << 0.00000;
301 *Mixture_Efficiency_Correlation << 0.05137 << 0.00862;
302 *Mixture_Efficiency_Correlation << 0.05179 << 0.21552;
303 *Mixture_Efficiency_Correlation << 0.05430 << 0.48276;
304 *Mixture_Efficiency_Correlation << 0.05842 << 0.70690;
305 *Mixture_Efficiency_Correlation << 0.06312 << 0.83621;
306 *Mixture_Efficiency_Correlation << 0.06942 << 0.93103;
307 *Mixture_Efficiency_Correlation << 0.07786 << 1.00000;
308 *Mixture_Efficiency_Correlation << 0.08845 << 1.00000;
309 *Mixture_Efficiency_Correlation << 0.09270 << 0.98276;
310 *Mixture_Efficiency_Correlation << 0.10120 << 0.93103;
311 *Mixture_Efficiency_Correlation << 0.11455 << 0.72414;
312 *Mixture_Efficiency_Correlation << 0.12158 << 0.45690;
313 *Mixture_Efficiency_Correlation << 0.12435 << 0.23276;
314 *Mixture_Efficiency_Correlation << 0.12500 << 0.00000;
317 string property_name, base_property_name;
318 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
319 property_name = base_property_name + "/power-hp";
320 PropertyManager->Tie(property_name, &HP);
321 property_name = base_property_name + "/bsfc-lbs_hphr";
322 PropertyManager->Tie(property_name, &ISFC);
323 property_name = base_property_name + "/volumetric-efficiency";
324 PropertyManager->Tie(property_name, &volumetric_efficiency);
325 property_name = base_property_name + "/map-pa";
326 PropertyManager->Tie(property_name, &MAP);
327 property_name = base_property_name + "/map-inhg";
328 PropertyManager->Tie(property_name, &ManifoldPressure_inHg);
329 property_name = base_property_name + "/air-intake-impedance-factor";
330 PropertyManager->Tie(property_name, &Z_airbox);
331 property_name = base_property_name + "/ram-air-factor";
332 PropertyManager->Tie(property_name, &Ram_Air_Factor);
333 property_name = base_property_name + "/cooling-factor";
334 PropertyManager->Tie(property_name, &Cooling_Factor);
335 property_name = base_property_name + "/boost-speed";
336 PropertyManager->Tie(property_name, &BoostSpeed);
337 property_name = base_property_name + "/cht-degF";
338 PropertyManager->Tie(property_name, this, &FGPiston::getCylinderHeadTemp_degF);
339 property_name = base_property_name + "/engine-rpm";
340 PropertyManager->Tie(property_name, this, &FGPiston::getRPM);
341 property_name = base_property_name + "/oil-temperature-degF";
342 PropertyManager->Tie(property_name, this, &FGPiston::getOilTemp_degF);
343 property_name = base_property_name + "/oil-pressure-psi";
344 PropertyManager->Tie(property_name, this, &FGPiston::getOilPressure_psi);
345 property_name = base_property_name + "/egt-degF";
346 PropertyManager->Tie(property_name, this, &FGPiston::getExhaustGasTemp_degF);
348 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
349 if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
350 for (i=0; i<BoostSpeeds; ++i) {
352 if (RatedBoost[i] <= 0.0) bad = true;
353 if (RatedPower[i] <= 0.0) bad = true;
354 if (RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
355 if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
357 // We can't recover from the above - don't use this supercharger speed.
359 // TODO - put out a massive error message!
362 // Now sanity-check stuff that is recoverable.
363 if (i < BoostSpeeds - 1) {
364 if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
365 // TODO - put out an error message
366 // But we can also make a reasonable estimate, as below.
367 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
369 BoostSwitchPressure[i] = GetStdPressure100K(BoostSwitchAltitude[i]) * psftopa;
370 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
371 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
372 BoostSwitchHysteresis = 1000;
374 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
375 RatedMAP[i] = standard_pressure + RatedBoost[i] * 6895; // psi*6895 = Pa.
376 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
377 if (TakeoffBoost > RatedBoost[0]) {
378 // Assume that the effect on the BCV is the same whichever speed is in use.
379 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
380 bTakeoffBoost = true;
382 TakeoffMAP[i] = RatedMAP[i];
383 bTakeoffBoost = false;
385 BoostMul[i] = RatedMAP[i] / (GetStdPressure100K(RatedAltitude[i]) * psftopa);
389 if (BoostSpeeds > 0) {
393 bBoostOverride = (BoostOverride == 1 ? true : false);
394 bBoostManual = (BoostManual == 1 ? true : false);
395 Debug(0); // Call Debug() routine from constructor if needed
398 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400 FGPiston::~FGPiston()
402 delete Lookup_Combustion_Efficiency;
403 delete Mixture_Efficiency_Correlation;
404 Debug(1); // Call Debug() routine from constructor if needed
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 void FGPiston::ResetToIC(void)
411 FGEngine::ResetToIC();
413 ManifoldPressure_inHg = in.Pressure * psftoinhg; // psf to in Hg
414 MAP = in.Pressure * psftopa;
416 double airTemperature_degK = RankineToKelvin(in.Temperature);
417 OilTemp_degK = airTemperature_degK;
418 CylinderHeadTemp_degK = airTemperature_degK;
419 ExhaustGasTemp_degK = airTemperature_degK;
420 EGT_degC = ExhaustGasTemp_degK - 273;
421 Thruster->SetRPM(0.0);
423 OilPressure_psi = 0.0;
426 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
428 void FGPiston::Calculate(void)
432 p_amb = in.Pressure * psftopa;
433 double p = in.TotalPressure * psftopa;
434 p_ram = (p - p_amb) * Ram_Air_Factor + p_amb;
435 T_amb = RankineToKelvin(in.Temperature);
439 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
440 MeanPistonSpeed_fps = ( RPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
445 if (Boosted) doBoostControl();
450 //Now that the fuel flow is done check if the mixture is too lean to run the engine
451 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
452 //This might be a bit generous, but since there's currently no audiable warning of impending
453 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
455 // if (equivalence_ratio < 0.668)
459 if (IndicatedHorsePower < 0.1250) Running = false;
466 if (Thruster->GetType() == FGThruster::ttPropeller) {
467 ((FGPropeller*)Thruster)->SetAdvance(in.PropAdvance[EngineNumber]);
468 ((FGPropeller*)Thruster)->SetFeather(in.PropFeather[EngineNumber]);
471 LoadThrusterInputs();
472 Thruster->Calculate(HP * hptoftlbssec);
477 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 double FGPiston::CalcFuelNeed(void)
481 FuelExpended = FuelFlowRate * in.TotalDeltaT;
485 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
487 int FGPiston::InitRunning(void)
490 in.MixtureCmd[EngineNumber] = in.PressureRatio/1.3;
491 in.MixturePos[EngineNumber] = in.PressureRatio/1.3;
492 Thruster->SetRPM( 2.0*IdleRPM/Thruster->GetGearRatio() );
497 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
499 * Start or stop the engine.
502 void FGPiston::doEngineStartup(void)
504 // Check parameters that may alter the operating state of the engine.
505 // (spark, fuel, starter motor etc)
509 Magneto_Left = false;
510 Magneto_Right = false;
511 // Magneto positions:
520 } // neglects battery voltage, master on switch, etc for now.
522 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
523 if (Magnetos > 1) Magneto_Right = true;
525 // Assume we have fuel for now
528 // Check if we are turning the starter motor
529 if (Cranking != Starter) {
530 // This check saves .../cranking from getting updated every loop - they
531 // only update when changed.
536 if (Cranking) crank_counter++; //Check mode of engine operation
538 if (!Running && spark && fuel) { // start the engine if revs high enough
540 if ((RPM > IdleRPM*0.8) && (crank_counter > 175)) // Add a little delay to startup
541 Running = true; // on the starter
543 if (RPM > IdleRPM*0.8) // This allows us to in-air start
544 Running = true; // when windmilling
548 // Cut the engine *power* - Note: the engine may continue to
549 // spin if the prop is in a moving airstream
551 if ( Running && (!spark || !fuel) ) Running = false;
553 // Check for stalling (RPM = 0).
557 } else if ((RPM <= IdleRPM *0.8 ) && (Cranking)) {
563 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566 * Calculate the Current Boost Speed
568 * This function calculates the current turbo/supercharger boost speed
569 * based on altitude and the (automatic) boost-speed control valve configuration.
571 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
573 * Outputs: BoostSpeed
576 void FGPiston::doBoostControl(void)
579 if(BoostSpeed > BoostSpeeds-1) BoostSpeed = BoostSpeeds-1;
580 if(BoostSpeed < 0) BoostSpeed = 0;
582 if(BoostSpeed < BoostSpeeds - 1) {
583 // Check if we need to change to a higher boost speed
584 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
587 } if(BoostSpeed > 0) {
588 // Check if we need to change to a lower boost speed
589 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
596 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599 * Calculate the manifold absolute pressure (MAP) in inches hg
601 * This function calculates manifold absolute pressure (MAP)
602 * from the throttle position, turbo/supercharger boost control
603 * system, engine speed and local ambient air density.
605 * Inputs: p_amb, Throttle,
606 * MeanPistonSpeed_fps, dt
608 * Outputs: MAP, ManifoldPressure_inHg, TMAP
611 void FGPiston::doMAP(void)
613 double Zt = (1 - in.ThrottlePos[EngineNumber])*(1 - in.ThrottlePos[EngineNumber])*Z_throttle; // throttle impedence
614 double Ze= MeanPistonSpeed_fps > 0 ? PeakMeanPistonSpeed_fps/MeanPistonSpeed_fps : 999999; // engine impedence
616 double map_coefficient = Ze/(Ze+Z_airbox+Zt);
618 // Add a one second lag to manifold pressure changes
620 if (in.TotalDeltaT > 0.0)
621 dMAP = (TMAP - p_ram * map_coefficient) * in.TotalDeltaT;
623 dMAP = (TMAP - p_ram * map_coefficient) / 120;
627 // Find the mean effective pressure required to achieve this manifold pressure
628 // Fixme: determine the HP consumed by the supercharger
630 PMEP = (TMAP - p_amb) * volumetric_efficiency; // Fixme: p_amb should be exhaust manifold pressure
633 // If takeoff boost is fitted, we currently assume the following throttle map:
634 // (In throttle % - actual input is 0 -> 1)
635 // 99 / 100 - Takeoff boost
636 // In real life, most planes would be fitted with a mechanical 'gate' between
637 // the rated boost and takeoff boost positions.
639 bool bTakeoffPos = false;
641 if (in.ThrottlePos[EngineNumber] > 0.98) {
645 // Boost the manifold pressure.
646 double boost_factor = (( BoostMul[BoostSpeed] - 1 ) / RatedRPM[BoostSpeed] ) * RPM + 1;
647 MAP = TMAP * boost_factor;
648 // Now clip the manifold pressure to BCV or Wastegate setting.
650 if (MAP > TakeoffMAP[BoostSpeed]) MAP = TakeoffMAP[BoostSpeed];
652 if (MAP > RatedMAP[BoostSpeed]) MAP = RatedMAP[BoostSpeed];
658 // And set the value in American units as well
659 ManifoldPressure_inHg = MAP / inhgtopa;
662 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664 * Calculate the air flow through the engine.
665 * Also calculates ambient air density
666 * (used in CHT calculation for air-cooled engines).
668 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
669 * RPM, volumetric_efficiency,
671 * TODO: Model inlet manifold air temperature.
673 * Outputs: rho_air, m_dot_air
676 void FGPiston::doAirFlow(void)
678 double gamma = 1.3; // specific heat constants
679 // loss of volumentric efficiency due to difference between MAP and exhaust pressure
680 // Eq 6-10 from The Internal Combustion Engine - Charles Taylor Vol 1
681 double ve =((gamma-1)/gamma) +( CompressionRatio -(p_amb/MAP))/(gamma*( CompressionRatio - 1));
683 rho_air = p_amb / (R_air * T_amb);
684 double swept_volume = (displacement_SI * (RPM/60)) / 2;
685 double v_dot_air = swept_volume * volumetric_efficiency *ve;
687 double rho_air_manifold = MAP / (R_air * T_amb);
688 m_dot_air = v_dot_air * rho_air_manifold;
692 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
694 * Calculate the fuel flow into the engine.
696 * Inputs: Mixture, thi_sea_level, p_amb, m_dot_air
698 * Outputs: equivalence_ratio, m_dot_fuel
701 void FGPiston::doFuelFlow(void)
703 double thi_sea_level = 1.3 * in.MixturePos[EngineNumber]; // Allows an AFR of infinity:1 to 11.3075:1
704 equivalence_ratio = thi_sea_level * 101325.0 / p_amb;
705 // double AFR = 10+(12*(1-in.Mixture[EngineNumber]));// mixture 10:1 to 22:1
706 // m_dot_fuel = m_dot_air / AFR;
707 m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;
708 FuelFlowRate = m_dot_fuel * 2.2046; // kg to lb
709 if(Starved) // There is no fuel, so zero out the flows we've calculated so far
711 equivalence_ratio = 0.0;
715 FuelFlow_pph = FuelFlowRate * 3600; // seconds to hours
716 FuelFlow_gph = FuelFlow_pph / 6.0; // Assumes 6 lbs / gallon
719 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
721 * Calculate the power produced by the engine.
723 * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb, ISFC,
724 * Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
725 * MeanPistonSpeed_fps
727 * Outputs: PctPower, HP, FMEP, IndicatedHorsePower
730 void FGPiston::doEnginePower(void)
732 IndicatedHorsePower = 0;
735 // FIXME: this needs to be generalized
736 double ME, percent_RPM, power; // Convienience term for use in the calculations
737 ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
739 percent_RPM = RPM/MaxRPM;
740 // Guestimate engine friction losses from Figure 4.4 of "Engines: An Introduction", John Lumley
741 FMEP = (-FMEPDynamic * MeanPistonSpeed_fps * fttom - FMEPStatic);
745 if ( Magnetos != 3 ) power *= SparkFailDrop;
748 IndicatedHorsePower = (FuelFlow_pph / ISFC )* ME * power;
751 // Power output when the engine is not running
754 IndicatedHorsePower = StarterHP;
755 } else if (RPM < IdleRPM*0.8) {
756 IndicatedHorsePower = StarterHP + ((IdleRPM*0.8 - RPM) / 8.0);
757 // This is a guess - would be nice to find a proper starter moter torque curve
759 IndicatedHorsePower = StarterHP;
764 // Constant is (1/2) * 60 * 745.7
765 // (1/2) convert cycles, 60 minutes to seconds, 745.7 watts to hp.
766 double pumping_hp = ((PMEP + FMEP) * displacement_SI * RPM)/(Cycles*22371);
768 HP = IndicatedHorsePower + pumping_hp - StaticFriction_HP; //FIXME static friction should depend on oil temp and configuration
769 // cout << "pumping_hp " <<pumping_hp << FMEP << PMEP <<endl;
770 PctPower = HP / MaxHP ;
771 // cout << "Power = " << HP << " RPM = " << RPM << " Running = " << Running << " Cranking = " << Cranking << endl;
774 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
776 * Calculate the exhaust gas temperature.
778 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
779 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, PctPower
781 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
784 void FGPiston::doEGT(void)
786 double delta_T_exhaust;
787 double enthalpy_exhaust;
788 double heat_capacity_exhaust;
791 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
792 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
793 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
794 combustion_efficiency * 0.30;
795 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
796 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
797 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
798 } else { // Drop towards ambient - guess an appropriate time constant for now
799 combustion_efficiency = 0;
800 dEGTdt = (RankineToKelvin(in.Temperature) - ExhaustGasTemp_degK) / 100.0;
801 if (in.TotalDeltaT > 0.0)
802 delta_T_exhaust = dEGTdt * in.TotalDeltaT;
804 delta_T_exhaust = dEGTdt / 120;
806 ExhaustGasTemp_degK += delta_T_exhaust;
810 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812 * Calculate the cylinder head temperature.
814 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
815 * combustion_efficiency, RPM, MaxRPM, Displacement, Cylinders
817 * Outputs: CylinderHeadTemp_degK
820 void FGPiston::doCHT(void)
824 double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
826 double arbitary_area = Displacement/360.0;
827 double CpCylinderHead = 800.0;
828 double MassCylinderHead = CylinderHeadMass * Cylinders;
830 double temperature_difference = CylinderHeadTemp_degK - T_amb;
831 double v_apparent = IAS * Cooling_Factor;
832 double v_dot_cooling_air = arbitary_area * v_apparent;
833 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
834 double dqdt_from_combustion =
835 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
836 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
837 (h3 * RPM * temperature_difference / MaxRPM);
838 double dqdt_free = h1 * temperature_difference * arbitary_area;
839 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
841 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
843 if (in.TotalDeltaT > 0.0)
844 CylinderHeadTemp_degK +=
845 (dqdt_cylinder_head / HeatCapacityCylinderHead) * in.TotalDeltaT;
847 CylinderHeadTemp_degK +=
848 (dqdt_cylinder_head / HeatCapacityCylinderHead) / 120.0;
851 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
853 * Calculate the oil temperature.
855 * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
857 * Outputs: OilTemp_degK
860 void FGPiston::doOilTemperature(void)
862 double target_oil_temp; // Steady state oil temp at the current engine conditions
863 double time_constant; // The time constant for the differential equation
864 double efficiency = 0.667; // The aproximate oil cooling system efficiency // FIXME: may vary by engine
866 // Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature
867 // target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;
868 target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;
870 if (OilPressure_psi > 5.0 ) {
871 time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
872 // The higher the pressure the faster it reaches
873 // target temperature. Oil pressure should be about
874 // 60 PSI yielding a TC of about 80.
876 time_constant = 1000; // Time constant for engine-off; reflects the fact
877 // that oil is no longer getting circulated
880 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
882 if (in.TotalDeltaT > 0.0)
883 OilTemp_degK += (dOilTempdt * in.TotalDeltaT);
885 OilTemp_degK += (dOilTempdt / 120.0);
888 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
890 * Calculate the oil pressure.
892 * Inputs: RPM, MaxRPM, OilTemp_degK
894 * Outputs: OilPressure_psi
897 void FGPiston::doOilPressure(void)
899 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
900 double Oil_Press_RPM_Max = MaxRPM * 0.75; // 75% of max rpm FIXME: may vary by engine
901 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
902 double Oil_Viscosity_Index = 0.25;
904 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
906 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
907 OilPressure_psi = Oil_Press_Relief_Valve;
910 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
913 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915 // This is a local copy of the same function in FGStandardAtmosphere.
917 double FGPiston::GetStdPressure100K(double altitude) const
919 // Limit this equation to input altitudes of 100000 ft.
920 if (altitude > 100000.0) altitude = 100000.0;
923 const double coef[5] = { 2116.217,
930 for (int pwr=1; pwr<=4; pwr++) alt[pwr] = alt[pwr-1]*altitude;
933 for (int ctr=0; ctr<=4; ctr++) press += coef[ctr]*alt[ctr];
937 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939 string FGPiston::GetEngineLabels(const string& delimiter)
941 std::ostringstream buf;
943 buf << Name << " Power Available (engine " << EngineNumber << " in ft-lbs/sec)" << delimiter
944 << Name << " HP (engine " << EngineNumber << ")" << delimiter
945 << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimiter
946 << Name << " MAP (engine " << EngineNumber << " in inHg)" << delimiter
947 << Thruster->GetThrusterLabels(EngineNumber, delimiter);
952 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
954 string FGPiston::GetEngineValues(const string& delimiter)
956 std::ostringstream buf;
958 buf << (HP * hptoftlbssec) << delimiter << HP << delimiter
959 << equivalence_ratio << delimiter << ManifoldPressure_inHg << delimiter
960 << Thruster->GetThrusterValues(EngineNumber, delimiter);
965 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
967 // The bitmasked value choices are as follows:
968 // unset: In this case (the default) JSBSim would only print
969 // out the normally expected messages, essentially echoing
970 // the config files as they are read. If the environment
971 // variable is not set, debug_lvl is set to 1 internally
972 // 0: This requests JSBSim not to output any messages
974 // 1: This value explicity requests the normal JSBSim
976 // 2: This value asks for a message to be printed out when
977 // a class is instantiated
978 // 4: When this value is set, a message is displayed when a
979 // FGModel object executes its Run() method
980 // 8: When this value is set, various runtime state variables
981 // are printed out periodically
982 // 16: When set various parameters are sanity checked and
983 // a message is printed out when they go out of bounds
985 void FGPiston::Debug(int from)
987 if (debug_lvl <= 0) return;
989 if (debug_lvl & 1) { // Standard console startup message output
990 if (from == 0) { // Constructor
992 cout << "\n Engine Name: " << Name << endl;
993 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
994 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
995 cout << " MinMaP (Pa): " << minMAP << endl;
996 cout << " MaxMaP (Pa): " << maxMAP << endl;
997 cout << " Displacement: " << Displacement << endl;
998 cout << " Bore: " << Bore << endl;
999 cout << " Stroke: " << Stroke << endl;
1000 cout << " Cylinders: " << Cylinders << endl;
1001 cout << " Cylinders Head Mass: " <<CylinderHeadMass << endl;
1002 cout << " Compression Ratio: " << CompressionRatio << endl;
1003 cout << " MaxHP: " << MaxHP << endl;
1004 cout << " Cycles: " << Cycles << endl;
1005 cout << " IdleRPM: " << IdleRPM << endl;
1006 cout << " MaxRPM: " << MaxRPM << endl;
1007 cout << " Throttle Constant: " << Z_throttle << endl;
1008 cout << " ISFC: " << ISFC << endl;
1009 cout << " Volumetric Efficiency: " << volumetric_efficiency << endl;
1010 cout << " PeakMeanPistonSpeed_fps: " << PeakMeanPistonSpeed_fps << endl;
1011 cout << " Intake Impedance Factor: " << Z_airbox << endl;
1012 cout << " Dynamic FMEP Factor: " << FMEPDynamic << endl;
1013 cout << " Static FMEP Factor: " << FMEPStatic << endl;
1016 cout << " Combustion Efficiency table:" << endl;
1017 Lookup_Combustion_Efficiency->Print();
1021 cout << " Mixture Efficiency Correlation table:" << endl;
1022 Mixture_Efficiency_Correlation->Print();
1027 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
1028 if (from == 0) cout << "Instantiated: FGPiston" << endl;
1029 if (from == 1) cout << "Destroyed: FGPiston" << endl;
1031 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
1033 if (debug_lvl & 8 ) { // Runtime state variables
1035 if (debug_lvl & 16) { // Sanity checking
1037 if (debug_lvl & 64) {
1038 if (from == 0) { // Constructor
1039 cout << IdSrc << endl;
1040 cout << IdHdr << endl;
1044 } // namespace JSBSim