实现test_mql PNL0001管路动态

This commit is contained in:
huojiarong committed 2026-07-17 03:28:36 +00:00
1 parent 2d33a8f4bc
commit 1193b2dcee
8 files changed
+995

No files matched your search

+176
View File
@@ -8,6 +8,7 @@ from PythonModels.components.amesim_pneumatic import (
AmesimPneumaticOrifice,
AmesimPneumaticVolume,
)
from PythonModels.components.amesim_pneumatic_line import AmesimPnl0001Pipe
from PythonModels.core.medium import ThermodynamicProperties
from PythonModels.core.ports import PortState
from PythonModels.core.state import VolumeState
@@ -98,6 +99,26 @@ class TestMqlPneumaticChamberSegmentSnapshot:
outlet_flow: float
@dataclass(frozen=True)
class TestMqlPnl0001ChamberSegmentComponents:
inlet_line: AmesimPnl0001Pipe
volume: AmesimPneumaticVolume
inlet_orifice: AmesimPneumaticOrifice
outlet_orifice: AmesimPneumaticOrifice
spec: TestMqlPneumaticChamberSegmentSpec
@dataclass(frozen=True)
class TestMqlPnl0001ChamberSegmentSnapshot:
inlet_line: ThermodynamicProperties
chamber: ThermodynamicProperties
inlet_node: ThermodynamicProperties
outlet_boundary: ThermodynamicProperties
node_to_line_flow: float
line_to_chamber_flow: float
outlet_flow: float
@dataclass(frozen=True)
class TestMqlPneumaticBranchComponents:
name: str
@@ -379,3 +400,158 @@ class TestMqlPneumaticChamberSegmentClosure:
internal_h=snapshot.chamber.h,
)
return derivative.as_vector()
class TestMqlPnl0001ChamberSegmentClosure:
"""Fixed chamber segment with the topology-derived inlet PNL0001 state.
The inlet line has a closed causal boundary here: port-1 pressure and
temperature come from the PN3 node boundary, while port-2 flow comes from
the fixed orifice. The outlet line remains a boundary until its three-line
PN3 node balance is assembled.
"""
def __init__(
self,
*,
components: TestMqlPnl0001ChamberSegmentComponents,
inlet_node: TestMqlPneumaticBoundaryCondition,
outlet_boundary: TestMqlPneumaticBoundaryCondition,
) -> None:
self.components = components
self.inlet_node = inlet_node
self.outlet_boundary = outlet_boundary
def initial_state_vector(self) -> list[float]:
return [
*self.components.inlet_line.get_state_vector(),
*self.components.volume.get_state_vector(),
]
def apply_state_vector(self, values: list[float]) -> None:
if len(values) != 4:
raise ValueError("PNL0001/chamber segment state vector requires four values")
self.components.inlet_line.set_state_vector(values[:2])
self.components.volume.set_state_vector(values[2:])
def snapshot(
self,
state_vector: list[float] | None = None,
) -> TestMqlPnl0001ChamberSegmentSnapshot:
if state_vector is not None:
self.apply_state_vector(state_vector)
line = self.components.inlet_line.properties()
chamber = self.components.volume.properties()
inlet_node = self.inlet_node.properties(self.components.inlet_line.gas)
outlet_boundary = self.outlet_boundary.properties(self.components.volume.gas)
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,
)
inlet_temperature = line.T if line.p >= chamber.p else chamber.T
line_to_chamber_flow = self.components.inlet_orifice.mass_flow(
line.p,
chamber.p,
inlet_temperature,
)
outlet_temperature = (
chamber.T if chamber.p >= outlet_boundary.p else outlet_boundary.T
)
outlet_flow = self.components.outlet_orifice.mass_flow(
chamber.p,
outlet_boundary.p,
outlet_temperature,
)
snapshot = TestMqlPnl0001ChamberSegmentSnapshot(
inlet_line=line,
chamber=chamber,
inlet_node=inlet_node,
outlet_boundary=outlet_boundary,
node_to_line_flow=node_to_line_flow,
line_to_chamber_flow=line_to_chamber_flow,
outlet_flow=outlet_flow,
)
self._write_port_states(snapshot)
return snapshot
@staticmethod
def _port(
component: AmesimPneumaticVolume | AmesimPneumaticOrifice,
port_name: str,
) -> PortState:
return TestMqlPneumaticChamberSegmentClosure._port(component, port_name)
def _write_port_states(
self,
snapshot: TestMqlPnl0001ChamberSegmentSnapshot,
) -> None:
spec = self.components.spec
line = self.components.inlet_line
chamber = self.components.volume
inlet_orifice = self.components.inlet_orifice
outlet_orifice = self.components.outlet_orifice
line.port_1.p = snapshot.inlet_node.p
line.port_1.m_flow = snapshot.node_to_line_flow
line.port_1.h_outflow = snapshot.inlet_line.h
line.port_2.p = snapshot.inlet_line.p
line.port_2.m_flow = -snapshot.line_to_chamber_flow
inlet_boundary_port = self._port(
inlet_orifice,
spec.inlet_orifice_boundary_port,
)
inlet_volume_port = self._port(inlet_orifice, spec.inlet_orifice_volume_port)
inlet_boundary_port.p = snapshot.inlet_line.p
inlet_boundary_port.m_flow = snapshot.line_to_chamber_flow
inlet_boundary_port.h_outflow = snapshot.inlet_line.h
inlet_volume_port.p = snapshot.chamber.p
inlet_volume_port.m_flow = -snapshot.line_to_chamber_flow
inlet_volume_port.h_outflow = snapshot.chamber.h
chamber_inlet_port = self._port(chamber, spec.volume_inlet_port)
chamber_outlet_port = self._port(chamber, spec.volume_outlet_port)
chamber_inlet_port.m_flow = snapshot.line_to_chamber_flow
chamber_outlet_port.m_flow = -snapshot.outlet_flow
outlet_volume_port = self._port(
outlet_orifice,
spec.outlet_orifice_volume_port,
)
outlet_boundary_port = self._port(
outlet_orifice,
spec.outlet_orifice_boundary_port,
)
outlet_volume_port.p = snapshot.chamber.p
outlet_volume_port.m_flow = snapshot.outlet_flow
outlet_volume_port.h_outflow = snapshot.chamber.h
outlet_boundary_port.p = snapshot.outlet_boundary.p
outlet_boundary_port.m_flow = -snapshot.outlet_flow
outlet_boundary_port.h_outflow = snapshot.outlet_boundary.h
def rhs(self, state_vector: list[float]) -> list[float]:
snapshot = self.snapshot(state_vector)
line_derivative = self.components.inlet_line.derivatives_from_connections(
port_1_m_flow=snapshot.node_to_line_flow,
connected_h_1=snapshot.inlet_node.h,
port_2_m_flow=-snapshot.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_boundary.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_boundary.h
),
internal_h=snapshot.chamber.h,
)
return [*line_derivative.as_vector(), *chamber_derivative.as_vector()]