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 "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, FGConfigFile* Eng_cfg, int engine_number)
58 : FGEngine(exec, engine_number),
60 rho_fuel(800), // estimate
61 calorific_value_fuel(47.3e6),
70 MinManifoldPressure_inHg = 6.5;
71 MaxManifoldPressure_inHg = 28.5;
72 ManifoldPressure_inHg = Atmosphere->GetPressure() * psftoinhg; // psf to in Hg
75 MAP = Atmosphere->GetPressure() * 47.88; // psf to Pa
76 CylinderHeadTemp_degK = 0.0;
82 ExhaustGasTemp_degK = 0.0;
88 BoostSpeeds = 0; // Default to no supercharging
92 bBoostOverride = false;
93 bTakeoffBoost = false;
94 TakeoffBoost = 0.0; // Default to no extra takeoff-boost
96 for(i=0; i<FG_MAX_BOOST_SPEEDS; ++i) {
99 RatedAltitude[i] = 0.0;
101 RatedMAP[i] = 100000;
103 TakeoffMAP[i] = 100000;
107 volumetric_efficiency = 0.8; // Actually f(speed, load) but this will get us running
109 // First column is thi, second is neta (combustion efficiency)
110 Lookup_Combustion_Efficiency = new FGTable(12);
111 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
112 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
113 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
114 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
115 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
116 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
117 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
118 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
119 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
120 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
121 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
122 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
124 Power_Mixture_Correlation = new FGTable(13);
125 *Power_Mixture_Correlation << (14.7/1.6) << 78.0;
126 *Power_Mixture_Correlation << 10 << 86.0;
127 *Power_Mixture_Correlation << 11 << 93.5;
128 *Power_Mixture_Correlation << 12 << 98.0;
129 *Power_Mixture_Correlation << 13 << 100.0;
130 *Power_Mixture_Correlation << 14 << 99.0;
131 *Power_Mixture_Correlation << 15 << 96.4;
132 *Power_Mixture_Correlation << 16 << 92.5;
133 *Power_Mixture_Correlation << 17 << 88.0;
134 *Power_Mixture_Correlation << 18 << 83.0;
135 *Power_Mixture_Correlation << 19 << 78.5;
136 *Power_Mixture_Correlation << 20 << 74.0;
137 *Power_Mixture_Correlation << (14.7/0.6) << 58;
139 Name = Eng_cfg->GetValue("NAME");
140 Eng_cfg->GetNextConfigLine();
141 while (Eng_cfg->GetValue() != string("/FG_PISTON")) {
143 if (token == "MINMP") *Eng_cfg >> MinManifoldPressure_inHg;
144 else if (token == "MAXMP") *Eng_cfg >> MaxManifoldPressure_inHg;
145 else if (token == "DISPLACEMENT") *Eng_cfg >> Displacement;
146 else if (token == "MAXHP") *Eng_cfg >> MaxHP;
147 else if (token == "CYCLES") *Eng_cfg >> Cycles;
148 else if (token == "IDLERPM") *Eng_cfg >> IdleRPM;
149 else if (token == "MAXTHROTTLE") *Eng_cfg >> MaxThrottle;
150 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
151 else if (token == "NUMBOOSTSPEEDS") *Eng_cfg >> BoostSpeeds;
152 else if (token == "BOOSTOVERRIDE") *Eng_cfg >> BoostOverride;
153 else if (token == "TAKEOFFBOOST") *Eng_cfg >> TakeoffBoost;
154 else if (token == "RATEDBOOST1") *Eng_cfg >> RatedBoost[0];
155 else if (token == "RATEDBOOST2") *Eng_cfg >> RatedBoost[1];
156 else if (token == "RATEDBOOST3") *Eng_cfg >> RatedBoost[2];
157 else if (token == "RATEDPOWER1") *Eng_cfg >> RatedPower[0];
158 else if (token == "RATEDPOWER2") *Eng_cfg >> RatedPower[1];
159 else if (token == "RATEDPOWER3") *Eng_cfg >> RatedPower[2];
160 else if (token == "RATEDRPM1") *Eng_cfg >> RatedRPM[0];
161 else if (token == "RATEDRPM2") *Eng_cfg >> RatedRPM[1];
162 else if (token == "RATEDRPM3") *Eng_cfg >> RatedRPM[2];
163 else if (token == "RATEDALTITUDE1") *Eng_cfg >> RatedAltitude[0];
164 else if (token == "RATEDALTITUDE2") *Eng_cfg >> RatedAltitude[1];
165 else if (token == "RATEDALTITUDE3") *Eng_cfg >> RatedAltitude[2];
166 else cerr << "Unhandled token in Engine config file: " << token << endl;
169 minMAP = MinManifoldPressure_inHg * 3376.85; // inHg to Pa
170 maxMAP = MaxManifoldPressure_inHg * 3376.85;
172 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
173 if(TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
174 for(i=0; i<BoostSpeeds; ++i) {
176 if(RatedBoost[i] <= 0.0) bad = true;
177 if(RatedPower[i] <= 0.0) bad = true;
178 if(RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
179 if(i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
181 // We can't recover from the above - don't use this supercharger speed.
183 // TODO - put out a massive error message!
186 // Now sanity-check stuff that is recoverable.
187 if(i < BoostSpeeds - 1) {
188 if(BoostSwitchAltitude[i] < RatedAltitude[i]) {
189 // TODO - put out an error message
190 // But we can also make a reasonable estimate, as below.
191 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
193 BoostSwitchPressure[i] = Atmosphere->GetPressure(BoostSwitchAltitude[i]) * 47.88;
194 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
195 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
196 BoostSwitchHysteresis = 1000;
198 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
199 RatedMAP[i] = Atmosphere->GetPressureSL() * 47.88 + RatedBoost[i] * 6895; // psf*47.88 = Pa, psi*6895 = Pa.
200 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
201 if(TakeoffBoost > RatedBoost[0]) {
202 // Assume that the effect on the BCV is the same whichever speed is in use.
203 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
204 bTakeoffBoost = true;
206 TakeoffMAP[i] = RatedMAP[i];
207 bTakeoffBoost = false;
209 BoostMul[i] = RatedMAP[i] / (Atmosphere->GetPressure(RatedAltitude[i]) * 47.88);
211 // TODO - get rid of the debugging output before sending it to Jon
212 //cout << "Speed " << i+1 << '\n';
213 //cout << "BoostMul = " << BoostMul[i] << ", RatedMAP = " << RatedMAP[i] << ", TakeoffMAP = " << TakeoffMAP[i] << '\n';
216 if(BoostSpeeds > 0) {
220 bBoostOverride = (BoostOverride == 1 ? true : false);
222 //cout << "Engine is " << (Boosted ? "supercharged" : "naturally aspirated") << '\n';
224 Debug(0); // Call Debug() routine from constructor if needed
227 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229 FGPiston::~FGPiston()
231 Debug(1); // Call Debug() routine from constructor if needed
234 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 double FGPiston::Calculate(void)
238 if (FuelFlow_gph > 0.0) ConsumeFuel();
240 Throttle = FCS->GetThrottlePos(EngineNumber);
241 Mixture = FCS->GetMixturePos(EngineNumber);
247 p_amb = Atmosphere->GetPressure() * 47.88; // convert from lbs/ft2 to Pa
248 p_amb_sea_level = Atmosphere->GetPressureSL() * 47.88;
249 T_amb = Atmosphere->GetTemperature() * (5.0 / 9.0); // convert from Rankine to Kelvin
251 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
253 IAS = Auxiliary->GetVcalibratedKTS();
256 if(Boosted) doBoostControl();
261 //Now that the fuel flow is done check if the mixture is too lean to run the engine
262 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
263 //This might be a bit generous, but since there's currently no audiable warning of impending
264 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
265 if (equivalence_ratio < 0.668)
274 if (Thruster->GetType() == FGThruster::ttPropeller) {
275 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
278 PowerAvailable = (HP * hptoftlbssec) - Thruster->GetPowerRequired();
280 return Thruster->Calculate(PowerAvailable);
283 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 * Start or stop the engine.
288 void FGPiston::doEngineStartup(void)
290 // Check parameters that may alter the operating state of the engine.
291 // (spark, fuel, starter motor etc)
296 Magneto_Left = false;
297 Magneto_Right = false;
298 // Magneto positions:
307 } // neglects battery voltage, master on switch, etc for now.
309 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
310 if (Magnetos > 1) Magneto_Right = true;
312 // Assume we have fuel for now
315 // Check if we are turning the starter motor
316 if (Cranking != Starter) {
317 // This check saves .../cranking from getting updated every loop - they
318 // only update when changed.
323 if (Cranking) crank_counter++; //Check mode of engine operation
325 if (!Running && spark && fuel) { // start the engine if revs high enough
327 if ((RPM > 450) && (crank_counter > 175)) // Add a little delay to startup
328 Running = true; // on the starter
330 if (RPM > 450) // This allows us to in-air start
331 Running = true; // when windmilling
335 // Cut the engine *power* - Note: the engine may continue to
336 // spin if the prop is in a moving airstream
338 if ( Running && (!spark || !fuel) ) Running = false;
340 // Check for stalling (RPM = 0).
344 } else if ((RPM <= 480) && (Cranking)) {
350 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 * Calculate the Current Boost Speed
355 * This function calculates the current turbo/supercharger boost speed
356 * based on altitude and the (automatic) boost-speed control valve configuration.
358 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
360 * Outputs: BoostSpeed
363 void FGPiston::doBoostControl(void)
365 if(BoostSpeed < BoostSpeeds - 1) {
366 // Check if we need to change to a higher boost speed
367 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
370 } else if(BoostSpeed > 0) {
371 // Check if we need to change to a lower boost speed
372 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
378 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381 * Calculate the manifold absolute pressure (MAP) in inches hg
383 * This function calculates manifold absolute pressure (MAP)
384 * from the throttle position, turbo/supercharger boost control
385 * system, engine speed and local ambient air density.
387 * TODO: changes in MP should not be instantaneous -- introduce
388 * a lag between throttle changes and MP changes, to allow pressure
389 * to build up or disperse.
391 * Inputs: minMAP, maxMAP, p_amb, Throttle
393 * Outputs: MAP, ManifoldPressure_inHg
396 void FGPiston::doMAP(void)
399 // Naturally aspirated
400 MAP = minMAP + (Throttle * (maxMAP - minMAP));
401 MAP *= p_amb / p_amb_sea_level;
403 // If takeoff boost is fitted, we currently assume the following throttle map:
404 // (In throttle % - actual input is 0 -> 1)
405 // 99 / 100 - Takeoff boost
406 // 96 / 97 / 98 - Rated boost
407 // 0 - 95 - Idle to Rated boost (MinManifoldPressure to MaxManifoldPressure)
408 // In real life, most planes would be fitted with a mechanical 'gate' between
409 // the rated boost and takeoff boost positions.
410 double T = Throttle; // processed throttle value.
411 bool bTakeoffPos = false;
413 if(Throttle > 0.98) {
414 //cout << "Takeoff Boost!!!!\n";
416 } else if(Throttle <= 0.95) {
421 //cout << "Rated Boost!!\n";
425 // Boost the manifold pressure.
426 MAP *= BoostMul[BoostSpeed];
427 // Now clip the manifold pressure to BCV or Wastegate setting.
429 if(MAP > TakeoffMAP[BoostSpeed]) {
430 MAP = TakeoffMAP[BoostSpeed];
433 if(MAP > RatedMAP[BoostSpeed]) {
434 MAP = RatedMAP[BoostSpeed];
439 // rpm < 10 - effectively stopped.
440 // TODO - add a better variation of MAP with engine speed
441 MAP = Atmosphere->GetPressure() * 47.88; // psf to Pa
444 // And set the value in American units as well
445 ManifoldPressure_inHg = MAP / 3376.85;
448 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 * Calculate the air flow through the engine.
451 * Also calculates ambient air density
452 * (used in CHT calculation for air-cooled engines).
454 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
455 * RPM, volumetric_efficiency
457 * TODO: Model inlet manifold air temperature.
459 * Outputs: rho_air, m_dot_air
462 void FGPiston::doAirFlow(void)
464 rho_air = p_amb / (R_air * T_amb);
465 double rho_air_manifold = MAP / (R_air * T_amb);
466 double displacement_SI = Displacement * in3tom3;
467 double swept_volume = (displacement_SI * (RPM/60)) / 2;
468 double v_dot_air = swept_volume * volumetric_efficiency;
469 m_dot_air = v_dot_air * rho_air_manifold;
472 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
474 * Calculate the fuel flow into the engine.
476 * Inputs: Mixture, thi_sea_level, p_amb_sea_level, p_amb, m_dot_air
478 * Outputs: equivalence_ratio, m_dot_fuel
481 void FGPiston::doFuelFlow(void)
483 double thi_sea_level = 1.3 * Mixture;
484 equivalence_ratio = thi_sea_level * p_amb_sea_level / p_amb;
485 m_dot_fuel = m_dot_air / 14.7 * equivalence_ratio;
486 FuelFlow_gph = m_dot_fuel
487 * 3600 // seconds to hours
489 / 6.6; // lb to gal_us of kerosene
492 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
494 * Calculate the power produced by the engine.
496 * Currently, the JSBSim propellor model does not allow the
497 * engine to produce enough RPMs to get up to a high horsepower.
498 * When tested with sufficient RPM, it has no trouble reaching
501 * Inputs: ManifoldPressure_inHg, p_amb, p_amb_sea_level, RPM, T_amb,
502 * equivalence_ratio, Cycles, MaxHP
504 * Outputs: Percentage_Power, HP
507 void FGPiston::doEnginePower(void)
510 double T_amb_degF = KelvinToFahrenheit(T_amb);
511 double T_amb_sea_lev_degF = KelvinToFahrenheit(288);
513 // FIXME: this needs to be generalized
514 double ManXRPM; // Convienience term for use in the calculations
516 // Currently a simple linear fit.
517 // The zero crossing is moved up the speed-load range to reduce the idling power.
519 double zeroOffset = (minMAP / 2.0) * (IdleRPM / 2.0);
520 ManXRPM = MAP * (RPM > RatedRPM[BoostSpeed] ? RatedRPM[BoostSpeed] : RPM);
521 // The speed clip in the line above is deliberate.
522 Percentage_Power = ((ManXRPM - zeroOffset) / ((RatedMAP[BoostSpeed] * RatedRPM[BoostSpeed]) - zeroOffset)) * 107.0;
523 Percentage_Power -= 7.0; // Another idle power reduction offset - see line above with 107.
524 if (Percentage_Power < 0.0) Percentage_Power = 0.0;
525 // Note that %power is allowed to go over 100 for boosted powerplants
526 // such as for the BCV-override or takeoff power settings.
527 // TODO - currently no altitude effect (temperature & exhaust back-pressure) modelled
528 // for boosted engines.
530 ManXRPM = ManifoldPressure_inHg * RPM; // Note that inHg must be used for the following correlation.
531 Percentage_Power = (6e-9 * ManXRPM * ManXRPM) + (8e-4 * ManXRPM) - 1.0;
532 Percentage_Power += ((T_amb_sea_lev_degF - T_amb_degF) * 7 /120);
533 if (Percentage_Power < 0.0) Percentage_Power = 0.0;
534 else if (Percentage_Power > 100.0) Percentage_Power = 100.0;
537 double Percentage_of_best_power_mixture_power =
538 Power_Mixture_Correlation->GetValue(14.7 / equivalence_ratio);
540 Percentage_Power *= Percentage_of_best_power_mixture_power / 100.0;
543 HP = Percentage_Power * RatedPower[BoostSpeed] / 100.0;
545 HP = Percentage_Power * MaxHP / 100.0;
550 // Power output when the engine is not running
553 HP = 3.0; // This is a hack to prevent overshooting the idle rpm in
554 // the first time step. It may possibly need to be changed
555 // if the prop model is changed.
556 } else if (RPM < 480) {
557 HP = 3.0 + ((480 - RPM) / 10.0);
558 // This is a guess - would be nice to find a proper starter moter torque curve
563 // Quick hack until we port the FMEP stuff
570 //cout << "Power = " << HP << '\n';
573 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
575 * Calculate the exhaust gas temperature.
577 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
578 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, Percentage_Power
580 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
583 void FGPiston::doEGT(void)
585 double delta_T_exhaust;
586 double enthalpy_exhaust;
587 double heat_capacity_exhaust;
590 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
591 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
592 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
593 combustion_efficiency * 0.33;
594 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
595 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
596 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
597 ExhaustGasTemp_degK *= 0.444 + ((0.544 - 0.444) * Percentage_Power / 100.0);
598 } else { // Drop towards ambient - guess an appropriate time constant for now
599 dEGTdt = (298.0 - ExhaustGasTemp_degK) / 100.0;
600 delta_T_exhaust = dEGTdt * dt;
601 ExhaustGasTemp_degK += delta_T_exhaust;
605 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607 * Calculate the cylinder head temperature.
609 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
610 * combustion_efficiency, RPM
612 * Outputs: CylinderHeadTemp_degK
615 void FGPiston::doCHT(void)
621 double arbitary_area = 1.0;
622 double CpCylinderHead = 800.0;
623 double MassCylinderHead = 8.0;
625 double temperature_difference = CylinderHeadTemp_degK - T_amb;
626 double v_apparent = IAS * 0.5144444;
627 double v_dot_cooling_air = arbitary_area * v_apparent;
628 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
629 double dqdt_from_combustion =
630 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
631 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
632 (h3 * RPM * temperature_difference);
633 double dqdt_free = h1 * temperature_difference;
634 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
636 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
638 CylinderHeadTemp_degK +=
639 (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;
642 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
644 * Calculate the oil temperature.
646 * Inputs: Percentage_Power, running flag.
648 * Outputs: OilTemp_degK
651 void FGPiston::doOilTemperature(void)
653 double idle_percentage_power = 2.3; // approximately
654 double target_oil_temp; // Steady state oil temp at the current engine conditions
655 double time_constant; // The time constant for the differential equation
658 target_oil_temp = 363;
659 time_constant = 500; // Time constant for engine-on idling.
660 if (Percentage_Power > idle_percentage_power) {
661 time_constant /= ((Percentage_Power / idle_percentage_power) / 10.0); // adjust for power
664 target_oil_temp = 298;
665 time_constant = 1000; // Time constant for engine-off; reflects the fact
666 // that oil is no longer getting circulated
669 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
671 OilTemp_degK += (dOilTempdt * dt);
674 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
676 * Calculate the oil pressure.
680 * Outputs: OilPressure_psi
683 void FGPiston::doOilPressure(void)
685 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
686 double Oil_Press_RPM_Max = 1800; // FIXME: may vary by engine
687 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
688 double Oil_Viscosity_Index = 0.25;
690 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
692 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
693 OilPressure_psi = Oil_Press_Relief_Valve;
696 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index;
699 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701 string FGPiston::GetEngineLabels(void)
703 std::ostringstream buf;
705 buf << Name << "_PwrAvail[" << EngineNumber << "], "
706 << Thruster->GetThrusterLabels(EngineNumber);
711 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
713 string FGPiston::GetEngineValues(void)
715 std::ostringstream buf;
717 buf << PowerAvailable << ", " << Thruster->GetThrusterValues(EngineNumber);
722 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
724 // The bitmasked value choices are as follows:
725 // unset: In this case (the default) JSBSim would only print
726 // out the normally expected messages, essentially echoing
727 // the config files as they are read. If the environment
728 // variable is not set, debug_lvl is set to 1 internally
729 // 0: This requests JSBSim not to output any messages
731 // 1: This value explicity requests the normal JSBSim
733 // 2: This value asks for a message to be printed out when
734 // a class is instantiated
735 // 4: When this value is set, a message is displayed when a
736 // FGModel object executes its Run() method
737 // 8: When this value is set, various runtime state variables
738 // are printed out periodically
739 // 16: When set various parameters are sanity checked and
740 // a message is printed out when they go out of bounds
742 void FGPiston::Debug(int from)
744 if (debug_lvl <= 0) return;
746 if (debug_lvl & 1) { // Standard console startup message output
747 if (from == 0) { // Constructor
749 cout << "\n Engine Name: " << Name << endl;
750 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
751 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
752 cout << " Displacement: " << Displacement << endl;
753 cout << " MaxHP: " << MaxHP << endl;
754 cout << " Cycles: " << Cycles << endl;
755 cout << " IdleRPM: " << IdleRPM << endl;
756 cout << " MaxThrottle: " << MaxThrottle << endl;
757 cout << " MinThrottle: " << MinThrottle << endl;
760 cout << " Combustion Efficiency table:" << endl;
761 Lookup_Combustion_Efficiency->Print();
765 cout << " Power Mixture Correlation table:" << endl;
766 Power_Mixture_Correlation->Print();
771 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
772 if (from == 0) cout << "Instantiated: FGPiston" << endl;
773 if (from == 1) cout << "Destroyed: FGPiston" << endl;
775 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
777 if (debug_lvl & 8 ) { // Runtime state variables
779 if (debug_lvl & 16) { // Sanity checking
781 if (debug_lvl & 64) {
782 if (from == 0) { // Constructor
783 cout << IdSrc << endl;
784 cout << IdHdr << endl;
790 FGPiston::CalcFuelNeed(void)
792 return FuelFlow_gph / 3600 * 6 * State->Getdt() * Propulsion->GetRate();
795 } // namespace JSBSim