]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/TurbineEngine.cpp
Oops, typo.
[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     _cond_lever = 1.0;
11
12     _rho0 = Atmosphere::getStdDensity(0);
13     _maxTorque = (power/omega) * _rho0 / Atmosphere::getStdDensity(alt);
14     _flatRating = flatRating;
15     _bsfc = 8.47e-08; // in kg/s per watt == 0.5 lb/hr per hp
16     _n2LowIdle = 50;
17     _n2HighIdle = 70;
18     _n2Max = 100;
19
20     _rho = _rho0;
21     _omega = 0;
22     _n2 = _n2Target = _n2Min = _n2LowIdle;
23     _torque = 0;
24     _fuelFlow = 0;
25
26     _running = true;
27 }
28
29 void TurbineEngine::setOutputFromN2()
30 {
31     float frac = (_n2 - _n2Min) / (_n2Max - _n2Min);
32     _torque = frac * _maxTorque * (_rho / _rho0);
33     _fuelFlow = _running ? _bsfc * _torque * _omega : 0;
34 }
35
36 void TurbineEngine::stabilize()
37 {
38     _n2 = _n2Target;
39     setOutputFromN2();
40 }
41
42 void TurbineEngine::integrate(float dt)
43 {
44     // Low-pass the N2 speed to give a realistic spooling time.  See
45     // the notes in Jet::setSpooling() for details; this corresponds
46     // to a hard-coded spool time of 2 seconds.
47     const float DECAY = 1.15;
48     _n2 = (_n2 + dt * DECAY * _n2Target)/(1 + dt * DECAY);
49     setOutputFromN2();
50 }
51
52 void TurbineEngine::calc(float pressure, float temp, float omega)
53 {
54     _running = _fuel && _cond_lever > 0.001;
55
56     _n2Min = _n2LowIdle + (_n2HighIdle - _n2LowIdle) * _cond_lever;
57     _omega = omega;
58     _rho = Atmosphere::calcStdDensity(pressure, temp);
59
60     float torque = _throttle * _maxTorque * _rho / _rho0;
61     float power = torque * omega;
62     if(power > _flatRating)
63         torque = _flatRating / omega;
64
65     float frac = torque / (_maxTorque * (_rho / _rho0));
66
67     _n2Target = _running ? _n2Min + (_n2Max - _n2Min) * frac : 0;
68 }
69
70 }; // namespace yasim