]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/TurbineEngine.cpp
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[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     _fuel = true;
39     _n2 = _n2Target;
40     setOutputFromN2();
41 }
42
43 void TurbineEngine::integrate(float dt)
44 {
45     // Low-pass the N2 speed to give a realistic spooling time.  See
46     // the notes in Jet::setSpooling() for details; this corresponds
47     // to a hard-coded spool time of 2 seconds.
48     const float DECAY = 1.15;
49     _n2 = (_n2 + dt * DECAY * _n2Target)/(1 + dt * DECAY);
50     setOutputFromN2();
51 }
52
53 void TurbineEngine::calc(float pressure, float temp, float omega)
54 {
55     _running = _fuel && _cond_lever > 0.001;
56
57     _n2Min = _n2LowIdle + (_n2HighIdle - _n2LowIdle) * _cond_lever;
58     _omega = omega;
59     _rho = Atmosphere::calcStdDensity(pressure, temp);
60
61     float torque = _throttle * _maxTorque * _rho / _rho0;
62     float power = torque * omega;
63     if(power > _flatRating)
64         torque = _flatRating / omega;
65
66     float frac = torque / (_maxTorque * (_rho / _rho0));
67
68     _n2Target = _running ? _n2Min + (_n2Max - _n2Min) * frac : 0;
69 }
70
71 }; // namespace yasim