STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_measurements.py
Go to the documentation of this file.
1"""Measured values in place of assumptions (engine/pipeline/measurements.py).
2
3Opt-in: no measurements, the config is used exactly as given. Each measurement reaches the physics
4where the assumed number entered, and forward mode marks the input measured (◇ -> ●)."""
5import copy
6
7import pytest
8
9PSI = 6894.757
10CFG = "tests/fixtures/ethalox_6500N_doublet_cad_2026-09-28.yaml"
11
12
13def _cfg():
14 from engine.pipeline.io import load_config
15 return load_config(CFG)
16
17
18def _mv(v):
19 from engine.pipeline.config_schemas import MeasuredValue
20 return MeasuredValue(value=v, source="test rig")
21
22
23def _solve(cfg):
24 from engine.core.runner import PintleEngineRunner
25 P = cfg.lox_tank.initial_pressure_psi * PSI
26 return PintleEngineRunner(copy.deepcopy(cfg)).evaluate(P, P, silent=True, rich_stability=True)
27
28
30 from engine.pipeline.measurements import apply_measurements
31 cfg = _cfg()
32 assert apply_measurements(cfg) is cfg
33
34
35@pytest.fixture(scope="module")
36def pair():
37 from engine.pipeline.config_schemas import MeasurementsConfig
38 base = _cfg()
39 m = copy.deepcopy(base)
40 m.measurements = MeasurementsConfig(cd_O=_mv(0.72), cd_F=_mv(0.70), em=_mv(0.85),
41 d32_O_um=_mv(80.0), d32_F_um=_mv(120.0), chug_frequency_hz=_mv(31.0))
42 return _solve(base), _solve(m), m
43
44
46 r0, r1, _ = pair
47 assert r1["Cd_O"] == pytest.approx(0.72, abs=1e-9) and r1["Cd_F"] == pytest.approx(0.70, abs=1e-9)
48 assert r1["diagnostics"]["cstar_efficiency"]["rupe_Em"] == pytest.approx(0.85, abs=1e-9)
49 assert r1["diagnostics"]["D32_O"] == pytest.approx(80e-6) and r1["diagnostics"]["D32_F"] == pytest.approx(120e-6)
50 # the stability model reads the same sprays
51 assert r1["stability_rich"]["vaporization"]["streams"][1]["smd_um"] == pytest.approx(120.0)
52 assert r1["F"] != pytest.approx(r0["F"], rel=1e-3)
53
54
56 from engine.pipeline.forward_report import forward_report
57 _, r1, m = pair
58 rep = forward_report(m, r1)
59 cal = rep["calibration"]
60 assert cal["cd"]["state"] == "measured" and cal["em"]["state"] == "measured" and cal["smd"]["state"] == "measured"
61 assert cal["nozzle"]["state"] == "assumed"
62 st = next(s for s in rep["sections"] if s["key"] == "stability")
63 assert next(q for q in st["quantities"] if q["key"] == "chug_f_measured")["value"] == 31.0
64
65
67 from engine.pipeline.config_schemas import MeasurementsConfig
68 from engine.pipeline.measurements import calibration_state
69 c = _cfg()
70 c.measurements = MeasurementsConfig(cd_O=_mv(0.7))
71 assert calibration_state(c)["cd"]["state"] == "partial"
72
73
75 from pydantic import ValidationError
76 from engine.pipeline.config_schemas import MeasuredValue
77 with pytest.raises(ValidationError):
78 MeasuredValue(value=0.7, source="")
test_forward_mode_marks_them_measured(pair)
test_a_measurement_without_a_source_is_refused()
test_each_measurement_reaches_the_physics(pair)