-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_performance_summary.py
More file actions
393 lines (341 loc) · 14 KB
/
plot_performance_summary.py
File metadata and controls
393 lines (341 loc) · 14 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
"""Create comprehensive performance summary plots"""
import numpy as np
import matplotlib.pyplot as plt
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from pintle_pipeline.io import load_config
from pintle_models.runner import PintleEngineRunner
# Load configuration
config_path = Path(__file__).parent / "config_minimal.yaml"
config = load_config(str(config_path))
# Initialize runner
runner = PintleEngineRunner(config)
# Test at target operating point
P_tank_O = 1305 * 6894.76 # psi to Pa
P_tank_F = 974 * 6894.76 # psi to Pa
# Run pipeline
results = runner.evaluate(P_tank_O, P_tank_F)
diagnostics = results.get('diagnostics', {})
if isinstance(diagnostics, list):
diagnostics = diagnostics[0] if diagnostics else {}
# Create comprehensive plots
fig = plt.figure(figsize=(16, 12))
# 1. Mass Flow Rates
ax1 = plt.subplot(3, 3, 1)
mdot_O = results['mdot_O']
mdot_F = results['mdot_F']
mdot_total = mdot_O + mdot_F
bars = ax1.bar(['LOX', 'Fuel', 'Total'],
[mdot_O, mdot_F, mdot_total],
color=['blue', 'orange', 'green'], alpha=0.7)
ax1.set_ylabel('Mass Flow Rate [kg/s]')
ax1.set_title('Mass Flow Rates')
ax1.grid(True, alpha=0.3)
for bar in bars:
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height,
f'{height:.3f}',
ha='center', va='bottom', fontsize=9)
# 2. Pressure Breakdown
ax2 = plt.subplot(3, 3, 2)
Pc = results['Pc'] / 6894.76
P_tank_O_psi = P_tank_O / 6894.76
P_tank_F_psi = P_tank_F / 6894.76
from pintle_pipeline.feed_loss import delta_p_feed
delta_p_feed_O = delta_p_feed(mdot_O, config.fluids["oxidizer"].density,
config.feed_system["oxidizer"], P_tank_O) / 6894.76
delta_p_feed_F = delta_p_feed(mdot_F, config.fluids["fuel"].density,
config.feed_system["fuel"], P_tank_F) / 6894.76
P_inj_O = P_tank_O_psi - delta_p_feed_O
P_inj_F = P_tank_F_psi - delta_p_feed_F
pressures = [P_tank_O_psi, P_inj_O, Pc, P_tank_F_psi, P_inj_F, Pc]
labels = ['P_tank_O', 'P_inj_O', 'Pc', 'P_tank_F', 'P_inj_F', 'Pc']
colors = ['blue', 'lightblue', 'red', 'orange', 'lightcoral', 'red']
ax2.barh(labels, pressures, color=colors, alpha=0.7)
ax2.set_xlabel('Pressure [psi]')
ax2.set_title('Pressure Breakdown')
ax2.grid(True, alpha=0.3)
# 3. Mixture Ratio
ax3 = plt.subplot(3, 3, 3)
MR = results['MR']
target_MR = 2.36
ax3.bar(['Actual', 'Target'], [MR, target_MR],
color=['blue', 'red'], alpha=0.7)
ax3.set_ylabel('O/F Ratio')
ax3.set_title(f'Mixture Ratio (Target: {target_MR:.2f})')
ax3.grid(True, alpha=0.3)
ax3.text(0, MR, f'{MR:.2f}', ha='center', va='bottom', fontsize=10, fontweight='bold')
ax3.text(1, target_MR, f'{target_MR:.2f}', ha='center', va='bottom', fontsize=10, fontweight='bold')
# 4. Thrust Components
ax4 = plt.subplot(3, 3, 4)
F = results['F'] / 1000
F_momentum = results.get('F_momentum', 0) / 1000
F_pressure = results.get('F_pressure', 0) / 1000
target_F = 5.308
ax4.bar(['Momentum', 'Pressure', 'Total', 'Target'],
[F_momentum, F_pressure, F, target_F],
color=['blue', 'green', 'purple', 'red'], alpha=0.7)
ax4.set_ylabel('Thrust [kN]')
ax4.set_title('Thrust Components')
ax4.grid(True, alpha=0.3)
# 5. Performance Metrics
ax5 = plt.subplot(3, 3, 5)
Isp = results['Isp']
target_Isp = 299.0
cstar = results['cstar_actual']
eta = diagnostics.get('eta_cstar', np.nan)
metrics = ['Isp [s]', 'c* [m/s]', 'η_c*']
values = [Isp, cstar/10, eta*100] # Scale for visibility
targets = [target_Isp, None, None]
colors_plot = ['blue', 'green', 'orange']
bars = ax5.bar(metrics, values, color=colors_plot, alpha=0.7)
ax5.set_ylabel('Value')
ax5.set_title('Performance Metrics')
ax5.grid(True, alpha=0.3)
for i, (bar, val) in enumerate(zip(bars, values)):
height = bar.get_height()
label = f'{val:.1f}' if i == 0 else f'{val:.0f}'
ax5.text(bar.get_x() + bar.get_width()/2., height,
label, ha='center', va='bottom', fontsize=9)
# 6. Chamber Properties
ax6 = plt.subplot(3, 3, 6)
Tc = diagnostics.get('Tc', np.nan)
gamma = diagnostics.get('gamma', np.nan)
R = diagnostics.get('R', np.nan)
if not np.isnan(Tc) and not np.isnan(gamma) and not np.isnan(R):
props = ['Tc [K]', 'γ', 'R [J/kg·K]']
vals = [Tc/100, gamma*10, R/10] # Scale for visibility
ax6.bar(props, vals, color=['red', 'blue', 'green'], alpha=0.7)
ax6.set_ylabel('Value (scaled)')
ax6.set_title('Chamber Properties')
ax6.grid(True, alpha=0.3)
for prop, val in zip(props, vals):
ax6.text(prop, val, f'{val:.1f}', ha='center', va='bottom', fontsize=9)
# 7. Injector Performance
ax7 = plt.subplot(3, 3, 7)
from pintle_models.geometry import get_effective_areas, get_hydraulic_diameters
from pintle_models.discharge import cd_from_re, calculate_reynolds_number
A_LOX, A_fuel = get_effective_areas(config.pintle_geometry)
rho_O = config.fluids["oxidizer"].density
rho_F = config.fluids["fuel"].density
u_O = mdot_O / (rho_O * A_LOX)
u_F = mdot_F / (rho_F * A_fuel)
d_hyd_O, d_hyd_F = get_hydraulic_diameters(config.pintle_geometry)
mu_O = config.fluids["oxidizer"].viscosity
mu_F = config.fluids["fuel"].viscosity
Re_O = calculate_reynolds_number(rho_O, u_O, d_hyd_O, mu_O)
Re_F = calculate_reynolds_number(rho_F, u_F, d_hyd_F, mu_F)
Cd_O = cd_from_re(Re_O, config.discharge["oxidizer"])
Cd_F = cd_from_re(Re_F, config.discharge["fuel"])
ax7.bar(['LOX', 'Fuel'], [u_O, u_F], color=['blue', 'orange'], alpha=0.7)
ax7.set_ylabel('Velocity [m/s]')
ax7.set_title('Injector Velocities')
ax7.grid(True, alpha=0.3)
ax7.text(0, u_O, f'{u_O:.1f}', ha='center', va='bottom', fontsize=10)
ax7.text(1, u_F, f'{u_F:.1f}', ha='center', va='bottom', fontsize=10)
# 8. Discharge Coefficients
ax8 = plt.subplot(3, 3, 8)
ax8.bar(['LOX', 'Fuel'], [Cd_O, Cd_F], color=['blue', 'orange'], alpha=0.7)
ax8.set_ylabel('Discharge Coefficient')
ax8.set_title(f'Cd (Re_O={Re_O:.0f}, Re_F={Re_F:.0f})')
ax8.grid(True, alpha=0.3)
ax8.text(0, Cd_O, f'{Cd_O:.3f}', ha='center', va='bottom', fontsize=10)
ax8.text(1, Cd_F, f'{Cd_F:.3f}', ha='center', va='bottom', fontsize=10)
# 9. Spray Diagnostics
ax9 = plt.subplot(3, 3, 9)
J = diagnostics.get('J', np.nan)
theta = diagnostics.get('theta', np.nan)
We_O = diagnostics.get('We_O', np.nan)
We_F = diagnostics.get('We_F', np.nan)
D32_O = diagnostics.get('D32_O', np.nan)
D32_F = diagnostics.get('D32_F', np.nan)
if not np.isnan(J) and not np.isnan(theta):
spray_data = {
'J': J,
'θ [deg]': theta*180/np.pi,
'We_O': We_O/1000, # Scale
'We_F': We_F/1000, # Scale
}
ax9.bar(list(spray_data.keys())[:2], list(spray_data.values())[:2],
color=['blue', 'green'], alpha=0.7)
ax9.set_ylabel('Value')
ax9.set_title('Spray Parameters')
ax9.grid(True, alpha=0.3)
for i, (key, val) in enumerate(list(spray_data.items())[:2]):
ax9.text(i, val, f'{val:.2f}', ha='center', va='bottom', fontsize=9)
plt.tight_layout()
output_path = Path(__file__).parent / 'performance_summary.png'
plt.savefig(str(output_path), dpi=150, bbox_inches='tight')
print("✅ Saved performance summary plot to examples/pintle_engine/performance_summary.png")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from pintle_pipeline.io import load_config
from pintle_models.runner import PintleEngineRunner
# Load configuration
config_path = Path(__file__).parent / "config_minimal.yaml"
config = load_config(str(config_path))
# Initialize runner
runner = PintleEngineRunner(config)
# Test at target operating point
P_tank_O = 1305 * 6894.76 # psi to Pa
P_tank_F = 974 * 6894.76 # psi to Pa
# Run pipeline
results = runner.evaluate(P_tank_O, P_tank_F)
diagnostics = results.get('diagnostics', {})
if isinstance(diagnostics, list):
diagnostics = diagnostics[0] if diagnostics else {}
# Create comprehensive plots
fig = plt.figure(figsize=(16, 12))
# 1. Mass Flow Rates
ax1 = plt.subplot(3, 3, 1)
mdot_O = results['mdot_O']
mdot_F = results['mdot_F']
mdot_total = mdot_O + mdot_F
bars = ax1.bar(['LOX', 'Fuel', 'Total'],
[mdot_O, mdot_F, mdot_total],
color=['blue', 'orange', 'green'], alpha=0.7)
ax1.set_ylabel('Mass Flow Rate [kg/s]')
ax1.set_title('Mass Flow Rates')
ax1.grid(True, alpha=0.3)
for bar in bars:
height = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2., height,
f'{height:.3f}',
ha='center', va='bottom', fontsize=9)
# 2. Pressure Breakdown
ax2 = plt.subplot(3, 3, 2)
Pc = results['Pc'] / 6894.76
P_tank_O_psi = P_tank_O / 6894.76
P_tank_F_psi = P_tank_F / 6894.76
from pintle_pipeline.feed_loss import delta_p_feed
delta_p_feed_O = delta_p_feed(mdot_O, config.fluids["oxidizer"].density,
config.feed_system["oxidizer"], P_tank_O) / 6894.76
delta_p_feed_F = delta_p_feed(mdot_F, config.fluids["fuel"].density,
config.feed_system["fuel"], P_tank_F) / 6894.76
P_inj_O = P_tank_O_psi - delta_p_feed_O
P_inj_F = P_tank_F_psi - delta_p_feed_F
pressures = [P_tank_O_psi, P_inj_O, Pc, P_tank_F_psi, P_inj_F, Pc]
labels = ['P_tank_O', 'P_inj_O', 'Pc', 'P_tank_F', 'P_inj_F', 'Pc']
colors = ['blue', 'lightblue', 'red', 'orange', 'lightcoral', 'red']
ax2.barh(labels, pressures, color=colors, alpha=0.7)
ax2.set_xlabel('Pressure [psi]')
ax2.set_title('Pressure Breakdown')
ax2.grid(True, alpha=0.3)
# 3. Mixture Ratio
ax3 = plt.subplot(3, 3, 3)
MR = results['MR']
target_MR = 2.36
ax3.bar(['Actual', 'Target'], [MR, target_MR],
color=['blue', 'red'], alpha=0.7)
ax3.set_ylabel('O/F Ratio')
ax3.set_title(f'Mixture Ratio (Target: {target_MR:.2f})')
ax3.grid(True, alpha=0.3)
ax3.text(0, MR, f'{MR:.2f}', ha='center', va='bottom', fontsize=10, fontweight='bold')
ax3.text(1, target_MR, f'{target_MR:.2f}', ha='center', va='bottom', fontsize=10, fontweight='bold')
# 4. Thrust Components
ax4 = plt.subplot(3, 3, 4)
F = results['F'] / 1000
F_momentum = results.get('F_momentum', 0) / 1000
F_pressure = results.get('F_pressure', 0) / 1000
target_F = 5.308
ax4.bar(['Momentum', 'Pressure', 'Total', 'Target'],
[F_momentum, F_pressure, F, target_F],
color=['blue', 'green', 'purple', 'red'], alpha=0.7)
ax4.set_ylabel('Thrust [kN]')
ax4.set_title('Thrust Components')
ax4.grid(True, alpha=0.3)
# 5. Performance Metrics
ax5 = plt.subplot(3, 3, 5)
Isp = results['Isp']
target_Isp = 299.0
cstar = results['cstar_actual']
eta = diagnostics.get('eta_cstar', np.nan)
metrics = ['Isp [s]', 'c* [m/s]', 'η_c*']
values = [Isp, cstar/10, eta*100] # Scale for visibility
targets = [target_Isp, None, None]
colors_plot = ['blue', 'green', 'orange']
bars = ax5.bar(metrics, values, color=colors_plot, alpha=0.7)
ax5.set_ylabel('Value')
ax5.set_title('Performance Metrics')
ax5.grid(True, alpha=0.3)
for i, (bar, val) in enumerate(zip(bars, values)):
height = bar.get_height()
label = f'{val:.1f}' if i == 0 else f'{val:.0f}'
ax5.text(bar.get_x() + bar.get_width()/2., height,
label, ha='center', va='bottom', fontsize=9)
# 6. Chamber Properties
ax6 = plt.subplot(3, 3, 6)
Tc = diagnostics.get('Tc', np.nan)
gamma = diagnostics.get('gamma', np.nan)
R = diagnostics.get('R', np.nan)
if not np.isnan(Tc) and not np.isnan(gamma) and not np.isnan(R):
props = ['Tc [K]', 'γ', 'R [J/kg·K]']
vals = [Tc/100, gamma*10, R/10] # Scale for visibility
ax6.bar(props, vals, color=['red', 'blue', 'green'], alpha=0.7)
ax6.set_ylabel('Value (scaled)')
ax6.set_title('Chamber Properties')
ax6.grid(True, alpha=0.3)
for prop, val in zip(props, vals):
ax6.text(prop, val, f'{val:.1f}', ha='center', va='bottom', fontsize=9)
# 7. Injector Performance
ax7 = plt.subplot(3, 3, 7)
from pintle_models.geometry import get_effective_areas, get_hydraulic_diameters
from pintle_models.discharge import cd_from_re, calculate_reynolds_number
A_LOX, A_fuel = get_effective_areas(config.pintle_geometry)
rho_O = config.fluids["oxidizer"].density
rho_F = config.fluids["fuel"].density
u_O = mdot_O / (rho_O * A_LOX)
u_F = mdot_F / (rho_F * A_fuel)
d_hyd_O, d_hyd_F = get_hydraulic_diameters(config.pintle_geometry)
mu_O = config.fluids["oxidizer"].viscosity
mu_F = config.fluids["fuel"].viscosity
Re_O = calculate_reynolds_number(rho_O, u_O, d_hyd_O, mu_O)
Re_F = calculate_reynolds_number(rho_F, u_F, d_hyd_F, mu_F)
Cd_O = cd_from_re(Re_O, config.discharge["oxidizer"])
Cd_F = cd_from_re(Re_F, config.discharge["fuel"])
ax7.bar(['LOX', 'Fuel'], [u_O, u_F], color=['blue', 'orange'], alpha=0.7)
ax7.set_ylabel('Velocity [m/s]')
ax7.set_title('Injector Velocities')
ax7.grid(True, alpha=0.3)
ax7.text(0, u_O, f'{u_O:.1f}', ha='center', va='bottom', fontsize=10)
ax7.text(1, u_F, f'{u_F:.1f}', ha='center', va='bottom', fontsize=10)
# 8. Discharge Coefficients
ax8 = plt.subplot(3, 3, 8)
ax8.bar(['LOX', 'Fuel'], [Cd_O, Cd_F], color=['blue', 'orange'], alpha=0.7)
ax8.set_ylabel('Discharge Coefficient')
ax8.set_title(f'Cd (Re_O={Re_O:.0f}, Re_F={Re_F:.0f})')
ax8.grid(True, alpha=0.3)
ax8.text(0, Cd_O, f'{Cd_O:.3f}', ha='center', va='bottom', fontsize=10)
ax8.text(1, Cd_F, f'{Cd_F:.3f}', ha='center', va='bottom', fontsize=10)
# 9. Spray Diagnostics
ax9 = plt.subplot(3, 3, 9)
J = diagnostics.get('J', np.nan)
theta = diagnostics.get('theta', np.nan)
We_O = diagnostics.get('We_O', np.nan)
We_F = diagnostics.get('We_F', np.nan)
D32_O = diagnostics.get('D32_O', np.nan)
D32_F = diagnostics.get('D32_F', np.nan)
if not np.isnan(J) and not np.isnan(theta):
spray_data = {
'J': J,
'θ [deg]': theta*180/np.pi,
'We_O': We_O/1000, # Scale
'We_F': We_F/1000, # Scale
}
ax9.bar(list(spray_data.keys())[:2], list(spray_data.values())[:2],
color=['blue', 'green'], alpha=0.7)
ax9.set_ylabel('Value')
ax9.set_title('Spray Parameters')
ax9.grid(True, alpha=0.3)
for i, (key, val) in enumerate(list(spray_data.items())[:2]):
ax9.text(i, val, f'{val:.2f}', ha='center', va='bottom', fontsize=9)
plt.tight_layout()
output_path = Path(__file__).parent / 'performance_summary.png'
plt.savefig(str(output_path), dpi=150, bbox_inches='tight')
print("✅ Saved performance summary plot to examples/pintle_engine/performance_summary.png")
plt.show()