-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturbineengine.py
More file actions
444 lines (393 loc) · 14.7 KB
/
turbineengine.py
File metadata and controls
444 lines (393 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import standardatmosphere as statm
import isentropic as isen
from copy import copy
class Fluid:
"""
An object that describes the working fluid.
"""
def __init__(
this,
machNumber: float,
gammaCold: float,
gammaHot: float,
cpCold: float,
cpHot: float,
altitude: float,
massFlowRate: float,
) -> None:
"""
machNumber -> unitless | gammaCold -> unitless | gammaHot -> unitless | cpCold -> J/(kg.K) | cpHot -> J/(kg.K) | altitude -> m | massFlowRate -> kg/s
"""
this.machNumber = machNumber
this.gammaCold = gammaCold
this.gammaHot = gammaHot
this.cpCold = cpCold
this.cpHot = cpHot
this.altitude = altitude
atmosphere = statm.findStandardAtmosphere(altitude)
this.isentropicRatios = isen.findIsentropicRatios(machNumber)
this.atmosphericPressure = atmosphere[0]
this.atmosphericTemperature = atmosphere[2]
this.totalAtmosphericPressure = atmosphere[0] * this.isentropicRatios[0]
this.totalAtmosphericTemperature = atmosphere[2] * this.isentropicRatios[2]
this.totalPressure = this.totalAtmosphericPressure
this.totalTemperature = this.totalAtmosphericTemperature
this.massFlowRate = massFlowRate
this.massFuelFlowRate = 0
this.bypassMassFlowRate = 0
this.work = {}
this.initialVelocity = (
this.machNumber
* (this.gammaCold * this.rCold * this.atmosphericTemperature) ** 0.5
)
this.finalVelocity = 0
this.bypassFinalVelocity = 0
def get_rCold(this):
return this.cpCold * (this.gammaCold - 1) / this.gammaCold
rCold = property(get_rCold)
def get_rHot(this):
return this.cpHot * (this.gammaHot - 1) / this.gammaHot
rHot = property(get_rHot)
def get_pressure(this):
return this.totalPressure / this.isentropicRatios[0]
pressure = property(get_pressure)
def GetPressure(this, totalPressure: float, mach: float, hot=True):
if hot:
k = this.gammaHot
else:
k = this.gammaCold
return totalPressure / ((1 + (k - 1) / 2 * mach ** 2) ** (k / (k - 1)))
def GetTemperature(this, totalTemperature: float, mach: float, hot=True):
if hot:
k = this.gammaHot
else:
k = this.gammaCold
return totalTemperature / (1 + (k - 1) / 2 * mach ** 2)
def GetDensity(
this, totalPressure: float, totalTemperature: float, mach: float, hot=True
):
if hot:
r = this.rHot
else:
r = this.rCold
return this.GetPressure(totalPressure, mach, hot) / (
r * this.GetTemperature(totalTemperature, mach, hot)
)
class Intake:
"""
An object that models an intake.
"""
def __init__(this) -> None:
pass
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the intake. The intake does not change any of the fluid's properties.
"""
this.fluid = copy(fluid)
return fluid
class NonMixingFan:
"""
An object that models a non-mixing fan.
"""
def __init__(
this,
efficiency: float,
pressureRatio: float,
bypassRatio: float,
bypassDuctTotalPressureLoss: float,
) -> None:
"""
efficiency -> unitless | pressureRatio -> unitless | bypassRatio -> unitless | bypassDuctTotalPressureLoss -> unitless
"""
this.efficiency = efficiency
this.pressureRatio = pressureRatio
this.bypassRatio = bypassRatio
this.bypassDuctTotalPressureLoss = bypassDuctTotalPressureLoss
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the fan. Work is done on the fluid increasing pressure and temperature. Some of the fluid mass is bypassed.
"""
pOut = fluid.totalPressure * this.pressureRatio
tOutIdeal = fluid.totalTemperature * (this.pressureRatio) ** (
(fluid.gammaCold - 1) / fluid.gammaCold
)
wIdeal = (
fluid.massFlowRate * fluid.cpCold * (tOutIdeal - fluid.totalTemperature)
)
this.work = wIdeal / this.efficiency
fluid.work[id(this)] = this.work
tOut = fluid.totalTemperature + this.work / (fluid.massFlowRate * fluid.cpCold)
fluid.totalPressure = pOut
fluid.totalTemperature = tOut
fluid.massFlowRate = fluid.massFlowRate / (1 + this.bypassRatio)
fluid.bypassMassFlowRate = fluid.massFlowRate * this.bypassRatio
# Handle the bypass
this.totalPressureBypass = fluid.totalPressure * (
1 - this.bypassDuctTotalPressureLoss
)
pRatioCritical = (1 + (fluid.gammaCold - 1) / 2) ** (
fluid.gammaCold / (fluid.gammaCold - 1)
)
mach = 1
if this.totalPressureBypass / fluid.atmosphericPressure <= pRatioCritical:
# Not choked
this.totalPressureBypass = fluid.totalAtmosphericPressure
mach = (
2
/ (fluid.gammaCold - 1)
* (
(this.totalPressureBypass / fluid.atmosphericPressure)
** ((fluid.gammaCold - 1) / fluid.gammaCold)
- 1
)
) ** (1 / 2)
this.pressureBypass = fluid.GetPressure(this.totalPressureBypass, mach, False)
this.temperatureBypass = fluid.GetTemperature(
fluid.totalTemperature, mach, False
)
fluid.bypassFinalVelocity = mach * (
fluid.gammaCold * fluid.rCold * this.temperatureBypass
) ** (1 / 2)
densityBypass = fluid.GetDensity(
this.totalPressureBypass, fluid.totalTemperature, mach, False
)
this.area = fluid.bypassMassFlowRate / (
densityBypass * fluid.bypassFinalVelocity
)
this.exitMach = mach
this.fluid = copy(fluid)
return fluid
class Compressor:
"""
An object that models a compressor.
"""
def __init__(this, efficiency: float, pressureRatio: float) -> None:
"""
efficiency -> unitless | pressureRatio -> unitless
"""
this.efficiency = efficiency
this.pressureRatio = pressureRatio
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the compressor. Work is done on the fluid increasing pressure and temperature.
"""
pOut = fluid.totalPressure * this.pressureRatio
tOutIdeal = fluid.totalTemperature * (this.pressureRatio) ** (
(fluid.gammaCold - 1) / fluid.gammaCold
)
wIdeal = (
fluid.massFlowRate * fluid.cpCold * (tOutIdeal - fluid.totalTemperature)
)
this.work = wIdeal / this.efficiency
fluid.work[id(this)] = this.work
tOut = fluid.totalTemperature + this.work / (fluid.massFlowRate * fluid.cpCold)
fluid.totalPressure = pOut
fluid.totalTemperature = tOut
this.fluid = copy(fluid)
return fluid
class CombustionChamber:
"""
An object that models a combustion chamber.
"""
def __init__(
this,
efficiency: float,
totalPressureLoss: float,
totalExitTemperature: float,
fuelLowerHeatingValue: float,
) -> None:
"""
efficiency -> unitless | totalPressureLoss -> unitless | totalExitTemperature -> K | fuelLowerHeatingValue -> J/kg
"""
this.efficiency = efficiency
this.totalPressureLoss = totalPressureLoss
this.totalExitTemperature = totalExitTemperature
this.fuelLowerHeatingValue = fuelLowerHeatingValue
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the combustion chamber. Heat is added to the fluid and total pressure is lost. Additional mass flow is added to the fluid from the fuel.
"""
mFuel = (
fluid.massFlowRate
* fluid.cpHot
* (this.totalExitTemperature - fluid.totalTemperature)
/ (
this.efficiency * this.fuelLowerHeatingValue
+ fluid.cpHot * (this.totalExitTemperature - fluid.totalTemperature)
)
)
fluid.massFlowRate += mFuel
fluid.massFuelFlowRate = mFuel
fluid.totalTemperature = this.totalExitTemperature
fluid.totalPressure = fluid.totalPressure * (1 - this.totalPressureLoss)
this.fluid = copy(fluid)
return fluid
class Turbine:
"""
An object that models a turbine.
"""
def __init__(this, efficiency: float, poweredComponent) -> None:
"""
efficiency -> unitless
"""
this.efficiency = efficiency
this.poweredComponentID = id(poweredComponent)
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the turbine. The fluid does work decreasing the total temperature and pressure.
"""
tOut = fluid.totalTemperature - fluid.work[this.poweredComponentID] / (
fluid.massFlowRate * fluid.cpHot
)
tSOut = (
fluid.totalTemperature - (fluid.totalTemperature - tOut) / this.efficiency
)
fluid.totalPressure = fluid.totalPressure * (
tSOut / fluid.totalTemperature
) ** (fluid.gammaHot / (fluid.gammaHot - 1))
fluid.totalTemperature = tOut
this.fluid = copy(fluid)
return fluid
class JetPipe:
"""
An object that models a jet pipe.
"""
def __init__(this) -> None:
pass
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the jet pipe. The jet pipe does not change any of the fluid's properties.
"""
this.fluid = copy(fluid)
return fluid
class ConvergentNozzle:
"""
An object that models a convergent nozzle.
"""
def __init__(this, totalPressureLoss: float) -> None:
"""
totalPressureLoss -> unitless
"""
this.totalPressureLoss = totalPressureLoss
def simulate(this, fluid: Fluid) -> Fluid:
"""
Updates the fluid properties by simulating the convergent nozzle.
"""
pRatioCritical = (1 + (fluid.gammaHot - 1) / 2) ** (
fluid.gammaHot / (fluid.gammaHot - 1)
)
pOut = fluid.totalPressure * (1 - this.totalPressureLoss)
mach = 1
if pOut / fluid.atmosphericPressure <= pRatioCritical:
# Not choked
pOut = fluid.totalAtmosphericPressure
mach = (
2
/ (fluid.gammaHot - 1)
* (
(pOut / fluid.atmosphericPressure)
** ((fluid.gammaHot - 1) / fluid.gammaHot)
- 1
)
) ** (1 / 2)
fluid.totalTemperature = fluid.totalTemperature * (
pOut / fluid.totalPressure
) ** ((fluid.gammaHot - 1) / fluid.gammaHot)
fluid.totalPressure = pOut
fluid.finalVelocity = mach * (
fluid.gammaHot
* fluid.rHot
* fluid.GetTemperature(fluid.totalTemperature, mach)
) ** (0.5)
this.area = fluid.massFlowRate / (
fluid.GetDensity(fluid.totalPressure, fluid.totalTemperature, mach)
* fluid.finalVelocity
)
this.exitMach = mach
this.fluid = copy(fluid)
return fluid
class TurbineEngine:
"""
An object that models a turbine engine made up of any variety of components.
"""
def __init__(
this,
fluid: Fluid,
engineComponents: list,
) -> None:
"""
The parameter engineComponents must be in the order that the fluid flows.
"""
this.fluid = fluid
this.engineComponents = engineComponents
this.thrust = 0
def simulate(this):
for component in this.engineComponents:
this.fluid = component.simulate(this.fluid)
if type(component) is ConvergentNozzle:
this.coreMomentumThrust = (
this.fluid.massFlowRate * this.fluid.finalVelocity
- (this.fluid.massFlowRate - this.fluid.massFuelFlowRate)
* this.fluid.initialVelocity
)
this.corePressureThrust = component.area * (
this.fluid.GetPressure(this.fluid.totalPressure, component.exitMach)
- this.fluid.atmosphericPressure
)
this.thrust += this.coreMomentumThrust + this.corePressureThrust
elif type(component) is NonMixingFan:
this.thrust += this.fluid.bypassMassFlowRate * (
this.fluid.bypassFinalVelocity - this.fluid.initialVelocity
) + component.area * (
component.pressureBypass - this.fluid.atmosphericPressure
)
this.thrustSpecificFuelConsumption = this.fluid.massFuelFlowRate / this.thrust
return copy(this)
class TripleSpoolNonMixingHighBypassTurbofanEngine:
"""
Models a specific Triple-Spool, Non-Mixing, High-Bypass Turbofan Engine
"""
def __init__(
this,
bypassRatio=6,
mach=0.84,
altitude=10000,
lFanPressureRatio=1.5,
iCompPressureRatio=6.5,
lFanEfficiency=0.78,
hCompEfficiency=0.82,
hTurbineEfficiency=0.92,
lTurbineEfficiency=0.88,
) -> None:
# Define the working fluid
fluid = Fluid(mach, 1.4, 1.333, 1005, 1150, altitude, 780)
# Build the engine components
intake = Intake()
lFan = NonMixingFan(lFanEfficiency, lFanPressureRatio, bypassRatio, 0.05)
iCompressor = Compressor(0.8, iCompPressureRatio)
hCompressor = Compressor(hCompEfficiency, 4.2)
combustionChamber = CombustionChamber(0.97, 0.05, 1750, 42.5 * 10 ** 6)
hTurbine = Turbine(hTurbineEfficiency, hCompressor)
iTurbine = Turbine(0.9, iCompressor)
lTurbine = Turbine(lTurbineEfficiency, lFan)
jetPipe = JetPipe()
nozzle = ConvergentNozzle(0.02)
# Put the components together
engineComponents = list(
[
intake,
lFan,
iCompressor,
hCompressor,
combustionChamber,
hTurbine,
iTurbine,
lTurbine,
jetPipe,
nozzle,
]
)
# Build the engine
this.turboFanEngine = TurbineEngine(fluid, engineComponents)
def simulate(this) -> TurbineEngine:
return this.turboFanEngine.simulate()