From a09a8c8dafe97453d8fd5645c21f92115db4e0dd Mon Sep 17 00:00:00 2001 From: huojiarong Date: Sat, 18 Jul 2026 09:38:52 +0000 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5test=5Fmql=20P4=E6=A1=A5?= =?UTF-8?q?=E6=8E=A5=E7=8E=AF=E7=BD=91=E7=AE=A1=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonModels/systems/test_mql.py | 40 +++++ PythonModels/systems/test_mql_closure.py | 200 +++++++++++++++++++++-- tests/test_test_mql_pnl0001_segment.py | 60 ++++++- 3 files changed, 274 insertions(+), 26 deletions(-) diff --git a/PythonModels/systems/test_mql.py b/PythonModels/systems/test_mql.py index 1eeee62..55190c9 100644 --- a/PythonModels/systems/test_mql.py +++ b/PythonModels/systems/test_mql.py @@ -4703,6 +4703,25 @@ class TestMqlSystem: p4_port1_next_primary_chamber = self.network.components[ p4_port1_next_primary_chamber_alias ] + p4_port1_next_port1 = self._pnl0002_connection_for_node_port( + p4_port1_next_node_alias, + "port_1", + ) + p4_port1_next_port1_line = self.pnl0002_assembly.lines[ + p4_port1_next_port1.line_alias + ] + p4_bridge_node_alias = p4_port1_next_port1.remote_node_alias + p4_bridge_node = self.node4_assembly[p4_bridge_node_alias] + p4_bridge_primary = self._p4_primary_connection_for_node( + p4_bridge_node_alias + ) + p4_bridge_primary_line = self.pnl0001_assembly.lines[ + p4_bridge_primary.line_alias + ] + p4_bridge_primary_chamber_alias = p4_bridge_primary.chamber_alias + p4_bridge_primary_chamber = self.network.components[ + p4_bridge_primary_chamber_alias + ] p4_port1_remote_orifice = self.pneumatic_assembly.variable_orifices[ p4_port1_remote_neighborhood.port_4.orifice_alias ] @@ -4761,6 +4780,18 @@ class TestMqlSystem: p4_port3_next_primary_chamber = self.network.components[ p4_port3_next_primary_chamber_alias ] + p4_port3_next_port3 = self._pnl0002_connection_for_node_port( + p4_port3_next_node_alias, + "port_3", + ) + if p4_port3_next_port3.remote_node_alias != p4_bridge_node_alias: + raise ValueError( + f"{p4_port3_next_port3.line_alias} does not connect back to " + f"{p4_bridge_node_alias}" + ) + p4_port3_next_port3_line = self.pnl0002_assembly.lines[ + p4_port3_next_port3.line_alias + ] p4_port3_remote_orifice = self.pneumatic_assembly.variable_orifices[ p4_port3_remote_neighborhood.port_4.orifice_alias ] @@ -4827,6 +4858,10 @@ class TestMqlSystem: raise TypeError( f"{p4_port3_next_primary_chamber_alias} is not an AMESim pneumatic volume" ) + if not isinstance(p4_bridge_primary_chamber, AmesimPneumaticVolume): + raise TypeError( + f"{p4_bridge_primary_chamber_alias} is not an AMESim pneumatic volume" + ) if not isinstance(inlet_orifice, AmesimPneumaticOrifice): raise TypeError( f"{spec.inlet_orifice_alias} is not an AMESim pneumatic orifice" @@ -4862,6 +4897,10 @@ class TestMqlSystem: p4_port1_next_node=p4_port1_next_node, p4_port1_next_primary_line=p4_port1_next_primary_line, p4_port1_next_primary_chamber=p4_port1_next_primary_chamber, + p4_port1_next_port1_line=p4_port1_next_port1_line, + p4_bridge_node=p4_bridge_node, + p4_bridge_primary_line=p4_bridge_primary_line, + p4_bridge_primary_chamber=p4_bridge_primary_chamber, p4_port1_remote_orifice=p4_port1_remote_orifice, p4_port1_remote_orifice_line=p4_port1_remote_orifice_line, p4_port1_remote_orifice_node=p4_port1_remote_orifice_node, @@ -4877,6 +4916,7 @@ class TestMqlSystem: p4_port3_next_node=p4_port3_next_node, p4_port3_next_primary_line=p4_port3_next_primary_line, p4_port3_next_primary_chamber=p4_port3_next_primary_chamber, + p4_port3_next_port3_line=p4_port3_next_port3_line, p4_port3_remote_orifice=p4_port3_remote_orifice, p4_port3_remote_orifice_line=p4_port3_remote_orifice_line, p4_port3_remote_orifice_node=p4_port3_remote_orifice_node, diff --git a/PythonModels/systems/test_mql_closure.py b/PythonModels/systems/test_mql_closure.py index 225f5dd..47caf15 100644 --- a/PythonModels/systems/test_mql_closure.py +++ b/PythonModels/systems/test_mql_closure.py @@ -211,6 +211,10 @@ class TestMqlPn3P4NodeChamberSegmentComponents: p4_port1_next_node: TestMqlPneumaticNode4 p4_port1_next_primary_line: AmesimPnl0001Pipe p4_port1_next_primary_chamber: AmesimPneumaticVolume + p4_port1_next_port1_line: AmesimPnl0002Pipe + p4_bridge_node: TestMqlPneumaticNode4 + p4_bridge_primary_line: AmesimPnl0001Pipe + p4_bridge_primary_chamber: AmesimPneumaticVolume p4_port1_remote_orifice: AmesimPneumaticOrifice p4_port1_remote_orifice_line: AmesimPnl0003Pipe p4_port1_remote_orifice_node: TestMqlPneumaticNode3 @@ -226,6 +230,7 @@ class TestMqlPn3P4NodeChamberSegmentComponents: p4_port3_next_node: TestMqlPneumaticNode4 p4_port3_next_primary_line: AmesimPnl0001Pipe p4_port3_next_primary_chamber: AmesimPneumaticVolume + p4_port3_next_port3_line: AmesimPnl0002Pipe p4_port3_remote_orifice: AmesimPneumaticOrifice p4_port3_remote_orifice_line: AmesimPnl0003Pipe p4_port3_remote_orifice_node: TestMqlPneumaticNode3 @@ -258,6 +263,9 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port1_far_port1_line: ThermodynamicProperties p4_port1_next_primary_line: ThermodynamicProperties p4_port1_next_primary_chamber: ThermodynamicProperties + p4_port1_next_port1_line: ThermodynamicProperties + p4_bridge_primary_line: ThermodynamicProperties + p4_bridge_primary_chamber: ThermodynamicProperties p4_port1_remote_orifice_line_port_1: ThermodynamicProperties p4_port1_remote_orifice_line_port_2: ThermodynamicProperties p4_port3_line: ThermodynamicProperties @@ -269,6 +277,7 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port3_far_port3_line: ThermodynamicProperties p4_port3_next_primary_line: ThermodynamicProperties p4_port3_next_primary_chamber: ThermodynamicProperties + p4_port3_next_port3_line: ThermodynamicProperties p4_port3_remote_orifice_line_port_1: ThermodynamicProperties p4_port3_remote_orifice_line_port_2: ThermodynamicProperties p4_port3_remote_resistance_node_line_port_1: ThermodynamicProperties @@ -280,6 +289,7 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port1_remote_balance: TestMqlPneumaticNode4Balance p4_port1_far_balance: TestMqlPneumaticNode4Balance p4_port1_next_balance: TestMqlPneumaticNode4Balance + p4_bridge_balance: TestMqlPneumaticNode4Balance p4_port1_remote_orifice_node_balance: TestMqlPneumaticNode3Balance p4_port3_remote_balance: TestMqlPneumaticNode4Balance p4_port3_far_balance: TestMqlPneumaticNode4Balance @@ -308,6 +318,10 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port1_next_node_to_line_flow: float p4_port1_next_chamber_to_line_flow: float p4_port1_next_node_to_primary_line_flow: float + p4_port1_next_to_bridge_line_flow: float + p4_bridge_to_port1_next_line_flow: float + p4_bridge_chamber_to_line_flow: float + p4_bridge_node_to_primary_line_flow: float p4_port1_remote_node_to_orifice_line_flow: float p4_port1_remote_orifice_line_center_flow: float p4_port1_remote_orifice_to_node_flow: float @@ -323,6 +337,8 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port3_next_node_to_line_flow: float p4_port3_next_chamber_to_line_flow: float p4_port3_next_node_to_primary_line_flow: float + p4_bridge_to_port3_next_line_flow: float + p4_port3_next_to_bridge_line_flow: float p4_port3_remote_node_to_orifice_line_flow: float p4_port3_remote_node_to_resistance_flow: float p4_port3_remote_resistance_node_to_line_flow: float @@ -368,6 +384,9 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *self.components.p4_port1_far_port1_line.get_state_vector(), *self.components.p4_port1_next_primary_line.get_state_vector(), *self.components.p4_port1_next_primary_chamber.get_state_vector(), + *self.components.p4_port1_next_port1_line.get_state_vector(), + *self.components.p4_bridge_primary_line.get_state_vector(), + *self.components.p4_bridge_primary_chamber.get_state_vector(), *self.components.p4_port1_remote_orifice_line.get_state_vector(), *self.components.p4_port3_line.get_state_vector(), *self.components.p4_port3_remote_primary_line.get_state_vector(), @@ -378,13 +397,14 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *self.components.p4_port3_far_port3_line.get_state_vector(), *self.components.p4_port3_next_primary_line.get_state_vector(), *self.components.p4_port3_next_primary_chamber.get_state_vector(), + *self.components.p4_port3_next_port3_line.get_state_vector(), *self.components.p4_port3_remote_resistance_node_line.get_state_vector(), *self.components.p4_port3_remote_orifice_line.get_state_vector(), ] def apply_state_vector(self, values: list[float]) -> None: - if len(values) != 62: - raise ValueError("PN3/P4 node chamber segment state vector requires sixty-two values") + if len(values) != 70: + raise ValueError("PN3/P4 node chamber segment state vector requires seventy values") self.components.inlet_line.set_state_vector(values[:2]) self.components.volume.set_state_vector(values[2:4]) self.components.outlet_line.set_state_vector(values[4:6]) @@ -400,18 +420,22 @@ class TestMqlPn3P4NodeChamberSegmentClosure: self.components.p4_port1_far_port1_line.set_state_vector(values[26:28]) self.components.p4_port1_next_primary_line.set_state_vector(values[28:30]) self.components.p4_port1_next_primary_chamber.set_state_vector(values[30:32]) - self.components.p4_port1_remote_orifice_line.set_state_vector(values[32:36]) - self.components.p4_port3_line.set_state_vector(values[36:38]) - self.components.p4_port3_remote_primary_line.set_state_vector(values[38:40]) - self.components.p4_port3_remote_primary_chamber.set_state_vector(values[40:42]) - self.components.p4_port3_remote_port3_line.set_state_vector(values[42:44]) - self.components.p4_port3_far_primary_line.set_state_vector(values[44:46]) - self.components.p4_port3_far_primary_chamber.set_state_vector(values[46:48]) - self.components.p4_port3_far_port3_line.set_state_vector(values[48:50]) - self.components.p4_port3_next_primary_line.set_state_vector(values[50:52]) - self.components.p4_port3_next_primary_chamber.set_state_vector(values[52:54]) - self.components.p4_port3_remote_resistance_node_line.set_state_vector(values[54:58]) - self.components.p4_port3_remote_orifice_line.set_state_vector(values[58:]) + self.components.p4_port1_next_port1_line.set_state_vector(values[32:34]) + self.components.p4_bridge_primary_line.set_state_vector(values[34:36]) + self.components.p4_bridge_primary_chamber.set_state_vector(values[36:38]) + self.components.p4_port1_remote_orifice_line.set_state_vector(values[38:42]) + self.components.p4_port3_line.set_state_vector(values[42:44]) + self.components.p4_port3_remote_primary_line.set_state_vector(values[44:46]) + self.components.p4_port3_remote_primary_chamber.set_state_vector(values[46:48]) + self.components.p4_port3_remote_port3_line.set_state_vector(values[48:50]) + self.components.p4_port3_far_primary_line.set_state_vector(values[50:52]) + self.components.p4_port3_far_primary_chamber.set_state_vector(values[52:54]) + self.components.p4_port3_far_port3_line.set_state_vector(values[54:56]) + self.components.p4_port3_next_primary_line.set_state_vector(values[56:58]) + self.components.p4_port3_next_primary_chamber.set_state_vector(values[58:60]) + self.components.p4_port3_next_port3_line.set_state_vector(values[60:62]) + self.components.p4_port3_remote_resistance_node_line.set_state_vector(values[62:66]) + self.components.p4_port3_remote_orifice_line.set_state_vector(values[66:]) def snapshot( self, @@ -445,6 +469,9 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_next_primary_chamber = ( self.components.p4_port1_next_primary_chamber.properties() ) + p4_port1_next_port1_line = self.components.p4_port1_next_port1_line.properties() + p4_bridge_primary_line = self.components.p4_bridge_primary_line.properties() + p4_bridge_primary_chamber = self.components.p4_bridge_primary_chamber.properties() p4_port1_remote_orifice_line_port_1 = ( self.components.p4_port1_remote_orifice_line.properties_1() ) @@ -470,6 +497,7 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_next_primary_chamber = ( self.components.p4_port3_next_primary_chamber.properties() ) + p4_port3_next_port3_line = self.components.p4_port3_next_port3_line.properties() p4_port3_remote_orifice_line_port_1 = ( self.components.p4_port3_remote_orifice_line.properties_1() ) @@ -592,6 +620,24 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_1_temperature_k=p4_port1_next_primary_chamber.T, ) ) + p4_port1_next_to_bridge_line_flow = ( + self.components.p4_port1_next_port1_line.port_mass_flow( + port_pressure_pa=p4_port1_next_primary_line.p, + port_temperature_k=p4_port1_next_primary_line.T, + ) + ) + p4_bridge_to_port1_next_line_flow = ( + self.components.p4_port1_next_port1_line.port_mass_flow( + port_pressure_pa=p4_bridge_primary_line.p, + port_temperature_k=p4_bridge_primary_line.T, + ) + ) + p4_bridge_chamber_to_line_flow = ( + self.components.p4_bridge_primary_line.resistance_mass_flow( + port_1_pressure_pa=p4_bridge_primary_chamber.p, + port_1_temperature_k=p4_bridge_primary_chamber.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, @@ -664,6 +710,18 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_1_temperature_k=p4_port3_next_primary_chamber.T, ) ) + p4_bridge_to_port3_next_line_flow = ( + self.components.p4_port3_next_port3_line.port_mass_flow( + port_pressure_pa=p4_bridge_primary_line.p, + port_temperature_k=p4_bridge_primary_line.T, + ) + ) + p4_port3_next_to_bridge_line_flow = ( + self.components.p4_port3_next_port3_line.port_mass_flow( + port_pressure_pa=p4_port3_next_primary_line.p, + port_temperature_k=p4_port3_next_primary_line.T, + ) + ) p4_port3_remote_node_to_resistance_flow = ( self.components.p4_port3_remote_orifice_resistance.mass_flow( port_1_pressure_pa=p4_port3_remote_orifice_line_port_1.p, @@ -812,8 +870,12 @@ class TestMqlPn3P4NodeChamberSegmentClosure: 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=0.0, - port_1_mass_flow_g_s=0.0, + port_1_enthalpy_flow_w=self._enthalpy_flow_from_node( + 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_1_mass_flow_g_s=-p4_port1_next_to_bridge_line_flow * 1.0e3, port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( flow_kg_s=p4_port1_next_node_to_line_flow, node_h=p4_port1_next_primary_line.h, @@ -885,14 +947,39 @@ class TestMqlPn3P4NodeChamberSegmentClosure: connected_h=p4_port3_far_port3_line.h, ), port_1_mass_flow_g_s=-p4_port3_next_node_to_line_flow * 1.0e3, - port_3_enthalpy_flow_w=0.0, - port_3_mass_flow_g_s=0.0, + port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + 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_3_mass_flow_g_s=-p4_port3_next_to_bridge_line_flow * 1.0e3, port_4_enthalpy_flow_w=0.0, port_4_mass_flow_g_s=0.0, ) 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( + 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_1_mass_flow_g_s=-p4_bridge_to_port3_next_line_flow * 1.0e3, + port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + 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_3_mass_flow_g_s=-p4_bridge_to_port1_next_line_flow * 1.0e3, + port_4_enthalpy_flow_w=0.0, + port_4_mass_flow_g_s=0.0, + ) + p4_bridge_node_to_primary_line_flow = ( + p4_bridge_balance.port_2_mass_flow_g_s * 1.0e-3 + ) snapshot = TestMqlPn3P4NodeChamberSegmentSnapshot( inlet_line=inlet_line, @@ -912,6 +999,9 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_far_port1_line=p4_port1_far_port1_line, p4_port1_next_primary_line=p4_port1_next_primary_line, p4_port1_next_primary_chamber=p4_port1_next_primary_chamber, + p4_port1_next_port1_line=p4_port1_next_port1_line, + p4_bridge_primary_line=p4_bridge_primary_line, + p4_bridge_primary_chamber=p4_bridge_primary_chamber, p4_port1_remote_orifice_line_port_1=p4_port1_remote_orifice_line_port_1, p4_port1_remote_orifice_line_port_2=p4_port1_remote_orifice_line_port_2, p4_port3_line=p4_port3_line, @@ -923,6 +1013,7 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_far_port3_line=p4_port3_far_port3_line, p4_port3_next_primary_line=p4_port3_next_primary_line, p4_port3_next_primary_chamber=p4_port3_next_primary_chamber, + p4_port3_next_port3_line=p4_port3_next_port3_line, p4_port3_remote_orifice_line_port_1=p4_port3_remote_orifice_line_port_1, p4_port3_remote_orifice_line_port_2=p4_port3_remote_orifice_line_port_2, p4_port3_remote_resistance_node_line_port_1=( @@ -938,6 +1029,7 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_remote_balance=p4_port1_remote_balance, p4_port1_far_balance=p4_port1_far_balance, p4_port1_next_balance=p4_port1_next_balance, + p4_bridge_balance=p4_bridge_balance, p4_port1_remote_orifice_node_balance=p4_port1_remote_orifice_node_balance, p4_port3_remote_balance=p4_port3_remote_balance, p4_port3_far_balance=p4_port3_far_balance, @@ -974,6 +1066,10 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_next_node_to_primary_line_flow=( p4_port1_next_node_to_primary_line_flow ), + p4_port1_next_to_bridge_line_flow=p4_port1_next_to_bridge_line_flow, + p4_bridge_to_port1_next_line_flow=p4_bridge_to_port1_next_line_flow, + p4_bridge_chamber_to_line_flow=p4_bridge_chamber_to_line_flow, + p4_bridge_node_to_primary_line_flow=p4_bridge_node_to_primary_line_flow, p4_port1_remote_node_to_orifice_line_flow=( p4_port1_remote_node_to_orifice_line_flow ), @@ -999,6 +1095,8 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_next_node_to_primary_line_flow=( p4_port3_next_node_to_primary_line_flow ), + p4_bridge_to_port3_next_line_flow=p4_bridge_to_port3_next_line_flow, + p4_port3_next_to_bridge_line_flow=p4_port3_next_to_bridge_line_flow, p4_port3_remote_node_to_orifice_line_flow=( p4_port3_remote_node_to_orifice_line_flow ), @@ -1232,6 +1330,27 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_next_primary_chamber.port_a.m_flow = -snapshot.p4_port1_next_chamber_to_line_flow p4_port1_next_primary_chamber.port_a.h_outflow = snapshot.p4_port1_next_primary_chamber.h + p4_port1_next_port1_line = self.components.p4_port1_next_port1_line + p4_port1_next_port1_line.port_1.p = snapshot.p4_port1_next_primary_line.p + p4_port1_next_port1_line.port_1.m_flow = snapshot.p4_port1_next_to_bridge_line_flow + p4_port1_next_port1_line.port_1.h_outflow = snapshot.p4_port1_next_port1_line.h + p4_port1_next_port1_line.port_2.p = snapshot.p4_bridge_primary_line.p + p4_port1_next_port1_line.port_2.m_flow = snapshot.p4_bridge_to_port1_next_line_flow + p4_port1_next_port1_line.port_2.h_outflow = snapshot.p4_port1_next_port1_line.h + + p4_bridge_primary_line = self.components.p4_bridge_primary_line + p4_bridge_primary_line.port_1.p = snapshot.p4_bridge_primary_chamber.p + p4_bridge_primary_line.port_1.m_flow = snapshot.p4_bridge_chamber_to_line_flow + p4_bridge_primary_line.port_1.h_outflow = snapshot.p4_bridge_primary_line.h + p4_bridge_primary_line.port_2.p = snapshot.p4_bridge_primary_line.p + p4_bridge_primary_line.port_2.m_flow = snapshot.p4_bridge_node_to_primary_line_flow + p4_bridge_primary_line.port_2.h_outflow = snapshot.p4_bridge_primary_line.h + + p4_bridge_primary_chamber = self.components.p4_bridge_primary_chamber + p4_bridge_primary_chamber.port_a.p = snapshot.p4_bridge_primary_chamber.p + p4_bridge_primary_chamber.port_a.m_flow = -snapshot.p4_bridge_chamber_to_line_flow + p4_bridge_primary_chamber.port_a.h_outflow = snapshot.p4_bridge_primary_chamber.h + p4_port1_remote_orifice_line = self.components.p4_port1_remote_orifice_line p4_port1_remote_orifice_line.port_1.p = snapshot.p4_port1_remote_orifice_line_port_1.p p4_port1_remote_orifice_line.port_1.m_flow = snapshot.p4_port1_remote_node_to_orifice_line_flow @@ -1329,6 +1448,14 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_next_primary_chamber.port_a.m_flow = -snapshot.p4_port3_next_chamber_to_line_flow p4_port3_next_primary_chamber.port_a.h_outflow = snapshot.p4_port3_next_primary_chamber.h + p4_port3_next_port3_line = self.components.p4_port3_next_port3_line + p4_port3_next_port3_line.port_1.p = snapshot.p4_bridge_primary_line.p + p4_port3_next_port3_line.port_1.m_flow = snapshot.p4_bridge_to_port3_next_line_flow + p4_port3_next_port3_line.port_1.h_outflow = snapshot.p4_port3_next_port3_line.h + p4_port3_next_port3_line.port_2.p = snapshot.p4_port3_next_primary_line.p + p4_port3_next_port3_line.port_2.m_flow = snapshot.p4_port3_next_to_bridge_line_flow + p4_port3_next_port3_line.port_2.h_outflow = snapshot.p4_port3_next_port3_line.h + p4_port3_remote_orifice_line = self.components.p4_port3_remote_orifice_line p4_port3_remote_orifice_line.port_1.p = snapshot.p4_port3_remote_orifice_line_port_1.p p4_port3_remote_orifice_line.port_1.m_flow = snapshot.p4_port3_remote_node_to_orifice_line_flow @@ -1498,6 +1625,31 @@ class TestMqlPn3P4NodeChamberSegmentClosure: internal_h=snapshot.p4_port1_next_primary_chamber.h, ) ) + p4_port1_next_port1_derivative = ( + self.components.p4_port1_next_port1_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_port1_next_to_bridge_line_flow, + connected_h_1=snapshot.p4_port1_next_primary_line.h, + port_2_m_flow=snapshot.p4_bridge_to_port1_next_line_flow, + connected_h_2=snapshot.p4_bridge_primary_line.h, + ) + ) + p4_bridge_primary_derivative = ( + self.components.p4_bridge_primary_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_bridge_chamber_to_line_flow, + connected_h_1=snapshot.p4_bridge_primary_chamber.h, + port_2_m_flow=snapshot.p4_bridge_node_to_primary_line_flow, + connected_h_2=snapshot.p4_bridge_primary_line.h, + ) + ) + p4_bridge_chamber_derivative = ( + self.components.p4_bridge_primary_chamber.derivatives_from_two_connections( + port_a_m_flow=-snapshot.p4_bridge_chamber_to_line_flow, + connected_h_a=snapshot.p4_bridge_primary_line.h, + port_b_m_flow=0.0, + connected_h_b=snapshot.p4_bridge_primary_chamber.h, + internal_h=snapshot.p4_bridge_primary_chamber.h, + ) + ) p4_port1_remote_orifice_derivative_1, p4_port1_remote_orifice_derivative_2 = ( self.components.p4_port1_remote_orifice_line.derivatives_from_connections( port_1_m_flow=snapshot.p4_port1_remote_node_to_orifice_line_flow, @@ -1579,6 +1731,14 @@ class TestMqlPn3P4NodeChamberSegmentClosure: internal_h=snapshot.p4_port3_next_primary_chamber.h, ) ) + p4_port3_next_port3_derivative = ( + self.components.p4_port3_next_port3_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_bridge_to_port3_next_line_flow, + connected_h_1=snapshot.p4_bridge_primary_line.h, + port_2_m_flow=snapshot.p4_port3_next_to_bridge_line_flow, + connected_h_2=snapshot.p4_port3_next_primary_line.h, + ) + ) ( p4_port3_remote_resistance_derivative_1, p4_port3_remote_resistance_derivative_2, @@ -1613,6 +1773,9 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *p4_port1_far_port1_derivative.as_vector(), *p4_port1_next_primary_derivative.as_vector(), *p4_port1_next_chamber_derivative.as_vector(), + *p4_port1_next_port1_derivative.as_vector(), + *p4_bridge_primary_derivative.as_vector(), + *p4_bridge_chamber_derivative.as_vector(), *p4_port1_remote_orifice_derivative_1.as_vector(), *p4_port1_remote_orifice_derivative_2.as_vector(), *p4_port3_derivative.as_vector(), @@ -1624,6 +1787,7 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *p4_port3_far_port3_derivative.as_vector(), *p4_port3_next_primary_derivative.as_vector(), *p4_port3_next_chamber_derivative.as_vector(), + *p4_port3_next_port3_derivative.as_vector(), *p4_port3_remote_resistance_derivative_1.as_vector(), *p4_port3_remote_resistance_derivative_2.as_vector(), *p4_port3_remote_orifice_derivative_1.as_vector(), diff --git a/tests/test_test_mql_pnl0001_segment.py b/tests/test_test_mql_pnl0001_segment.py index a1cd276..a8fc44f 100644 --- a/tests/test_test_mql_pnl0001_segment.py +++ b/tests/test_test_mql_pnl0001_segment.py @@ -298,6 +298,10 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port1_next_primary_chamber.name, "pn_c1_12", ) + self.assertEqual(closure.components.p4_port1_next_port1_line.name, "pneumatic_81") + self.assertEqual(closure.components.p4_bridge_node.alias, "pnnode4_20") + self.assertEqual(closure.components.p4_bridge_primary_line.name, "pneumatic_72") + self.assertEqual(closure.components.p4_bridge_primary_chamber.name, "pn_c1_13") self.assertEqual( closure.components.p4_port1_remote_orifice.name, "pn_morifice_10", @@ -343,6 +347,7 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port3_next_primary_chamber.name, "pn_c1_14", ) + self.assertEqual(closure.components.p4_port3_next_port3_line.name, "pneumatic_84") self.assertEqual( closure.components.p4_port3_remote_orifice.name, "pn_morifice_1", @@ -371,8 +376,8 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port3_remote_resistance_orifice.name, "pn_morifice_14", ) - self.assertEqual(len(closure.initial_state_vector()), 62) - self.assertEqual(len(rhs), 62) + self.assertEqual(len(closure.initial_state_vector()), 70) + self.assertEqual(len(rhs), 70) self.assertAlmostEqual( snapshot.p4_balance.pressure_pa, snapshot.p4_primary_line.p, @@ -441,6 +446,24 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): port1_far_port1.remote_node_alias ).line_alias, ) + port1_next_port1 = self.system._pnl0002_connection_for_node_port( + closure.components.p4_port1_next_node.alias, + "port_1", + ) + self.assertEqual( + closure.components.p4_port1_next_port1_line.name, + port1_next_port1.line_alias, + ) + self.assertEqual( + closure.components.p4_bridge_node.alias, + port1_next_port1.remote_node_alias, + ) + self.assertEqual( + closure.components.p4_bridge_primary_line.name, + self.system._p4_primary_connection_for_node( + closure.components.p4_bridge_node.alias + ).line_alias, + ) self.assertEqual( closure.components.p4_port1_remote_orifice.name, port1_remote_neighborhood.port_4.orifice_alias, @@ -496,6 +519,18 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): port3_far_port3.remote_node_alias ).line_alias, ) + port3_next_port3 = self.system._pnl0002_connection_for_node_port( + closure.components.p4_port3_next_node.alias, + "port_3", + ) + self.assertEqual( + closure.components.p4_port3_next_port3_line.name, + port3_next_port3.line_alias, + ) + self.assertEqual( + closure.components.p4_bridge_node.alias, + port3_next_port3.remote_node_alias, + ) self.assertEqual( closure.components.p4_port3_remote_orifice.name, port3_remote_neighborhood.port_4.orifice_alias, @@ -578,7 +613,15 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): ) self.assertAlmostEqual( snapshot.p4_port1_next_node_to_primary_line_flow - + snapshot.p4_port1_next_node_to_line_flow, + + snapshot.p4_port1_next_node_to_line_flow + + snapshot.p4_port1_next_to_bridge_line_flow, + 0.0, + delta=1.0e-12, + ) + self.assertAlmostEqual( + snapshot.p4_bridge_node_to_primary_line_flow + + snapshot.p4_bridge_to_port1_next_line_flow + + snapshot.p4_bridge_to_port3_next_line_flow, 0.0, delta=1.0e-12, ) @@ -617,18 +660,19 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): ) self.assertAlmostEqual( snapshot.p4_port3_next_node_to_primary_line_flow - + snapshot.p4_port3_next_node_to_line_flow, + + snapshot.p4_port3_next_node_to_line_flow + + snapshot.p4_port3_next_to_bridge_line_flow, 0.0, delta=1.0e-12, ) - mass_derivative_sum = sum(rhs[index] for index in range(0, 62, 2)) + mass_derivative_sum = sum(rhs[index] for index in range(0, 70, 2)) self.assertAlmostEqual( mass_derivative_sum, 0.0, delta=1.0e-12, ) - def test_simulates_sixty_two_state_pn3_p4_node_chamber_segment(self) -> None: + def test_simulates_seventy_state_pn3_p4_node_chamber_segment(self) -> None: solution = self.system.simulate_pn3_p4_node_chamber_segment_from_spec( self.spec, inlet_node_pressure_pa=15.31e6, @@ -643,8 +687,8 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): self.assertTrue(solution.success) self.assertEqual(len(solution.t), 3) - self.assertEqual(len(solution.y), 62) - self.assertEqual([len(row) for row in solution.y], [3] * 62) + self.assertEqual(len(solution.y), 70) + self.assertEqual([len(row) for row in solution.y], [3] * 70) if __name__ == "__main__":