1"""A measured component whose flow-bench sweep does not start at zero.
3Flow benches rarely measure at zero flow, and a Newton solve starts every
4branch at 1 g/s and probes past the top of any sweep. A measurement that
5brackets the operating point must solve, the excursions off its ends are
6continued (``dp ~ mdot^2``, the law the curve measures) and flagged, and a solve
7asked not to raise never raises.
10from __future__
import annotations
20PSI = 6894.757293168361
26 source=Provenance.MEASURED,
31 return build_component(
32 ComponentInstance.build(
33 tag,
"valve", {}, curves={
"dp_mdot": BENCH}, model=
"measured"
38def _ethanol(net: Network, *nodes: tuple[str, float |
None]) ->
None:
39 for node_id, psia
in nodes:
41 node_id,
"ethanol", 293.0, pressure=
None if psia
is None else psia * PSI
43 net.nodes[node_id].phase =
"liquid"
47 """20 psi across a sweep of 2-32 psi over 0.05-0.2 kg/s: inside the curve
48 (8 psi at 0.1, 32 at 0.2, so about 0.158 kg/s). The first iterate at
49 1 g/s used to raise off the bottom of the curve and fail the solve."""
51 _ethanol(net, (
"A", 520.0), (
"B", 500.0))
52 net.add_branch(
"M",
_measured(
"M"),
"A",
"B")
53 result = solve_steady(net)
54 assert result.converged
55 flow = result.flows[
"M"]
56 assert 0.1 < flow < 0.2
57 assert BENCH(flow) / PSI == pytest.approx(20.0, rel=1e-6)
58 assert result.diagnostics[
"M"][
"extrapolated"] == 0.0
62 """A capped stub is back-filled at exactly zero flow, off the curve."""
64 _ethanol(net, (
"A", 520.0), (
"D", 500.0), (
"S",
None))
65 pipe = build_component(
66 ComponentInstance.build(
70 "length":
Param(1.0,
"m", Provenance.MEASURED,
""),
71 "bore":
Param(9.5,
"mm", Provenance.MEASURED,
""),
75 net.add_branch(
"L", pipe,
"A",
"D")
76 net.add_branch(
"M",
_measured(
"M"),
"A",
"S")
77 result = solve_steady(net, raise_on_failure=
False)
78 assert result.converged
79 assert result.flows[
"M"] == 0.0
80 assert result.pressures[
"S"] == pytest.approx(result.pressures[
"A"])
84 """Above the sweep the loss keeps its measured ``mdot^2`` shape, and the
85 diagnostics say the point was not measured."""
89 flow = net.conditions(
"A", 600.0 * PSI)
91 assert element.pressure_drop(0.4, flow) == pytest.approx(4.0 * top)
92 assert element.pressure_drop(0.025, flow) == pytest.approx(
BENCH(0.05) / 4.0)
93 assert element.pressure_drop(0.0, flow) == 0.0
94 assert element.diagnostics(0.4, flow)[
"extrapolated"] == 1.0
95 assert element.diagnostics(0.1, flow)[
"extrapolated"] == 0.0
None _ethanol(Network net, *tuple[str, float|None] nodes)
None test_a_capped_measured_stub_back_fills_without_raising()
None test_a_sweep_that_brackets_the_answer_solves()
object _measured(str tag)
None test_off_the_ends_is_continued_quadratically_and_flagged()