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
74 // Defaults are from a Lycoming O-360, more or less
82 MinManifoldPressure_inHg = 6.5;
83 MaxManifoldPressure_inHg = 28.5;
85 volumetric_efficiency = -0.1;
89 CompressionRatio = 8.5;
91 // These are internal program variables
101 BoostSpeeds = 0; // Default to no supercharging
105 bBoostOverride = false;
106 bTakeoffBoost = false;
107 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
109 for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
112 RatedAltitude[i] = 0.0;
114 RatedMAP[i] = 100000;
116 TakeoffMAP[i] = 100000;
118 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
119 BoostSwitchAltitude[i] = 0.0;
120 BoostSwitchPressure[i] = 0.0;
123 // First column is thi, second is neta (combustion efficiency)
124 Lookup_Combustion_Efficiency = new FGTable(12);
125 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
126 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
127 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
128 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
129 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
130 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
131 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
132 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
133 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
134 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
135 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
136 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
138 Mixture_Efficiency_Correlation = new FGTable(15);
139 *Mixture_Efficiency_Correlation << 0.05000 << 0.00000;
140 *Mixture_Efficiency_Correlation << 0.05137 << 0.00862;
141 *Mixture_Efficiency_Correlation << 0.05179 << 0.21552;
142 *Mixture_Efficiency_Correlation << 0.05430 << 0.48276;
143 *Mixture_Efficiency_Correlation << 0.05842 << 0.70690;
144 *Mixture_Efficiency_Correlation << 0.06312 << 0.83621;
145 *Mixture_Efficiency_Correlation << 0.06942 << 0.93103;
146 *Mixture_Efficiency_Correlation << 0.07786 << 1.00000;
147 *Mixture_Efficiency_Correlation << 0.08845 << 1.00000;
148 *Mixture_Efficiency_Correlation << 0.09270 << 0.98276;
149 *Mixture_Efficiency_Correlation << 0.10120 << 0.93103;
150 *Mixture_Efficiency_Correlation << 0.11455 << 0.72414;
151 *Mixture_Efficiency_Correlation << 0.12158 << 0.45690;
152 *Mixture_Efficiency_Correlation << 0.12435 << 0.23276;
153 *Mixture_Efficiency_Correlation << 0.12500 << 0.00000;
156 // Read inputs from engine data file where present.
158 if (el->FindElement("minmp")) // Should have ELSE statement telling default value used?
159 MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
160 if (el->FindElement("maxmp"))
161 MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
162 if (el->FindElement("displacement"))
163 Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
164 if (el->FindElement("maxhp"))
165 MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
166 if (el->FindElement("sparkfaildrop"))
167 SparkFailDrop = Constrain(0, 1 - el->FindElementValueAsNumber("sparkfaildrop"), 1);
168 if (el->FindElement("cycles"))
169 Cycles = el->FindElementValueAsNumber("cycles");
170 if (el->FindElement("idlerpm"))
171 IdleRPM = el->FindElementValueAsNumber("idlerpm");
172 if (el->FindElement("maxrpm"))
173 MaxRPM = el->FindElementValueAsNumber("maxrpm");
174 if (el->FindElement("maxthrottle"))
175 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
176 if (el->FindElement("minthrottle"))
177 MinThrottle = el->FindElementValueAsNumber("minthrottle");
178 if (el->FindElement("bsfc"))
179 ISFC = el->FindElementValueAsNumberConvertTo("bsfc", "LBS/HP*HR");
180 if (el->FindElement("volumetric-efficiency"))
181 volumetric_efficiency = el->FindElementValueAsNumber("volumetric-efficiency");
182 if (el->FindElement("compression-ratio"))
183 CompressionRatio = el->FindElementValueAsNumber("compression-ratio");
184 if (el->FindElement("bore"))
185 Bore = el->FindElementValueAsNumberConvertTo("bore","IN");
186 if (el->FindElement("stroke"))
187 Stroke = el->FindElementValueAsNumberConvertTo("stroke","IN");
188 if (el->FindElement("stroke"))
189 Cylinders = el->FindElementValueAsNumber("cylinders");
190 if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
191 BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
192 if (el->FindElement("boostoverride"))
193 BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
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 StarterHP = sqrt(MaxHP) * 0.4;
223 displacement_SI = Displacement * in3tom3;
225 // Create IFSC and VE to match the engine if not provided
227 if (volumetric_efficiency < 0) {
228 volumetric_efficiency = MaxManifoldPressure_inHg / 29.92;
232 double pmep = MaxManifoldPressure_inHg > 29.92 ? 0 : 29.92 - MaxManifoldPressure_inHg;
234 double fmep = (18400 * (2*(Stroke/12)*(MaxRPM/60)) * fttom + 46500)/2;
235 double hp_loss = ((pmep + fmep) * displacement_SI * MaxRPM)/(Cycles*22371);
236 ISFC = ( Displacement * MaxRPM * volumetric_efficiency ) / (9411 * (MaxHP+hp_loss));
237 // cout <<"FMEP: "<< fmep <<" PMEP: "<< pmep << " hp_loss: " <<hp_loss <<endl;
239 if ( MaxManifoldPressure_inHg > 29.9 ) { // Don't allow boosting with a bogus number
240 MaxManifoldPressure_inHg = 29.9;
241 if (calculated_ve) volumetric_efficiency = 1.0;
243 minMAP = MinManifoldPressure_inHg * inhgtopa; // inHg to Pa
244 maxMAP = MaxManifoldPressure_inHg * inhgtopa;
246 string property_name, base_property_name;
247 base_property_name = CreateIndexedPropertyName("propulsion/engine", EngineNumber);
248 property_name = base_property_name + "/power-hp";
249 PropertyManager->Tie(property_name, &HP);
250 property_name = base_property_name + "/bsfc-lbs_hphr";
251 PropertyManager->Tie(property_name, &ISFC);
252 property_name = base_property_name + "/volumetric-efficiency";
253 PropertyManager->Tie(property_name, &volumetric_efficiency);
254 property_name = base_property_name + "/map-pa";
255 PropertyManager->Tie(property_name, &MAP);
256 property_name = base_property_name + "/map-inhg";
257 PropertyManager->Tie(property_name, &ManifoldPressure_inHg);
259 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
260 if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
261 for (i=0; i<BoostSpeeds; ++i) {
263 if (RatedBoost[i] <= 0.0) bad = true;
264 if (RatedPower[i] <= 0.0) bad = true;
265 if (RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
266 if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
268 // We can't recover from the above - don't use this supercharger speed.
270 // TODO - put out a massive error message!
273 // Now sanity-check stuff that is recoverable.
274 if (i < BoostSpeeds - 1) {
275 if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
276 // TODO - put out an error message
277 // But we can also make a reasonable estimate, as below.
278 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
280 BoostSwitchPressure[i] = Atmosphere->GetPressure(BoostSwitchAltitude[i]) * psftopa;
281 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
282 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
283 BoostSwitchHysteresis = 1000;
285 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
286 RatedMAP[i] = Atmosphere->GetPressureSL() * psftopa + RatedBoost[i] * 6895; // psi*6895 = Pa.
287 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
288 if (TakeoffBoost > RatedBoost[0]) {
289 // Assume that the effect on the BCV is the same whichever speed is in use.
290 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
291 bTakeoffBoost = true;
293 TakeoffMAP[i] = RatedMAP[i];
294 bTakeoffBoost = false;
296 BoostMul[i] = RatedMAP[i] / (Atmosphere->GetPressure(RatedAltitude[i]) * psftopa);
300 if (BoostSpeeds > 0) {
304 bBoostOverride = (BoostOverride == 1 ? true : false);
305 Debug(0); // Call Debug() routine from constructor if needed
308 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310 FGPiston::~FGPiston()
312 delete Lookup_Combustion_Efficiency;
313 delete Mixture_Efficiency_Correlation;
314 Debug(1); // Call Debug() routine from constructor if needed
317 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 void FGPiston::ResetToIC(void)
321 FGEngine::ResetToIC();
323 ManifoldPressure_inHg = Atmosphere->GetPressure() * psftoinhg; // psf to in Hg
324 MAP = Atmosphere->GetPressure() * psftopa;
326 double airTemperature_degK = RankineToKelvin(Atmosphere->GetTemperature());
327 OilTemp_degK = airTemperature_degK;
328 CylinderHeadTemp_degK = airTemperature_degK;
329 ExhaustGasTemp_degK = airTemperature_degK;
330 EGT_degC = ExhaustGasTemp_degK - 273;
331 Thruster->SetRPM(0.0);
333 OilPressure_psi = 0.0;
336 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 double FGPiston::Calculate(void)
340 if (FuelFlow_gph > 0.0) ConsumeFuel();
342 Throttle = FCS->GetThrottlePos(EngineNumber);
343 // calculate the throttle plate angle. 1 unit is approx pi/2 radians.
344 ThrottleAngle = MinThrottle+((MaxThrottle-MinThrottle)*Throttle );
345 Mixture = FCS->GetMixturePos(EngineNumber);
351 p_amb = Atmosphere->GetPressure() * psftopa;
352 T_amb = RankineToKelvin(Atmosphere->GetTemperature());
354 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
355 MeanPistonSpeed_fps = ( RPM * Stroke) / (360); // AKA 2 * (RPM/60) * ( Stroke / 12) or 2NS
357 IAS = Auxiliary->GetVcalibratedKTS();
360 if (Boosted) doBoostControl();
365 //Now that the fuel flow is done check if the mixture is too lean to run the engine
366 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
367 //This might be a bit generous, but since there's currently no audiable warning of impending
368 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
369 // if (equivalence_ratio < 0.668)
373 if (IndicatedHorsePower < 0.1250) Running = false;
380 if (Thruster->GetType() == FGThruster::ttPropeller) {
381 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
382 ((FGPropeller*)Thruster)->SetFeather(FCS->GetPropFeather(EngineNumber));
385 PowerAvailable = (HP * hptoftlbssec) - Thruster->GetPowerRequired();
387 return Thruster->Calculate(PowerAvailable);
390 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392 double FGPiston::CalcFuelNeed(void)
394 double dT = State->Getdt() * Propulsion->GetRate();
395 FuelExpended = FuelFlowRate * dT;
399 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
401 int FGPiston::InitRunning(void) {
403 //Thruster->SetRPM( 1.1*IdleRPM/Thruster->GetGearRatio() );
404 Thruster->SetRPM( 1000 );
409 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411 * Start or stop the engine.
414 void FGPiston::doEngineStartup(void)
416 // Check parameters that may alter the operating state of the engine.
417 // (spark, fuel, starter motor etc)
422 Magneto_Left = false;
423 Magneto_Right = false;
424 // Magneto positions:
433 } // neglects battery voltage, master on switch, etc for now.
435 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
436 if (Magnetos > 1) Magneto_Right = true;
438 // Assume we have fuel for now
441 // Check if we are turning the starter motor
442 if (Cranking != Starter) {
443 // This check saves .../cranking from getting updated every loop - they
444 // only update when changed.
449 if (Cranking) crank_counter++; //Check mode of engine operation
451 if (!Running && spark && fuel) { // start the engine if revs high enough
453 if ((RPM > IdleRPM*0.8) && (crank_counter > 175)) // Add a little delay to startup
454 Running = true; // on the starter
456 if (RPM > IdleRPM*0.8) // This allows us to in-air start
457 Running = true; // when windmilling
461 // Cut the engine *power* - Note: the engine may continue to
462 // spin if the prop is in a moving airstream
464 if ( Running && (!spark || !fuel) ) Running = false;
466 // Check for stalling (RPM = 0).
470 } else if ((RPM <= IdleRPM *0.8 ) && (Cranking)) {
476 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 * Calculate the Current Boost Speed
481 * This function calculates the current turbo/supercharger boost speed
482 * based on altitude and the (automatic) boost-speed control valve configuration.
484 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
486 * Outputs: BoostSpeed
489 void FGPiston::doBoostControl(void)
491 if(BoostSpeed < BoostSpeeds - 1) {
492 // Check if we need to change to a higher boost speed
493 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
496 } else if(BoostSpeed > 0) {
497 // Check if we need to change to a lower boost speed
498 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
504 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
507 * Calculate the manifold absolute pressure (MAP) in inches hg
509 * This function calculates manifold absolute pressure (MAP)
510 * from the throttle position, turbo/supercharger boost control
511 * system, engine speed and local ambient air density.
513 * Inputs: p_amb, Throttle, ThrottleAngle,
514 * MeanPistonSpeed_fps, dt
516 * Outputs: MAP, ManifoldPressure_inHg, TMAP
519 void FGPiston::doMAP(void)
521 // estimate throttle plate area.
522 double throttle_area = ThrottleAngle*ThrottleAngle;
523 // Internal Combustion Engine in Theory and Practice, Volume 2. Charles Fayette Taylor. Revised Edition, 1985 fig 6-13
524 double map_coefficient = 1-((MeanPistonSpeed_fps*MeanPistonSpeed_fps)/(24978*throttle_area));
526 if ( map_coefficient < 0.1 ) map_coefficient = 0.1;
528 // Add a one second lag to manifold pressure changes
529 double dMAP = (TMAP - p_amb * map_coefficient) * dt;
532 // Find the mean effective pressure required to achieve this manifold pressure
533 // Fixme: determine the HP consumed by the supercharger
535 PMEP = TMAP - p_amb; // Fixme: p_amb should be exhaust manifold pressure
538 // If takeoff boost is fitted, we currently assume the following throttle map:
539 // (In throttle % - actual input is 0 -> 1)
540 // 99 / 100 - Takeoff boost
541 // In real life, most planes would be fitted with a mechanical 'gate' between
542 // the rated boost and takeoff boost positions.
544 bool bTakeoffPos = false;
546 if (Throttle > 0.98) {
550 // Boost the manifold pressure.
551 double boost_factor = BoostMul[BoostSpeed] * map_coefficient * RPM/RatedRPM[BoostSpeed];
552 if (boost_factor < 1.0) boost_factor = 1.0; // boost will never reduce the MAP
553 MAP = TMAP * boost_factor;
554 // Now clip the manifold pressure to BCV or Wastegate setting.
556 if (MAP > TakeoffMAP[BoostSpeed]) MAP = TakeoffMAP[BoostSpeed];
558 if (MAP > RatedMAP[BoostSpeed]) MAP = RatedMAP[BoostSpeed];
564 // And set the value in American units as well
565 ManifoldPressure_inHg = MAP / inhgtopa;
568 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
570 * Calculate the air flow through the engine.
571 * Also calculates ambient air density
572 * (used in CHT calculation for air-cooled engines).
574 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
575 * RPM, volumetric_efficiency, ThrottleAngle
577 * TODO: Model inlet manifold air temperature.
579 * Outputs: rho_air, m_dot_air
582 void FGPiston::doAirFlow(void)
584 double gamma = 1.4; // specific heat constants
585 // loss of volumentric efficiency due to difference between MAP and exhaust pressure
586 double ve =((gamma-1)/gamma)+( CompressionRatio -(p_amb/MAP))/(gamma*( CompressionRatio - 1));
588 rho_air = p_amb / (R_air * T_amb);
589 double swept_volume = (displacement_SI * (RPM/60)) / 2;
590 double v_dot_air = swept_volume * volumetric_efficiency *ve;
592 double rho_air_manifold = MAP / (R_air * T_amb);
593 m_dot_air = v_dot_air * rho_air_manifold;
597 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599 * Calculate the fuel flow into the engine.
601 * Inputs: Mixture, thi_sea_level, p_amb, m_dot_air
603 * Outputs: equivalence_ratio, m_dot_fuel
606 void FGPiston::doFuelFlow(void)
608 double thi_sea_level = 1.3 * Mixture; // Allows an AFR of infinity:1 to 11.3075:1
609 equivalence_ratio = thi_sea_level * 101325.0 / p_amb;
610 // double AFR = 10+(12*(1-Mixture));// mixture 10:1 to 22:1
611 // m_dot_fuel = m_dot_air / AFR;
612 m_dot_fuel = (m_dot_air * equivalence_ratio) / 14.7;
613 FuelFlowRate = m_dot_fuel * 2.2046; // kg to lb
614 FuelFlow_pph = FuelFlowRate * 3600; // seconds to hours
615 FuelFlow_gph = FuelFlow_pph / 6.0; // Assumes 6 lbs / gallon
618 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620 * Calculate the power produced by the engine.
622 * Currently, the JSBSim propellor model does not allow the
623 * engine to produce enough RPMs to get up to a high horsepower.
624 * When tested with sufficient RPM, it has no trouble reaching
627 * Inputs: ManifoldPressure_inHg, p_amb, RPM, T_amb,
628 * Mixture_Efficiency_Correlation, Cycles, MaxHP, PMEP,
630 * Outputs: PctPower, HP
633 void FGPiston::doEnginePower(void)
635 IndicatedHorsePower = 0;
638 // FIXME: this needs to be generalized
639 double ME, percent_RPM, power; // Convienience term for use in the calculations
640 ME = Mixture_Efficiency_Correlation->GetValue(m_dot_fuel/m_dot_air);
642 percent_RPM = RPM/MaxRPM;
643 // Guestimate engine friction as a percentage of rated HP + a percentage of rpm + a percentage of Indicted HP
644 // friction = 1 - (percent_RPM * percent_RPM * percent_RPM/10);
645 FMEP = (-18400 * MeanPistonSpeed_fps * fttom - 46500);
649 if ( Magnetos != 3 ) power *= SparkFailDrop;
652 IndicatedHorsePower = (FuelFlow_pph / ISFC )* ME * power;
655 // Power output when the engine is not running
658 IndicatedHorsePower = StarterHP;
659 } else if (RPM < IdleRPM*0.8) {
660 IndicatedHorsePower = StarterHP + ((IdleRPM*0.8 - RPM) / 8.0);
661 // This is a guess - would be nice to find a proper starter moter torque curve
663 IndicatedHorsePower = StarterHP;
668 // Constant is (1/2) * 60 * 745.7
669 // (1/2) convert cycles, 60 minutes to seconds, 745.7 watts to hp.
670 double pumping_hp = ((PMEP + FMEP) * displacement_SI * RPM)/(Cycles*22371);
672 HP = IndicatedHorsePower + pumping_hp - 1.5; //FIXME 1.5 static friction should depend on oil temp and configuration
673 // cout << "pumping_hp " <<pumping_hp << FMEP << PMEP <<endl;
674 PctPower = HP / MaxHP ;
675 // cout << "Power = " << HP << " RPM = " << RPM << " Running = " << Running << " Cranking = " << Cranking << endl;
678 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
680 * Calculate the exhaust gas temperature.
682 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
683 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, PctPower
685 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
688 void FGPiston::doEGT(void)
690 double delta_T_exhaust;
691 double enthalpy_exhaust;
692 double heat_capacity_exhaust;
695 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
696 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
697 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
698 combustion_efficiency * 0.33;
699 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
700 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
701 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
702 ExhaustGasTemp_degK *= 0.444 + ((0.544 - 0.444) * PctPower);
703 } else { // Drop towards ambient - guess an appropriate time constant for now
704 combustion_efficiency = 0;
705 dEGTdt = (RankineToKelvin(Atmosphere->GetTemperature()) - ExhaustGasTemp_degK) / 100.0;
706 delta_T_exhaust = dEGTdt * dt;
707 ExhaustGasTemp_degK += delta_T_exhaust;
711 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
713 * Calculate the cylinder head temperature.
715 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
716 * combustion_efficiency, RPM, MaxRPM
718 * Outputs: CylinderHeadTemp_degK
721 void FGPiston::doCHT(void)
725 double h3 = -140.0; // -0.05 * 2800 (default maxrpm)
727 double arbitary_area = 1.0;
728 double CpCylinderHead = 800.0;
729 double MassCylinderHead = 8.0;
731 double temperature_difference = CylinderHeadTemp_degK - T_amb;
732 double v_apparent = IAS * 0.5144444;
733 double v_dot_cooling_air = arbitary_area * v_apparent;
734 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
735 double dqdt_from_combustion =
736 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
737 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
738 (h3 * RPM * temperature_difference / MaxRPM);
739 double dqdt_free = h1 * temperature_difference;
740 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
742 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
744 CylinderHeadTemp_degK +=
745 (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;
748 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
750 * Calculate the oil temperature.
752 * Inputs: CylinderHeadTemp_degK, T_amb, OilPressure_psi.
754 * Outputs: OilTemp_degK
757 void FGPiston::doOilTemperature(void)
759 double target_oil_temp; // Steady state oil temp at the current engine conditions
760 double time_constant; // The time constant for the differential equation
761 double efficiency = 0.667; // The aproximate oil cooling system efficiency // FIXME: may vary by engine
763 // Target oil temp is interpolated between ambient temperature and Cylinder Head Tempurature
764 // target_oil_temp = ( T_amb * efficiency ) + (CylinderHeadTemp_degK *(1-efficiency)) ;
765 target_oil_temp = CylinderHeadTemp_degK + efficiency * (T_amb - CylinderHeadTemp_degK) ;
767 if (OilPressure_psi > 5.0 ) {
768 time_constant = 5000 / OilPressure_psi; // Guess at a time constant for circulated oil.
769 // The higher the pressure the faster it reaches
770 // target temperature. Oil pressure should be about
771 // 60 PSI yielding a TC of about 80.
773 time_constant = 1000; // Time constant for engine-off; reflects the fact
774 // that oil is no longer getting circulated
777 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
779 OilTemp_degK += (dOilTempdt * dt);
782 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
784 * Calculate the oil pressure.
786 * Inputs: RPM, MaxRPM, OilTemp_degK
788 * Outputs: OilPressure_psi
791 void FGPiston::doOilPressure(void)
793 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
794 double Oil_Press_RPM_Max = MaxRPM * 0.75; // 75% of max rpm FIXME: may vary by engine
795 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
796 double Oil_Viscosity_Index = 0.25;
798 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
800 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
801 OilPressure_psi = Oil_Press_Relief_Valve;
804 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index * OilPressure_psi / Oil_Press_Relief_Valve;
807 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
809 string FGPiston::GetEngineLabels(string delimeter)
811 std::ostringstream buf;
813 buf << Name << " Power Available (engine " << EngineNumber << " in HP)" << delimeter
814 << Name << " HP (engine " << EngineNumber << ")" << delimeter
815 << Name << " equivalent ratio (engine " << EngineNumber << ")" << delimeter
816 << Name << " MAP (engine " << EngineNumber << ")" << delimeter
817 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
822 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
824 string FGPiston::GetEngineValues(string delimeter)
826 std::ostringstream buf;
828 buf << PowerAvailable << delimeter << HP << delimeter
829 << equivalence_ratio << delimeter << MAP << delimeter
830 << Thruster->GetThrusterValues(EngineNumber, delimeter);
835 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
837 // The bitmasked value choices are as follows:
838 // unset: In this case (the default) JSBSim would only print
839 // out the normally expected messages, essentially echoing
840 // the config files as they are read. If the environment
841 // variable is not set, debug_lvl is set to 1 internally
842 // 0: This requests JSBSim not to output any messages
844 // 1: This value explicity requests the normal JSBSim
846 // 2: This value asks for a message to be printed out when
847 // a class is instantiated
848 // 4: When this value is set, a message is displayed when a
849 // FGModel object executes its Run() method
850 // 8: When this value is set, various runtime state variables
851 // are printed out periodically
852 // 16: When set various parameters are sanity checked and
853 // a message is printed out when they go out of bounds
855 void FGPiston::Debug(int from)
857 if (debug_lvl <= 0) return;
859 if (debug_lvl & 1) { // Standard console startup message output
860 if (from == 0) { // Constructor
862 cout << "\n Engine Name: " << Name << endl;
863 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
864 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
865 cout << " MinMaP (Pa): " << minMAP << endl;
866 cout << " MaxMaP (Pa): " << maxMAP << endl;
867 cout << " Displacement: " << Displacement << endl;
868 cout << " Bore: " << Bore << endl;
869 cout << " Stroke: " << Stroke << endl;
870 cout << " Cylinders: " << Cylinders << endl;
871 cout << " Compression Ratio: " << CompressionRatio << endl;
872 cout << " MaxHP: " << MaxHP << endl;
873 cout << " Cycles: " << Cycles << endl;
874 cout << " IdleRPM: " << IdleRPM << endl;
875 cout << " MaxThrottle: " << MaxThrottle << endl;
876 cout << " MinThrottle: " << MinThrottle << endl;
877 cout << " ISFC: " << ISFC << endl;
878 cout << " Volumentric Efficiency: " << volumetric_efficiency << endl;
881 cout << " Combustion Efficiency table:" << endl;
882 Lookup_Combustion_Efficiency->Print();
886 cout << " Mixture Efficiency Correlation table:" << endl;
887 Mixture_Efficiency_Correlation->Print();
892 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
893 if (from == 0) cout << "Instantiated: FGPiston" << endl;
894 if (from == 1) cout << "Destroyed: FGPiston" << endl;
896 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
898 if (debug_lvl & 8 ) { // Runtime state variables
900 if (debug_lvl & 16) { // Sanity checking
902 if (debug_lvl & 64) {
903 if (from == 0) { // Constructor
904 cout << IdSrc << endl;
905 cout << IdHdr << endl;
909 } // namespace JSBSim