]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/PistonEngine.cpp
Initial revision of Andy Ross's YASim code. This is (Y)et (A)nother Flight
[flightgear.git] / src / FDM / YASim / PistonEngine.cpp
1 #include "PistonEngine.hpp"
2 namespace yasim {
3
4 PistonEngine::PistonEngine(float power, float speed)
5 {
6     // Presume a BSFC (in lb/hour per HP) of 0.45.  In SI that becomes
7     // (2.2 lb/kg, 745.7 W/hp, 3600 sec/hour) 3.69e-07 kg/Ws.
8     _f0 = power * 3.69e-07;
9
10     _P0 = power;
11     _omega0 = speed;
12
13     // We must be at sea level under standard conditions
14     _rho0 = 1.225; // kg/m^3
15
16     // Further presume that takeoff is (duh) full throttle and
17     // peak-power, that means that by our efficiency function, we are
18     // at 11/8 of "ideal" fuel flow.
19     float realFlow = _f0 * (11.0/8.0);
20     _mixCoeff = realFlow * 1.1 / _omega0;
21 }
22
23 void PistonEngine::setThrottle(float t)
24 {
25     _throttle = t;
26 }
27
28 void PistonEngine::setMixture(float m)
29 {
30     _mixture = m;
31 }
32
33 void PistonEngine::calc(float density, float speed,
34                         float* torqueOut, float* fuelFlowOut)
35 {
36     // The actual fuel flow
37     float fuel = _mixture * _mixCoeff * speed;
38
39     // manifold air density
40     float rho = density * _throttle;
41
42     // How much fuel could be burned with ideal (i.e. uncorrected!)
43     // combustion.
44     float burnable = _f0 * (rho/_rho0) * (speed/_omega0);
45
46     // Calculate the fuel that actually burns to produce work.  The
47     // idea is that less than 5/8 of ideal, we get complete
48     // combustion.  We use up all the oxygen at 1 3/8 of ideal (that
49     // is, you need to waste fuel to use all your O2).  In between,
50     // interpolate.  This vaguely matches a curve I copied out of a
51     // book for a single engine.  Shrug.
52     float burned;
53     float r = fuel/burnable;
54     if     (burnable == 0) burned = 0;
55     else if(r < .625)      burned = fuel;
56     else if(r > 1.375)     burned = burnable;
57     else                   burned = fuel + (burnable-fuel)*(r-.625)*(4.0/3.0);
58
59     // And finally the power is just the reference power scaled by the
60     // amount of fuel burned.
61     float power = _P0 * burned/_f0;
62
63     *torqueOut = power/speed;
64     *fuelFlowOut = fuel;
65 }
66
67 }; // namespace yasim