]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/TurbineEngine.cpp
Initial checkin of a TurbineEngine implementation. This hasn't been
[flightgear.git] / src / FDM / YASim / TurbineEngine.cpp
1 #include "Atmosphere.hpp"
2
3 #include "TurbineEngine.hpp"
4
5 namespace yasim {
6
7 TurbineEngine::TurbineEngine(float power, float omega, float alt,
8                              float flatRating)
9 {
10     _rho0 = Atmosphere::getStdDensity(0);
11     _maxTorque = (power/omega) * _rho0 / Atmosphere::getStdDensity(alt);
12     _flatRating = flatRating;
13     _bsfc = 0.047; // == 0.5 lb/hr per hp
14     _n2Min = 65;
15     _n2Max = 100;
16
17     _rho = _rho0;
18     _omega = 0;
19     _n2 = _n2Target = _n2Min;
20     _torque = 0;
21     _fuelFlow = 0;
22 }
23
24 void TurbineEngine::setOutputFromN2()
25 {
26     float frac = (_n2 - _n2Min) / (_n2Max - _n2Min);
27     _torque = frac * _maxTorque * (_rho / _rho0);
28     _fuelFlow = _bsfc * _torque * _omega;
29 }
30
31 void TurbineEngine::stabilize()
32 {
33     _n2 = _n2Target;
34     setOutputFromN2();
35 }
36
37 void TurbineEngine::integrate(float dt)
38 {
39     // Low-pass the N2 speed to give a realistic spooling time.  See
40     // the notes in Jet::setSpooling() for details; this corresponds
41     // to a hard-coded spool time of 2 seconds.
42     const float DECAY = 1.15;
43     _n2 = (_n2 + dt * DECAY * _n2Target)/(1 + dt * DECAY);
44     setOutputFromN2();
45 }
46
47 void TurbineEngine::calc(float pressure, float temp, float omega)
48 {
49     _omega = omega;
50     _rho = Atmosphere::calcStdDensity(pressure, temp);
51
52     float torque = _throttle * _maxTorque * _rho / _rho0;
53     float power = torque * omega;
54     if(power > _flatRating)
55         torque = _flatRating / omega;
56
57     float frac = torque / (_maxTorque * (_rho / _rho0));
58     _n2Target = _n2Min + (_n2Max - _n2Min) * frac;
59 }
60
61 }; // namespace yasim