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 (jsb@hal-pc.org) --------------
12 This program is free software; you can redistribute it and/or modify it under
13 the terms of the GNU Lesser General Public License as published by the Free Software
14 Foundation; either version 2 of the License, or (at your option) any later
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
22 You should have received a copy of the GNU Lesser General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24 Place - Suite 330, Boston, MA 02111-1307, USA.
26 Further information about the GNU Lesser General Public License can also be found on
27 the world wide web at http://www.gnu.org.
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
32 This class descends from the FGEngine class and models a Piston engine based on
33 parameters given in the engine config file for this class
36 --------------------------------------------------------------------------------
37 09/12/2000 JSB Created
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 #include <models/FGPropulsion.h>
47 #include "FGPropeller.h"
51 static const char *IdSrc = "$Id$";
52 static const char *IdHdr = ID_PISTON;
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number)
59 : FGEngine(exec, el, engine_number),
60 R_air(287.3), // Gas constant for air J/Kg/K
61 rho_fuel(800), // estimate
62 calorific_value_fuel(47.3e6),
63 Cp_air(1005), // Specific heat (constant pressure) J/Kg/K
68 // Defaults and initializations
73 // These items are read from the configuration file
81 MinManifoldPressure_inHg = 6.5;
82 MaxManifoldPressure_inHg = 28.5;
86 volumetric_efficiency = 0.8; // Actually f(speed, load) but this will get us running
88 // These are internal program variables
98 BoostSpeeds = 0; // Default to no supercharging
102 bBoostOverride = false;
103 bTakeoffBoost = false;
104 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
106 for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
109 RatedAltitude[i] = 0.0;
111 RatedMAP[i] = 100000;
113 TakeoffMAP[i] = 100000;
115 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
116 BoostSwitchAltitude[i] = 0.0;
117 BoostSwitchPressure[i] = 0.0;
120 // First column is thi, second is neta (combustion efficiency)
121 Lookup_Combustion_Efficiency = new FGTable(12);
122 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
123 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
124 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
125 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
126 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
127 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
128 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
129 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
130 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
131 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
132 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
133 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
135 Mixture_Efficiency_Correlation = new FGTable(15);
136 *Mixture_Efficiency_Correlation << 0.05000 << 0.00000;
137 *Mixture_Efficiency_Correlation << 0.05137 << 0.00862;
138 *Mixture_Efficiency_Correlation << 0.05179 << 0.21552;
139 *Mixture_Efficiency_Correlation << 0.05430 << 0.48276;
140 *Mixture_Efficiency_Correlation << 0.05842 << 0.70690;
141 *Mixture_Efficiency_Correlation << 0.06312 << 0.83621;
142 *Mixture_Efficiency_Correlation << 0.06942 << 0.93103;
143 *Mixture_Efficiency_Correlation << 0.07786 << 1.00000;
144 *Mixture_Efficiency_Correlation << 0.08845 << 1.00000;
145 *Mixture_Efficiency_Correlation << 0.09270 << 0.98276;
146 *Mixture_Efficiency_Correlation << 0.10120 << 0.93103;
147 *Mixture_Efficiency_Correlation << 0.11455 << 0.72414;
148 *Mixture_Efficiency_Correlation << 0.12158 << 0.45690;
149 *Mixture_Efficiency_Correlation << 0.12435 << 0.23276;
150 *Mixture_Efficiency_Correlation << 0.12500 << 0.00000;
153 // Read inputs from engine data file where present.
155 if (el->FindElement("minmp")) // Should have ELSE statement telling default value used?
156 MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
157 if (el->FindElement("maxmp"))
158 MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
159 if (el->FindElement("displacement"))
160 Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
161 if (el->FindElement("maxhp"))
162 MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
163 if (el->FindElement("sparkfaildrop"))
164 SparkFailDrop = Constrain(0, 1 - el->FindElementValueAsNumber("sparkfaildrop"), 1);
165 if (el->FindElement("cycles"))
166 Cycles = el->FindElementValueAsNumber("cycles");
167 if (el->FindElement("idlerpm"))
168 IdleRPM = el->FindElementValueAsNumber("idlerpm");
169 if (el->FindElement("maxrpm"))
170 MaxRPM = el->FindElementValueAsNumber("maxrpm");
171 if (el->FindElement("maxthrottle"))
172 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
173 if (el->FindElement("minthrottle"))
174 MinThrottle = el->FindElementValueAsNumber("minthrottle");
175 if (el->FindElement("bsfc"))
176 BSFC = el->FindElementValueAsNumberConvertTo("bsfc", "LBS/HP*HR");
177 if (el->FindElement("volumetric-efficiency"))
178 volumetric_efficiency = el->FindElementValueAsNumber("volumetric-efficiency");
179 if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
180 BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
181 if (el->FindElement("boostoverride"))
182 BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
183 if (el->FindElement("takeoffboost"))
184 TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI");
185 if (el->FindElement("ratedboost1"))
186 RatedBoost[0] = el->FindElementValueAsNumberConvertTo("ratedboost1", "PSI");
187 if (el->FindElement("ratedboost2"))
188 RatedBoost[1] = el->FindElementValueAsNumberConvertTo("ratedboost2", "PSI");
189 if (el->FindElement("ratedboost3"))
190 RatedBoost[2] = el->FindElementValueAsNumberConvertTo("ratedboost3", "PSI");
191 if (el->FindElement("ratedpower1"))
192 RatedPower[0] = el->FindElementValueAsNumberConvertTo("ratedpower1", "HP");
193 if (el->FindElement("ratedpower2"))
194 RatedPower[1] = el->FindElementValueAsNumberConvertTo("ratedpower2", "HP");
195 if (el->FindElement("ratedpower3"))
196 RatedPower[2] = el->FindElementValueAsNumberConvertTo("ratedpower3", "HP");
197 if (el->FindElement("ratedrpm1"))
198 RatedRPM[0] = el->FindElementValueAsNumber("ratedrpm1");
199 if (el->FindElement("ratedrpm2"))
200 RatedRPM[1] = el->FindElementValueAsNumber("ratedrpm2");
201 if (el->FindElement("ratedrpm3"))
202 RatedRPM[2] = el->FindElementValueAsNumber("ratedrpm3");
203 if (el->FindElement("ratedaltitude1"))
204 RatedAltitude[0] = el->FindElementValueAsNumberConvertTo("ratedaltitude1", "FT");
205 if (el->FindElement("ratedaltitude2"))
206 RatedAltitude[1] = el->FindElementValueAsNumberConvertTo("ratedaltitude2", "FT");
207 if (el->FindElement("ratedaltitude3"))
208 RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT");
211 MaxManifoldPressure_Percent = MaxManifoldPressure_inHg / 29.92;
212 // Create a BSFC to match the engine if not provided
214 BSFC = ( Displacement * MaxRPM * volumetric_efficiency ) / (9411 * MaxHP);
215 BSFC *= (MaxManifoldPressure_Percent * MaxManifoldPressure_Percent * MaxManifoldPressure_Percent);
217 if ( MaxManifoldPressure_inHg > 29.9 ) { // Don't allow boosting with a bogus number
218 MaxManifoldPressure_inHg = 29.9;
219 MaxManifoldPressure_Percent = MaxManifoldPressure_inHg / 29.92;
222 string property_name, base_property_name;
223 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
224 property_name = base_property_name + "/power-hp";
225 PropertyManager->Tie(property_name.c_str(), &HP);
226 property_name = base_property_name + "/bsfc-lbs_hphr";
227 PropertyManager->Tie(property_name.c_str(), &BSFC);
228 property_name = base_property_name + "/volumetric-efficiency";
229 PropertyManager->Tie(property_name.c_str(), &volumetric_efficiency);
230 minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa
231 maxMAP = MaxManifoldPressure_inHg * inhgtopa;
232 StarterHP = sqrt(MaxHP) * 0.4;
234 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
235 if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
236 for (i=0; i<BoostSpeeds; ++i) {
238 if (RatedBoost[i] <= 0.0) bad = true;
239 if (RatedPower[i] <= 0.0) bad = true;
240 if (RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
241 if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
243 // We can't recover from the above - don't use this supercharger speed.
245 // TODO - put out a massive error message!
248 // Now sanity-check stuff that is recoverable.
249 if (i < BoostSpeeds - 1) {
250 if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
251 // TODO - put out an error message
252 // But we can also make a reasonable estimate, as below.
253 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
255 BoostSwitchPressure[i] = Atmosphere->GetPressure(BoostSwitchAltitude[i]) * psftopa;
256 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
257 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
258 BoostSwitchHysteresis = 1000;
260 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
261 RatedMAP[i] = Atmosphere->GetPressureSL() * psftopa + RatedBoost[i] * 6895; // psi*6895 = Pa.
262 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
263 if (TakeoffBoost > RatedBoost[0]) {
264 // Assume that the effect on the BCV is the same whichever speed is in use.
265 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
266 bTakeoffBoost = true;
268 TakeoffMAP[i] = RatedMAP[i];
269 bTakeoffBoost = false;
271 BoostMul[i] = RatedMAP[i] / (Atmosphere->GetPressure(RatedAltitude[i]) * psftopa);
275 if (BoostSpeeds > 0) {
279 bBoostOverride = (BoostOverride == 1 ? true : false);
280 if (MinThrottle < 0.12) MinThrottle = 0.12; //MinThrottle is limited to 0.12 to prevent the
281 // throttle area equation from going negative
282 // 0.12 is 1% of maximum area
283 Debug(0); // Call Debug() routine from constructor if needed
286 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288 FGPiston::~FGPiston()
290 delete Lookup_Combustion_Efficiency;
291 delete Mixture_Efficiency_Correlation;
292 Debug(1); // Call Debug() routine from constructor if needed
295 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
297 void FGPiston::ResetToIC(void)
299 FGEngine::ResetToIC();
301 ManifoldPressure_inHg = Atmosphere->GetPressure() * psftoinhg; // psf to in Hg
302 MAP = Atmosphere->GetPressure() * psftopa;
303 double airTemperature_degK = RankineToKelvin(Atmosphere->GetTemperature());
304 OilTemp_degK = airTemperature_degK;
305 CylinderHeadTemp_degK = airTemperature_degK;
306 ExhaustGasTemp_degK = airTemperature_degK;
307 EGT_degC = ExhaustGasTemp_degK - 273;
308 Thruster->SetRPM(0.0);
310 OilPressure_psi = 0.0;
313 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 double FGPiston::Calculate(void)
317 if (FuelFlow_gph > 0.0) ConsumeFuel();
319 Throttle = FCS->GetThrottlePos(EngineNumber);
320 // calculate the throttle plate angle. 1 unit is pi/2 radians.
321 ThrottleAngle = MinThrottle+((MaxThrottle-MinThrottle)*Throttle );
322 Mixture = FCS->GetMixturePos(EngineNumber);
328 p_amb = Atmosphere->GetPressure() * psftopa;
329 p_amb_sea_level = Atmosphere->GetPressureSL() * psftopa;
330 T_amb = RankineToKelvin(Atmosphere->GetTemperature());
332 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
334 IAS = Auxiliary->GetVcalibratedKTS();
337 if (Boosted) doBoostControl();
342 //Now that the fuel flow is done check if the mixture is too lean to run the engine
343 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
344 //This might be a bit generous, but since there's currently no audiable warning of impending
345 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
346 // if (equivalence_ratio < 0.668)
350 if (HP < 0.1250) Running = false;
357 if (Thruster->GetType() == FGThruster::ttPropeller) {
358 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
359 ((FGPropeller*)Thruster)->SetFeather(FCS->GetPropFeather(EngineNumber));
362 PowerAvailable = (HP * hptoftlbssec) - Thruster->GetPowerRequired();
364 return Thruster->Calculate(PowerAvailable);
367 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 double FGPiston::CalcFuelNeed(void)
371 double dT = State->Getdt() * Propulsion->GetRate();
372 FuelExpended = FuelFlowRate * dT;
376 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
378 int FGPiston::InitRunning(void) {
380 //Thruster->SetRPM( 1.1*IdleRPM/Thruster->GetGearRatio() );
381 Thruster->SetRPM( 1000 );
386 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388 * Start or stop the engine.
391 void FGPiston::doEngineStartup(void)
393 // Check parameters that may alter the operating state of the engine.
394 // (spark, fuel, starter motor etc)
399 Magneto_Left = false;
400 Magneto_Right = false;
401 // Magneto positions:
410 } // neglects battery voltage, master on switch, etc for now.
412 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
413 if (Magnetos > 1) Magneto_Right = true;
415 // Assume we have fuel for now
418 // Check if we are turning the starter motor
419 if (Cranking != Starter) {
420 // This check saves .../cranking from getting updated every loop - they
421 // only update when changed.
426 if (Cranking) crank_counter++; //Check mode of engine operation
428 if (!Running && spark && fuel) { // start the engine if revs high enough
430 if ((RPM > IdleRPM*0.8) && (crank_counter > 175)) // Add a little delay to startup
431 Running = true; // on the starter
433 if (RPM > IdleRPM*0.8) // This allows us to in-air start
434 Running = true; // when windmilling
438 // Cut the engine *power* - Note: the engine may continue to
439 // spin if the prop is in a moving airstream
441 if ( Running && (!spark || !fuel) ) Running = false;
443 // Check for stalling (RPM = 0).
447 } else if ((RPM <= IdleRPM *0.8 ) && (Cranking)) {
453 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
456 * Calculate the Current Boost Speed
458 * This function calculates the current turbo/supercharger boost speed
459 * based on altitude and the (automatic) boost-speed control valve configuration.
461 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
463 * Outputs: BoostSpeed
466 void FGPiston::doBoostControl(void)
468 if(BoostSpeed < BoostSpeeds - 1) {
469 // Check if we need to change to a higher boost speed
470 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
473 } else if(BoostSpeed > 0) {
474 // Check if we need to change to a lower boost speed
475 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
481 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484 * Calculate the manifold absolute pressure (MAP) in inches hg
486 * This function calculates manifold absolute pressure (MAP)
487 * from the throttle position, turbo/supercharger boost control
488 * system, engine speed and local ambient air density.
490 * Inputs: p_amb, Throttle, MaxManifoldPressure_Percent, ThrottleAngle
493 * Outputs: MAP, ManifoldPressure_inHg
496 void FGPiston::doMAP(void)
498 // estimate throttle plate area. This maps 0.2 -> 0.1 for historical performance reasons
499 double throttle_area = ThrottleAngle * 1.125 - 0.125;
500 map_coefficient = pow ((throttle_area * MaxManifoldPressure_Percent),RPM/MaxRPM);
501 MAP = p_amb * map_coefficient;
504 // If takeoff boost is fitted, we currently assume the following throttle map:
505 // (In throttle % - actual input is 0 -> 1)
506 // 99 / 100 - Takeoff boost
507 // 96 / 97 / 98 - Rated boost
508 // 0 - 95 - Idle to Rated boost (MinManifoldPressure to MaxManifoldPressure)
509 // In real life, most planes would be fitted with a mechanical 'gate' between
510 // the rated boost and takeoff boost positions.
511 double T = Throttle; // processed throttle value.
512 bool bTakeoffPos = false;
514 if(Throttle > 0.98) {
515 //cout << "Takeoff Boost!!!!\n";
517 } else if(Throttle <= 0.95) {
522 //cout << "Rated Boost!!\n";
526 // Boost the manifold pressure.
527 double boost_factor = BoostMul[BoostSpeed] * map_coefficient * RPM/RatedRPM[BoostSpeed];
528 if (boost_factor < 1.0) boost_factor = 1.0; // boost will never reduce the MAP
530 // Now clip the manifold pressure to BCV or Wastegate setting.
532 if(MAP > TakeoffMAP[BoostSpeed]) {
533 MAP = TakeoffMAP[BoostSpeed];
536 if(MAP > RatedMAP[BoostSpeed]) {
537 MAP = RatedMAP[BoostSpeed];
542 // And set the value in American units as well
543 ManifoldPressure_inHg = MAP / inhgtopa;
546 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
548 * Calculate the air flow through the engine.
549 * Also calculates ambient air density
550 * (used in CHT calculation for air-cooled engines).
552 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
553 * RPM, volumetric_efficiency, ThrottleAngle
555 * TODO: Model inlet manifold air temperature.
557 * Outputs: rho_air, m_dot_air
560 void FGPiston::doAirFlow(void)
562 rho_air = p_amb / (R_air * T_amb);
563 double displacement_SI = Displacement * in3tom3;
564 double swept_volume = (displacement_SI * (RPM/60)) / 2;
565 double v_dot_air = swept_volume * volumetric_efficiency * map_coefficient;
567 double rho_air_manifold = MAP / (R_air * T_amb);
568 m_dot_air = v_dot_air * rho_air_manifold;
571 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573 * Calculate the fuel flow into the engine.
575 * Inputs: Mixture, thi_sea_level, p_amb_sea_level, p_amb, m_dot_air
577 * Outputs: equivalence_ratio, m_dot_fuel
580 void FGPiston::doFuelFlow(void)
582 double thi_sea_level = 1.3 * Mixture; // Allows an AFR of infinity:1 to 11.3075:1
583 equivalence_ratio = thi_sea_level * 101325.0 / p_amb;
584 // double AFR = 10+(12*(1-Mixture));// mixture 10:1 to 22:1
585 // m_dot_fuel = m_dot_air / AFR;
586 m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;
587 FuelFlowRate = m_dot_fuel * 2.2046; // kg to lb
588 FuelFlow_pph = FuelFlowRate * 3600; // seconds to hours
589 FuelFlow_gph = FuelFlow_pph / 6.0; // Assumes 6 lbs / gallon
592 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
594 * Calculate the power produced by the engine.
596 * Currently, the JSBSim propellor model does not allow the
597 * engine to produce enough RPMs to get up to a high horsepower.
598 * When tested with sufficient RPM, it has no trouble reaching
601 * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb,
602 * Mixture_Efficiency_Correlation, Cycles, MaxHP
604 * Outputs: Percentage_Power, HP
607 void FGPiston::doEnginePower(void)
610 double T_amb_degF = KelvinToFahrenheit(T_amb);
611 double T_amb_sea_lev_degF = KelvinToFahrenheit(288);
613 // FIXME: this needs to be generalized
614 double ME, friction, percent_RPM, power; // Convienience term for use in the calculations
615 ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
617 percent_RPM = RPM/MaxRPM;
618 friction = 1 - (percent_RPM * percent_RPM * percent_RPM * percent_RPM/10);
619 if (friction < 0 ) friction = 0;
622 if ( Magnetos != 3 ) power *= SparkFailDrop;
625 HP = (FuelFlow_gph * 6.0 / BSFC )* ME * map_coefficient * power;
629 // Power output when the engine is not running
633 } else if (RPM < IdleRPM*0.8) {
634 HP = StarterHP + ((IdleRPM*0.8 - RPM) / 8.0);
635 // This is a guess - would be nice to find a proper starter moter torque curve
640 // Quick hack until we port the FMEP stuff
647 Percentage_Power = HP / MaxHP ;
648 // cout << "Power = " << HP << " RPM = " << RPM << " Running = " << Running << " Cranking = " << Cranking << endl;
651 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 * Calculate the exhaust gas temperature.
655 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
656 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, Percentage_Power
658 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
661 void FGPiston::doEGT(void)
663 double delta_T_exhaust;
664 double enthalpy_exhaust;
665 double heat_capacity_exhaust;
668 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
669 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
670 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
671 combustion_efficiency * 0.33;
672 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
673 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
674 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
675 ExhaustGasTemp_degK *= 0.444 + ((0.544 - 0.444) * Percentage_Power);
676 } else { // Drop towards ambient - guess an appropriate time constant for now
677 combustion_efficiency = 0;
678 dEGTdt = (RankineToKelvin(Atmosphere->GetTemperature()) - ExhaustGasTemp_degK) / 100.0;
679 delta_T_exhaust = dEGTdt * dt;
680 ExhaustGasTemp_degK += delta_T_exhaust;
684 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
686 * Calculate the cylinder head temperature.
688 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
689 * combustion_efficiency, RPM, MaxRPM
691 * Outputs: CylinderHeadTemp_degK
694 void FGPiston::doCHT(void)
698 double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
700 double arbitary_area = 1.0;
701 double CpCylinderHead = 800.0;
702 double MassCylinderHead = 8.0;
704 double temperature_difference = CylinderHeadTemp_degK - T_amb;
705 double v_apparent = IAS * 0.5144444;
706 double v_dot_cooling_air = arbitary_area * v_apparent;
707 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
708 double dqdt_from_combustion =
709 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
710 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
711 (h3 * RPM * temperature_difference / MaxRPM);
712 double dqdt_free = h1 * temperature_difference;
713 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
715 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
717 CylinderHeadTemp_degK +=
718 (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;
721 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
723 * Calculate the oil temperature.
725 * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
727 * Outputs: OilTemp_degK
730 void FGPiston::doOilTemperature(void)
732 double idle_percentage_power = 0.023; // approximately
733 double target_oil_temp; // Steady state oil temp at the current engine conditions
734 double time_constant; // The time constant for the differential equation
735 double efficiency = 0.667; // The aproximate oil cooling system efficiency // FIXME: may vary by engine
737 // Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature
738 // target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;
739 target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;
741 if (OilPressure_psi > 5.0 ) {
742 time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
743 // The higher the pressure the faster it reaches
744 // target temperature. Oil pressure should be about
745 // 60 PSI yielding a TC of about 80.
747 time_constant = 1000; // Time constant for engine-off; reflects the fact
748 // that oil is no longer getting circulated
751 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
753 OilTemp_degK += (dOilTempdt * dt);
756 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
758 * Calculate the oil pressure.
760 * Inputs: RPM, MaxRPM, OilTemp_degK
762 * Outputs: OilPressure_psi
765 void FGPiston::doOilPressure(void)
767 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
768 double Oil_Press_RPM_Max = MaxRPM * 0.75; // 75% of max rpm FIXME: may vary by engine
769 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
770 double Oil_Viscosity_Index = 0.25;
772 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
774 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
775 OilPressure_psi = Oil_Press_Relief_Valve;
778 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
781 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
783 string FGPiston::GetEngineLabels(string delimeter)
785 std::ostringstream buf;
787 buf << Name << " Power Available (engine " << EngineNumber << " in HP)" << delimeter
788 << Name << " HP (engine " << EngineNumber << ")" << delimeter
789 << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimeter
790 << Name << " MAP (engine " << EngineNumber << ")" << delimeter
791 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
796 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798 string FGPiston::GetEngineValues(string delimeter)
800 std::ostringstream buf;
802 buf << PowerAvailable << delimeter << HP << delimeter
803 << equivalence_ratio << delimeter << MAP << delimeter
804 << Thruster->GetThrusterValues(EngineNumber, delimeter);
809 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
811 // The bitmasked value choices are as follows:
812 // unset: In this case (the default) JSBSim would only print
813 // out the normally expected messages, essentially echoing
814 // the config files as they are read. If the environment
815 // variable is not set, debug_lvl is set to 1 internally
816 // 0: This requests JSBSim not to output any messages
818 // 1: This value explicity requests the normal JSBSim
820 // 2: This value asks for a message to be printed out when
821 // a class is instantiated
822 // 4: When this value is set, a message is displayed when a
823 // FGModel object executes its Run() method
824 // 8: When this value is set, various runtime state variables
825 // are printed out periodically
826 // 16: When set various parameters are sanity checked and
827 // a message is printed out when they go out of bounds
829 void FGPiston::Debug(int from)
831 if (debug_lvl <= 0) return;
833 if (debug_lvl & 1) { // Standard console startup message output
834 if (from == 0) { // Constructor
836 cout << "\n Engine Name: " << Name << endl;
837 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
838 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
839 cout << " MinMaP (Pa): " << minMAP << endl;
840 cout << " MaxMaP (Pa): " << maxMAP << endl;
841 cout << " Displacement: " << Displacement << endl;
842 cout << " MaxHP: " << MaxHP << endl;
843 cout << " Cycles: " << Cycles << endl;
844 cout << " IdleRPM: " << IdleRPM << endl;
845 cout << " MaxThrottle: " << MaxThrottle << endl;
846 cout << " MinThrottle: " << MinThrottle << endl;
847 cout << " BSFC: " << BSFC << endl;
850 cout << " Combustion Efficiency table:" << endl;
851 Lookup_Combustion_Efficiency->Print();
855 cout << " Mixture Efficiency Correlation table:" << endl;
856 Mixture_Efficiency_Correlation->Print();
861 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
862 if (from == 0) cout << "Instantiated: FGPiston" << endl;
863 if (from == 1) cout << "Destroyed: FGPiston" << endl;
865 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
867 if (debug_lvl & 8 ) { // Runtime state variables
869 if (debug_lvl & 16) { // Sanity checking
871 if (debug_lvl & 64) {
872 if (from == 0) { // Constructor
873 cout << IdSrc << endl;
874 cout << IdHdr << endl;
878 } // namespace JSBSim