STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_blowdown_coupled.py
Go to the documentation of this file.
1"""Test coupled blowdown solver with mock engine callback."""
2import numpy as np
3import sys
4from types import SimpleNamespace
5
6sys.path.insert(0, '/home/adnan/EngineDesign')
7
8from copv.blowdown_solver import simulate_coupled_blowdown
9
10# Valid mock config structure
11mock_config = SimpleNamespace(
12 fluids={
13 'oxidizer': SimpleNamespace(density=1140.0),
14 'fuel': SimpleNamespace(density=800.0)
15 },
16 lox_tank=SimpleNamespace(tank_volume_m3=0.1, mass=50.0),
17 fuel_tank=SimpleNamespace(tank_volume_m3=0.1, mass=40.0)
18)
19
20def mock_engine_evaluator(P_lox, P_fuel):
21 # Simple impedance model: mdot = C * sqrt(P)
22 # k = 1.0 kg/s at 500 psi
23 P_ref = 500 * 6894.76
24 mdot_lox = 1.0 * np.sqrt(P_lox / P_ref)
25 mdot_fuel = 0.8 * np.sqrt(P_fuel / P_ref)
26 return mdot_lox, mdot_fuel
27
28# Run simulation
29times = np.linspace(0, 5, 51) # 0.1s steps
30results = simulate_coupled_blowdown(
31 times=times,
32 evaluate_engine_fn=mock_engine_evaluator,
33 P_lox_initial_Pa=600 * 6894.76,
34 P_fuel_initial_Pa=600 * 6894.76,
35 config=mock_config,
36 use_real_gas=False
37)
38
39print("\nāœ“ Coupled Blowdown Solver Test")
40print("------------------------------")
41print(f"Time steps: {len(times)}")
42print(f"LOX Pressure: {results['lox']['P_Pa'][0]/6894.76:.1f} -> {results['lox']['P_Pa'][-1]/6894.76:.1f} psi")
43print(f"Fuel Pressure: {results['fuel']['P_Pa'][0]/6894.76:.1f} -> {results['fuel']['P_Pa'][-1]/6894.76:.1f} psi")
44print(f"LOX Mass: {results['lox']['m_prop_kg'][0]:.1f} -> {results['lox']['m_prop_kg'][-1]:.1f} kg")
45
46# Verify mass flow decreased as pressure dropped (coupling check)
47mdot_0 = results['lox']['mdot_kg_s'][0]
48mdot_end = results['lox']['mdot_kg_s'][-1]
49print(f"LOX Flow Rate: {mdot_0:.3f} -> {mdot_end:.3f} kg/s")
50
51if mdot_end < mdot_0:
52 print("āœ“ Flow rate decreased with pressure (Coupling verified)")
53else:
54 print("āœ— Flow rate did not decrease correctly!")
55
56# Validation check
57assert results['lox']['P_Pa'][0] > results['lox']['P_Pa'][-1], "Pressure should decrease"
58assert results['lox']['m_prop_kg'][0] > results['lox']['m_prop_kg'][-1], "Mass should decrease"