STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_timeseries_copv_charge.py
Go to the documentation of this file.
1"""The Time-Series COPV panel checks the charge the config loads, and labels a sized number as one.
2
3It always SIZED: the P0 that just meets the curve in the configured volume, so the margin is zero
4by construction -- and the panel showed that as "P0 2644 psia, Min Margin 0.1 psi" in green on the
5LE4 (3) stand, whose press_tank.initial_gas_mass of 1.312 kg in 4.619 L is a ~3,800 psia charge.
6"""
7
8from __future__ import annotations
9
10import numpy as np
11import pytest
12
13from backend.routers import timeseries as ts
14
15CFG = "tests/fixtures/ethalox_6500N_doublet_cad_2026-09-28.yaml"
16R_N2, T0 = 296.8, 300.0
17
18
19@pytest.fixture
20def cfg():
21 from engine.pipeline.io import load_config
22
23 return load_config(CFG)
24
25
26def _run(cfg):
27 t = np.linspace(0.0, 4.0, 41)
28 return ts._run_copv_analysis(cfg, t, [1.87] * 41, [1.24] * 41, 578.0 * np.ones(41), 578.0 * np.ones(41))
29
30
32 assert cfg.press_tank.initial_gas_mass == pytest.approx(1.312)
33 out = _run(cfg)
34 assert out["copv_mode"] == "configured"
35 assert out["copv_initial_mass_kg"] == pytest.approx(1.312)
36 # P0 is the charge's own state at T0: m0 = P0 V / (Z R T0), Z from the solver's own table.
37 V = cfg.press_tank.free_volume_L / 1000.0
38 P0 = out["copv_initial_pressure_psi"] * 6894.757
39 Z = P0 * V / (1.312 * R_N2 * T0)
40 assert 0.95 < Z < 1.3, Z
41 assert out["copv_pressure_psi"][0] == pytest.approx(out["copv_initial_pressure_psi"], rel=1e-6)
42 # the requirement still reported beside it, and below it: this charge has margin to spare
43 assert out["copv_required_mass_kg"] < 1.312
44 assert out["copv_required_pressure_psi"] < out["copv_initial_pressure_psi"]
45 assert out["copv_min_margin_psi"] > 500.0, "the check returned the sized (zero) margin"
46
47
49 cfg.press_tank.initial_gas_mass = None
50 cfg.press_tank.mass = None
51 out = _run(cfg)
52 assert out["copv_mode"] == "sized"
53 assert out["copv_initial_pressure_psi"] == pytest.approx(out["copv_required_pressure_psi"])
54 assert abs(out["copv_min_margin_psi"]) < 5.0, "sized for zero margin"
55
56
58 """Checking the charge the sizing asks for gives back the sizing's P0 and a ~zero margin."""
59 cfg.press_tank.initial_gas_mass = None
60 cfg.press_tank.mass = None
61 sized = _run(cfg)
62 cfg.press_tank.initial_gas_mass = sized["copv_required_mass_kg"]
63 checked = _run(cfg)
64 assert checked["copv_mode"] == "configured"
65 assert checked["copv_initial_pressure_psi"] == pytest.approx(sized["copv_required_pressure_psi"], rel=1e-4)
66 assert abs(checked["copv_min_margin_psi"]) < 5.0