STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_cd_valves.py
Go to the documentation of this file.
1"""A valve given as Cd is the Cv valve with the number converted once."""
2
3from __future__ import annotations
4
5import math
6
7import pytest
8
9from feedtwin.comps.elements import cv_from_cd
10from feedtwin.model.spec import get_component_spec
11from feedtwin.model.component import ComponentInstance
12from feedtwin.model.param import Param, Provenance
13from feedtwin.comps import build_component
14
15
16def _p(value: float, unit: str) -> Param:
17 return Param(value, unit, Provenance.MANUFACTURER, "test")
18
19
21 # A bore of 1.1284 in is one square inch.
22 assert cv_from_cd(1.0, 1.1284 * 0.0254) == pytest.approx(38.0, rel=1e-3)
23 assert cv_from_cd(0.6, 1.1284 * 0.0254) == pytest.approx(22.8, rel=1e-3)
24
25
27 bore = 12.7e-3
28 cd = 0.6
29 cv_twin = build_component(
30 ComponentInstance.build(
31 "MV-CV",
32 "valve",
33 {"Cv": _p(cv_from_cd(cd, bore), "Cv"), "bore": _p(bore, "m")},
34 model="cv",
35 )
36 )
37 cd_valve = build_component(
38 ComponentInstance.build(
39 "MV-CD", "valve", {"Cd": _p(cd, "-"), "bore": _p(bore, "m")}, model="cd"
40 )
41 )
42 from feedtwin.comps.base import FlowConditions
43
44 flow = FlowConditions(rho=998.0, mu=1e-3, p_upstream=50e5)
45 for mdot in (0.05, 0.2, 0.5):
46 assert cd_valve.pressure_drop(mdot, flow) == pytest.approx(
47 cv_twin.pressure_drop(mdot, flow), rel=1e-9
48 )
49
50
52 for kind in ("valve", "check_valve"):
53 spec = get_component_spec(kind)
54 assert "cd" in spec.models
55 assert "Cd" in {ps.name for ps in spec.params}
56
57
59 from feedtwin.comps.base import FlowConditions
60
61 cv = build_component(
62 ComponentInstance.build(
63 "CV-1",
64 "check_valve",
65 {"Cd": _p(0.7, "-"), "bore": _p(9.5e-3, "m")},
66 model="cd",
67 )
68 )
69 flow = FlowConditions(rho=998.0, mu=1e-3, p_upstream=50e5)
70 assert math.isfinite(cv.pressure_drop(0.1, flow))
71 assert cv.pressure_drop(0.1, flow) > 0.0
None test_the_catalogue_offers_cd_for_valves_and_check_valves()
None test_a_cd_valve_drops_the_same_pressure_as_its_cv_twin()
None test_a_cd_check_valve_builds_and_flows_forward()
Param _p(float value, str unit)
None test_cv_from_cd_is_38_per_square_inch()