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