From 62c8aabeabf8ca0b32f7750e9c175fce49d80ba1 Mon Sep 17 00:00:00 2001 From: huojiarong Date: Sat, 18 Jul 2026 08:35:42 +0000 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=85=A5test=5Fmql=E7=9B=B8=E9=82=BBP?= =?UTF-8?q?4=E8=BF=9C=E7=AB=AF=E4=B8=BB=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PythonModels/systems/test_mql.py | 87 +++++- PythonModels/systems/test_mql_closure.py | 348 ++++++++++++++++++++++- tests/test_test_mql_pnl0001_segment.py | 110 ++++++- 3 files changed, 524 insertions(+), 21 deletions(-) diff --git a/PythonModels/systems/test_mql.py b/PythonModels/systems/test_mql.py index b6ad0ed..e9b216d 100644 --- a/PythonModels/systems/test_mql.py +++ b/PythonModels/systems/test_mql.py @@ -4564,12 +4564,17 @@ class TestMqlSystem: resistance_boundary_pressure_pa: float, inlet_node_temperature_k: float = 293.15, resistance_boundary_temperature_k: float = 293.15, + p4_port1_remote_orifice_boundary_pressure_pa: float = 15.3e6, + p4_port1_remote_orifice_boundary_temperature_k: float = 293.15, + p4_port3_remote_orifice_boundary_pressure_pa: float = 15.3e6, + p4_port3_remote_orifice_boundary_temperature_k: float = 293.15, ): """Close a PN3 chamber segment through the adjacent real P4 node. The P4 primary pressure/temperature is supplied by the PNL0001 line on - P4 port 2. Ports 1 and 3 use the adjacent PNL0002 center compliances; - their far P4 nodes remain prescribed boundaries in this local closure. + P4 port 2. Ports 1 and 3 use the adjacent PNL0002 center compliances. + The next P4 nodes contribute their primary PNL0001/chamber states; + PNVO upstream endpoints remain prescribed boundaries in this local closure. """ from PythonModels.components.amesim_pneumatic import ( AmesimPneumaticOrifice, @@ -4635,6 +4640,24 @@ class TestMqlSystem: p4_port1_remote_primary_chamber = self.network.components[ p4_port1_remote_primary_chamber_alias ] + p4_port1_remote_port1_line = self.pnl0002_assembly.lines[ + p4_port1_remote_neighborhood.port_1.line_alias + ] + p4_port1_far_node_alias = p4_port1_remote_neighborhood.port_1.remote_node_alias + p4_port1_far_node = self.node4_assembly[p4_port1_far_node_alias] + p4_port1_far_primary = self._p4_primary_connection_for_node( + p4_port1_far_node_alias + ) + p4_port1_far_primary_line = self.pnl0001_assembly.lines[ + p4_port1_far_primary.line_alias + ] + p4_port1_far_primary_chamber_alias = p4_port1_far_primary.chamber_alias + p4_port1_far_primary_chamber = self.network.components[ + p4_port1_far_primary_chamber_alias + ] + p4_port1_remote_orifice = self.pneumatic_assembly.variable_orifices[ + p4_port1_remote_neighborhood.port_4.orifice_alias + ] p4_port3_remote_neighborhood = self.p4_node_neighborhood( p4_neighborhood.port_3.remote_node_alias ) @@ -4650,6 +4673,24 @@ class TestMqlSystem: p4_port3_remote_primary_chamber = self.network.components[ p4_port3_remote_primary_chamber_alias ] + p4_port3_remote_port3_line = self.pnl0002_assembly.lines[ + p4_port3_remote_neighborhood.port_3.line_alias + ] + p4_port3_far_node_alias = p4_port3_remote_neighborhood.port_3.remote_node_alias + p4_port3_far_node = self.node4_assembly[p4_port3_far_node_alias] + p4_port3_far_primary = self._p4_primary_connection_for_node( + p4_port3_far_node_alias + ) + p4_port3_far_primary_line = self.pnl0001_assembly.lines[ + p4_port3_far_primary.line_alias + ] + p4_port3_far_primary_chamber_alias = p4_port3_far_primary.chamber_alias + p4_port3_far_primary_chamber = self.network.components[ + p4_port3_far_primary_chamber_alias + ] + p4_port3_remote_orifice = self.pneumatic_assembly.variable_orifices[ + p4_port3_remote_neighborhood.port_4.orifice_alias + ] volume = self.network.components[spec.volume_alias] inlet_orifice = self.network.components[spec.inlet_orifice_alias] outlet_orifice = self.network.components[spec.outlet_orifice_alias] @@ -4667,6 +4708,14 @@ class TestMqlSystem: raise TypeError( f"{p4_port3_remote_primary_chamber_alias} is not an AMESim pneumatic volume" ) + if not isinstance(p4_port1_far_primary_chamber, AmesimPneumaticVolume): + raise TypeError( + f"{p4_port1_far_primary_chamber_alias} is not an AMESim pneumatic volume" + ) + if not isinstance(p4_port3_far_primary_chamber, AmesimPneumaticVolume): + raise TypeError( + f"{p4_port3_far_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" @@ -4690,10 +4739,20 @@ class TestMqlSystem: p4_port1_remote_node=p4_port1_remote_node, p4_port1_remote_primary_line=p4_port1_remote_primary_line, p4_port1_remote_primary_chamber=p4_port1_remote_primary_chamber, + p4_port1_remote_port1_line=p4_port1_remote_port1_line, + p4_port1_far_node=p4_port1_far_node, + p4_port1_far_primary_line=p4_port1_far_primary_line, + p4_port1_far_primary_chamber=p4_port1_far_primary_chamber, + p4_port1_remote_orifice=p4_port1_remote_orifice, p4_port3_line=p4_port3_line, p4_port3_remote_node=p4_port3_remote_node, p4_port3_remote_primary_line=p4_port3_remote_primary_line, p4_port3_remote_primary_chamber=p4_port3_remote_primary_chamber, + p4_port3_remote_port3_line=p4_port3_remote_port3_line, + p4_port3_far_node=p4_port3_far_node, + p4_port3_far_primary_line=p4_port3_far_primary_line, + p4_port3_far_primary_chamber=p4_port3_far_primary_chamber, + p4_port3_remote_orifice=p4_port3_remote_orifice, volume=volume, inlet_orifice=inlet_orifice, outlet_orifice=outlet_orifice, @@ -4707,6 +4766,14 @@ class TestMqlSystem: pressure_pa=resistance_boundary_pressure_pa, temperature_k=resistance_boundary_temperature_k, ), + p4_port1_remote_orifice_boundary=TestMqlPneumaticBoundaryCondition( + pressure_pa=p4_port1_remote_orifice_boundary_pressure_pa, + temperature_k=p4_port1_remote_orifice_boundary_temperature_k, + ), + p4_port3_remote_orifice_boundary=TestMqlPneumaticBoundaryCondition( + pressure_pa=p4_port3_remote_orifice_boundary_pressure_pa, + temperature_k=p4_port3_remote_orifice_boundary_temperature_k, + ), ) def simulate_pn3_p4_node_chamber_segment_from_spec( @@ -4717,6 +4784,10 @@ class TestMqlSystem: resistance_boundary_pressure_pa: float, inlet_node_temperature_k: float = 293.15, resistance_boundary_temperature_k: float = 293.15, + p4_port1_remote_orifice_boundary_pressure_pa: float = 15.3e6, + p4_port1_remote_orifice_boundary_temperature_k: float = 293.15, + p4_port3_remote_orifice_boundary_pressure_pa: float = 15.3e6, + p4_port3_remote_orifice_boundary_temperature_k: float = 293.15, config: SolveIVPConfig | None = None, t_eval: list[float] | None = None, ): @@ -4726,6 +4797,18 @@ class TestMqlSystem: resistance_boundary_pressure_pa=resistance_boundary_pressure_pa, inlet_node_temperature_k=inlet_node_temperature_k, resistance_boundary_temperature_k=resistance_boundary_temperature_k, + p4_port1_remote_orifice_boundary_pressure_pa=( + p4_port1_remote_orifice_boundary_pressure_pa + ), + p4_port1_remote_orifice_boundary_temperature_k=( + p4_port1_remote_orifice_boundary_temperature_k + ), + p4_port3_remote_orifice_boundary_pressure_pa=( + p4_port3_remote_orifice_boundary_pressure_pa + ), + p4_port3_remote_orifice_boundary_temperature_k=( + p4_port3_remote_orifice_boundary_temperature_k + ), ) run_config = config or SolveIVPConfig(t_stop=1.0e-4, max_step=1.0e-5) return integrate_ode( diff --git a/PythonModels/systems/test_mql_closure.py b/PythonModels/systems/test_mql_closure.py index 1c97d06..74f4956 100644 --- a/PythonModels/systems/test_mql_closure.py +++ b/PythonModels/systems/test_mql_closure.py @@ -203,10 +203,20 @@ class TestMqlPn3P4NodeChamberSegmentComponents: p4_port1_remote_node: TestMqlPneumaticNode4 p4_port1_remote_primary_line: AmesimPnl0001Pipe p4_port1_remote_primary_chamber: AmesimPneumaticVolume + p4_port1_remote_port1_line: AmesimPnl0002Pipe + p4_port1_far_node: TestMqlPneumaticNode4 + p4_port1_far_primary_line: AmesimPnl0001Pipe + p4_port1_far_primary_chamber: AmesimPneumaticVolume + p4_port1_remote_orifice: AmesimPneumaticOrifice p4_port3_line: AmesimPnl0002Pipe p4_port3_remote_node: TestMqlPneumaticNode4 p4_port3_remote_primary_line: AmesimPnl0001Pipe p4_port3_remote_primary_chamber: AmesimPneumaticVolume + p4_port3_remote_port3_line: AmesimPnl0002Pipe + p4_port3_far_node: TestMqlPneumaticNode4 + p4_port3_far_primary_line: AmesimPnl0001Pipe + p4_port3_far_primary_chamber: AmesimPneumaticVolume + p4_port3_remote_orifice: AmesimPneumaticOrifice volume: AmesimPneumaticVolume inlet_orifice: AmesimPneumaticOrifice outlet_orifice: AmesimPneumaticOrifice @@ -226,15 +236,25 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port1_line: ThermodynamicProperties p4_port1_remote_primary_line: ThermodynamicProperties p4_port1_remote_primary_chamber: ThermodynamicProperties + p4_port1_remote_port1_line: ThermodynamicProperties + p4_port1_far_primary_line: ThermodynamicProperties + p4_port1_far_primary_chamber: ThermodynamicProperties + p4_port1_remote_orifice_boundary: ThermodynamicProperties p4_port3_line: ThermodynamicProperties p4_port3_remote_primary_line: ThermodynamicProperties p4_port3_remote_primary_chamber: ThermodynamicProperties + p4_port3_remote_port3_line: ThermodynamicProperties + p4_port3_far_primary_line: ThermodynamicProperties + p4_port3_far_primary_chamber: ThermodynamicProperties + p4_port3_remote_orifice_boundary: ThermodynamicProperties inlet_node: ThermodynamicProperties resistance_boundary: ThermodynamicProperties node_balance: TestMqlPneumaticNode3Balance p4_balance: TestMqlPneumaticNode4Balance p4_port1_remote_balance: TestMqlPneumaticNode4Balance + p4_port1_far_balance: TestMqlPneumaticNode4Balance p4_port3_remote_balance: TestMqlPneumaticNode4Balance + p4_port3_far_balance: TestMqlPneumaticNode4Balance inlet_node_to_line_flow: float inlet_line_to_chamber_flow: float outlet_node_to_line_flow: float @@ -249,10 +269,20 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port1_remote_node_to_line_flow: float p4_port1_remote_chamber_to_line_flow: float p4_port1_remote_node_to_primary_line_flow: float + p4_port1_remote_to_port1_line_flow: float + p4_port1_far_node_to_line_flow: float + p4_port1_far_chamber_to_line_flow: float + p4_port1_far_node_to_primary_line_flow: float + p4_port1_remote_orifice_to_node_flow: float p4_to_port3_line_flow: float p4_port3_remote_node_to_line_flow: float p4_port3_remote_chamber_to_line_flow: float p4_port3_remote_node_to_primary_line_flow: float + p4_port3_remote_to_port3_line_flow: float + p4_port3_far_node_to_line_flow: float + p4_port3_far_chamber_to_line_flow: float + p4_port3_far_node_to_primary_line_flow: float + p4_port3_remote_orifice_to_node_flow: float class TestMqlPn3P4NodeChamberSegmentClosure: @@ -269,10 +299,14 @@ class TestMqlPn3P4NodeChamberSegmentClosure: components: TestMqlPn3P4NodeChamberSegmentComponents, inlet_node: TestMqlPneumaticBoundaryCondition, resistance_boundary: TestMqlPneumaticBoundaryCondition, + p4_port1_remote_orifice_boundary: TestMqlPneumaticBoundaryCondition, + p4_port3_remote_orifice_boundary: TestMqlPneumaticBoundaryCondition, ) -> None: self.components = components self.inlet_node = inlet_node self.resistance_boundary = resistance_boundary + self.p4_port1_remote_orifice_boundary = p4_port1_remote_orifice_boundary + self.p4_port3_remote_orifice_boundary = p4_port3_remote_orifice_boundary def initial_state_vector(self) -> list[float]: return [ @@ -285,14 +319,20 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *self.components.p4_port1_line.get_state_vector(), *self.components.p4_port1_remote_primary_line.get_state_vector(), *self.components.p4_port1_remote_primary_chamber.get_state_vector(), + *self.components.p4_port1_remote_port1_line.get_state_vector(), + *self.components.p4_port1_far_primary_line.get_state_vector(), + *self.components.p4_port1_far_primary_chamber.get_state_vector(), *self.components.p4_port3_line.get_state_vector(), *self.components.p4_port3_remote_primary_line.get_state_vector(), *self.components.p4_port3_remote_primary_chamber.get_state_vector(), + *self.components.p4_port3_remote_port3_line.get_state_vector(), + *self.components.p4_port3_far_primary_line.get_state_vector(), + *self.components.p4_port3_far_primary_chamber.get_state_vector(), ] def apply_state_vector(self, values: list[float]) -> None: - if len(values) != 26: - raise ValueError("PN3/P4 node chamber segment state vector requires twenty-six values") + if len(values) != 38: + raise ValueError("PN3/P4 node chamber segment state vector requires thirty-eight 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]) @@ -302,9 +342,15 @@ class TestMqlPn3P4NodeChamberSegmentClosure: self.components.p4_port1_line.set_state_vector(values[14:16]) self.components.p4_port1_remote_primary_line.set_state_vector(values[16:18]) self.components.p4_port1_remote_primary_chamber.set_state_vector(values[18:20]) - self.components.p4_port3_line.set_state_vector(values[20:22]) - self.components.p4_port3_remote_primary_line.set_state_vector(values[22:24]) - self.components.p4_port3_remote_primary_chamber.set_state_vector(values[24:]) + self.components.p4_port1_remote_port1_line.set_state_vector(values[20:22]) + self.components.p4_port1_far_primary_line.set_state_vector(values[22:24]) + self.components.p4_port1_far_primary_chamber.set_state_vector(values[24:26]) + self.components.p4_port3_line.set_state_vector(values[26:28]) + self.components.p4_port3_remote_primary_line.set_state_vector(values[28:30]) + self.components.p4_port3_remote_primary_chamber.set_state_vector(values[30:32]) + self.components.p4_port3_remote_port3_line.set_state_vector(values[32:34]) + self.components.p4_port3_far_primary_line.set_state_vector(values[34:36]) + self.components.p4_port3_far_primary_chamber.set_state_vector(values[36:]) def snapshot( self, @@ -326,6 +372,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_remote_primary_chamber = ( self.components.p4_port1_remote_primary_chamber.properties() ) + p4_port1_remote_port1_line = ( + self.components.p4_port1_remote_port1_line.properties() + ) + p4_port1_far_primary_line = self.components.p4_port1_far_primary_line.properties() + p4_port1_far_primary_chamber = ( + self.components.p4_port1_far_primary_chamber.properties() + ) p4_port3_line = self.components.p4_port3_line.properties() p4_port3_remote_primary_line = ( self.components.p4_port3_remote_primary_line.properties() @@ -333,10 +386,27 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_remote_primary_chamber = ( self.components.p4_port3_remote_primary_chamber.properties() ) + p4_port3_remote_port3_line = ( + self.components.p4_port3_remote_port3_line.properties() + ) + p4_port3_far_primary_line = self.components.p4_port3_far_primary_line.properties() + p4_port3_far_primary_chamber = ( + self.components.p4_port3_far_primary_chamber.properties() + ) inlet_node = self.inlet_node.properties(self.components.inlet_line.gas) resistance_boundary = self.resistance_boundary.properties( self.components.node_resistance.gas ) + p4_port1_remote_orifice_boundary = ( + self.p4_port1_remote_orifice_boundary.properties( + self.components.p4_port1_remote_orifice.gas + ) + ) + p4_port3_remote_orifice_boundary = ( + self.p4_port3_remote_orifice_boundary.properties( + self.components.p4_port3_remote_orifice.gas + ) + ) inlet_node_to_line_flow = self.components.inlet_line.resistance_mass_flow( port_1_pressure_pa=inlet_node.p, port_1_temperature_k=inlet_node.T, @@ -407,6 +477,29 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_1_temperature_k=p4_port1_remote_primary_chamber.T, ) ) + p4_port1_remote_to_port1_line_flow = ( + self.components.p4_port1_remote_port1_line.port_mass_flow( + port_pressure_pa=p4_port1_remote_primary_line.p, + port_temperature_k=p4_port1_remote_primary_line.T, + ) + ) + p4_port1_far_node_to_line_flow = ( + self.components.p4_port1_remote_port1_line.port_mass_flow( + port_pressure_pa=p4_port1_far_primary_line.p, + port_temperature_k=p4_port1_far_primary_line.T, + ) + ) + p4_port1_far_chamber_to_line_flow = ( + self.components.p4_port1_far_primary_line.resistance_mass_flow( + port_1_pressure_pa=p4_port1_far_primary_chamber.p, + port_1_temperature_k=p4_port1_far_primary_chamber.T, + ) + ) + p4_port1_remote_orifice_to_node_flow = self._boundary_to_p4_flow( + boundary=p4_port1_remote_orifice_boundary, + p4_boundary=p4_port1_remote_primary_line, + orifice=self.components.p4_port1_remote_orifice, + ) p4_to_port3_line_flow = self.components.p4_port3_line.port_mass_flow( port_pressure_pa=p4_primary_line.p, port_temperature_k=p4_primary_line.T, @@ -423,6 +516,29 @@ class TestMqlPn3P4NodeChamberSegmentClosure: port_1_temperature_k=p4_port3_remote_primary_chamber.T, ) ) + p4_port3_remote_to_port3_line_flow = ( + self.components.p4_port3_remote_port3_line.port_mass_flow( + port_pressure_pa=p4_port3_remote_primary_line.p, + port_temperature_k=p4_port3_remote_primary_line.T, + ) + ) + p4_port3_far_node_to_line_flow = ( + self.components.p4_port3_remote_port3_line.port_mass_flow( + port_pressure_pa=p4_port3_far_primary_line.p, + port_temperature_k=p4_port3_far_primary_line.T, + ) + ) + p4_port3_far_chamber_to_line_flow = ( + self.components.p4_port3_far_primary_line.resistance_mass_flow( + port_1_pressure_pa=p4_port3_far_primary_chamber.p, + port_1_temperature_k=p4_port3_far_primary_chamber.T, + ) + ) + p4_port3_remote_orifice_to_node_flow = self._boundary_to_p4_flow( + boundary=p4_port3_remote_orifice_boundary, + 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, @@ -449,20 +565,45 @@ class TestMqlPn3P4NodeChamberSegmentClosure: 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=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_remote_to_port1_line_flow, + node_h=p4_port1_remote_primary_line.h, + connected_h=p4_port1_remote_port1_line.h, + ), + 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( 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_3_mass_flow_g_s=-p4_port1_remote_node_to_line_flow * 1.0e3, - port_4_enthalpy_flow_w=0.0, - port_4_mass_flow_g_s=0.0, + port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + flow_kg_s=p4_port1_remote_orifice_to_node_flow, + node_h=p4_port1_remote_orifice_boundary.h, + connected_h=p4_port1_remote_primary_line.h, + ), + 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 ) + 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=0.0, + port_1_mass_flow_g_s=0.0, + port_3_enthalpy_flow_w=self._enthalpy_flow_from_node( + 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_3_mass_flow_g_s=-p4_port1_far_node_to_line_flow * 1.0e3, + port_4_enthalpy_flow_w=0.0, + port_4_mass_flow_g_s=0.0, + ) + p4_port1_far_node_to_primary_line_flow = ( + p4_port1_far_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, @@ -472,13 +613,38 @@ class TestMqlPn3P4NodeChamberSegmentClosure: connected_h=p4_port3_line.h, ), 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( + 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_3_mass_flow_g_s=-p4_port3_remote_to_port3_line_flow * 1.0e3, + port_4_enthalpy_flow_w=self._enthalpy_flow_from_node( + flow_kg_s=p4_port3_remote_orifice_to_node_flow, + node_h=p4_port3_remote_orifice_boundary.h, + connected_h=p4_port3_remote_primary_line.h, + ), + 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( + 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_1_mass_flow_g_s=-p4_port3_far_node_to_line_flow * 1.0e3, port_3_enthalpy_flow_w=0.0, port_3_mass_flow_g_s=0.0, port_4_enthalpy_flow_w=0.0, port_4_mass_flow_g_s=0.0, ) - p4_port3_remote_node_to_primary_line_flow = ( - p4_port3_remote_balance.port_2_mass_flow_g_s * 1.0e-3 + p4_port3_far_node_to_primary_line_flow = ( + p4_port3_far_balance.port_2_mass_flow_g_s * 1.0e-3 ) snapshot = TestMqlPn3P4NodeChamberSegmentSnapshot( @@ -493,15 +659,25 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_line=p4_port1_line, p4_port1_remote_primary_line=p4_port1_remote_primary_line, p4_port1_remote_primary_chamber=p4_port1_remote_primary_chamber, + p4_port1_remote_port1_line=p4_port1_remote_port1_line, + p4_port1_far_primary_line=p4_port1_far_primary_line, + p4_port1_far_primary_chamber=p4_port1_far_primary_chamber, + p4_port1_remote_orifice_boundary=p4_port1_remote_orifice_boundary, p4_port3_line=p4_port3_line, p4_port3_remote_primary_line=p4_port3_remote_primary_line, p4_port3_remote_primary_chamber=p4_port3_remote_primary_chamber, + p4_port3_remote_port3_line=p4_port3_remote_port3_line, + p4_port3_far_primary_line=p4_port3_far_primary_line, + p4_port3_far_primary_chamber=p4_port3_far_primary_chamber, + p4_port3_remote_orifice_boundary=p4_port3_remote_orifice_boundary, inlet_node=inlet_node, resistance_boundary=resistance_boundary, node_balance=node_balance, p4_balance=p4_balance, p4_port1_remote_balance=p4_port1_remote_balance, + p4_port1_far_balance=p4_port1_far_balance, p4_port3_remote_balance=p4_port3_remote_balance, + p4_port3_far_balance=p4_port3_far_balance, inlet_node_to_line_flow=inlet_node_to_line_flow, inlet_line_to_chamber_flow=inlet_line_to_chamber_flow, outlet_node_to_line_flow=outlet_node_to_line_flow, @@ -518,12 +694,26 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port1_remote_node_to_primary_line_flow=( p4_port1_remote_node_to_primary_line_flow ), + p4_port1_remote_to_port1_line_flow=p4_port1_remote_to_port1_line_flow, + p4_port1_far_node_to_line_flow=p4_port1_far_node_to_line_flow, + p4_port1_far_chamber_to_line_flow=p4_port1_far_chamber_to_line_flow, + p4_port1_far_node_to_primary_line_flow=( + p4_port1_far_node_to_primary_line_flow + ), + p4_port1_remote_orifice_to_node_flow=p4_port1_remote_orifice_to_node_flow, p4_to_port3_line_flow=p4_to_port3_line_flow, p4_port3_remote_node_to_line_flow=p4_port3_remote_node_to_line_flow, p4_port3_remote_chamber_to_line_flow=p4_port3_remote_chamber_to_line_flow, p4_port3_remote_node_to_primary_line_flow=( p4_port3_remote_node_to_primary_line_flow ), + p4_port3_remote_to_port3_line_flow=p4_port3_remote_to_port3_line_flow, + p4_port3_far_node_to_line_flow=p4_port3_far_node_to_line_flow, + p4_port3_far_chamber_to_line_flow=p4_port3_far_chamber_to_line_flow, + p4_port3_far_node_to_primary_line_flow=( + p4_port3_far_node_to_primary_line_flow + ), + p4_port3_remote_orifice_to_node_flow=p4_port3_remote_orifice_to_node_flow, ) self._write_port_states(snapshot) return snapshot @@ -554,6 +744,16 @@ class TestMqlPn3P4NodeChamberSegmentClosure: orifice=orifice, ) + @staticmethod + def _boundary_to_p4_flow( + *, + boundary: ThermodynamicProperties, + p4_boundary: ThermodynamicProperties, + orifice: AmesimPneumaticOrifice, + ) -> float: + upstream_temperature = boundary.T if boundary.p >= p4_boundary.p else p4_boundary.T + return orifice.mass_flow(boundary.p, p4_boundary.p, upstream_temperature) + @staticmethod def _port( component: AmesimPneumaticVolume | AmesimPneumaticOrifice, @@ -626,6 +826,41 @@ class TestMqlPn3P4NodeChamberSegmentClosure: snapshot.p4_port1_remote_primary_chamber.h ) + p4_port1_remote_port1_line = self.components.p4_port1_remote_port1_line + p4_port1_remote_port1_line.port_1.p = snapshot.p4_port1_remote_primary_line.p + p4_port1_remote_port1_line.port_1.m_flow = ( + snapshot.p4_port1_remote_to_port1_line_flow + ) + p4_port1_remote_port1_line.port_1.h_outflow = ( + snapshot.p4_port1_remote_port1_line.h + ) + p4_port1_remote_port1_line.port_2.p = snapshot.p4_port1_far_primary_line.p + p4_port1_remote_port1_line.port_2.m_flow = snapshot.p4_port1_far_node_to_line_flow + p4_port1_remote_port1_line.port_2.h_outflow = ( + snapshot.p4_port1_remote_port1_line.h + ) + + p4_port1_far_primary_line = self.components.p4_port1_far_primary_line + p4_port1_far_primary_line.port_1.p = snapshot.p4_port1_far_primary_chamber.p + p4_port1_far_primary_line.port_1.m_flow = snapshot.p4_port1_far_chamber_to_line_flow + p4_port1_far_primary_line.port_1.h_outflow = snapshot.p4_port1_far_primary_line.h + p4_port1_far_primary_line.port_2.p = snapshot.p4_port1_far_primary_line.p + p4_port1_far_primary_line.port_2.m_flow = snapshot.p4_port1_far_node_to_primary_line_flow + p4_port1_far_primary_line.port_2.h_outflow = snapshot.p4_port1_far_primary_line.h + + p4_port1_far_primary_chamber = self.components.p4_port1_far_primary_chamber + p4_port1_far_primary_chamber.port_a.p = snapshot.p4_port1_far_primary_chamber.p + p4_port1_far_primary_chamber.port_a.m_flow = -snapshot.p4_port1_far_chamber_to_line_flow + p4_port1_far_primary_chamber.port_a.h_outflow = snapshot.p4_port1_far_primary_chamber.h + + p4_port1_remote_orifice = self.components.p4_port1_remote_orifice + p4_port1_remote_orifice.port_a.p = snapshot.p4_port1_remote_orifice_boundary.p + p4_port1_remote_orifice.port_a.m_flow = snapshot.p4_port1_remote_orifice_to_node_flow + p4_port1_remote_orifice.port_a.h_outflow = snapshot.p4_port1_remote_orifice_boundary.h + p4_port1_remote_orifice.port_b.p = snapshot.p4_port1_remote_primary_line.p + p4_port1_remote_orifice.port_b.m_flow = -snapshot.p4_port1_remote_orifice_to_node_flow + p4_port1_remote_orifice.port_b.h_outflow = snapshot.p4_port1_remote_primary_line.h + p4_port3_line = self.components.p4_port3_line p4_port3_line.port_1.p = snapshot.p4_port3_remote_primary_line.p p4_port3_line.port_1.m_flow = snapshot.p4_port3_remote_node_to_line_flow @@ -659,6 +894,41 @@ class TestMqlPn3P4NodeChamberSegmentClosure: snapshot.p4_port3_remote_primary_chamber.h ) + p4_port3_remote_port3_line = self.components.p4_port3_remote_port3_line + p4_port3_remote_port3_line.port_1.p = snapshot.p4_port3_far_primary_line.p + p4_port3_remote_port3_line.port_1.m_flow = snapshot.p4_port3_far_node_to_line_flow + p4_port3_remote_port3_line.port_1.h_outflow = ( + snapshot.p4_port3_remote_port3_line.h + ) + p4_port3_remote_port3_line.port_2.p = snapshot.p4_port3_remote_primary_line.p + p4_port3_remote_port3_line.port_2.m_flow = ( + snapshot.p4_port3_remote_to_port3_line_flow + ) + p4_port3_remote_port3_line.port_2.h_outflow = ( + snapshot.p4_port3_remote_port3_line.h + ) + + p4_port3_far_primary_line = self.components.p4_port3_far_primary_line + p4_port3_far_primary_line.port_1.p = snapshot.p4_port3_far_primary_chamber.p + p4_port3_far_primary_line.port_1.m_flow = snapshot.p4_port3_far_chamber_to_line_flow + p4_port3_far_primary_line.port_1.h_outflow = snapshot.p4_port3_far_primary_line.h + p4_port3_far_primary_line.port_2.p = snapshot.p4_port3_far_primary_line.p + p4_port3_far_primary_line.port_2.m_flow = snapshot.p4_port3_far_node_to_primary_line_flow + p4_port3_far_primary_line.port_2.h_outflow = snapshot.p4_port3_far_primary_line.h + + p4_port3_far_primary_chamber = self.components.p4_port3_far_primary_chamber + p4_port3_far_primary_chamber.port_a.p = snapshot.p4_port3_far_primary_chamber.p + p4_port3_far_primary_chamber.port_a.m_flow = -snapshot.p4_port3_far_chamber_to_line_flow + p4_port3_far_primary_chamber.port_a.h_outflow = snapshot.p4_port3_far_primary_chamber.h + + p4_port3_remote_orifice = self.components.p4_port3_remote_orifice + p4_port3_remote_orifice.port_a.p = snapshot.p4_port3_remote_orifice_boundary.p + p4_port3_remote_orifice.port_a.m_flow = snapshot.p4_port3_remote_orifice_to_node_flow + p4_port3_remote_orifice.port_a.h_outflow = snapshot.p4_port3_remote_orifice_boundary.h + p4_port3_remote_orifice.port_b.p = snapshot.p4_port3_remote_primary_line.p + p4_port3_remote_orifice.port_b.m_flow = -snapshot.p4_port3_remote_orifice_to_node_flow + p4_port3_remote_orifice.port_b.h_outflow = snapshot.p4_port3_remote_primary_line.h + def rhs(self, state_vector: list[float]) -> list[float]: snapshot = self.snapshot(state_vector) base_rhs = TestMqlPn3NodeChamberSegmentClosure.rhs(self, state_vector)[:10] @@ -708,6 +978,31 @@ class TestMqlPn3P4NodeChamberSegmentClosure: internal_h=snapshot.p4_port1_remote_primary_chamber.h, ) ) + p4_port1_remote_port1_derivative = ( + self.components.p4_port1_remote_port1_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_port1_remote_to_port1_line_flow, + connected_h_1=snapshot.p4_port1_remote_primary_line.h, + port_2_m_flow=snapshot.p4_port1_far_node_to_line_flow, + connected_h_2=snapshot.p4_port1_far_primary_line.h, + ) + ) + p4_port1_far_primary_derivative = ( + self.components.p4_port1_far_primary_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_port1_far_chamber_to_line_flow, + connected_h_1=snapshot.p4_port1_far_primary_chamber.h, + port_2_m_flow=snapshot.p4_port1_far_node_to_primary_line_flow, + connected_h_2=snapshot.p4_port1_far_primary_line.h, + ) + ) + p4_port1_far_chamber_derivative = ( + self.components.p4_port1_far_primary_chamber.derivatives_from_two_connections( + port_a_m_flow=-snapshot.p4_port1_far_chamber_to_line_flow, + connected_h_a=snapshot.p4_port1_far_primary_line.h, + port_b_m_flow=0.0, + connected_h_b=snapshot.p4_port1_far_primary_chamber.h, + internal_h=snapshot.p4_port1_far_primary_chamber.h, + ) + ) p4_port3_remote_primary_derivative = ( self.components.p4_port3_remote_primary_line.derivatives_from_connections( port_1_m_flow=snapshot.p4_port3_remote_chamber_to_line_flow, @@ -725,6 +1020,31 @@ class TestMqlPn3P4NodeChamberSegmentClosure: internal_h=snapshot.p4_port3_remote_primary_chamber.h, ) ) + p4_port3_remote_port3_derivative = ( + self.components.p4_port3_remote_port3_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_port3_far_node_to_line_flow, + connected_h_1=snapshot.p4_port3_far_primary_line.h, + port_2_m_flow=snapshot.p4_port3_remote_to_port3_line_flow, + connected_h_2=snapshot.p4_port3_remote_primary_line.h, + ) + ) + p4_port3_far_primary_derivative = ( + self.components.p4_port3_far_primary_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_port3_far_chamber_to_line_flow, + connected_h_1=snapshot.p4_port3_far_primary_chamber.h, + port_2_m_flow=snapshot.p4_port3_far_node_to_primary_line_flow, + connected_h_2=snapshot.p4_port3_far_primary_line.h, + ) + ) + p4_port3_far_chamber_derivative = ( + self.components.p4_port3_far_primary_chamber.derivatives_from_two_connections( + port_a_m_flow=-snapshot.p4_port3_far_chamber_to_line_flow, + connected_h_a=snapshot.p4_port3_far_primary_line.h, + port_b_m_flow=0.0, + connected_h_b=snapshot.p4_port3_far_primary_chamber.h, + internal_h=snapshot.p4_port3_far_primary_chamber.h, + ) + ) return [ *base_rhs, *p4_primary_derivative.as_vector(), @@ -732,9 +1052,15 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *p4_port1_derivative.as_vector(), *p4_port1_remote_primary_derivative.as_vector(), *p4_port1_remote_chamber_derivative.as_vector(), + *p4_port1_remote_port1_derivative.as_vector(), + *p4_port1_far_primary_derivative.as_vector(), + *p4_port1_far_chamber_derivative.as_vector(), *p4_port3_derivative.as_vector(), *p4_port3_remote_primary_derivative.as_vector(), *p4_port3_remote_chamber_derivative.as_vector(), + *p4_port3_remote_port3_derivative.as_vector(), + *p4_port3_far_primary_derivative.as_vector(), + *p4_port3_far_chamber_derivative.as_vector(), ] diff --git a/tests/test_test_mql_pnl0001_segment.py b/tests/test_test_mql_pnl0001_segment.py index 144a858..b9c5fb8 100644 --- a/tests/test_test_mql_pnl0001_segment.py +++ b/tests/test_test_mql_pnl0001_segment.py @@ -275,6 +275,23 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port1_remote_primary_chamber.name, "pn_c1_10", ) + self.assertEqual( + closure.components.p4_port1_remote_port1_line.name, + "pneumatic_80", + ) + self.assertEqual(closure.components.p4_port1_far_node.alias, "pnnode4_19") + self.assertEqual( + closure.components.p4_port1_far_primary_line.name, + "pneumatic_65", + ) + self.assertEqual( + closure.components.p4_port1_far_primary_chamber.name, + "pn_c1_11", + ) + self.assertEqual( + closure.components.p4_port1_remote_orifice.name, + "pn_morifice_10", + ) self.assertEqual(closure.components.p4_port3_line.name, "pneumatic_83") self.assertEqual(closure.components.p4_port3_remote_node.alias, "pnnode4_16") self.assertEqual( @@ -285,8 +302,25 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port3_remote_primary_chamber.name, "pn_c1_8", ) - self.assertEqual(len(closure.initial_state_vector()), 26) - self.assertEqual(len(rhs), 26) + self.assertEqual( + closure.components.p4_port3_remote_port3_line.name, + "pneumatic_95", + ) + self.assertEqual(closure.components.p4_port3_far_node.alias, "pnnode4_22") + self.assertEqual( + closure.components.p4_port3_far_primary_line.name, + "pneumatic_74", + ) + self.assertEqual( + closure.components.p4_port3_far_primary_chamber.name, + "pn_c1_15", + ) + self.assertEqual( + closure.components.p4_port3_remote_orifice.name, + "pn_morifice_1", + ) + self.assertEqual(len(closure.initial_state_vector()), 38) + self.assertEqual(len(rhs), 38) self.assertAlmostEqual( snapshot.p4_balance.pressure_pa, snapshot.p4_primary_line.p, @@ -320,6 +354,27 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port1_remote_node.alias, neighborhood.port_1.remote_node_alias, ) + port1_remote_neighborhood = self.system.p4_node_neighborhood( + neighborhood.port_1.remote_node_alias + ) + self.assertEqual( + closure.components.p4_port1_remote_port1_line.name, + port1_remote_neighborhood.port_1.line_alias, + ) + self.assertEqual( + closure.components.p4_port1_far_node.alias, + port1_remote_neighborhood.port_1.remote_node_alias, + ) + self.assertEqual( + closure.components.p4_port1_far_primary_line.name, + self.system._p4_primary_connection_for_node( + port1_remote_neighborhood.port_1.remote_node_alias + ).line_alias, + ) + self.assertEqual( + closure.components.p4_port1_remote_orifice.name, + port1_remote_neighborhood.port_4.orifice_alias, + ) self.assertEqual( closure.components.p4_port3_line.name, neighborhood.port_3.line_alias, @@ -328,6 +383,27 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port3_remote_node.alias, neighborhood.port_3.remote_node_alias, ) + port3_remote_neighborhood = self.system.p4_node_neighborhood( + neighborhood.port_3.remote_node_alias + ) + self.assertEqual( + closure.components.p4_port3_remote_port3_line.name, + port3_remote_neighborhood.port_3.line_alias, + ) + self.assertEqual( + closure.components.p4_port3_far_node.alias, + port3_remote_neighborhood.port_3.remote_node_alias, + ) + self.assertEqual( + closure.components.p4_port3_far_primary_line.name, + self.system._p4_primary_connection_for_node( + port3_remote_neighborhood.port_3.remote_node_alias + ).line_alias, + ) + self.assertEqual( + closure.components.p4_port3_remote_orifice.name, + port3_remote_neighborhood.port_4.orifice_alias, + ) self.assertEqual( closure.components.node_orifice.name, neighborhood.port_4.orifice_alias, @@ -367,27 +443,45 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): ) self.assertAlmostEqual( snapshot.p4_port1_remote_node_to_primary_line_flow - + snapshot.p4_port1_remote_node_to_line_flow, + + snapshot.p4_port1_remote_node_to_line_flow + + snapshot.p4_port1_remote_to_port1_line_flow + - snapshot.p4_port1_remote_orifice_to_node_flow, + 0.0, + delta=1.0e-12, + ) + self.assertAlmostEqual( + snapshot.p4_port1_far_node_to_primary_line_flow + + snapshot.p4_port1_far_node_to_line_flow, 0.0, delta=1.0e-12, ) self.assertAlmostEqual( snapshot.p4_port3_remote_node_to_primary_line_flow - + snapshot.p4_port3_remote_node_to_line_flow, + + snapshot.p4_port3_remote_node_to_line_flow + + snapshot.p4_port3_remote_to_port3_line_flow + - snapshot.p4_port3_remote_orifice_to_node_flow, 0.0, delta=1.0e-12, ) - mass_derivative_sum = sum(rhs[index] for index in range(0, 26, 2)) + self.assertAlmostEqual( + snapshot.p4_port3_far_node_to_primary_line_flow + + snapshot.p4_port3_far_node_to_line_flow, + 0.0, + delta=1.0e-12, + ) + mass_derivative_sum = sum(rhs[index] for index in range(0, 38, 2)) self.assertAlmostEqual( mass_derivative_sum, ( snapshot.inlet_node_to_line_flow - snapshot.node_to_resistance_flow + + snapshot.p4_port1_remote_orifice_to_node_flow + + snapshot.p4_port3_remote_orifice_to_node_flow ), delta=1.0e-12, ) - def test_simulates_twenty_six_state_pn3_p4_node_chamber_segment(self) -> None: + def test_simulates_thirty_eight_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, @@ -402,8 +496,8 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): self.assertTrue(solution.success) self.assertEqual(len(solution.t), 3) - self.assertEqual(len(solution.y), 26) - self.assertEqual([len(row) for row in solution.y], [3] * 26) + self.assertEqual(len(solution.y), 38) + self.assertEqual([len(row) for row in solution.y], [3] * 38) if __name__ == "__main__":