STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_chug_supply_share.py
Go to the documentation of this file.
1"""The chug loop reads the line's resistance, not the regulator's droop folded into K0.
2
3Layer X's feed fit makes Forward mode agree with a burn by writing K0 = K_line + K_supply: the
4supply term is the regulator sagging under flow. It lowers the injector inlet like a line loss, so
5it belongs in K0 for the operating point; at chug frequencies it is the regulator's compliance,
6which the stability model carries separately (Regulator), so as a feed resistance it was counted
7twice and raised the gain margin. ``feed_system.<side>.supply_K`` names that share.
8
9Judged on the model's own structure, not on a number it produced: the operating point must not
10move at all, the default must be exactly the old behaviour, and the margin must fall when the
11share is declared.
12"""
13import copy
14import os
15import sys
16
17import pytest
18
19sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
20
21from engine.core.runner import PintleEngineRunner # noqa: E402
22from engine.pipeline.io import load_config # noqa: E402
23
24CFG = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "configs", "ethalox_6800N.yaml")
25PSI = 6894.757293168361
26
27
28@pytest.fixture(autouse=True)
29def _python_physics(monkeypatch):
30 monkeypatch.setenv("ED_ACCEL", "off")
31
32
33def _eval(cfg):
34 P = 578.0 * PSI
35 out = PintleEngineRunner(copy.deepcopy(cfg)).evaluate(P, P, P_ambient=94070.0, silent=True)
36 ch = out["stability_results"]["chugging"]
37 return out["Pc"], out["F"], ch["chug_gain_margin"]
38
39
41 base = load_config(CFG)
42 fitted = copy.deepcopy(base)
43 # The stand fit's own numbers: K0 1.27 of which 0.63 is the regulator (K_line 0.643).
44 for side, k_supply in (("oxidizer", 0.63), ("fuel", 0.85)):
45 fitted.feed_system[side].K0 = base.feed_system[side].K0 + k_supply
46 folded = copy.deepcopy(fitted) # K0 with the supply in it, undeclared
47 declared = copy.deepcopy(fitted)
48 for side, k_supply in (("oxidizer", 0.63), ("fuel", 0.85)):
49 declared.feed_system[side].supply_K = k_supply
50
51 pc_f, F_f, gm_folded = _eval(folded)
52 pc_d, F_d, gm_declared = _eval(declared)
53 assert pc_d == pytest.approx(pc_f, rel=1e-12) and F_d == pytest.approx(F_f, rel=1e-12)
54 assert gm_declared < gm_folded
55
56 # Default: supply_K 0 is the old model exactly.
57 assert base.feed_system["oxidizer"].supply_K == 0.0
58 zero = copy.deepcopy(folded)
59 for side in ("oxidizer", "fuel"):
60 zero.feed_system[side].supply_K = 0.0
61 assert _eval(zero)[2] == gm_folded
test_declaring_the_supply_share_lowers_the_margin_and_moves_nothing_else()