diff --git a/PythonModels/systems/test_mql.py b/PythonModels/systems/test_mql.py index 55190c9..8ee1c5a 100644 --- a/PythonModels/systems/test_mql.py +++ b/PythonModels/systems/test_mql.py @@ -4825,6 +4825,21 @@ class TestMqlSystem: p4_port3_remote_resistance_orifice = self.pneumatic_assembly.variable_orifices[ p4_port3_remote_resistance_orifice_alias ] + p4_port3_remote_resistance_output_spec = self._pnl0001_spec_for_node_port( + p4_port3_far_node_alias, + "port_4", + ) + if ( + p4_port3_remote_resistance_output_spec.source_component + != p4_port3_remote_resistance_orifice_alias + ): + raise ValueError( + f"{p4_port3_remote_resistance_output_spec.alias} is not fed by " + f"{p4_port3_remote_resistance_orifice_alias}" + ) + p4_port3_remote_resistance_output_line = self.pnl0001_assembly.lines[ + p4_port3_remote_resistance_output_spec.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] @@ -4928,6 +4943,9 @@ class TestMqlSystem: p4_port3_remote_resistance_orifice=( p4_port3_remote_resistance_orifice ), + p4_port3_remote_resistance_output_line=( + p4_port3_remote_resistance_output_line + ), volume=volume, inlet_orifice=inlet_orifice, outlet_orifice=outlet_orifice, diff --git a/PythonModels/systems/test_mql_closure.py b/PythonModels/systems/test_mql_closure.py index 47caf15..7bd4656 100644 --- a/PythonModels/systems/test_mql_closure.py +++ b/PythonModels/systems/test_mql_closure.py @@ -238,6 +238,7 @@ class TestMqlPn3P4NodeChamberSegmentComponents: p4_port3_remote_resistance_node: TestMqlPneumaticNode3 p4_port3_remote_resistance_node_line: AmesimPnl0003Pipe p4_port3_remote_resistance_orifice: AmesimPneumaticOrifice + p4_port3_remote_resistance_output_line: AmesimPnl0001Pipe volume: AmesimPneumaticVolume inlet_orifice: AmesimPneumaticOrifice outlet_orifice: AmesimPneumaticOrifice @@ -282,6 +283,7 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port3_remote_orifice_line_port_2: ThermodynamicProperties p4_port3_remote_resistance_node_line_port_1: ThermodynamicProperties p4_port3_remote_resistance_node_line_port_2: ThermodynamicProperties + p4_port3_remote_resistance_output_line: ThermodynamicProperties inlet_node: ThermodynamicProperties resistance_boundary: ThermodynamicProperties node_balance: TestMqlPneumaticNode3Balance @@ -343,7 +345,8 @@ class TestMqlPn3P4NodeChamberSegmentSnapshot: p4_port3_remote_node_to_resistance_flow: float p4_port3_remote_resistance_node_to_line_flow: float p4_port3_remote_resistance_line_center_flow: float - p4_port3_remote_resistance_to_p4_flow: float + p4_port3_remote_resistance_to_output_line_flow: float + p4_port3_remote_resistance_output_to_p4_flow: float p4_port3_remote_orifice_line_center_flow: float p4_port3_remote_orifice_to_node_flow: float @@ -399,12 +402,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *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_resistance_output_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) != 70: - raise ValueError("PN3/P4 node chamber segment state vector requires seventy values") + if len(values) != 72: + raise ValueError("PN3/P4 node chamber segment state vector requires seventy-two 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]) @@ -435,7 +439,8 @@ class TestMqlPn3P4NodeChamberSegmentClosure: 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:]) + self.components.p4_port3_remote_resistance_output_line.set_state_vector(values[66:68]) + self.components.p4_port3_remote_orifice_line.set_state_vector(values[68:]) def snapshot( self, @@ -510,6 +515,9 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_remote_resistance_node_line_port_2 = ( self.components.p4_port3_remote_resistance_node_line.properties_2() ) + p4_port3_remote_resistance_output_line = ( + self.components.p4_port3_remote_resistance_output_line.properties() + ) inlet_node = self.inlet_node.properties(self.components.inlet_line.gas) resistance_boundary = self.resistance_boundary.properties( self.components.node_resistance.gas @@ -771,11 +779,14 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_remote_resistance_line_center_flow = ( self.components.p4_port3_remote_resistance_node_line.resistance_mass_flow() ) - p4_port3_remote_resistance_to_p4_flow = self._line_to_p4_flow( + p4_port3_remote_resistance_to_output_line_flow = self._line_to_p4_flow( line=p4_port3_remote_resistance_node_line_port_2, - p4_boundary=p4_port3_far_primary_line, + p4_boundary=p4_port3_remote_resistance_output_line, orifice=self.components.p4_port3_remote_resistance_orifice, ) + p4_port3_remote_resistance_output_to_p4_flow = ( + p4_port3_remote_resistance_to_output_line_flow + ) p4_port3_remote_orifice_line_center_flow = ( self.components.p4_port3_remote_orifice_line.resistance_mass_flow() ) @@ -929,11 +940,11 @@ class TestMqlPn3P4NodeChamberSegmentClosure: ), 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( - flow_kg_s=p4_port3_remote_resistance_to_p4_flow, - node_h=p4_port3_remote_resistance_node_line_port_2.h, + 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_4_mass_flow_g_s=p4_port3_remote_resistance_to_p4_flow * 1.0e3, + 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 @@ -1022,6 +1033,9 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_remote_resistance_node_line_port_2=( p4_port3_remote_resistance_node_line_port_2 ), + p4_port3_remote_resistance_output_line=( + p4_port3_remote_resistance_output_line + ), inlet_node=inlet_node, resistance_boundary=resistance_boundary, node_balance=node_balance, @@ -1109,8 +1123,11 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_remote_resistance_line_center_flow=( p4_port3_remote_resistance_line_center_flow ), - p4_port3_remote_resistance_to_p4_flow=( - p4_port3_remote_resistance_to_p4_flow + p4_port3_remote_resistance_to_output_line_flow=( + p4_port3_remote_resistance_to_output_line_flow + ), + p4_port3_remote_resistance_output_to_p4_flow=( + p4_port3_remote_resistance_output_to_p4_flow ), p4_port3_remote_orifice_line_center_flow=( p4_port3_remote_orifice_line_center_flow @@ -1477,16 +1494,24 @@ class TestMqlPn3P4NodeChamberSegmentClosure: p4_port3_remote_resistance_node_line.port_1.m_flow = snapshot.p4_port3_remote_resistance_node_to_line_flow p4_port3_remote_resistance_node_line.port_1.h_outflow = snapshot.p4_port3_remote_resistance_node_line_port_1.h p4_port3_remote_resistance_node_line.port_2.p = snapshot.p4_port3_remote_resistance_node_line_port_2.p - p4_port3_remote_resistance_node_line.port_2.m_flow = -snapshot.p4_port3_remote_resistance_to_p4_flow + p4_port3_remote_resistance_node_line.port_2.m_flow = -snapshot.p4_port3_remote_resistance_to_output_line_flow p4_port3_remote_resistance_node_line.port_2.h_outflow = snapshot.p4_port3_remote_resistance_node_line_port_2.h p4_port3_remote_resistance_orifice = self.components.p4_port3_remote_resistance_orifice p4_port3_remote_resistance_orifice.port_a.p = snapshot.p4_port3_remote_resistance_node_line_port_2.p - p4_port3_remote_resistance_orifice.port_a.m_flow = snapshot.p4_port3_remote_resistance_to_p4_flow + p4_port3_remote_resistance_orifice.port_a.m_flow = snapshot.p4_port3_remote_resistance_to_output_line_flow p4_port3_remote_resistance_orifice.port_a.h_outflow = snapshot.p4_port3_remote_resistance_node_line_port_2.h - p4_port3_remote_resistance_orifice.port_b.p = snapshot.p4_port3_far_primary_line.p - p4_port3_remote_resistance_orifice.port_b.m_flow = -snapshot.p4_port3_remote_resistance_to_p4_flow - p4_port3_remote_resistance_orifice.port_b.h_outflow = snapshot.p4_port3_far_primary_line.h + p4_port3_remote_resistance_orifice.port_b.p = snapshot.p4_port3_remote_resistance_output_line.p + p4_port3_remote_resistance_orifice.port_b.m_flow = -snapshot.p4_port3_remote_resistance_to_output_line_flow + p4_port3_remote_resistance_orifice.port_b.h_outflow = snapshot.p4_port3_remote_resistance_output_line.h + + p4_port3_remote_resistance_output_line = self.components.p4_port3_remote_resistance_output_line + p4_port3_remote_resistance_output_line.port_1.p = snapshot.p4_port3_remote_resistance_node_line_port_2.p + p4_port3_remote_resistance_output_line.port_1.m_flow = snapshot.p4_port3_remote_resistance_to_output_line_flow + p4_port3_remote_resistance_output_line.port_1.h_outflow = snapshot.p4_port3_remote_resistance_output_line.h + p4_port3_remote_resistance_output_line.port_2.p = snapshot.p4_port3_remote_resistance_output_line.p + p4_port3_remote_resistance_output_line.port_2.m_flow = -snapshot.p4_port3_remote_resistance_output_to_p4_flow + p4_port3_remote_resistance_output_line.port_2.h_outflow = snapshot.p4_port3_remote_resistance_output_line.h p4_port3_remote_orifice = self.components.p4_port3_remote_orifice p4_port3_remote_orifice.port_a.p = snapshot.p4_port3_remote_orifice_line_port_2.p @@ -1745,8 +1770,16 @@ class TestMqlPn3P4NodeChamberSegmentClosure: ) = self.components.p4_port3_remote_resistance_node_line.derivatives_from_connections( port_1_m_flow=snapshot.p4_port3_remote_resistance_node_to_line_flow, connected_h_1=snapshot.p4_port3_remote_resistance_node_line_port_1.h, - port_2_m_flow=-snapshot.p4_port3_remote_resistance_to_p4_flow, - connected_h_2=snapshot.p4_port3_far_primary_line.h, + port_2_m_flow=-snapshot.p4_port3_remote_resistance_to_output_line_flow, + connected_h_2=snapshot.p4_port3_remote_resistance_output_line.h, + ) + p4_port3_remote_resistance_output_derivative = ( + self.components.p4_port3_remote_resistance_output_line.derivatives_from_connections( + port_1_m_flow=snapshot.p4_port3_remote_resistance_to_output_line_flow, + connected_h_1=snapshot.p4_port3_remote_resistance_node_line_port_2.h, + port_2_m_flow=-snapshot.p4_port3_remote_resistance_output_to_p4_flow, + connected_h_2=snapshot.p4_port3_far_primary_line.h, + ) ) p4_port3_remote_orifice_derivative_1, p4_port3_remote_orifice_derivative_2 = ( self.components.p4_port3_remote_orifice_line.derivatives_from_connections( @@ -1790,6 +1823,7 @@ class TestMqlPn3P4NodeChamberSegmentClosure: *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_resistance_output_derivative.as_vector(), *p4_port3_remote_orifice_derivative_1.as_vector(), *p4_port3_remote_orifice_derivative_2.as_vector(), ] diff --git a/tests/test_test_mql_pnl0001_segment.py b/tests/test_test_mql_pnl0001_segment.py index a8fc44f..36fb80f 100644 --- a/tests/test_test_mql_pnl0001_segment.py +++ b/tests/test_test_mql_pnl0001_segment.py @@ -376,8 +376,12 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port3_remote_resistance_orifice.name, "pn_morifice_14", ) - self.assertEqual(len(closure.initial_state_vector()), 70) - self.assertEqual(len(rhs), 70) + self.assertEqual( + closure.components.p4_port3_remote_resistance_output_line.name, + "pneumatic_94", + ) + self.assertEqual(len(closure.initial_state_vector()), 72) + self.assertEqual(len(rhs), 72) self.assertAlmostEqual( snapshot.p4_balance.pressure_pa, snapshot.p4_primary_line.p, @@ -559,6 +563,13 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): closure.components.p4_port3_remote_resistance_orifice.name, "pn_morifice_14", ) + self.assertEqual( + closure.components.p4_port3_remote_resistance_output_line.name, + self.system._pnl0001_line_for_node_port( + closure.components.p4_port3_far_node.alias, + "port_4", + ).name, + ) self.assertEqual( closure.components.node_orifice.name, neighborhood.port_4.orifice_alias, @@ -650,11 +661,16 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): snapshot.p4_port3_remote_node_to_resistance_flow, delta=1.0e-12, ) + self.assertAlmostEqual( + snapshot.p4_port3_remote_resistance_output_to_p4_flow, + snapshot.p4_port3_remote_resistance_to_output_line_flow, + delta=1.0e-12, + ) self.assertAlmostEqual( snapshot.p4_port3_far_node_to_primary_line_flow + snapshot.p4_port3_far_node_to_line_flow + snapshot.p4_port3_far_to_next_line_flow - - snapshot.p4_port3_remote_resistance_to_p4_flow, + - snapshot.p4_port3_remote_resistance_output_to_p4_flow, 0.0, delta=1.0e-12, ) @@ -665,14 +681,14 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): 0.0, delta=1.0e-12, ) - mass_derivative_sum = sum(rhs[index] for index in range(0, 70, 2)) + mass_derivative_sum = sum(rhs[index] for index in range(0, 72, 2)) self.assertAlmostEqual( mass_derivative_sum, 0.0, delta=1.0e-12, ) - def test_simulates_seventy_state_pn3_p4_node_chamber_segment(self) -> None: + def test_simulates_seventy_two_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, @@ -687,8 +703,8 @@ class TestMqlPn3P4NodeChamberSegmentTests(unittest.TestCase): self.assertTrue(solution.success) self.assertEqual(len(solution.t), 3) - self.assertEqual(len(solution.y), 70) - self.assertEqual([len(row) for row in solution.y], [3] * 70) + self.assertEqual(len(solution.y), 72) + self.assertEqual([len(row) for row in solution.y], [3] * 72) if __name__ == "__main__":