STAR
Cal STAR โ€” firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
simple_example.py
Go to the documentation of this file.
1"""Simple example: Tank Pressure โ†’ Thrust"""
2
3import numpy as np
4import sys
5from pathlib import Path
6
7sys.path.insert(0, str(Path(__file__).parent.parent))
8
9from engine.pipeline.io import load_config
10from engine.core.runner import PintleEngineRunner
11
12# Load configuration
13config = load_config(str(Path(__file__).parent.parent / "configs" / "default.yaml"))
14
15# Initialize runner
16runner = PintleEngineRunner(config)
17
18print("=" * 60)
19print("PINTLE ENGINE PIPELINE: Tank Pressure โ†’ Thrust")
20print("=" * 60)
21print("\nINPUT: Tank Pressures")
22print("OUTPUT: Chamber Pressure (SOLVED), Thrust, and all performance parameters")
23print("\n" + "-" * 60)
24
25# Example: Single point
26print("\n๐Ÿ“Š Example 1: Single Point Evaluation")
27print("-" * 60)
28
29P_tank_O = 5.0e6 # 5 MPa (oxidizer tank)
30P_tank_F = 4.5e6 # 4.5 MPa (fuel tank)
31
32print(f"Input Tank Pressures:")
33print(f" P_tank_O = {P_tank_O/1e6:.2f} MPa")
34print(f" P_tank_F = {P_tank_F/1e6:.2f} MPa")
35
36# Solve for everything
37results = runner.evaluate(P_tank_O, P_tank_F)
38
39print(f"\nSolved Results:")
40print(f" Pc (SOLVED) = {results['Pc']/1e6:.2f} MPa")
41print(f" MR = {results['MR']:.2f}")
42print(f" แน_O = {results['mdot_O']:.3f} kg/s")
43print(f" แน_F = {results['mdot_F']:.3f} kg/s")
44print(f" c*_actual = {results['cstar_actual']:.0f} m/s")
45print(f" Thrust = {results['F']/1000:.2f} kN")
46print(f" Isp = {results['Isp']:.1f} s")
47
48# Example: Pressure arrays (sweep)
49print("\n๐Ÿ“Š Example 2: Pressure Array (Sweep)")
50print("-" * 60)
51
52# Create arrays of different tank pressures
53P_tank_O_sweep = np.array([4.0e6, 5.0e6, 6.0e6, 7.0e6]) # Different oxidizer pressures
54P_tank_F_sweep = np.array([3.6e6, 4.5e6, 5.4e6, 6.3e6]) # Corresponding fuel pressures
55
56print(f"Evaluating {len(P_tank_O_sweep)} different pressure combinations:")
57for i in range(len(P_tank_O_sweep)):
58 print(f" Point {i+1}: P_O={P_tank_O_sweep[i]/6894.76:.0f} psi, P_F={P_tank_F_sweep[i]/6894.76:.0f} psi")
59
60results_sweep = runner.evaluate(P_tank_O_sweep, P_tank_F_sweep)
61
62print(f"\nResults for each pressure combination:")
63for i in range(len(P_tank_O_sweep)):
64 print(f" Point {i+1}:")
65 print(f" Solved Pc = {results_sweep['Pc'][i]/6894.76:.0f} psi")
66 print(f" Thrust = {results_sweep['F'][i]/1000:.2f} kN")
67 print(f" MR = {results_sweep['MR'][i]:.2f}")
68 print(f" Isp = {results_sweep['Isp'][i]:.1f} s")
69
70# Example: Time series (blowdown)
71print("\n๐Ÿ“Š Example 3: Time Series (Blowdown Simulation)")
72print("-" * 60)
73
74t = np.linspace(0, 10, 100) # 10 seconds, 100 points
75# Simple exponential blowdown
76P_tank_O_ts = 6.0e6 * np.exp(-t / 5.0) + 1.0e6
77P_tank_F_ts = 5.5e6 * np.exp(-t / 5.0) + 1.0e6
78
79print(f"Time series: {len(t)} points over {t[-1]:.1f} seconds")
80print(f"Initial tank pressures: P_O={P_tank_O_ts[0]/6894.76:.0f} psi, P_F={P_tank_F_ts[0]/6894.76:.0f} psi")
81print(f"Final tank pressures: P_O={P_tank_O_ts[-1]/6894.76:.0f} psi, P_F={P_tank_F_ts[-1]/6894.76:.0f} psi")
82
83# Solve for entire time series
84results_ts = runner.evaluate_time_series(t, P_tank_O_ts, P_tank_F_ts)
85
86print(f"\nSolved Results (time series):")
87print(f" Initial Pc (SOLVED) = {results_ts['Pc'][0]/6894.76:.0f} psi")
88print(f" Final Pc (SOLVED) = {results_ts['Pc'][-1]/6894.76:.0f} psi")
89print(f" Initial Thrust = {results_ts['F'][0]/1000:.2f} kN")
90print(f" Final Thrust = {results_ts['F'][-1]/1000:.2f} kN")
91print(f" Initial Isp = {results_ts['Isp'][0]:.1f} s")
92print(f" Final Isp = {results_ts['Isp'][-1]:.1f} s")
93
94print("\n" + "=" * 60)
95print("โœ… Pipeline correctly solves Pc from tank pressures!")
96print("=" * 60)
97