merge/model-development-into-main #2

Merged
lujingze merged 126 commits from merge/model-development-into-main into main 2026-07-31 09:52:44 +08:00
Showing only changes of commit 777f943660 - Show all commits
+138 -112
View File
@@ -1960,6 +1960,38 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
line.port_2.m_flow = port_2_flow
line.port_2.h_outflow = port_2_properties.h
@staticmethod
def _write_orifice_ports(
*,
orifice: AmesimPneumaticOrifice,
port_a_properties: ThermodynamicProperties,
port_a_flow: float,
port_b_properties: ThermodynamicProperties,
port_b_flow: float,
) -> None:
orifice.port_a.p = port_a_properties.p
orifice.port_a.m_flow = port_a_flow
orifice.port_a.h_outflow = port_a_properties.h
orifice.port_b.p = port_b_properties.p
orifice.port_b.m_flow = port_b_flow
orifice.port_b.h_outflow = port_b_properties.h
@staticmethod
def _write_resistance_ports(
*,
resistance: AmesimPnl00rPipe,
port_1_properties: ThermodynamicProperties,
port_1_flow: float,
port_2_properties: ThermodynamicProperties,
port_2_flow: float,
) -> None:
resistance.port_1.p = port_1_properties.p
resistance.port_1.m_flow = port_1_flow
resistance.port_1.h_outflow = port_1_properties.h
resistance.port_2.p = port_2_properties.p
resistance.port_2.m_flow = port_2_flow
resistance.port_2.h_outflow = port_2_properties.h
@staticmethod
def _two_state_connection_line_derivatives(
*,
@@ -2006,21 +2038,21 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.pnl0003_to_p4_flow,
)
node_orifice = self.components.node_orifice
node_orifice.port_a.p = snapshot.node_line_port_2.p
node_orifice.port_a.m_flow = snapshot.pnl0003_to_p4_flow
node_orifice.port_a.h_outflow = snapshot.node_line_port_2.h
node_orifice.port_b.p = snapshot.p4_primary_line.p
node_orifice.port_b.m_flow = -snapshot.pnl0003_to_p4_flow
node_orifice.port_b.h_outflow = snapshot.p4_primary_line.h
self._write_orifice_ports(
orifice=self.components.node_orifice,
port_a_properties=snapshot.node_line_port_2,
port_a_flow=snapshot.pnl0003_to_p4_flow,
port_b_properties=snapshot.p4_primary_line,
port_b_flow=-snapshot.pnl0003_to_p4_flow,
)
resistance = self.components.node_resistance
resistance.port_1.p = snapshot.node_line_port_1.p
resistance.port_1.m_flow = snapshot.node_to_resistance_flow
resistance.port_1.h_outflow = snapshot.node_line_port_1.h
resistance.port_2.p = snapshot.p4_port1_remote_orifice_line_port_1.p
resistance.port_2.m_flow = -snapshot.node_to_resistance_flow
resistance.port_2.h_outflow = snapshot.p4_port1_remote_orifice_line_port_1.h
self._write_resistance_ports(
resistance=self.components.node_resistance,
port_1_properties=snapshot.node_line_port_1,
port_1_flow=snapshot.node_to_resistance_flow,
port_2_properties=snapshot.p4_port1_remote_orifice_line_port_1,
port_2_flow=-snapshot.node_to_resistance_flow,
)
self._write_primary_chamber_line(
line=self.components.p4_primary_line,
@@ -2102,13 +2134,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port1_next_orifice_to_output_line_flow,
)
p4_port1_next_orifice = self.components.p4_port1_next_orifice
p4_port1_next_orifice.port_a.p = snapshot.p4_port1_next_orifice_line_port_2.p
p4_port1_next_orifice.port_a.m_flow = snapshot.p4_port1_next_orifice_to_output_line_flow
p4_port1_next_orifice.port_a.h_outflow = snapshot.p4_port1_next_orifice_line_port_2.h
p4_port1_next_orifice.port_b.p = snapshot.p4_port1_next_orifice_output_line.p
p4_port1_next_orifice.port_b.m_flow = -snapshot.p4_port1_next_orifice_to_output_line_flow
p4_port1_next_orifice.port_b.h_outflow = snapshot.p4_port1_next_orifice_output_line.h
self._write_orifice_ports(
orifice=self.components.p4_port1_next_orifice,
port_a_properties=snapshot.p4_port1_next_orifice_line_port_2,
port_a_flow=snapshot.p4_port1_next_orifice_to_output_line_flow,
port_b_properties=snapshot.p4_port1_next_orifice_output_line,
port_b_flow=-snapshot.p4_port1_next_orifice_to_output_line_flow,
)
self._write_connection_line(
line=self.components.p4_port1_next_orifice_output_line,
@@ -2119,13 +2151,17 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=snapshot.p4_port1_next_orifice_to_output_line_flow,
)
p4_port1_next_orifice_resistance = self.components.p4_port1_next_orifice_resistance
p4_port1_next_orifice_resistance.port_1.p = snapshot.p4_port1_next_orifice_resistance_line_port_1.p
p4_port1_next_orifice_resistance.port_1.m_flow = snapshot.p4_port1_next_orifice_resistance_node_to_next_flow
p4_port1_next_orifice_resistance.port_1.h_outflow = snapshot.p4_port1_next_orifice_resistance_line_port_1.h
p4_port1_next_orifice_resistance.port_2.p = snapshot.p4_port1_next_orifice_line_port_1.p
p4_port1_next_orifice_resistance.port_2.m_flow = -snapshot.p4_port1_next_orifice_resistance_node_to_next_flow
p4_port1_next_orifice_resistance.port_2.h_outflow = snapshot.p4_port1_next_orifice_line_port_1.h
self._write_resistance_ports(
resistance=self.components.p4_port1_next_orifice_resistance,
port_1_properties=snapshot.p4_port1_next_orifice_resistance_line_port_1,
port_1_flow=(
snapshot.p4_port1_next_orifice_resistance_node_to_next_flow
),
port_2_properties=snapshot.p4_port1_next_orifice_line_port_1,
port_2_flow=(
-snapshot.p4_port1_next_orifice_resistance_node_to_next_flow
),
)
self._write_two_state_connection_line(
line=self.components.p4_port1_next_orifice_resistance_line,
@@ -2135,13 +2171,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port1_next_orifice_resistance_to_p4_flow,
)
p4_port1_next_orifice_resistance_orifice = self.components.p4_port1_next_orifice_resistance_orifice
p4_port1_next_orifice_resistance_orifice.port_a.p = snapshot.p4_port1_next_orifice_resistance_line_port_2.p
p4_port1_next_orifice_resistance_orifice.port_a.m_flow = snapshot.p4_port1_next_orifice_resistance_to_p4_flow
p4_port1_next_orifice_resistance_orifice.port_a.h_outflow = snapshot.p4_port1_next_orifice_resistance_line_port_2.h
p4_port1_next_orifice_resistance_orifice.port_b.p = snapshot.p4_port1_far_primary_line.p
p4_port1_next_orifice_resistance_orifice.port_b.m_flow = -snapshot.p4_port1_next_orifice_resistance_to_p4_flow
p4_port1_next_orifice_resistance_orifice.port_b.h_outflow = snapshot.p4_port1_far_primary_line.h
self._write_orifice_ports(
orifice=self.components.p4_port1_next_orifice_resistance_orifice,
port_a_properties=snapshot.p4_port1_next_orifice_resistance_line_port_2,
port_a_flow=snapshot.p4_port1_next_orifice_resistance_to_p4_flow,
port_b_properties=snapshot.p4_port1_far_primary_line,
port_b_flow=-snapshot.p4_port1_next_orifice_resistance_to_p4_flow,
)
self._write_fixed_chamber_segment(
spec=self.components.p4_port1_next_orifice_resistance_chamber_spec,
@@ -2198,13 +2234,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port1_remote_orifice_to_node_flow,
)
p4_port1_remote_orifice = self.components.p4_port1_remote_orifice
p4_port1_remote_orifice.port_a.p = snapshot.p4_port1_remote_orifice_line_port_2.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_line_port_2.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
self._write_orifice_ports(
orifice=self.components.p4_port1_remote_orifice,
port_a_properties=snapshot.p4_port1_remote_orifice_line_port_2,
port_a_flow=snapshot.p4_port1_remote_orifice_to_node_flow,
port_b_properties=snapshot.p4_port1_remote_primary_line,
port_b_flow=-snapshot.p4_port1_remote_orifice_to_node_flow,
)
self._write_connection_line(
line=self.components.p4_port3_line,
@@ -2277,13 +2313,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port3_next_orifice_to_output_line_flow,
)
p4_port3_next_orifice = self.components.p4_port3_next_orifice
p4_port3_next_orifice.port_a.p = snapshot.p4_port3_next_orifice_line_port_2.p
p4_port3_next_orifice.port_a.m_flow = snapshot.p4_port3_next_orifice_to_output_line_flow
p4_port3_next_orifice.port_a.h_outflow = snapshot.p4_port3_next_orifice_line_port_2.h
p4_port3_next_orifice.port_b.p = snapshot.p4_port3_next_orifice_output_line.p
p4_port3_next_orifice.port_b.m_flow = -snapshot.p4_port3_next_orifice_to_output_line_flow
p4_port3_next_orifice.port_b.h_outflow = snapshot.p4_port3_next_orifice_output_line.h
self._write_orifice_ports(
orifice=self.components.p4_port3_next_orifice,
port_a_properties=snapshot.p4_port3_next_orifice_line_port_2,
port_a_flow=snapshot.p4_port3_next_orifice_to_output_line_flow,
port_b_properties=snapshot.p4_port3_next_orifice_output_line,
port_b_flow=-snapshot.p4_port3_next_orifice_to_output_line_flow,
)
self._write_connection_line(
line=self.components.p4_port3_next_orifice_output_line,
@@ -2320,13 +2356,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
outlet_orifice=self.components.p4_port3_next_chamber_outlet_orifice,
)
p4_port3_next_orifice_resistance = self.components.p4_port3_next_orifice_resistance
p4_port3_next_orifice_resistance.port_1.p = snapshot.p4_port3_next_resistance_node_line_port_1.p
p4_port3_next_orifice_resistance.port_1.m_flow = snapshot.p4_port3_next_resistance_node_to_next_flow
p4_port3_next_orifice_resistance.port_1.h_outflow = snapshot.p4_port3_next_resistance_node_line_port_1.h
p4_port3_next_orifice_resistance.port_2.p = snapshot.p4_port3_next_orifice_line_port_1.p
p4_port3_next_orifice_resistance.port_2.m_flow = -snapshot.p4_port3_next_resistance_node_to_next_flow
p4_port3_next_orifice_resistance.port_2.h_outflow = snapshot.p4_port3_next_orifice_line_port_1.h
self._write_resistance_ports(
resistance=self.components.p4_port3_next_orifice_resistance,
port_1_properties=snapshot.p4_port3_next_resistance_node_line_port_1,
port_1_flow=snapshot.p4_port3_next_resistance_node_to_next_flow,
port_2_properties=snapshot.p4_port3_next_orifice_line_port_1,
port_2_flow=-snapshot.p4_port3_next_resistance_node_to_next_flow,
)
self._write_two_state_connection_line(
line=self.components.p4_port3_next_resistance_node_line,
@@ -2336,13 +2372,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port3_next_resistance_to_output_line_flow,
)
p4_port3_next_resistance_orifice = self.components.p4_port3_next_resistance_orifice
p4_port3_next_resistance_orifice.port_a.p = snapshot.p4_port3_next_resistance_node_line_port_2.p
p4_port3_next_resistance_orifice.port_a.m_flow = snapshot.p4_port3_next_resistance_to_output_line_flow
p4_port3_next_resistance_orifice.port_a.h_outflow = snapshot.p4_port3_next_resistance_node_line_port_2.h
p4_port3_next_resistance_orifice.port_b.p = snapshot.p4_port3_next_resistance_output_line.p
p4_port3_next_resistance_orifice.port_b.m_flow = -snapshot.p4_port3_next_resistance_to_output_line_flow
p4_port3_next_resistance_orifice.port_b.h_outflow = snapshot.p4_port3_next_resistance_output_line.h
self._write_orifice_ports(
orifice=self.components.p4_port3_next_resistance_orifice,
port_a_properties=snapshot.p4_port3_next_resistance_node_line_port_2,
port_a_flow=snapshot.p4_port3_next_resistance_to_output_line_flow,
port_b_properties=snapshot.p4_port3_next_resistance_output_line,
port_b_flow=-snapshot.p4_port3_next_resistance_to_output_line_flow,
)
self._write_connection_line(
line=self.components.p4_port3_next_resistance_output_line,
@@ -2395,13 +2431,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port3_remote_orifice_to_node_flow,
)
p4_port3_remote_orifice_resistance = self.components.p4_port3_remote_orifice_resistance
p4_port3_remote_orifice_resistance.port_1.p = snapshot.p4_port3_remote_orifice_line_port_1.p
p4_port3_remote_orifice_resistance.port_1.m_flow = snapshot.p4_port3_remote_node_to_resistance_flow
p4_port3_remote_orifice_resistance.port_1.h_outflow = snapshot.p4_port3_remote_orifice_line_port_1.h
p4_port3_remote_orifice_resistance.port_2.p = snapshot.p4_port3_remote_resistance_node_line_port_1.p
p4_port3_remote_orifice_resistance.port_2.m_flow = -snapshot.p4_port3_remote_node_to_resistance_flow
p4_port3_remote_orifice_resistance.port_2.h_outflow = snapshot.p4_port3_remote_resistance_node_line_port_1.h
self._write_resistance_ports(
resistance=self.components.p4_port3_remote_orifice_resistance,
port_1_properties=snapshot.p4_port3_remote_orifice_line_port_1,
port_1_flow=snapshot.p4_port3_remote_node_to_resistance_flow,
port_2_properties=snapshot.p4_port3_remote_resistance_node_line_port_1,
port_2_flow=-snapshot.p4_port3_remote_node_to_resistance_flow,
)
self._write_two_state_connection_line(
line=self.components.p4_port3_remote_resistance_node_line,
@@ -2411,13 +2447,13 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port3_remote_resistance_to_output_line_flow,
)
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_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_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
self._write_orifice_ports(
orifice=self.components.p4_port3_remote_resistance_orifice,
port_a_properties=snapshot.p4_port3_remote_resistance_node_line_port_2,
port_a_flow=snapshot.p4_port3_remote_resistance_to_output_line_flow,
port_b_properties=snapshot.p4_port3_remote_resistance_output_line,
port_b_flow=-snapshot.p4_port3_remote_resistance_to_output_line_flow,
)
self._write_connection_line(
line=self.components.p4_port3_remote_resistance_output_line,
@@ -2428,44 +2464,34 @@ class TestMqlPn3P4NodeChamberSegmentClosure:
port_2_flow=-snapshot.p4_port3_remote_resistance_output_to_p4_flow,
)
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
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_line_port_2.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
self._write_orifice_ports(
orifice=self.components.p4_port3_remote_orifice,
port_a_properties=snapshot.p4_port3_remote_orifice_line_port_2,
port_a_flow=snapshot.p4_port3_remote_orifice_to_node_flow,
port_b_properties=snapshot.p4_port3_remote_primary_line,
port_b_flow=-snapshot.p4_port3_remote_orifice_to_node_flow,
)
def rhs(self, state_vector: list[float]) -> list[float]:
snapshot = self.snapshot(state_vector)
inlet_derivative = self.components.inlet_line.derivatives_from_connections(
port_1_m_flow=snapshot.inlet_node_to_line_flow,
connected_h_1=snapshot.p4_port3_remote_orifice_line_port_1.h,
port_2_m_flow=-snapshot.inlet_line_to_chamber_flow,
connected_h_2=snapshot.chamber.h,
)
outlet_derivative = self.components.outlet_line.derivatives_from_connections(
port_1_m_flow=snapshot.outlet_node_to_line_flow,
connected_h_1=snapshot.node_line_port_1.h,
port_2_m_flow=-snapshot.outlet_line_to_chamber_flow,
connected_h_2=snapshot.chamber.h,
)
chamber = self.components.volume
spec = self.components.spec
chamber_derivative = chamber.derivatives_from_two_connections(
port_a_m_flow=self._port(chamber, "port_1").m_flow,
connected_h_a=(
snapshot.inlet_line.h
if spec.volume_inlet_port == "port_1"
else snapshot.outlet_line.h
),
port_b_m_flow=self._port(chamber, "port_2").m_flow,
connected_h_b=(
snapshot.inlet_line.h
if spec.volume_inlet_port == "port_2"
else snapshot.outlet_line.h
),
internal_h=snapshot.chamber.h,
(
inlet_derivative,
chamber_derivative,
outlet_derivative,
) = self._fixed_chamber_segment_derivatives(
spec=self.components.spec,
chamber=self.components.volume,
chamber_properties=snapshot.chamber,
inlet_line=self.components.inlet_line,
inlet_line_properties=snapshot.inlet_line,
inlet_connected_properties=snapshot.p4_port3_remote_orifice_line_port_1,
inlet_node_to_line_flow=snapshot.inlet_node_to_line_flow,
inlet_line_to_chamber_flow=snapshot.inlet_line_to_chamber_flow,
outlet_line=self.components.outlet_line,
outlet_line_properties=snapshot.outlet_line,
outlet_connected_properties=snapshot.node_line_port_1,
outlet_node_to_line_flow=snapshot.outlet_node_to_line_flow,
outlet_line_to_chamber_flow=snapshot.outlet_line_to_chamber_flow,
)
(
node_line_derivative_1,