diff --git a/PythonModels/systems/test_mql_closure.py b/PythonModels/systems/test_mql_closure.py index 61b434d..d2fa0dc 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 TestMqlPn3NodeBalancePort: + flow_kg_s: float + node_h: float + connected_h: float + port_mass_flow_kg_s: float + + @dataclass(frozen=True) class TestMqlP4NodeBalancePort: flow_kg_s: float @@ -732,21 +740,21 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_2_pressure_pa=p4_port1_remote_orifice_line_port_1.p, port_2_temperature_k=p4_port1_remote_orifice_line_port_1.T, ) - node_balance = self.components.node.balance( - port_2_temperature_k=node_line_port_1.T, - port_2_pressure_pa=node_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + node_balance = self._pn3_node_balance( + node=self.components.node, + primary_properties=node_line_port_1, + port_1=TestMqlPn3NodeBalancePort( flow_kg_s=node_to_resistance_flow, node_h=node_line_port_1.h, connected_h=p4_port1_remote_orifice_line_port_1.h, + port_mass_flow_kg_s=node_to_resistance_flow, ), - port_1_mass_flow_g_s=node_to_resistance_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlPn3NodeBalancePort( flow_kg_s=outlet_node_to_line_flow, node_h=node_line_port_1.h, connected_h=outlet_line.h, + port_mass_flow_kg_s=outlet_node_to_line_flow, ), - port_3_mass_flow_g_s=outlet_node_to_line_flow * 1.0e3, ) node_to_pnl0003_flow = -node_balance.port_2_mass_flow_g_s * 1.0e-3 pnl0003_center_flow = self.components.node_line.resistance_mass_flow() @@ -844,25 +852,29 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_1_temperature_k=p4_port1_remote_orifice_line_port_1.T, ) ) - p4_port1_remote_node_to_orifice_line_flow = -self.components.p4_port1_remote_orifice_node.balance( - port_2_temperature_k=p4_port1_remote_orifice_line_port_1.T, - port_2_pressure_pa=p4_port1_remote_orifice_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port1_next_orifice_resistance_chamber_inlet_node_to_line_flow, + p4_port1_remote_orifice_node_balance = self._pn3_node_balance( + node=self.components.p4_port1_remote_orifice_node, + primary_properties=p4_port1_remote_orifice_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=( + p4_port1_next_orifice_resistance_chamber_inlet_node_to_line_flow + ), node_h=p4_port1_remote_orifice_line_port_1.h, connected_h=p4_port1_next_orifice_resistance_chamber_inlet_line.h, + port_mass_flow_kg_s=( + p4_port1_next_orifice_resistance_chamber_inlet_node_to_line_flow + ), ), - port_1_mass_flow_g_s=( - p4_port1_next_orifice_resistance_chamber_inlet_node_to_line_flow - * 1.0e3 - ), - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + port_3=TestMqlPn3NodeBalancePort( flow_kg_s=-node_to_resistance_flow, node_h=p4_port1_remote_orifice_line_port_1.h, connected_h=node_line_port_1.h, + port_mass_flow_kg_s=-node_to_resistance_flow, ), - port_3_mass_flow_g_s=-node_to_resistance_flow * 1.0e3, - ).port_2_mass_flow_g_s * 1.0e-3 + ) + p4_port1_remote_node_to_orifice_line_flow = ( + -p4_port1_remote_orifice_node_balance.port_2_mass_flow_g_s * 1.0e-3 + ) p4_port1_remote_orifice_line_center_flow = ( self.components.p4_port1_remote_orifice_line.resistance_mass_flow() ) @@ -965,23 +977,21 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_2_temperature_k=p4_port3_next_orifice_line_port_1.T, ) ) - p4_port3_next_orifice_node_balance = ( - self.components.p4_port3_next_orifice_node.balance( - port_2_temperature_k=p4_port3_next_orifice_line_port_1.T, - port_2_pressure_pa=p4_port3_next_orifice_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port3_next_chamber_inlet_node_to_line_flow, - node_h=p4_port3_next_orifice_line_port_1.h, - connected_h=p4_port3_next_chamber_inlet_line.h, - ), - port_1_mass_flow_g_s=p4_port3_next_chamber_inlet_node_to_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=-p4_port3_next_resistance_node_to_next_flow, - node_h=p4_port3_next_orifice_line_port_1.h, - connected_h=p4_port3_next_resistance_node_line_port_1.h, - ), - port_3_mass_flow_g_s=-p4_port3_next_resistance_node_to_next_flow * 1.0e3, - ) + p4_port3_next_orifice_node_balance = self._pn3_node_balance( + node=self.components.p4_port3_next_orifice_node, + primary_properties=p4_port3_next_orifice_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port3_next_chamber_inlet_node_to_line_flow, + node_h=p4_port3_next_orifice_line_port_1.h, + connected_h=p4_port3_next_chamber_inlet_line.h, + port_mass_flow_kg_s=p4_port3_next_chamber_inlet_node_to_line_flow, + ), + port_3=TestMqlPn3NodeBalancePort( + flow_kg_s=-p4_port3_next_resistance_node_to_next_flow, + node_h=p4_port3_next_orifice_line_port_1.h, + connected_h=p4_port3_next_resistance_node_line_port_1.h, + port_mass_flow_kg_s=-p4_port3_next_resistance_node_to_next_flow, + ), ) p4_port3_next_orifice_node_to_line_flow = ( -p4_port3_next_orifice_node_balance.port_2_mass_flow_g_s * 1.0e-3 @@ -1051,27 +1061,25 @@ class TestMqlPn3P4NodeChamberSegmentClosure: orifice=self.components.p4_port1_next_orifice_resistance_chamber_outlet_orifice, ) ) - p4_port1_next_orifice_node_balance = ( - self.components.p4_port1_next_orifice_node.balance( - port_2_temperature_k=p4_port1_next_orifice_line_port_1.T, - port_2_pressure_pa=p4_port1_next_orifice_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port3_next_resistance_chamber_inlet_node_to_line_flow, - node_h=p4_port1_next_orifice_line_port_1.h, - connected_h=p4_port3_next_resistance_chamber_inlet_line.h, + p4_port1_next_orifice_node_balance = self._pn3_node_balance( + node=self.components.p4_port1_next_orifice_node, + primary_properties=p4_port1_next_orifice_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port3_next_resistance_chamber_inlet_node_to_line_flow, + node_h=p4_port1_next_orifice_line_port_1.h, + connected_h=p4_port3_next_resistance_chamber_inlet_line.h, + port_mass_flow_kg_s=( + p4_port3_next_resistance_chamber_inlet_node_to_line_flow ), - port_1_mass_flow_g_s=( - p4_port3_next_resistance_chamber_inlet_node_to_line_flow * 1.0e3 + ), + port_3=TestMqlPn3NodeBalancePort( + flow_kg_s=-p4_port1_next_orifice_resistance_node_to_next_flow, + node_h=p4_port1_next_orifice_line_port_1.h, + connected_h=p4_port1_next_orifice_resistance_line_port_1.h, + port_mass_flow_kg_s=( + -p4_port1_next_orifice_resistance_node_to_next_flow ), - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=-p4_port1_next_orifice_resistance_node_to_next_flow, - node_h=p4_port1_next_orifice_line_port_1.h, - connected_h=p4_port1_next_orifice_resistance_line_port_1.h, - ), - port_3_mass_flow_g_s=( - -p4_port1_next_orifice_resistance_node_to_next_flow * 1.0e3 - ), - ) + ), ) p4_port1_next_orifice_node_to_line_flow = ( -p4_port1_next_orifice_node_balance.port_2_mass_flow_g_s * 1.0e-3 @@ -1084,28 +1092,25 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_boundary=p4_port1_next_orifice_output_line, orifice=self.components.p4_port1_next_orifice, ) - p4_port1_next_orifice_resistance_node_balance = ( - self.components.p4_port1_next_orifice_resistance_node.balance( - port_2_temperature_k=p4_port1_next_orifice_resistance_line_port_1.T, - port_2_pressure_pa=p4_port1_next_orifice_resistance_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port1_next_orifice_resistance_node_to_next_flow, - node_h=p4_port1_next_orifice_resistance_line_port_1.h, - connected_h=p4_port1_next_orifice_line_port_1.h, - ), - port_1_mass_flow_g_s=( - p4_port1_next_orifice_resistance_node_to_next_flow * 1.0e3 - ), - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port1_next_orifice_resistance_chamber_outlet_node_to_line_flow, - node_h=p4_port1_next_orifice_resistance_line_port_1.h, - connected_h=p4_port1_next_orifice_resistance_chamber_outlet_line.h, - ), - port_3_mass_flow_g_s=( + p4_port1_next_orifice_resistance_node_balance = self._pn3_node_balance( + node=self.components.p4_port1_next_orifice_resistance_node, + primary_properties=p4_port1_next_orifice_resistance_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port1_next_orifice_resistance_node_to_next_flow, + node_h=p4_port1_next_orifice_resistance_line_port_1.h, + connected_h=p4_port1_next_orifice_line_port_1.h, + port_mass_flow_kg_s=p4_port1_next_orifice_resistance_node_to_next_flow, + ), + port_3=TestMqlPn3NodeBalancePort( + flow_kg_s=( p4_port1_next_orifice_resistance_chamber_outlet_node_to_line_flow - * 1.0e3 ), - ) + node_h=p4_port1_next_orifice_resistance_line_port_1.h, + connected_h=p4_port1_next_orifice_resistance_chamber_outlet_line.h, + port_mass_flow_kg_s=( + p4_port1_next_orifice_resistance_chamber_outlet_node_to_line_flow + ), + ), ) p4_port1_next_orifice_resistance_node_to_line_flow = ( -p4_port1_next_orifice_resistance_node_balance.port_2_mass_flow_g_s @@ -1119,25 +1124,23 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_boundary=p4_port1_far_primary_line, orifice=self.components.p4_port1_next_orifice_resistance_orifice, ) - p4_port3_next_resistance_node_balance = ( - self.components.p4_port3_next_resistance_node.balance( - port_2_temperature_k=p4_port3_next_resistance_node_line_port_1.T, - port_2_pressure_pa=p4_port3_next_resistance_node_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port3_next_resistance_node_to_next_flow, - node_h=p4_port3_next_resistance_node_line_port_1.h, - connected_h=p4_port3_next_orifice_line_port_1.h, + p4_port3_next_resistance_node_balance = self._pn3_node_balance( + node=self.components.p4_port3_next_resistance_node, + primary_properties=p4_port3_next_resistance_node_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port3_next_resistance_node_to_next_flow, + node_h=p4_port3_next_resistance_node_line_port_1.h, + connected_h=p4_port3_next_orifice_line_port_1.h, + port_mass_flow_kg_s=p4_port3_next_resistance_node_to_next_flow, + ), + port_3=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port3_next_resistance_chamber_outlet_node_to_line_flow, + node_h=p4_port3_next_resistance_node_line_port_1.h, + connected_h=p4_port3_next_resistance_chamber_outlet_line.h, + port_mass_flow_kg_s=( + p4_port3_next_resistance_chamber_outlet_node_to_line_flow ), - port_1_mass_flow_g_s=p4_port3_next_resistance_node_to_next_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port3_next_resistance_chamber_outlet_node_to_line_flow, - node_h=p4_port3_next_resistance_node_line_port_1.h, - connected_h=p4_port3_next_resistance_chamber_outlet_line.h, - ), - port_3_mass_flow_g_s=( - p4_port3_next_resistance_chamber_outlet_node_to_line_flow * 1.0e3 - ), - ) + ), ) p4_port3_next_resistance_node_to_line_flow = ( -p4_port3_next_resistance_node_balance.port_2_mass_flow_g_s * 1.0e-3 @@ -1161,44 +1164,40 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_2_temperature_k=p4_port3_remote_resistance_node_line_port_1.T, ) ) - p4_port3_remote_orifice_node_balance = ( - self.components.p4_port3_remote_orifice_node.balance( - port_2_temperature_k=p4_port3_remote_orifice_line_port_1.T, - port_2_pressure_pa=p4_port3_remote_orifice_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=inlet_node_to_line_flow, - node_h=p4_port3_remote_orifice_line_port_1.h, - connected_h=inlet_line.h, - ), - port_1_mass_flow_g_s=inlet_node_to_line_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port3_remote_node_to_resistance_flow, - node_h=p4_port3_remote_orifice_line_port_1.h, - connected_h=p4_port3_remote_resistance_node_line_port_1.h, - ), - port_3_mass_flow_g_s=p4_port3_remote_node_to_resistance_flow * 1.0e3, - ) + p4_port3_remote_orifice_node_balance = self._pn3_node_balance( + node=self.components.p4_port3_remote_orifice_node, + primary_properties=p4_port3_remote_orifice_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=inlet_node_to_line_flow, + node_h=p4_port3_remote_orifice_line_port_1.h, + connected_h=inlet_line.h, + port_mass_flow_kg_s=inlet_node_to_line_flow, + ), + port_3=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port3_remote_node_to_resistance_flow, + node_h=p4_port3_remote_orifice_line_port_1.h, + connected_h=p4_port3_remote_resistance_node_line_port_1.h, + port_mass_flow_kg_s=p4_port3_remote_node_to_resistance_flow, + ), ) p4_port3_remote_node_to_orifice_line_flow = ( -p4_port3_remote_orifice_node_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_port3_remote_resistance_node_balance = ( - self.components.p4_port3_remote_resistance_node.balance( - port_2_temperature_k=p4_port3_remote_resistance_node_line_port_1.T, - port_2_pressure_pa=p4_port3_remote_resistance_node_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=-p4_port3_remote_node_to_resistance_flow, - node_h=p4_port3_remote_resistance_node_line_port_1.h, - connected_h=p4_port3_remote_orifice_line_port_1.h, - ), - port_1_mass_flow_g_s=-p4_port3_remote_node_to_resistance_flow * 1.0e3, - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port3_next_chamber_outlet_node_to_line_flow, - node_h=p4_port3_remote_resistance_node_line_port_1.h, - connected_h=p4_port3_next_chamber_outlet_line.h, - ), - port_3_mass_flow_g_s=p4_port3_next_chamber_outlet_node_to_line_flow * 1.0e3, - ) + p4_port3_remote_resistance_node_balance = self._pn3_node_balance( + node=self.components.p4_port3_remote_resistance_node, + primary_properties=p4_port3_remote_resistance_node_line_port_1, + port_1=TestMqlPn3NodeBalancePort( + flow_kg_s=-p4_port3_remote_node_to_resistance_flow, + node_h=p4_port3_remote_resistance_node_line_port_1.h, + connected_h=p4_port3_remote_orifice_line_port_1.h, + port_mass_flow_kg_s=-p4_port3_remote_node_to_resistance_flow, + ), + port_3=TestMqlPn3NodeBalancePort( + flow_kg_s=p4_port3_next_chamber_outlet_node_to_line_flow, + node_h=p4_port3_remote_resistance_node_line_port_1.h, + connected_h=p4_port3_next_chamber_outlet_line.h, + port_mass_flow_kg_s=p4_port3_next_chamber_outlet_node_to_line_flow, + ), ) p4_port3_remote_resistance_node_to_line_flow = ( -p4_port3_remote_resistance_node_balance.port_2_mass_flow_g_s * 1.0e-3 @@ -1270,27 +1269,6 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_remote_node_to_primary_line_flow = ( p4_port1_remote_balance.port_2_mass_flow_g_s * 1.0e-3 ) - p4_port1_remote_orifice_node_balance = ( - self.components.p4_port1_remote_orifice_node.balance( - port_2_temperature_k=p4_port1_remote_orifice_line_port_1.T, - port_2_pressure_pa=p4_port1_remote_orifice_line_port_1.p, - port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=p4_port1_next_orifice_resistance_chamber_inlet_node_to_line_flow, - node_h=p4_port1_remote_orifice_line_port_1.h, - connected_h=p4_port1_next_orifice_resistance_chamber_inlet_line.h, - ), - port_1_mass_flow_g_s=( - p4_port1_next_orifice_resistance_chamber_inlet_node_to_line_flow - * 1.0e3 - ), - port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( - flow_kg_s=-node_to_resistance_flow, - node_h=p4_port1_remote_orifice_line_port_1.h, - connected_h=node_line_port_1.h, - ), - port_3_mass_flow_g_s=-node_to_resistance_flow * 1.0e3, - ) - ) p4_port1_far_balance = self._p4_node_balance( node=self.components.p4_port1_far_node, primary_properties=p4_port1_far_primary_line, @@ -1774,6 +1752,31 @@ class TestMqlPn3P4NodeChamberSegmentClosure: connected_h=connected_h, ) + def _pn3_node_balance( + self, + *, + node: TestMqlPneumaticNode3, + primary_properties: ThermodynamicProperties, + port_1: TestMqlPn3NodeBalancePort, + port_3: TestMqlPn3NodeBalancePort, + ) -> TestMqlPneumaticNode3Balance: + 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, + ) + def _p4_node_balance( self, *,