Fix pneumatic node zero-flow reversal

This commit is contained in:
huojiarong committed 2026-08-17 09:24:35 +00:00
1 parent 16a7eb2d6c
commit 0fa166c8e5
3 files changed
+159 -3

No files matched your search

@@ -123,6 +123,37 @@ class AmesimPneumaticNodeComponentTests(unittest.TestCase):
)
self.assertAlmostEqual(energy_flow, 0.0, places=10)
def test_port_2_outflow_enthalpy_remains_finite_through_flow_reversal(self) -> None:
node = AmesimP4Node2("p4_1")
connected_h = {
"port_1": 300.0,
"port_2": 300.0,
"port_3": 200.0,
"port_4": 100.0,
}
outflow_enthalpies: list[float] = []
for reference_flow in (-1.0e-6, 0.0, 1.0e-6):
node.port_1.m_flow = -1.0
node.port_2.m_flow = reference_flow
node.port_3.m_flow = -reference_flow
node.port_4.m_flow = 1.0
node.update_stream_outflows(connected_h)
self.assertAlmostEqual(
sum(port.m_flow for port in node.ports.values()),
0.0,
places=15,
)
outflow_enthalpies.append(node.port_2.h_outflow)
self.assertTrue(all(abs(value) < 1.0e4 for value in outflow_enthalpies))
self.assertLess(
max(outflow_enthalpies) - min(outflow_enthalpies),
1.0,
)
if __name__ == "__main__":
unittest.main()