1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 Author: Jon S. Berndt, JSBSim framework
5 Dave Luff, Piston engine model
6 Date started: 09/12/2000
7 Purpose: This module models a Piston engine
9 ------------- Copyright (C) 2000 Jon S. Berndt (jsb@hal-pc.org) --------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
31 This class descends from the FGEngine class and models a Piston engine based on
32 parameters given in the engine config file for this class
35 --------------------------------------------------------------------------------
36 09/12/2000 JSB Created
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
45 #include <models/FGPropulsion.h>
46 #include "FGPropeller.h"
50 static const char *IdSrc = "$Id$";
51 static const char *IdHdr = ID_PISTON;
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number)
58 : FGEngine(exec, el, engine_number),
59 R_air(287.3), // Gas constant for air J/Kg/K
60 rho_fuel(800), // estimate
61 calorific_value_fuel(47.3e6),
62 Cp_air(1005), // Specific heat (constant pressure) J/Kg/K
67 // Defaults and initializations
71 // These items are read from the configuration file
77 MinManifoldPressure_inHg = 6.5;
78 MaxManifoldPressure_inHg = 28.5;
80 // These are internal program variables
84 ManifoldPressure_inHg = Atmosphere->GetPressure() * psftoinhg; // psf to in Hg
87 MAP = Atmosphere->GetPressure() * psftopa;
88 CylinderHeadTemp_degK = 0.0;
90 ExhaustGasTemp_degK = 0.0;
96 BoostSpeeds = 0; // Default to no supercharging
100 bBoostOverride = false;
101 bTakeoffBoost = false;
102 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
104 for (i=0; i<FG_MAX_BOOST_SPEEDS; i++) {
107 RatedAltitude[i] = 0.0;
109 RatedMAP[i] = 100000;
111 TakeoffMAP[i] = 100000;
113 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
114 BoostSwitchAltitude[i] = 0.0;
115 BoostSwitchPressure[i] = 0.0;
118 volumetric_efficiency = 0.8; // Actually f(speed, load) but this will get us running
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 Power_Mixture_Correlation = new FGTable(13);
136 *Power_Mixture_Correlation << (14.7/1.6) << 78.0;
137 *Power_Mixture_Correlation << 10 << 86.0;
138 *Power_Mixture_Correlation << 11 << 93.5;
139 *Power_Mixture_Correlation << 12 << 98.0;
140 *Power_Mixture_Correlation << 13 << 100.0;
141 *Power_Mixture_Correlation << 14 << 99.0;
142 *Power_Mixture_Correlation << 15 << 96.4;
143 *Power_Mixture_Correlation << 16 << 92.5;
144 *Power_Mixture_Correlation << 17 << 88.0;
145 *Power_Mixture_Correlation << 18 << 83.0;
146 *Power_Mixture_Correlation << 19 << 78.5;
147 *Power_Mixture_Correlation << 20 << 74.0;
148 *Power_Mixture_Correlation << (14.7/0.6) << 58;
150 // Read inputs from engine data file where present.
152 if (el->FindElement("minmp")) // Should have ELSE statement telling default value used?
153 MinManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("minmp","INHG");
154 if (el->FindElement("maxmp"))
155 MaxManifoldPressure_inHg = el->FindElementValueAsNumberConvertTo("maxmp","INHG");
156 if (el->FindElement("displacement"))
157 Displacement = el->FindElementValueAsNumberConvertTo("displacement","IN3");
158 if (el->FindElement("maxhp"))
159 MaxHP = el->FindElementValueAsNumberConvertTo("maxhp","HP");
160 if (el->FindElement("cycles"))
161 Cycles = el->FindElementValueAsNumber("cycles");
162 if (el->FindElement("idlerpm"))
163 IdleRPM = el->FindElementValueAsNumber("idlerpm");
164 if (el->FindElement("maxthrottle"))
165 MaxThrottle = el->FindElementValueAsNumber("maxthrottle");
166 if (el->FindElement("minthrottle"))
167 MinThrottle = el->FindElementValueAsNumber("minthrottle");
168 if (el->FindElement("numboostspeeds")) { // Turbo- and super-charging parameters
169 BoostSpeeds = (int)el->FindElementValueAsNumber("numboostspeeds");
170 if (el->FindElement("boostoverride"))
171 BoostOverride = (int)el->FindElementValueAsNumber("boostoverride");
172 if (el->FindElement("takeoffboost"))
173 TakeoffBoost = el->FindElementValueAsNumberConvertTo("takeoffboost", "PSI");
174 if (el->FindElement("ratedboost1"))
175 RatedBoost[0] = el->FindElementValueAsNumberConvertTo("ratedboost1", "PSI");
176 if (el->FindElement("ratedboost2"))
177 RatedBoost[1] = el->FindElementValueAsNumberConvertTo("ratedboost2", "PSI");
178 if (el->FindElement("ratedboost3"))
179 RatedBoost[2] = el->FindElementValueAsNumberConvertTo("ratedboost3", "PSI");
180 if (el->FindElement("ratedpower1"))
181 RatedPower[0] = el->FindElementValueAsNumberConvertTo("ratedpower1", "HP");
182 if (el->FindElement("ratedpower2"))
183 RatedPower[1] = el->FindElementValueAsNumberConvertTo("ratedpower2", "HP");
184 if (el->FindElement("ratedpower3"))
185 RatedPower[2] = el->FindElementValueAsNumberConvertTo("ratedpower3", "HP");
186 if (el->FindElement("ratedrpm1"))
187 RatedRPM[0] = el->FindElementValueAsNumber("ratedrpm1");
188 if (el->FindElement("ratedrpm2"))
189 RatedRPM[1] = el->FindElementValueAsNumber("ratedrpm2");
190 if (el->FindElement("ratedrpm3"))
191 RatedRPM[2] = el->FindElementValueAsNumber("ratedrpm3");
192 if (el->FindElement("ratedaltitude1"))
193 RatedAltitude[0] = el->FindElementValueAsNumberConvertTo("ratedaltitude1", "FT");
194 if (el->FindElement("ratedaltitude2"))
195 RatedAltitude[1] = el->FindElementValueAsNumberConvertTo("ratedaltitude2", "FT");
196 if (el->FindElement("ratedaltitude3"))
197 RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT");
199 minMAP = MinManifoldPressure_inHg * 3376.85; // inHg to Pa
200 maxMAP = MaxManifoldPressure_inHg * 3376.85;
202 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
203 if (TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
204 for (i=0; i<BoostSpeeds; ++i) {
206 if (RatedBoost[i] <= 0.0) bad = true;
207 if (RatedPower[i] <= 0.0) bad = true;
208 if (RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
209 if (i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
211 // We can't recover from the above - don't use this supercharger speed.
213 // TODO - put out a massive error message!
216 // Now sanity-check stuff that is recoverable.
217 if (i < BoostSpeeds - 1) {
218 if (BoostSwitchAltitude[i] < RatedAltitude[i]) {
219 // TODO - put out an error message
220 // But we can also make a reasonable estimate, as below.
221 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
223 BoostSwitchPressure[i] = Atmosphere->GetPressure(BoostSwitchAltitude[i]) * psftopa;
224 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
225 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
226 BoostSwitchHysteresis = 1000;
228 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
229 RatedMAP[i] = Atmosphere->GetPressureSL() * psftopa + RatedBoost[i] * 6895; // psi*6895 = Pa.
230 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
231 if (TakeoffBoost > RatedBoost[0]) {
232 // Assume that the effect on the BCV is the same whichever speed is in use.
233 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
234 bTakeoffBoost = true;
236 TakeoffMAP[i] = RatedMAP[i];
237 bTakeoffBoost = false;
239 BoostMul[i] = RatedMAP[i] / (Atmosphere->GetPressure(RatedAltitude[i]) * psftopa);
243 if (BoostSpeeds > 0) {
247 bBoostOverride = (BoostOverride == 1 ? true : false);
249 Debug(0); // Call Debug() routine from constructor if needed
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 FGPiston::~FGPiston()
256 Debug(1); // Call Debug() routine from constructor if needed
259 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 double FGPiston::Calculate(void)
263 if (FuelFlow_gph > 0.0) ConsumeFuel();
265 Throttle = FCS->GetThrottlePos(EngineNumber);
266 Mixture = FCS->GetMixturePos(EngineNumber);
272 p_amb = Atmosphere->GetPressure() * psftopa;
273 p_amb_sea_level = Atmosphere->GetPressureSL() * psftopa;
274 T_amb = Atmosphere->GetTemperature() * (5.0 / 9.0); // convert from Rankine to Kelvin
276 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
278 IAS = Auxiliary->GetVcalibratedKTS();
281 if (Boosted) doBoostControl();
286 //Now that the fuel flow is done check if the mixture is too lean to run the engine
287 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
288 //This might be a bit generous, but since there's currently no audiable warning of impending
289 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
290 if (equivalence_ratio < 0.668)
299 if (Thruster->GetType() == FGThruster::ttPropeller) {
300 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
301 ((FGPropeller*)Thruster)->SetFeather(FCS->GetPropFeather(EngineNumber));
304 PowerAvailable = (HP * hptoftlbssec) - Thruster->GetPowerRequired();
306 return Thruster->Calculate(PowerAvailable);
309 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 * Start or stop the engine.
314 void FGPiston::doEngineStartup(void)
316 // Check parameters that may alter the operating state of the engine.
317 // (spark, fuel, starter motor etc)
322 Magneto_Left = false;
323 Magneto_Right = false;
324 // Magneto positions:
333 } // neglects battery voltage, master on switch, etc for now.
335 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
336 if (Magnetos > 1) Magneto_Right = true;
338 // Assume we have fuel for now
341 // Check if we are turning the starter motor
342 if (Cranking != Starter) {
343 // This check saves .../cranking from getting updated every loop - they
344 // only update when changed.
349 if (Cranking) crank_counter++; //Check mode of engine operation
351 if (!Running && spark && fuel) { // start the engine if revs high enough
353 if ((RPM > 450) && (crank_counter > 175)) // Add a little delay to startup
354 Running = true; // on the starter
356 if (RPM > 450) // This allows us to in-air start
357 Running = true; // when windmilling
361 // Cut the engine *power* - Note: the engine may continue to
362 // spin if the prop is in a moving airstream
364 if ( Running && (!spark || !fuel) ) Running = false;
366 // Check for stalling (RPM = 0).
370 } else if ((RPM <= 480) && (Cranking)) {
376 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 * Calculate the Current Boost Speed
381 * This function calculates the current turbo/supercharger boost speed
382 * based on altitude and the (automatic) boost-speed control valve configuration.
384 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
386 * Outputs: BoostSpeed
389 void FGPiston::doBoostControl(void)
391 if(BoostSpeed < BoostSpeeds - 1) {
392 // Check if we need to change to a higher boost speed
393 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
396 } else if(BoostSpeed > 0) {
397 // Check if we need to change to a lower boost speed
398 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
404 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
407 * Calculate the manifold absolute pressure (MAP) in inches hg
409 * This function calculates manifold absolute pressure (MAP)
410 * from the throttle position, turbo/supercharger boost control
411 * system, engine speed and local ambient air density.
413 * TODO: changes in MP should not be instantaneous -- introduce
414 * a lag between throttle changes and MP changes, to allow pressure
415 * to build up or disperse.
417 * Inputs: minMAP, maxMAP, p_amb, Throttle
419 * Outputs: MAP, ManifoldPressure_inHg
422 void FGPiston::doMAP(void)
425 // Naturally aspirated
426 MAP = minMAP + (Throttle * (maxMAP - minMAP));
427 MAP *= p_amb / p_amb_sea_level;
429 // If takeoff boost is fitted, we currently assume the following throttle map:
430 // (In throttle % - actual input is 0 -> 1)
431 // 99 / 100 - Takeoff boost
432 // 96 / 97 / 98 - Rated boost
433 // 0 - 95 - Idle to Rated boost (MinManifoldPressure to MaxManifoldPressure)
434 // In real life, most planes would be fitted with a mechanical 'gate' between
435 // the rated boost and takeoff boost positions.
436 double T = Throttle; // processed throttle value.
437 bool bTakeoffPos = false;
439 if(Throttle > 0.98) {
440 //cout << "Takeoff Boost!!!!\n";
442 } else if(Throttle <= 0.95) {
447 //cout << "Rated Boost!!\n";
451 // Boost the manifold pressure.
452 MAP *= BoostMul[BoostSpeed];
453 // Now clip the manifold pressure to BCV or Wastegate setting.
455 if(MAP > TakeoffMAP[BoostSpeed]) {
456 MAP = TakeoffMAP[BoostSpeed];
459 if(MAP > RatedMAP[BoostSpeed]) {
460 MAP = RatedMAP[BoostSpeed];
465 // rpm < 10 - effectively stopped.
466 // TODO - add a better variation of MAP with engine speed
467 MAP = Atmosphere->GetPressure() * psftopa;
470 // And set the value in American units as well
471 ManifoldPressure_inHg = MAP / 3376.85;
474 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
476 * Calculate the air flow through the engine.
477 * Also calculates ambient air density
478 * (used in CHT calculation for air-cooled engines).
480 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
481 * RPM, volumetric_efficiency
483 * TODO: Model inlet manifold air temperature.
485 * Outputs: rho_air, m_dot_air
488 void FGPiston::doAirFlow(void)
490 rho_air = p_amb / (R_air * T_amb);
491 double rho_air_manifold = MAP / (R_air * T_amb);
492 double displacement_SI = Displacement * in3tom3;
493 double swept_volume = (displacement_SI * (RPM/60)) / 2;
494 double v_dot_air = swept_volume * volumetric_efficiency;
495 m_dot_air = v_dot_air * rho_air_manifold;
498 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500 * Calculate the fuel flow into the engine.
502 * Inputs: Mixture, thi_sea_level, p_amb_sea_level, p_amb, m_dot_air
504 * Outputs: equivalence_ratio, m_dot_fuel
507 void FGPiston::doFuelFlow(void)
509 double thi_sea_level = 1.3 * Mixture;
510 equivalence_ratio = thi_sea_level * p_amb_sea_level / p_amb;
511 m_dot_fuel = m_dot_air / 14.7 * equivalence_ratio;
512 FuelFlow_gph = m_dot_fuel
513 * 3600 // seconds to hours
515 / 6.6; // lb to gal_us of kerosene
518 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520 * Calculate the power produced by the engine.
522 * Currently, the JSBSim propellor model does not allow the
523 * engine to produce enough RPMs to get up to a high horsepower.
524 * When tested with sufficient RPM, it has no trouble reaching
527 * Inputs: ManifoldPressure_inHg, p_amb, p_amb_sea_level, RPM, T_amb,
528 * equivalence_ratio, Cycles, MaxHP
530 * Outputs: Percentage_Power, HP
533 void FGPiston::doEnginePower(void)
536 double T_amb_degF = KelvinToFahrenheit(T_amb);
537 double T_amb_sea_lev_degF = KelvinToFahrenheit(288);
539 // FIXME: this needs to be generalized
540 double ManXRPM; // Convienience term for use in the calculations
542 // Currently a simple linear fit.
543 // The zero crossing is moved up the speed-load range to reduce the idling power.
545 double zeroOffset = (minMAP / 2.0) * (IdleRPM / 2.0);
546 ManXRPM = MAP * (RPM > RatedRPM[BoostSpeed] ? RatedRPM[BoostSpeed] : RPM);
547 // The speed clip in the line above is deliberate.
548 Percentage_Power = ((ManXRPM - zeroOffset) / ((RatedMAP[BoostSpeed] * RatedRPM[BoostSpeed]) - zeroOffset)) * 107.0;
549 Percentage_Power -= 7.0; // Another idle power reduction offset - see line above with 107.
550 if (Percentage_Power < 0.0) Percentage_Power = 0.0;
551 // Note that %power is allowed to go over 100 for boosted powerplants
552 // such as for the BCV-override or takeoff power settings.
553 // TODO - currently no altitude effect (temperature & exhaust back-pressure) modelled
554 // for boosted engines.
556 ManXRPM = ManifoldPressure_inHg * RPM; // Note that inHg must be used for the following correlation.
557 Percentage_Power = (6e-9 * ManXRPM * ManXRPM) + (8e-4 * ManXRPM) - 1.0;
558 Percentage_Power += ((T_amb_sea_lev_degF - T_amb_degF) * 7 /120);
559 if (Percentage_Power < 0.0) Percentage_Power = 0.0;
560 else if (Percentage_Power > 100.0) Percentage_Power = 100.0;
563 double Percentage_of_best_power_mixture_power =
564 Power_Mixture_Correlation->GetValue(14.7 / equivalence_ratio);
566 Percentage_Power *= Percentage_of_best_power_mixture_power / 100.0;
569 HP = Percentage_Power * RatedPower[BoostSpeed] / 100.0;
571 HP = Percentage_Power * MaxHP / 100.0;
576 // Power output when the engine is not running
579 HP = 3.0; // This is a hack to prevent overshooting the idle rpm in
580 // the first time step. It may possibly need to be changed
581 // if the prop model is changed.
582 } else if (RPM < 480) {
583 HP = 3.0 + ((480 - RPM) / 10.0);
584 // This is a guess - would be nice to find a proper starter moter torque curve
589 // Quick hack until we port the FMEP stuff
596 //cout << "Power = " << HP << '\n';
599 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601 * Calculate the exhaust gas temperature.
603 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
604 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, Percentage_Power
606 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
609 void FGPiston::doEGT(void)
611 double delta_T_exhaust;
612 double enthalpy_exhaust;
613 double heat_capacity_exhaust;
616 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
617 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
618 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
619 combustion_efficiency * 0.33;
620 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
621 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
622 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
623 ExhaustGasTemp_degK *= 0.444 + ((0.544 - 0.444) * Percentage_Power / 100.0);
624 } else { // Drop towards ambient - guess an appropriate time constant for now
625 dEGTdt = (298.0 - ExhaustGasTemp_degK) / 100.0;
626 delta_T_exhaust = dEGTdt * dt;
627 ExhaustGasTemp_degK += delta_T_exhaust;
631 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
633 * Calculate the cylinder head temperature.
635 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
636 * combustion_efficiency, RPM
638 * Outputs: CylinderHeadTemp_degK
641 void FGPiston::doCHT(void)
647 double arbitary_area = 1.0;
648 double CpCylinderHead = 800.0;
649 double MassCylinderHead = 8.0;
651 double temperature_difference = CylinderHeadTemp_degK - T_amb;
652 double v_apparent = IAS * 0.5144444;
653 double v_dot_cooling_air = arbitary_area * v_apparent;
654 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
655 double dqdt_from_combustion =
656 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
657 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
658 (h3 * RPM * temperature_difference);
659 double dqdt_free = h1 * temperature_difference;
660 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
662 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
664 CylinderHeadTemp_degK +=
665 (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;
668 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670 * Calculate the oil temperature.
672 * Inputs: Percentage_Power, running flag.
674 * Outputs: OilTemp_degK
677 void FGPiston::doOilTemperature(void)
679 double idle_percentage_power = 2.3; // approximately
680 double target_oil_temp; // Steady state oil temp at the current engine conditions
681 double time_constant; // The time constant for the differential equation
684 target_oil_temp = 363;
685 time_constant = 500; // Time constant for engine-on idling.
686 if (Percentage_Power > idle_percentage_power) {
687 time_constant /= ((Percentage_Power / idle_percentage_power) / 10.0); // adjust for power
690 target_oil_temp = 298;
691 time_constant = 1000; // Time constant for engine-off; reflects the fact
692 // that oil is no longer getting circulated
695 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
697 OilTemp_degK += (dOilTempdt * dt);
700 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
702 * Calculate the oil pressure.
706 * Outputs: OilPressure_psi
709 void FGPiston::doOilPressure(void)
711 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
712 double Oil_Press_RPM_Max = 1800; // FIXME: may vary by engine
713 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
714 double Oil_Viscosity_Index = 0.25;
716 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
718 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
719 OilPressure_psi = Oil_Press_Relief_Valve;
722 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index;
725 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727 string FGPiston::GetEngineLabels(string delimeter)
729 std::ostringstream buf;
731 buf << Name << "_PwrAvail[" << EngineNumber << "]" << delimeter
732 << Name << "_HP[" << EngineNumber << "]" << delimeter
733 << Name << "_equiv_ratio[" << EngineNumber << "]" << delimeter
734 << Name << "_MAP[" << EngineNumber << "]" << delimeter
735 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
740 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742 string FGPiston::GetEngineValues(string delimeter)
744 std::ostringstream buf;
746 buf << PowerAvailable << delimeter << HP << delimeter
747 << equivalence_ratio << delimeter << MAP << delimeter
748 << Thruster->GetThrusterValues(EngineNumber, delimeter);
753 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
755 // The bitmasked value choices are as follows:
756 // unset: In this case (the default) JSBSim would only print
757 // out the normally expected messages, essentially echoing
758 // the config files as they are read. If the environment
759 // variable is not set, debug_lvl is set to 1 internally
760 // 0: This requests JSBSim not to output any messages
762 // 1: This value explicity requests the normal JSBSim
764 // 2: This value asks for a message to be printed out when
765 // a class is instantiated
766 // 4: When this value is set, a message is displayed when a
767 // FGModel object executes its Run() method
768 // 8: When this value is set, various runtime state variables
769 // are printed out periodically
770 // 16: When set various parameters are sanity checked and
771 // a message is printed out when they go out of bounds
773 void FGPiston::Debug(int from)
775 if (debug_lvl <= 0) return;
777 if (debug_lvl & 1) { // Standard console startup message output
778 if (from == 0) { // Constructor
780 cout << "\n Engine Name: " << Name << endl;
781 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
782 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
783 cout << " MinMaP (Pa): " << minMAP << endl;
784 cout << " MaxMaP (Pa): " << maxMAP << endl;
785 cout << " Displacement: " << Displacement << endl;
786 cout << " MaxHP: " << MaxHP << endl;
787 cout << " Cycles: " << Cycles << endl;
788 cout << " IdleRPM: " << IdleRPM << endl;
789 cout << " MaxThrottle: " << MaxThrottle << endl;
790 cout << " MinThrottle: " << MinThrottle << endl;
793 cout << " Combustion Efficiency table:" << endl;
794 Lookup_Combustion_Efficiency->Print();
798 cout << " Power Mixture Correlation table:" << endl;
799 Power_Mixture_Correlation->Print();
804 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
805 if (from == 0) cout << "Instantiated: FGPiston" << endl;
806 if (from == 1) cout << "Destroyed: FGPiston" << endl;
808 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
810 if (debug_lvl & 8 ) { // Runtime state variables
812 if (debug_lvl & 16) { // Sanity checking
814 if (debug_lvl & 64) {
815 if (from == 0) { // Constructor
816 cout << IdSrc << endl;
817 cout << IdHdr << endl;
823 FGPiston::CalcFuelNeed(void)
825 return FuelFlow_gph / 3600 * 6 * State->Getdt() * Propulsion->GetRate();
828 } // namespace JSBSim