STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_flow_capacity_effective_area.py
Go to the documentation of this file.
1"""Effective injector flow area A_eff = Cd × A_geom and integration checks."""
2
3import unittest
4from pathlib import Path
5
6import numpy as np
7
8from engine.core.injectors.flow_capacity import effective_flow_areas_from_cd
9from engine.pipeline.io import load_config
10from engine.core.runner import PintleEngineRunner
11
12
13ROOT = Path(__file__).resolve().parents[1]
14
15
16class TestFlowCapacityEffectiveArea(unittest.TestCase):
18 ag_o, ag_f = 1e-4, 8e-5
19 d1 = {"Cd_O": 0.5, "Cd_F": 0.6}
20 d2 = {"Cd_O": 0.7, "Cd_F": 0.6}
21 e1o, e1f, _ = effective_flow_areas_from_cd(d1, ag_o, ag_f)
22 e2o, e2f, _ = effective_flow_areas_from_cd(d2, ag_o, ag_f)
23 self.assertAlmostEqual(e2o / e1o, 0.7 / 0.5, places=7)
24 self.assertAlmostEqual(e2f, e1f, places=12)
25
27 ag_o, ag_f = 2e-4, 2e-4
28 eo, ef, w = effective_flow_areas_from_cd(None, ag_o, ag_f)
29 self.assertEqual(eo, ag_o)
30 self.assertEqual(ef, ag_f)
31 self.assertIn("no_diagnostics", w)
32 eo2, ef2, w2 = effective_flow_areas_from_cd({}, ag_o, ag_f)
33 self.assertEqual(eo2, ag_o)
34 self.assertTrue(any("fallback_geometric" in x for x in w2))
35
37 cfg = load_config(str(ROOT / "configs" / "impinging_smoke.yaml"))
38 r = PintleEngineRunner(cfg)
39 Po = cfg.lox_tank.initial_pressure_psi * 6894.76
40 Pf = cfg.fuel_tank.initial_pressure_psi * 6894.76
41 res = r.evaluate(Po, Pf, P_ambient=101325.0, silent=True)
42 self.assertIn("Cd_O", res)
43 self.assertIn("Cd_F", res)
44 self.assertTrue(np.isfinite(res["Cd_O"]) and float(res["Cd_O"]) > 0)
45 self.assertTrue(np.isfinite(res["Cd_F"]) and float(res["Cd_F"]) > 0)
46 for k in ("A_geom_O", "A_geom_F", "A_eff_O", "A_eff_F"):
47 self.assertIn(k, res)
48 self.assertTrue(np.isfinite(res[k]))
49 self.assertAlmostEqual(float(res["A_eff_O"]), float(res["Cd_O"]) * float(res["A_geom_O"]), places=6)
50 self.assertAlmostEqual(float(res["A_eff_F"]), float(res["Cd_F"]) * float(res["A_geom_F"]), places=6)
51 d = res.get("diagnostics") or {}
52 self.assertAlmostEqual(float(res["Cd_O"]), float(d.get("Cd_O")), places=7)
53 diag_mr = d.get("momentum_ratio_R")
54 self.assertIsNotNone(diag_mr)
55 self.assertTrue(np.isfinite(diag_mr))
56
58 cfg = load_config(str(ROOT / "configs" / "impinging_smoke.yaml"))
59 r = PintleEngineRunner(cfg)
60 P0o = cfg.lox_tank.initial_pressure_psi * 6894.76
61 P0f = cfg.fuel_tank.initial_pressure_psi * 6894.76
62 n = 5
63 Po = np.full(n, P0o)
64 Pf = np.linspace(P0f * 0.85, P0f * 1.05, n)
65 out = r.evaluate_arrays(Po, Pf, P_ambient=101325.0)
66 md = out["mdot_total"]
67 self.assertEqual(len(md), n)
68 # The fuel tank drives the fuel flow up and the O/F down. The TOTAL need not rise: on this
69 # methalox doublet the mixing term climbs steeply as Rupe's M falls toward 1 (0.77 -> 0.94),
70 # Pc climbs with c*, and the oxidizer flow it throttles falls faster than the fuel rises.
71 self.assertGreater(float(out["mdot_F"][-1]), float(out["mdot_F"][0]))
72 self.assertLess(float(out["MR"][-1]), float(out["MR"][0]))
73 self.assertNotAlmostEqual(float(md[-1]), float(md[0]), places=3)
74
75
76if __name__ == "__main__":
77 unittest.main()