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.
43 // Just run it for an hour, there's no need to iterate given the
48 void Jet::setMaxThrust(float thrust, float afterburner)
51 if(afterburner == 0) _abFactor = 1;
52 else _abFactor = afterburner/thrust;
55 void Jet::setVMax(float spd)
60 void Jet::setTSFC(float tsfc)
65 void Jet::setRPMs(float idleN1, float maxN1, float idleN2, float maxN2)
73 void Jet::setEGT(float takeoffEGT)
78 void Jet::setEPR(float takeoffEPR)
83 void Jet::setSpooling(float time)
85 // 2.3 = -ln(0.1), i.e. x=2.3 is the 90% point we're defining
86 // The extra fudge factor is there because the N1 speed (which
87 // determines thrust) lags the N2 speed.
88 _decay = 1.5 * 2.3 / time;
91 void Jet::setVectorAngle(float angle)
96 void Jet::setReheat(float reheat)
98 _reheat = Math::clamp(reheat, 0, 1);
101 void Jet::setRotation(float rot)
110 return _n1 * _tempCorrect;
115 return _n2 * _tempCorrect;
125 // Exactly zero means "off" -- return the ambient temperature
126 if(_egt == 0) return _temp;
128 return _egt * _tempCorrect * _tempCorrect;
131 float Jet::getFuelFlow()
133 return _fuelFlow * _pressureCorrect;
136 void Jet::integrate(float dt)
139 const static float P0 = Atmosphere::getStdPressure(0);
140 const static float T0 = Atmosphere::getStdTemperature(0);
141 const static float D0 = Atmosphere::getStdDensity(0);
143 float speed = -Math::dot3(_wind, _dir);
145 float statT, statP, statD;
146 Atmosphere::calcStaticAir(_pressure, _temp, _rho, speed,
147 &statP, &statT, &statD);
148 _pressureCorrect = statP/P0;
149 _tempCorrect = Math::sqrt(statT/T0);
151 // Linearly taper maxThrust to zero at vMax
152 float vCorr = 1 - (speed/_vMax);
154 float maxThrust = _maxThrust * vCorr * (statD/D0);
155 _thrust = maxThrust * _throttle;
157 // Now get a "beta" (i.e. EPR - 1) value. The output values are
158 // expressed as functions of beta.
159 float ibeta0 = 1/(_epr0 - 1);
160 float betaTarget = (_epr0 - 1) * (_thrust/_maxThrust) * (P0/_pressure)
162 float n2Target = _n2Min + (betaTarget*ibeta0) * (_n2Max - _n2Min);
164 // Note that this "first" beta value is used to compute a target
165 // for N2 only Integrate the N2 speed and back-calculate a beta1
166 // target. The N1 speed will seek to this.
167 _n2 = (_n2 + dt*_decay * n2Target) / (1 + dt*_decay);
169 float betaN2 = (_epr0-1) * (_n2 - _n2Min) / (_n2Max - _n2Min);
170 float n1Target = _n1Min + betaN2*ibeta0 * (_n1Max - _n1Min);
171 _n1 = (_n1 + dt*_decay * n1Target) / (1 + dt*_decay);
173 // The actual thrust produced is keyed to the N1 speed. Add the
174 // afterburners in at the end.
175 float betaN1 = (_epr0-1) * (_n1 - _n1Min) / (_n1Max - _n1Min);
176 _thrust *= betaN1/(betaTarget+.00001); // blowup protection
177 _thrust *= 1 + _reheat*(_abFactor-1);
179 // Finally, calculate the output variables. Use a 80/20 mix of
180 // the N2/N1 speeds as the key.
181 float beta = 0.8*betaN2 + 0.2*betaN1;
183 float ff0 = _maxThrust*_tsfc*(1/(3600*9.8)); // takeoff fuel flow, kg/s
184 _fuelFlow = ff0 * beta*ibeta0;
185 _fuelFlow *= 1 + (3.5 * _reheat * _abFactor); // Afterburners take
187 // fuel per thrust unit
188 _egt = T0 + beta*ibeta0 * (_egt0 - T0);
191 bool Jet::isRunning()
196 bool Jet::isCranking()
201 void Jet::getThrust(float* out)
203 Math::mul3(_thrust, _dir, out);
205 // Rotate about the Y axis for thrust vectoring
206 float angle = _rotControl * _maxRot;
207 float s = Math::sin(angle);
208 float c = Math::cos(angle);
210 out[0] = c * o0 + s * out[2];
211 out[2] = -s * o0 + c * out[2];
214 void Jet::getTorque(float* out)
216 out[0] = out[1] = out[2] = 0;
220 void Jet::getGyro(float* out)
222 out[0] = out[1] = out[2] = 0;
226 }; // namespace yasim