STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
optimize_cgt.py
Go to the documentation of this file.
1import numpy as np
2from scipy.optimize import minimize_scalar
3
4from payload.cold_gas_thruster import ColdGasThrusterConfig, ColdGasThruster
5
6
7def objective(exit_diameter: float) -> float:
8 """
9 Objective function: minimize negative specific impulse (to maximize Isp/Thrust).
10 We use the baseline configuration and only vary the exit_diameter.
11 """
13 throat_diameter=0.005, # 5 mm throat
14 exit_diameter=exit_diameter,
15 inlet_pressure=800_000, # 800 kPa
16 chamber_diameter=0.012, # 12 mm
17 chamber_length=0.020, # 20 mm
18 volume_chamber=np.pi / 4 * 0.012**2 * 0.020,
19 )
20
21 try:
22 cgt = ColdGasThruster(cfg)
23 result = cgt.compute()
24 # Maximize specific impulse (or thrust, they are proportional here since mdot is fixed by throat & P0)
25 return -result.specific_impulse
26 except Exception:
27 # Penalize if solver fails (e.g., non-converging expansion ratio)
28 return 0.0
29
30def main():
31 print("Running super simple optimization on Cold Gas Thruster...")
32 print("Baseline:")
33 print(" throat_diameter = 5 mm")
34 print(" inlet_pressure = 800 kPa")
35 print("Objective: Maximize Specific Impulse (Isp) by optimizing exit_diameter (expansion perfectly matched).\n")
36
37 # Base throat is 0.005. Exit diameter must be > throat_diameter.
38 # Set bounds from slightly above throat up to something very large.
39 res = minimize_scalar(
40 objective,
41 bounds=(0.00501, 0.050),
42 method='bounded'
43 )
44
45 if res.success:
46 optimal_exit_diameter = res.x
47 max_isp = -res.fun
48
49 print("Optimization Successful!")
50 print(f"Optimal Exit Diameter: {optimal_exit_diameter * 1000:.3f} mm")
51 print(f"Maximum Isp Achieved: {max_isp:.2f} s\n")
52
53 # Evaluate and show the full summary for the optimal design
54 cfg_opt = ColdGasThrusterConfig(
55 throat_diameter=0.005,
56 exit_diameter=optimal_exit_diameter,
57 inlet_pressure=800_000,
58 chamber_diameter=0.012,
59 chamber_length=0.020,
60 volume_chamber=np.pi / 4 * 0.012**2 * 0.020,
61 )
62 cgt_opt = ColdGasThruster(cfg_opt)
63 result_opt = cgt_opt.compute()
64 print("Optimal Configuration Summary:")
65 print(result_opt.summary())
66 else:
67 print("Optimization failed:", res.message)
68
69if __name__ == "__main__":
70 main()
float objective(float exit_diameter)