diff --git a/PythonModels/systems/test_mql_closure.py b/PythonModels/systems/test_mql_closure.py index 9f5395c..61b434d 100644 --- a/PythonModels/systems/test_mql_closure.py +++ b/PythonModels/systems/test_mql_closure.py @@ -280,6 +280,14 @@ class TestMqlPn3P4NodeChamberSegmentComponents: spec: TestMqlPneumaticChamberSegmentSpec +@dataclass(frozen=True) +class TestMqlP4NodeBalancePort: + flow_kg_s: float + node_h: float + connected_h: float + port_mass_flow_kg_s: float + + @dataclass(frozen=True) class TestMqlPn3P4NodeChamberSegmentSnapshot: inlet_line: ThermodynamicProperties @@ -1214,50 +1222,50 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_boundary=p4_port3_remote_primary_line, orifice=self.components.p4_port3_remote_orifice, ) - p4_balance = self.components.p4_node.balance( - port_2_temperature_k=p4_primary_line.T, - port_2_pressure_pa=p4_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_balance = self._p4_node_balance( + node=self.components.p4_node, + primary_properties=p4_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_to_port1_line_flow, node_h=p4_primary_line.h, connected_h=p4_port1_line.h, + port_mass_flow_kg_s=-p4_to_port1_line_flow, ), - port_1_mass_flow_g_s=-p4_to_port1_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_to_port3_line_flow, node_h=p4_primary_line.h, connected_h=p4_port3_line.h, + port_mass_flow_kg_s=-p4_to_port3_line_flow, ), - port_3_mass_flow_g_s=-p4_to_port3_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=pnl0003_to_p4_flow, node_h=node_line_port_2.h, connected_h=p4_primary_line.h, + port_mass_flow_kg_s=pnl0003_to_p4_flow, ), - port_4_mass_flow_g_s=pnl0003_to_p4_flow * 1.0e3, ) p4_node_to_primary_line_flow = p4_balance.port_2_mass_flow_g_s * 1.0e-3 - p4_port1_remote_balance = self.components.p4_port1_remote_node.balance( - port_2_temperature_k=p4_port1_remote_primary_line.T, - port_2_pressure_pa=p4_port1_remote_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_port1_remote_balance = self._p4_node_balance( + node=self.components.p4_port1_remote_node, + primary_properties=p4_port1_remote_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_remote_to_port1_line_flow, node_h=p4_port1_remote_primary_line.h, connected_h=p4_port1_remote_port1_line.h, + port_mass_flow_kg_s=-p4_port1_remote_to_port1_line_flow, ), - port_1_mass_flow_g_s=-p4_port1_remote_to_port1_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_remote_node_to_line_flow, node_h=p4_port1_remote_primary_line.h, connected_h=p4_port1_line.h, + port_mass_flow_kg_s=-p4_port1_remote_node_to_line_flow, ), - port_3_mass_flow_g_s=-p4_port1_remote_node_to_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_remote_orifice_to_node_flow, node_h=p4_port1_remote_orifice_line_port_2.h, connected_h=p4_port1_remote_primary_line.h, + port_mass_flow_kg_s=p4_port1_remote_orifice_to_node_flow, ), - port_4_mass_flow_g_s=p4_port1_remote_orifice_to_node_flow * 1.0e3, ) p4_port1_remote_node_to_primary_line_flow = ( p4_port1_remote_balance.port_2_mass_flow_g_s * 1.0e-3 @@ -1283,156 +1291,152 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_3_mass_flow_g_s=-node_to_resistance_flow * 1.0e3, ) ) - p4_port1_far_balance = self.components.p4_port1_far_node.balance( - port_2_temperature_k=p4_port1_far_primary_line.T, - port_2_pressure_pa=p4_port1_far_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_port1_far_balance = self._p4_node_balance( + node=self.components.p4_port1_far_node, + primary_properties=p4_port1_far_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_far_to_next_line_flow, node_h=p4_port1_far_primary_line.h, connected_h=p4_port1_far_port1_line.h, + port_mass_flow_kg_s=-p4_port1_far_to_next_line_flow, ), - port_1_mass_flow_g_s=-p4_port1_far_to_next_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_far_node_to_line_flow, node_h=p4_port1_far_primary_line.h, connected_h=p4_port1_remote_port1_line.h, + port_mass_flow_kg_s=-p4_port1_far_node_to_line_flow, ), - port_3_mass_flow_g_s=-p4_port1_far_node_to_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_next_orifice_resistance_to_p4_flow, node_h=p4_port1_next_orifice_resistance_line_port_2.h, connected_h=p4_port1_far_primary_line.h, - ), - port_4_mass_flow_g_s=( - p4_port1_next_orifice_resistance_to_p4_flow * 1.0e3 + port_mass_flow_kg_s=p4_port1_next_orifice_resistance_to_p4_flow, ), ) p4_port1_far_node_to_primary_line_flow = ( p4_port1_far_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_port1_next_balance = self.components.p4_port1_next_node.balance( - port_2_temperature_k=p4_port1_next_primary_line.T, - port_2_pressure_pa=p4_port1_next_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_port1_next_balance = self._p4_node_balance( + node=self.components.p4_port1_next_node, + primary_properties=p4_port1_next_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_next_to_bridge_line_flow, node_h=p4_port1_next_primary_line.h, connected_h=p4_port1_next_port1_line.h, + port_mass_flow_kg_s=-p4_port1_next_to_bridge_line_flow, ), - port_1_mass_flow_g_s=-p4_port1_next_to_bridge_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_next_node_to_line_flow, node_h=p4_port1_next_primary_line.h, connected_h=p4_port1_far_port1_line.h, + port_mass_flow_kg_s=-p4_port1_next_node_to_line_flow, ), - port_3_mass_flow_g_s=-p4_port1_next_node_to_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port1_next_orifice_p4_to_output_line_flow, node_h=p4_port1_next_primary_line.h, connected_h=p4_port1_next_orifice_output_line.h, - ), - port_4_mass_flow_g_s=( - -p4_port1_next_orifice_p4_to_output_line_flow * 1.0e3 + port_mass_flow_kg_s=-p4_port1_next_orifice_p4_to_output_line_flow, ), ) p4_port1_next_node_to_primary_line_flow = ( p4_port1_next_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_port3_remote_balance = self.components.p4_port3_remote_node.balance( - port_2_temperature_k=p4_port3_remote_primary_line.T, - port_2_pressure_pa=p4_port3_remote_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_port3_remote_balance = self._p4_node_balance( + node=self.components.p4_port3_remote_node, + primary_properties=p4_port3_remote_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_remote_node_to_line_flow, node_h=p4_port3_remote_primary_line.h, connected_h=p4_port3_line.h, + port_mass_flow_kg_s=-p4_port3_remote_node_to_line_flow, ), - port_1_mass_flow_g_s=-p4_port3_remote_node_to_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_remote_to_port3_line_flow, node_h=p4_port3_remote_primary_line.h, connected_h=p4_port3_remote_port3_line.h, + port_mass_flow_kg_s=-p4_port3_remote_to_port3_line_flow, ), - port_3_mass_flow_g_s=-p4_port3_remote_to_port3_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_remote_orifice_to_node_flow, node_h=p4_port3_remote_orifice_line_port_2.h, connected_h=p4_port3_remote_primary_line.h, + port_mass_flow_kg_s=p4_port3_remote_orifice_to_node_flow, ), - port_4_mass_flow_g_s=p4_port3_remote_orifice_to_node_flow * 1.0e3, ) p4_port3_remote_node_to_primary_line_flow = ( p4_port3_remote_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_port3_far_balance = self.components.p4_port3_far_node.balance( - port_2_temperature_k=p4_port3_far_primary_line.T, - port_2_pressure_pa=p4_port3_far_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_port3_far_balance = self._p4_node_balance( + node=self.components.p4_port3_far_node, + primary_properties=p4_port3_far_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_far_node_to_line_flow, node_h=p4_port3_far_primary_line.h, connected_h=p4_port3_remote_port3_line.h, + port_mass_flow_kg_s=-p4_port3_far_node_to_line_flow, ), - port_1_mass_flow_g_s=-p4_port3_far_node_to_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_far_to_next_line_flow, node_h=p4_port3_far_primary_line.h, connected_h=p4_port3_far_port3_line.h, + port_mass_flow_kg_s=-p4_port3_far_to_next_line_flow, ), - port_3_mass_flow_g_s=-p4_port3_far_to_next_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_remote_resistance_output_to_p4_flow, node_h=p4_port3_remote_resistance_output_line.h, connected_h=p4_port3_far_primary_line.h, + port_mass_flow_kg_s=p4_port3_remote_resistance_output_to_p4_flow, ), - port_4_mass_flow_g_s=p4_port3_remote_resistance_output_to_p4_flow * 1.0e3, ) p4_port3_far_node_to_primary_line_flow = ( p4_port3_far_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_port3_next_balance = self.components.p4_port3_next_node.balance( - port_2_temperature_k=p4_port3_next_primary_line.T, - port_2_pressure_pa=p4_port3_next_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_port3_next_balance = self._p4_node_balance( + node=self.components.p4_port3_next_node, + primary_properties=p4_port3_next_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_next_node_to_line_flow, node_h=p4_port3_next_primary_line.h, connected_h=p4_port3_far_port3_line.h, + port_mass_flow_kg_s=-p4_port3_next_node_to_line_flow, ), - port_1_mass_flow_g_s=-p4_port3_next_node_to_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_next_to_bridge_line_flow, node_h=p4_port3_next_primary_line.h, connected_h=p4_port3_next_port3_line.h, + port_mass_flow_kg_s=-p4_port3_next_to_bridge_line_flow, ), - port_3_mass_flow_g_s=-p4_port3_next_to_bridge_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_next_orifice_output_to_p4_flow, node_h=p4_port3_next_orifice_output_line.h, connected_h=p4_port3_next_primary_line.h, + port_mass_flow_kg_s=p4_port3_next_orifice_output_to_p4_flow, ), - port_4_mass_flow_g_s=p4_port3_next_orifice_output_to_p4_flow * 1.0e3, ) p4_port3_next_node_to_primary_line_flow = ( p4_port3_next_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_bridge_balance = self.components.p4_bridge_node.balance( - port_2_temperature_k=p4_bridge_primary_line.T, - port_2_pressure_pa=p4_bridge_primary_line.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + p4_bridge_balance = self._p4_node_balance( + node=self.components.p4_bridge_node, + primary_properties=p4_bridge_primary_line, + port_1=TestMqlP4NodeBalancePort( flow_kg_s=p4_bridge_to_port3_next_line_flow, node_h=p4_bridge_primary_line.h, connected_h=p4_port3_next_port3_line.h, + port_mass_flow_kg_s=-p4_bridge_to_port3_next_line_flow, ), - port_1_mass_flow_g_s=-p4_bridge_to_port3_next_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlP4NodeBalancePort( flow_kg_s=p4_bridge_to_port1_next_line_flow, node_h=p4_bridge_primary_line.h, connected_h=p4_port1_next_port1_line.h, + port_mass_flow_kg_s=-p4_bridge_to_port1_next_line_flow, ), - port_3_mass_flow_g_s=-p4_bridge_to_port1_next_line_flow * 1.0e3, - port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_4=TestMqlP4NodeBalancePort( flow_kg_s=p4_port3_next_resistance_output_to_p4_flow, node_h=p4_port3_next_resistance_output_line.h, connected_h=p4_bridge_primary_line.h, + port_mass_flow_kg_s=p4_port3_next_resistance_output_to_p4_flow, ), - port_4_mass_flow_g_s=p4_port3_next_resistance_output_to_p4_flow * 1.0e3, ) p4_bridge_node_to_primary_line_flow = ( p4_bridge_balance.port_2_mass_flow_g_s * 1.0e-3 @@ -1770,6 +1774,38 @@ class TestMqlPn3P4NodeChamberSegmentClosure: connected_h=connected_h, ) + def _p4_node_balance( + self, + *, + node: TestMqlPneumaticNode4, + primary_properties: ThermodynamicProperties, + port_1: TestMqlP4NodeBalancePort, + port_3: TestMqlP4NodeBalancePort, + port_4: TestMqlP4NodeBalancePort, + ) -> TestMqlPneumaticNode4Balance: + return node.balance( + port_2_temperature_k=primary_properties.T, + port_2_pressure_pa=primary_properties.p, + port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + flow_kg_s=port_1.flow_kg_s, + node_h=port_1.node_h, + connected_h=port_1.connected_h, + ), + port_1_mass_flow_g_s=port_1.port_mass_flow_kg_s * 1.0e3, + port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + flow_kg_s=port_3.flow_kg_s, + node_h=port_3.node_h, + connected_h=port_3.connected_h, + ), + port_3_mass_flow_g_s=port_3.port_mass_flow_kg_s * 1.0e3, + port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + flow_kg_s=port_4.flow_kg_s, + node_h=port_4.node_h, + connected_h=port_4.connected_h, + ), + port_4_mass_flow_g_s=port_4.port_mass_flow_kg_s * 1.0e3, + ) + def _write_fixed_chamber_segment( self, *,