STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_pressure_curve_segments.py
Go to the documentation of this file.
1"""Tank-pressure curves from segments (layer2_pressure.generate_pressure_curve_from_segments).
2
3The Time-Series tab asks for what it draws: a segment may rise or fall as the user's feed system
4does, and a blowdown segment ends at its end pressure. Layer 2's
5search keeps the old behaviour: rises forced into a 5 % fall, blowdown stopping short.
6"""
7import numpy as np
8import pytest
9
10from engine.optimizer.layers.layer2_pressure import generate_pressure_curve_from_segments as gen
11
12PSI = 6894.757
13
14
16 seg = [{"length_ratio": 1.0, "type": "linear", "start_pressure": 500 * PSI, "end_pressure": 540 * PSI}]
17 c = gen(seg, n_points=50, allow_rise=True, exact_ends=True)
18 assert c[0] == pytest.approx(500 * PSI) and c[-1] == pytest.approx(540 * PSI)
19 assert np.all(np.diff(c) > 0)
20
21
23 seg = [{"length_ratio": 1.0, "type": "linear", "start_pressure": 500 * PSI, "end_pressure": 540 * PSI}]
24 assert gen(seg, n_points=50)[-1] == pytest.approx(475 * PSI) # forced 5 % fall
25 bd = [{"length_ratio": 1.0, "type": "blowdown", "start_pressure": 600 * PSI, "end_pressure": 400 * PSI, "k": 0.5}]
26 assert gen(bd, n_points=50)[-1] == pytest.approx((400 + 200 * np.exp(-0.5)) * PSI)
27
28
30 bd = [{"length_ratio": 1.0, "type": "blowdown", "start_pressure": 600 * PSI, "end_pressure": 400 * PSI, "k": 0.5}]
31 c = gen(bd, n_points=50, exact_ends=True)
32 assert c[0] == pytest.approx(600 * PSI) and c[-1] == pytest.approx(400 * PSI)