1 #include "Atmosphere.hpp"
14 // Initialize parameters for an early-ish subsonic turbojet. More
15 // recent turbofans will typically have a lower vMax, epr0, and
25 setSpooling(4); // 4 second spool time? s'bout right.
27 // And initialize to an engine that is idling
31 // And sanify the remaining junk, just in case.
41 // Just run it for an hour, there's no need to iterate given the
46 void Jet::setMaxThrust(float thrust, float afterburner)
49 if(afterburner == 0) _abFactor = 1;
50 else _abFactor = afterburner/thrust;
53 void Jet::setVMax(float spd)
58 void Jet::setTSFC(float tsfc)
63 void Jet::setRPMs(float idleN1, float maxN1, float idleN2, float maxN2)
71 void Jet::setEGT(float takeoffEGT)
76 void Jet::setEPR(float takeoffEPR)
81 void Jet::setSpooling(float time)
83 // 2.3 = -ln(0.1), i.e. x=2.3 is the 90% point we're defining
84 // The extra fudge factor is there because the N1 speed (which
85 // determines thrust) lags the N2 speed.
86 _decay = 1.5 * 2.3 / time;
89 void Jet::setVectorAngle(float angle)
94 void Jet::setReheat(float reheat)
96 _reheat = Math::clamp(reheat, 0, 1);
99 void Jet::setRotation(float rot)
109 return _n1 * _tempCorrect;
114 return _n2 * _tempCorrect;
124 // Exactly zero means "off" -- return the ambient temperature
125 if(_egt == 0) return _temp;
127 return _egt * _tempCorrect * _tempCorrect;
130 float Jet::getFuelFlow()
132 return _fuelFlow * _pressureCorrect;
135 void Jet::integrate(float dt)
138 const static float P0 = Atmosphere::getStdPressure(0);
139 const static float T0 = Atmosphere::getStdTemperature(0);
140 const static float D0 = Atmosphere::getStdDensity(0);
142 float speed = -Math::dot3(_wind, _dir);
144 float statT, statP, statD;
145 Atmosphere::calcStaticAir(_pressure, _temp, _rho, speed,
146 &statP, &statT, &statD);
147 _pressureCorrect = statP/P0;
148 _tempCorrect = Math::sqrt(statT/T0);
150 // Linearly taper maxThrust to zero at vMax
151 float vCorr = 1 - (speed/_vMax);
153 float maxThrust = _maxThrust * vCorr * (statD/D0);
154 _thrust = maxThrust * _throttle;
156 // Now get a "beta" (i.e. EPR - 1) value. The output values are
157 // expressed as functions of beta.
158 float ibeta0 = 1/(_epr0 - 1);
159 float betaTarget = (_epr0 - 1) * (_thrust/_maxThrust) * (P0/_pressure)
161 float n2Target = _n2Min + (betaTarget*ibeta0) * (_n2Max - _n2Min);
163 // Note that this "first" beta value is used to compute a target
164 // for N2 only Integrate the N2 speed and back-calculate a beta1
165 // target. The N1 speed will seek to this.
166 _n2 = (_n2 + dt*_decay * n2Target) / (1 + dt*_decay);
168 float betaN2 = (_epr0-1) * (_n2 - _n2Min) / (_n2Max - _n2Min);
169 float n1Target = _n1Min + betaN2*ibeta0 * (_n1Max - _n1Min);
170 _n1 = (_n1 + dt*_decay * n1Target) / (1 + dt*_decay);
172 // The actual thrust produced is keyed to the N1 speed. Add the
173 // afterburners in at the end.
174 float betaN1 = (_epr0-1) * (_n1 - _n1Min) / (_n1Max - _n1Min);
175 _thrust *= betaN1/(betaTarget+.00001); // blowup protection
176 _thrust *= 1 + _reheat*(_abFactor-1);
178 // Finally, calculate the output variables. Use a 80/20 mix of
179 // the N2/N1 speeds as the key.
180 float beta = 0.8*betaN2 + 0.2*betaN1;
182 float ff0 = _maxThrust*_tsfc*(1/(3600*9.8)); // takeoff fuel flow, kg/s
183 _fuelFlow = ff0 * beta*ibeta0;
184 _fuelFlow *= 1 + (3.5 * _reheat * _abFactor); // Afterburners take
186 // fuel per thrust unit
187 _egt = T0 + beta*ibeta0 * (_egt0 - T0);
190 void Jet::getThrust(float* out)
192 Math::mul3(_thrust, _dir, out);
194 // Rotate about the Y axis for thrust vectoring
195 float angle = _rotControl * _maxRot;
196 float s = Math::sin(angle);
197 float c = Math::cos(angle);
199 out[0] = c * o0 + s * out[2];
200 out[2] = -s * o0 + c * out[2];
203 void Jet::getTorque(float* out)
205 out[0] = out[1] = out[2] = 0;
209 void Jet::getGyro(float* out)
211 out[0] = out[1] = out[2] = 0;
215 }; // namespace yasim