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;
105 for (i=0; i<FG_MAX_BOOST_SPEEDS-1; i++) {
106 BoostSwitchAltitude[i] = 0.0;
107 BoostSwitchPressure[i] = 0.0;
111 volumetric_efficiency = 0.8; // Actually f(speed, load) but this will get us running
113 // First column is thi, second is neta (combustion efficiency)
114 Lookup_Combustion_Efficiency = new FGTable(12);
115 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
116 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
117 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
118 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
119 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
120 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
121 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
122 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
123 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
124 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
125 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
126 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
128 Power_Mixture_Correlation = new FGTable(13);
129 *Power_Mixture_Correlation << (14.7/1.6) << 78.0;
130 *Power_Mixture_Correlation << 10 << 86.0;
131 *Power_Mixture_Correlation << 11 << 93.5;
132 *Power_Mixture_Correlation << 12 << 98.0;
133 *Power_Mixture_Correlation << 13 << 100.0;
134 *Power_Mixture_Correlation << 14 << 99.0;
135 *Power_Mixture_Correlation << 15 << 96.4;
136 *Power_Mixture_Correlation << 16 << 92.5;
137 *Power_Mixture_Correlation << 17 << 88.0;
138 *Power_Mixture_Correlation << 18 << 83.0;
139 *Power_Mixture_Correlation << 19 << 78.5;
140 *Power_Mixture_Correlation << 20 << 74.0;
141 *Power_Mixture_Correlation << (14.7/0.6) << 58;
143 Name = Eng_cfg->GetValue("NAME");
144 Eng_cfg->GetNextConfigLine();
145 while (Eng_cfg->GetValue() != string("/FG_PISTON")) {
147 if (token == "MINMP") *Eng_cfg >> MinManifoldPressure_inHg;
148 else if (token == "MAXMP") *Eng_cfg >> MaxManifoldPressure_inHg;
149 else if (token == "DISPLACEMENT") *Eng_cfg >> Displacement;
150 else if (token == "MAXHP") *Eng_cfg >> MaxHP;
151 else if (token == "CYCLES") *Eng_cfg >> Cycles;
152 else if (token == "IDLERPM") *Eng_cfg >> IdleRPM;
153 else if (token == "MAXTHROTTLE") *Eng_cfg >> MaxThrottle;
154 else if (token == "MINTHROTTLE") *Eng_cfg >> MinThrottle;
155 else if (token == "NUMBOOSTSPEEDS") *Eng_cfg >> BoostSpeeds;
156 else if (token == "BOOSTOVERRIDE") *Eng_cfg >> BoostOverride;
157 else if (token == "TAKEOFFBOOST") *Eng_cfg >> TakeoffBoost;
158 else if (token == "RATEDBOOST1") *Eng_cfg >> RatedBoost[0];
159 else if (token == "RATEDBOOST2") *Eng_cfg >> RatedBoost[1];
160 else if (token == "RATEDBOOST3") *Eng_cfg >> RatedBoost[2];
161 else if (token == "RATEDPOWER1") *Eng_cfg >> RatedPower[0];
162 else if (token == "RATEDPOWER2") *Eng_cfg >> RatedPower[1];
163 else if (token == "RATEDPOWER3") *Eng_cfg >> RatedPower[2];
164 else if (token == "RATEDRPM1") *Eng_cfg >> RatedRPM[0];
165 else if (token == "RATEDRPM2") *Eng_cfg >> RatedRPM[1];
166 else if (token == "RATEDRPM3") *Eng_cfg >> RatedRPM[2];
167 else if (token == "RATEDALTITUDE1") *Eng_cfg >> RatedAltitude[0];
168 else if (token == "RATEDALTITUDE2") *Eng_cfg >> RatedAltitude[1];
169 else if (token == "RATEDALTITUDE3") *Eng_cfg >> RatedAltitude[2];
170 else cerr << "Unhandled token in Engine config file: " << token << endl;
173 minMAP = MinManifoldPressure_inHg * 3376.85; // inHg to Pa
174 maxMAP = MaxManifoldPressure_inHg * 3376.85;
176 // Set up and sanity-check the turbo/supercharging configuration based on the input values.
177 if(TakeoffBoost > RatedBoost[0]) bTakeoffBoost = true;
178 for(i=0; i<BoostSpeeds; ++i) {
180 if(RatedBoost[i] <= 0.0) bad = true;
181 if(RatedPower[i] <= 0.0) bad = true;
182 if(RatedAltitude[i] < 0.0) bad = true; // 0.0 is deliberately allowed - this corresponds to unregulated supercharging.
183 if(i > 0 && RatedAltitude[i] < RatedAltitude[i - 1]) bad = true;
185 // We can't recover from the above - don't use this supercharger speed.
187 // TODO - put out a massive error message!
190 // Now sanity-check stuff that is recoverable.
191 if(i < BoostSpeeds - 1) {
192 if(BoostSwitchAltitude[i] < RatedAltitude[i]) {
193 // TODO - put out an error message
194 // But we can also make a reasonable estimate, as below.
195 BoostSwitchAltitude[i] = RatedAltitude[i] + 1000;
197 BoostSwitchPressure[i] = Atmosphere->GetPressure(BoostSwitchAltitude[i]) * 47.88;
198 //cout << "BoostSwitchAlt = " << BoostSwitchAltitude[i] << ", pressure = " << BoostSwitchPressure[i] << '\n';
199 // Assume there is some hysteresis on the supercharger gear switch, and guess the value for now
200 BoostSwitchHysteresis = 1000;
202 // Now work out the supercharger pressure multiplier of this speed from the rated boost and altitude.
203 RatedMAP[i] = Atmosphere->GetPressureSL() * 47.88 + RatedBoost[i] * 6895; // psf*47.88 = Pa, psi*6895 = Pa.
204 // Sometimes a separate BCV setting for takeoff or extra power is fitted.
205 if(TakeoffBoost > RatedBoost[0]) {
206 // Assume that the effect on the BCV is the same whichever speed is in use.
207 TakeoffMAP[i] = RatedMAP[i] + ((TakeoffBoost - RatedBoost[0]) * 6895);
208 bTakeoffBoost = true;
210 TakeoffMAP[i] = RatedMAP[i];
211 bTakeoffBoost = false;
213 BoostMul[i] = RatedMAP[i] / (Atmosphere->GetPressure(RatedAltitude[i]) * 47.88);
215 // TODO - get rid of the debugging output before sending it to Jon
216 //cout << "Speed " << i+1 << '\n';
217 //cout << "BoostMul = " << BoostMul[i] << ", RatedMAP = " << RatedMAP[i] << ", TakeoffMAP = " << TakeoffMAP[i] << '\n';
220 if(BoostSpeeds > 0) {
224 bBoostOverride = (BoostOverride == 1 ? true : false);
226 //cout << "Engine is " << (Boosted ? "supercharged" : "naturally aspirated") << '\n';
228 Debug(0); // Call Debug() routine from constructor if needed
231 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 FGPiston::~FGPiston()
235 Debug(1); // Call Debug() routine from constructor if needed
238 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 double FGPiston::Calculate(void)
242 if (FuelFlow_gph > 0.0) ConsumeFuel();
244 Throttle = FCS->GetThrottlePos(EngineNumber);
245 Mixture = FCS->GetMixturePos(EngineNumber);
251 p_amb = Atmosphere->GetPressure() * 47.88; // convert from lbs/ft2 to Pa
252 p_amb_sea_level = Atmosphere->GetPressureSL() * 47.88;
253 T_amb = Atmosphere->GetTemperature() * (5.0 / 9.0); // convert from Rankine to Kelvin
255 RPM = Thruster->GetRPM() * Thruster->GetGearRatio();
257 IAS = Auxiliary->GetVcalibratedKTS();
260 if(Boosted) doBoostControl();
265 //Now that the fuel flow is done check if the mixture is too lean to run the engine
266 //Assume lean limit at 22 AFR for now - thats a thi of 0.668
267 //This might be a bit generous, but since there's currently no audiable warning of impending
268 //cutout in the form of misfiring and/or rough running its probably reasonable for now.
269 if (equivalence_ratio < 0.668)
278 if (Thruster->GetType() == FGThruster::ttPropeller) {
279 ((FGPropeller*)Thruster)->SetAdvance(FCS->GetPropAdvance(EngineNumber));
282 PowerAvailable = (HP * hptoftlbssec) - Thruster->GetPowerRequired();
284 return Thrust = Thruster->Calculate(PowerAvailable);
287 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
289 * Start or stop the engine.
292 void FGPiston::doEngineStartup(void)
294 // Check parameters that may alter the operating state of the engine.
295 // (spark, fuel, starter motor etc)
300 Magneto_Left = false;
301 Magneto_Right = false;
302 // Magneto positions:
311 } // neglects battery voltage, master on switch, etc for now.
313 if ((Magnetos == 1) || (Magnetos > 2)) Magneto_Left = true;
314 if (Magnetos > 1) Magneto_Right = true;
316 // Assume we have fuel for now
319 // Check if we are turning the starter motor
320 if (Cranking != Starter) {
321 // This check saves .../cranking from getting updated every loop - they
322 // only update when changed.
327 if (Cranking) crank_counter++; //Check mode of engine operation
329 if (!Running && spark && fuel) { // start the engine if revs high enough
331 if ((RPM > 450) && (crank_counter > 175)) // Add a little delay to startup
332 Running = true; // on the starter
334 if (RPM > 450) // This allows us to in-air start
335 Running = true; // when windmilling
339 // Cut the engine *power* - Note: the engine may continue to
340 // spin if the prop is in a moving airstream
342 if ( Running && (!spark || !fuel) ) Running = false;
344 // Check for stalling (RPM = 0).
348 } else if ((RPM <= 480) && (Cranking)) {
354 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
357 * Calculate the Current Boost Speed
359 * This function calculates the current turbo/supercharger boost speed
360 * based on altitude and the (automatic) boost-speed control valve configuration.
362 * Inputs: p_amb, BoostSwitchPressure, BoostSwitchHysteresis
364 * Outputs: BoostSpeed
367 void FGPiston::doBoostControl(void)
369 if(BoostSpeed < BoostSpeeds - 1) {
370 // Check if we need to change to a higher boost speed
371 if(p_amb < BoostSwitchPressure[BoostSpeed] - BoostSwitchHysteresis) {
374 } else if(BoostSpeed > 0) {
375 // Check if we need to change to a lower boost speed
376 if(p_amb > BoostSwitchPressure[BoostSpeed - 1] + BoostSwitchHysteresis) {
382 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385 * Calculate the manifold absolute pressure (MAP) in inches hg
387 * This function calculates manifold absolute pressure (MAP)
388 * from the throttle position, turbo/supercharger boost control
389 * system, engine speed and local ambient air density.
391 * TODO: changes in MP should not be instantaneous -- introduce
392 * a lag between throttle changes and MP changes, to allow pressure
393 * to build up or disperse.
395 * Inputs: minMAP, maxMAP, p_amb, Throttle
397 * Outputs: MAP, ManifoldPressure_inHg
400 void FGPiston::doMAP(void)
403 // Naturally aspirated
404 MAP = minMAP + (Throttle * (maxMAP - minMAP));
405 MAP *= p_amb / p_amb_sea_level;
407 // If takeoff boost is fitted, we currently assume the following throttle map:
408 // (In throttle % - actual input is 0 -> 1)
409 // 99 / 100 - Takeoff boost
410 // 96 / 97 / 98 - Rated boost
411 // 0 - 95 - Idle to Rated boost (MinManifoldPressure to MaxManifoldPressure)
412 // In real life, most planes would be fitted with a mechanical 'gate' between
413 // the rated boost and takeoff boost positions.
414 double T = Throttle; // processed throttle value.
415 bool bTakeoffPos = false;
417 if(Throttle > 0.98) {
418 //cout << "Takeoff Boost!!!!\n";
420 } else if(Throttle <= 0.95) {
425 //cout << "Rated Boost!!\n";
429 // Boost the manifold pressure.
430 MAP *= BoostMul[BoostSpeed];
431 // Now clip the manifold pressure to BCV or Wastegate setting.
433 if(MAP > TakeoffMAP[BoostSpeed]) {
434 MAP = TakeoffMAP[BoostSpeed];
437 if(MAP > RatedMAP[BoostSpeed]) {
438 MAP = RatedMAP[BoostSpeed];
443 // rpm < 10 - effectively stopped.
444 // TODO - add a better variation of MAP with engine speed
445 MAP = Atmosphere->GetPressure() * 47.88; // psf to Pa
448 // And set the value in American units as well
449 ManifoldPressure_inHg = MAP / 3376.85;
452 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454 * Calculate the air flow through the engine.
455 * Also calculates ambient air density
456 * (used in CHT calculation for air-cooled engines).
458 * Inputs: p_amb, R_air, T_amb, MAP, Displacement,
459 * RPM, volumetric_efficiency
461 * TODO: Model inlet manifold air temperature.
463 * Outputs: rho_air, m_dot_air
466 void FGPiston::doAirFlow(void)
468 rho_air = p_amb / (R_air * T_amb);
469 double rho_air_manifold = MAP / (R_air * T_amb);
470 double displacement_SI = Displacement * in3tom3;
471 double swept_volume = (displacement_SI * (RPM/60)) / 2;
472 double v_dot_air = swept_volume * volumetric_efficiency;
473 m_dot_air = v_dot_air * rho_air_manifold;
476 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
478 * Calculate the fuel flow into the engine.
480 * Inputs: Mixture, thi_sea_level, p_amb_sea_level, p_amb, m_dot_air
482 * Outputs: equivalence_ratio, m_dot_fuel
485 void FGPiston::doFuelFlow(void)
487 double thi_sea_level = 1.3 * Mixture;
488 equivalence_ratio = thi_sea_level * p_amb_sea_level / p_amb;
489 m_dot_fuel = m_dot_air / 14.7 * equivalence_ratio;
490 FuelFlow_gph = m_dot_fuel
491 * 3600 // seconds to hours
493 / 6.6; // lb to gal_us of kerosene
496 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
498 * Calculate the power produced by the engine.
500 * Currently, the JSBSim propellor model does not allow the
501 * engine to produce enough RPMs to get up to a high horsepower.
502 * When tested with sufficient RPM, it has no trouble reaching
505 * Inputs: ManifoldPressure_inHg, p_amb, p_amb_sea_level, RPM, T_amb,
506 * equivalence_ratio, Cycles, MaxHP
508 * Outputs: Percentage_Power, HP
511 void FGPiston::doEnginePower(void)
514 double T_amb_degF = KelvinToFahrenheit(T_amb);
515 double T_amb_sea_lev_degF = KelvinToFahrenheit(288);
517 // FIXME: this needs to be generalized
518 double ManXRPM; // Convienience term for use in the calculations
520 // Currently a simple linear fit.
521 // The zero crossing is moved up the speed-load range to reduce the idling power.
523 double zeroOffset = (minMAP / 2.0) * (IdleRPM / 2.0);
524 ManXRPM = MAP * (RPM > RatedRPM[BoostSpeed] ? RatedRPM[BoostSpeed] : RPM);
525 // The speed clip in the line above is deliberate.
526 Percentage_Power = ((ManXRPM - zeroOffset) / ((RatedMAP[BoostSpeed] * RatedRPM[BoostSpeed]) - zeroOffset)) * 107.0;
527 Percentage_Power -= 7.0; // Another idle power reduction offset - see line above with 107.
528 if (Percentage_Power < 0.0) Percentage_Power = 0.0;
529 // Note that %power is allowed to go over 100 for boosted powerplants
530 // such as for the BCV-override or takeoff power settings.
531 // TODO - currently no altitude effect (temperature & exhaust back-pressure) modelled
532 // for boosted engines.
534 ManXRPM = ManifoldPressure_inHg * RPM; // Note that inHg must be used for the following correlation.
535 Percentage_Power = (6e-9 * ManXRPM * ManXRPM) + (8e-4 * ManXRPM) - 1.0;
536 Percentage_Power += ((T_amb_sea_lev_degF - T_amb_degF) * 7 /120);
537 if (Percentage_Power < 0.0) Percentage_Power = 0.0;
538 else if (Percentage_Power > 100.0) Percentage_Power = 100.0;
541 double Percentage_of_best_power_mixture_power =
542 Power_Mixture_Correlation->GetValue(14.7 / equivalence_ratio);
544 Percentage_Power *= Percentage_of_best_power_mixture_power / 100.0;
547 HP = Percentage_Power * RatedPower[BoostSpeed] / 100.0;
549 HP = Percentage_Power * MaxHP / 100.0;
554 // Power output when the engine is not running
557 HP = 3.0; // This is a hack to prevent overshooting the idle rpm in
558 // the first time step. It may possibly need to be changed
559 // if the prop model is changed.
560 } else if (RPM < 480) {
561 HP = 3.0 + ((480 - RPM) / 10.0);
562 // This is a guess - would be nice to find a proper starter moter torque curve
567 // Quick hack until we port the FMEP stuff
574 //cout << "Power = " << HP << '\n';
577 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579 * Calculate the exhaust gas temperature.
581 * Inputs: equivalence_ratio, m_dot_fuel, calorific_value_fuel,
582 * Cp_air, m_dot_air, Cp_fuel, m_dot_fuel, T_amb, Percentage_Power
584 * Outputs: combustion_efficiency, ExhaustGasTemp_degK
587 void FGPiston::doEGT(void)
589 double delta_T_exhaust;
590 double enthalpy_exhaust;
591 double heat_capacity_exhaust;
594 if ((Running) && (m_dot_air > 0.0)) { // do the energy balance
595 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
596 enthalpy_exhaust = m_dot_fuel * calorific_value_fuel *
597 combustion_efficiency * 0.33;
598 heat_capacity_exhaust = (Cp_air * m_dot_air) + (Cp_fuel * m_dot_fuel);
599 delta_T_exhaust = enthalpy_exhaust / heat_capacity_exhaust;
600 ExhaustGasTemp_degK = T_amb + delta_T_exhaust;
601 ExhaustGasTemp_degK *= 0.444 + ((0.544 - 0.444) * Percentage_Power / 100.0);
602 } else { // Drop towards ambient - guess an appropriate time constant for now
603 dEGTdt = (298.0 - ExhaustGasTemp_degK) / 100.0;
604 delta_T_exhaust = dEGTdt * dt;
605 ExhaustGasTemp_degK += delta_T_exhaust;
609 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
611 * Calculate the cylinder head temperature.
613 * Inputs: T_amb, IAS, rho_air, m_dot_fuel, calorific_value_fuel,
614 * combustion_efficiency, RPM
616 * Outputs: CylinderHeadTemp_degK
619 void FGPiston::doCHT(void)
625 double arbitary_area = 1.0;
626 double CpCylinderHead = 800.0;
627 double MassCylinderHead = 8.0;
629 double temperature_difference = CylinderHeadTemp_degK - T_amb;
630 double v_apparent = IAS * 0.5144444;
631 double v_dot_cooling_air = arbitary_area * v_apparent;
632 double m_dot_cooling_air = v_dot_cooling_air * rho_air;
633 double dqdt_from_combustion =
634 m_dot_fuel * calorific_value_fuel * combustion_efficiency * 0.33;
635 double dqdt_forced = (h2 * m_dot_cooling_air * temperature_difference) +
636 (h3 * RPM * temperature_difference);
637 double dqdt_free = h1 * temperature_difference;
638 double dqdt_cylinder_head = dqdt_from_combustion + dqdt_forced + dqdt_free;
640 double HeatCapacityCylinderHead = CpCylinderHead * MassCylinderHead;
642 CylinderHeadTemp_degK +=
643 (dqdt_cylinder_head / HeatCapacityCylinderHead) * dt;
646 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
648 * Calculate the oil temperature.
650 * Inputs: Percentage_Power, running flag.
652 * Outputs: OilTemp_degK
655 void FGPiston::doOilTemperature(void)
657 double idle_percentage_power = 2.3; // approximately
658 double target_oil_temp; // Steady state oil temp at the current engine conditions
659 double time_constant; // The time constant for the differential equation
662 target_oil_temp = 363;
663 time_constant = 500; // Time constant for engine-on idling.
664 if (Percentage_Power > idle_percentage_power) {
665 time_constant /= ((Percentage_Power / idle_percentage_power) / 10.0); // adjust for power
668 target_oil_temp = 298;
669 time_constant = 1000; // Time constant for engine-off; reflects the fact
670 // that oil is no longer getting circulated
673 double dOilTempdt = (target_oil_temp - OilTemp_degK) / time_constant;
675 OilTemp_degK += (dOilTempdt * dt);
678 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
680 * Calculate the oil pressure.
684 * Outputs: OilPressure_psi
687 void FGPiston::doOilPressure(void)
689 double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine
690 double Oil_Press_RPM_Max = 1800; // FIXME: may vary by engine
691 double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine
692 double Oil_Viscosity_Index = 0.25;
694 OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM;
696 if (OilPressure_psi >= Oil_Press_Relief_Valve) {
697 OilPressure_psi = Oil_Press_Relief_Valve;
700 OilPressure_psi += (Design_Oil_Temp - OilTemp_degK) * Oil_Viscosity_Index;
703 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
705 string FGPiston::GetEngineLabels(string delimeter)
707 std::ostringstream buf;
709 buf << Name << "_PwrAvail[" << EngineNumber << "]" << delimeter
710 << Name << "_HP[" << EngineNumber << "]" << delimeter
711 << Name << "_equiv_ratio[" << EngineNumber << "]" << delimeter
712 << Name << "_MAP[" << EngineNumber << "]" << delimeter
713 << Thruster->GetThrusterLabels(EngineNumber, delimeter);
718 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
720 string FGPiston::GetEngineValues(string delimeter)
722 std::ostringstream buf;
724 buf << PowerAvailable << delimeter << HP << delimeter
725 << equivalence_ratio << delimeter << MAP << delimeter
726 << Thruster->GetThrusterValues(EngineNumber, delimeter);
731 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733 // The bitmasked value choices are as follows:
734 // unset: In this case (the default) JSBSim would only print
735 // out the normally expected messages, essentially echoing
736 // the config files as they are read. If the environment
737 // variable is not set, debug_lvl is set to 1 internally
738 // 0: This requests JSBSim not to output any messages
740 // 1: This value explicity requests the normal JSBSim
742 // 2: This value asks for a message to be printed out when
743 // a class is instantiated
744 // 4: When this value is set, a message is displayed when a
745 // FGModel object executes its Run() method
746 // 8: When this value is set, various runtime state variables
747 // are printed out periodically
748 // 16: When set various parameters are sanity checked and
749 // a message is printed out when they go out of bounds
751 void FGPiston::Debug(int from)
753 if (debug_lvl <= 0) return;
755 if (debug_lvl & 1) { // Standard console startup message output
756 if (from == 0) { // Constructor
758 cout << "\n Engine Name: " << Name << endl;
759 cout << " MinManifoldPressure: " << MinManifoldPressure_inHg << endl;
760 cout << " MaxManifoldPressure: " << MaxManifoldPressure_inHg << endl;
761 cout << " Displacement: " << Displacement << endl;
762 cout << " MaxHP: " << MaxHP << endl;
763 cout << " Cycles: " << Cycles << endl;
764 cout << " IdleRPM: " << IdleRPM << endl;
765 cout << " MaxThrottle: " << MaxThrottle << endl;
766 cout << " MinThrottle: " << MinThrottle << endl;
769 cout << " Combustion Efficiency table:" << endl;
770 Lookup_Combustion_Efficiency->Print();
774 cout << " Power Mixture Correlation table:" << endl;
775 Power_Mixture_Correlation->Print();
780 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
781 if (from == 0) cout << "Instantiated: FGPiston" << endl;
782 if (from == 1) cout << "Destroyed: FGPiston" << endl;
784 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
786 if (debug_lvl & 8 ) { // Runtime state variables
788 if (debug_lvl & 16) { // Sanity checking
790 if (debug_lvl & 64) {
791 if (from == 0) { // Constructor
792 cout << IdSrc << endl;
793 cout << IdHdr << endl;
799 FGPiston::CalcFuelNeed(void)
801 return FuelFlow_gph / 3600 * 6 * State->Getdt() * Propulsion->GetRate();
804 } // namespace JSBSim