接入test_mql P4节点局部闭合
This commit is contained in:
1 parent
a071896834
commit
fafce0af87
3 files changed
+647
No files matched your search
@@ -10,6 +10,7 @@ from PythonModels.components.amesim_pneumatic import (
|
||||
)
|
||||
from PythonModels.components.amesim_pneumatic_line import (
|
||||
AmesimPnl0001Pipe,
|
||||
AmesimPnl0002Pipe,
|
||||
AmesimPnl0003Pipe,
|
||||
AmesimPnl00rPipe,
|
||||
)
|
||||
@@ -19,6 +20,8 @@ from PythonModels.core.state import VolumeState
|
||||
from PythonModels.systems.test_mql_nodes import (
|
||||
TestMqlPneumaticNode3,
|
||||
TestMqlPneumaticNode3Balance,
|
||||
TestMqlPneumaticNode4,
|
||||
TestMqlPneumaticNode4Balance,
|
||||
)
|
||||
|
||||
|
||||
@@ -185,6 +188,369 @@ class TestMqlPn3NodeChamberSegmentSnapshot:
|
||||
pnl0003_to_p4_flow: float
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPn3P4NodeChamberSegmentComponents:
|
||||
inlet_line: AmesimPnl0001Pipe
|
||||
outlet_line: AmesimPnl0001Pipe
|
||||
node_line: AmesimPnl0003Pipe
|
||||
node_resistance: AmesimPnl00rPipe
|
||||
node_orifice: AmesimPneumaticOrifice
|
||||
node: TestMqlPneumaticNode3
|
||||
p4_node: TestMqlPneumaticNode4
|
||||
p4_primary_line: AmesimPnl0001Pipe
|
||||
p4_port1_line: AmesimPnl0002Pipe
|
||||
p4_port3_line: AmesimPnl0002Pipe
|
||||
volume: AmesimPneumaticVolume
|
||||
inlet_orifice: AmesimPneumaticOrifice
|
||||
outlet_orifice: AmesimPneumaticOrifice
|
||||
spec: TestMqlPneumaticChamberSegmentSpec
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPn3P4NodeChamberSegmentSnapshot:
|
||||
inlet_line: ThermodynamicProperties
|
||||
chamber: ThermodynamicProperties
|
||||
outlet_line: ThermodynamicProperties
|
||||
node_line_port_1: ThermodynamicProperties
|
||||
node_line_port_2: ThermodynamicProperties
|
||||
p4_primary_line: ThermodynamicProperties
|
||||
p4_boundary: ThermodynamicProperties
|
||||
p4_port1_line: ThermodynamicProperties
|
||||
p4_port3_line: ThermodynamicProperties
|
||||
inlet_node: ThermodynamicProperties
|
||||
resistance_boundary: ThermodynamicProperties
|
||||
p4_primary_boundary: ThermodynamicProperties
|
||||
p4_port1_boundary: ThermodynamicProperties
|
||||
p4_port3_boundary: ThermodynamicProperties
|
||||
node_balance: TestMqlPneumaticNode3Balance
|
||||
p4_balance: TestMqlPneumaticNode4Balance
|
||||
inlet_node_to_line_flow: float
|
||||
inlet_line_to_chamber_flow: float
|
||||
outlet_node_to_line_flow: float
|
||||
outlet_line_to_chamber_flow: float
|
||||
node_to_resistance_flow: float
|
||||
node_to_pnl0003_flow: float
|
||||
pnl0003_center_flow: float
|
||||
pnl0003_to_p4_flow: float
|
||||
p4_boundary_to_primary_line_flow: float
|
||||
p4_node_to_primary_line_flow: float
|
||||
p4_to_port1_line_flow: float
|
||||
p4_port1_boundary_to_line_flow: float
|
||||
p4_to_port3_line_flow: float
|
||||
p4_port3_boundary_to_line_flow: float
|
||||
|
||||
|
||||
class TestMqlPn3P4NodeChamberSegmentClosure:
|
||||
"""PN3 chamber segment closed through the adjacent real P4 node.
|
||||
|
||||
The P4 primary pressure/temperature comes from the PNL0001 storage on
|
||||
``port_2``. P4 ports 1 and 3 are represented by the adjacent PNL0002 center
|
||||
compliances; their far nodes remain prescribed pressure boundaries.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
components: TestMqlPn3P4NodeChamberSegmentComponents,
|
||||
inlet_node: TestMqlPneumaticBoundaryCondition,
|
||||
resistance_boundary: TestMqlPneumaticBoundaryCondition,
|
||||
p4_primary_boundary: TestMqlPneumaticBoundaryCondition,
|
||||
p4_port1_boundary: TestMqlPneumaticBoundaryCondition,
|
||||
p4_port3_boundary: TestMqlPneumaticBoundaryCondition,
|
||||
) -> None:
|
||||
self.components = components
|
||||
self.inlet_node = inlet_node
|
||||
self.resistance_boundary = resistance_boundary
|
||||
self.p4_primary_boundary = p4_primary_boundary
|
||||
self.p4_port1_boundary = p4_port1_boundary
|
||||
self.p4_port3_boundary = p4_port3_boundary
|
||||
|
||||
def initial_state_vector(self) -> list[float]:
|
||||
return [
|
||||
*self.components.inlet_line.get_state_vector(),
|
||||
*self.components.volume.get_state_vector(),
|
||||
*self.components.outlet_line.get_state_vector(),
|
||||
*self.components.node_line.get_state_vector(),
|
||||
*self.components.p4_primary_line.get_state_vector(),
|
||||
*self.components.p4_port1_line.get_state_vector(),
|
||||
*self.components.p4_port3_line.get_state_vector(),
|
||||
]
|
||||
|
||||
def apply_state_vector(self, values: list[float]) -> None:
|
||||
if len(values) != 16:
|
||||
raise ValueError("PN3/P4 node chamber segment state vector requires sixteen 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])
|
||||
self.components.node_line.set_state_vector(values[6:10])
|
||||
self.components.p4_primary_line.set_state_vector(values[10:12])
|
||||
self.components.p4_port1_line.set_state_vector(values[12:14])
|
||||
self.components.p4_port3_line.set_state_vector(values[14:])
|
||||
|
||||
def snapshot(
|
||||
self,
|
||||
state_vector: list[float] | None = None,
|
||||
) -> TestMqlPn3P4NodeChamberSegmentSnapshot:
|
||||
if state_vector is not None:
|
||||
self.apply_state_vector(state_vector)
|
||||
inlet_line = self.components.inlet_line.properties()
|
||||
chamber = self.components.volume.properties()
|
||||
outlet_line = self.components.outlet_line.properties()
|
||||
node_line_port_1 = self.components.node_line.properties_1()
|
||||
node_line_port_2 = self.components.node_line.properties_2()
|
||||
p4_primary_line = self.components.p4_primary_line.properties()
|
||||
p4_port1_line = self.components.p4_port1_line.properties()
|
||||
p4_port3_line = self.components.p4_port3_line.properties()
|
||||
inlet_node = self.inlet_node.properties(self.components.inlet_line.gas)
|
||||
resistance_boundary = self.resistance_boundary.properties(
|
||||
self.components.node_resistance.gas
|
||||
)
|
||||
p4_primary_boundary = self.p4_primary_boundary.properties(
|
||||
self.components.p4_primary_line.gas
|
||||
)
|
||||
p4_port1_boundary = self.p4_port1_boundary.properties(
|
||||
self.components.p4_port1_line.gas
|
||||
)
|
||||
p4_port3_boundary = self.p4_port3_boundary.properties(
|
||||
self.components.p4_port3_line.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,
|
||||
)
|
||||
outlet_node_to_line_flow = self.components.outlet_line.resistance_mass_flow(
|
||||
port_1_pressure_pa=node_line_port_1.p,
|
||||
port_1_temperature_k=node_line_port_1.T,
|
||||
)
|
||||
inlet_line_to_chamber_flow = self._line_to_chamber_flow(
|
||||
line=inlet_line,
|
||||
chamber=chamber,
|
||||
orifice=self.components.inlet_orifice,
|
||||
)
|
||||
outlet_line_to_chamber_flow = self._line_to_chamber_flow(
|
||||
line=outlet_line,
|
||||
chamber=chamber,
|
||||
orifice=self.components.outlet_orifice,
|
||||
)
|
||||
node_to_resistance_flow = self.components.node_resistance.mass_flow(
|
||||
port_1_pressure_pa=node_line_port_1.p,
|
||||
port_1_temperature_k=node_line_port_1.T,
|
||||
port_2_pressure_pa=resistance_boundary.p,
|
||||
port_2_temperature_k=resistance_boundary.T,
|
||||
)
|
||||
node_balance = self.components.node.balance(
|
||||
port_2_temperature_k=node_line_port_1.T,
|
||||
port_2_pressure_pa=node_line_port_1.p,
|
||||
port_1_enthalpy_flow_w=self._enthalpy_flow_from_node(
|
||||
flow_kg_s=node_to_resistance_flow,
|
||||
node_h=node_line_port_1.h,
|
||||
connected_h=resistance_boundary.h,
|
||||
),
|
||||
port_1_mass_flow_g_s=node_to_resistance_flow * 1.0e3,
|
||||
port_3_enthalpy_flow_w=self._enthalpy_flow_from_node(
|
||||
flow_kg_s=outlet_node_to_line_flow,
|
||||
node_h=node_line_port_1.h,
|
||||
connected_h=outlet_line.h,
|
||||
),
|
||||
port_3_mass_flow_g_s=outlet_node_to_line_flow * 1.0e3,
|
||||
)
|
||||
node_to_pnl0003_flow = -node_balance.port_2_mass_flow_g_s * 1.0e-3
|
||||
pnl0003_center_flow = self.components.node_line.resistance_mass_flow()
|
||||
pnl0003_to_p4_flow = self._line_to_p4_flow(
|
||||
line=node_line_port_2,
|
||||
p4_boundary=p4_primary_line,
|
||||
orifice=self.components.node_orifice,
|
||||
)
|
||||
|
||||
p4_boundary_to_primary_line_flow = (
|
||||
self.components.p4_primary_line.resistance_mass_flow(
|
||||
port_1_pressure_pa=p4_primary_boundary.p,
|
||||
port_1_temperature_k=p4_primary_boundary.T,
|
||||
)
|
||||
)
|
||||
p4_to_port1_line_flow = self.components.p4_port1_line.port_mass_flow(
|
||||
port_pressure_pa=p4_primary_line.p,
|
||||
port_temperature_k=p4_primary_line.T,
|
||||
)
|
||||
p4_port1_boundary_to_line_flow = self.components.p4_port1_line.port_mass_flow(
|
||||
port_pressure_pa=p4_port1_boundary.p,
|
||||
port_temperature_k=p4_port1_boundary.T,
|
||||
)
|
||||
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,
|
||||
)
|
||||
p4_port3_boundary_to_line_flow = self.components.p4_port3_line.port_mass_flow(
|
||||
port_pressure_pa=p4_port3_boundary.p,
|
||||
port_temperature_k=p4_port3_boundary.T,
|
||||
)
|
||||
p4_balance = self.components.p4_node.balance(
|
||||
port_2_temperature_k=p4_primary_line.T,
|
||||
port_2_pressure_pa=p4_primary_line.p,
|
||||
port_1_enthalpy_flow_w=self._enthalpy_flow_from_node(
|
||||
flow_kg_s=p4_to_port1_line_flow,
|
||||
node_h=p4_primary_line.h,
|
||||
connected_h=p4_port1_line.h,
|
||||
),
|
||||
port_1_mass_flow_g_s=-p4_to_port1_line_flow * 1.0e3,
|
||||
port_3_enthalpy_flow_w=self._enthalpy_flow_from_node(
|
||||
flow_kg_s=p4_to_port3_line_flow,
|
||||
node_h=p4_primary_line.h,
|
||||
connected_h=p4_port3_line.h,
|
||||
),
|
||||
port_3_mass_flow_g_s=-p4_to_port3_line_flow * 1.0e3,
|
||||
port_4_enthalpy_flow_w=self._enthalpy_flow_from_node(
|
||||
flow_kg_s=pnl0003_to_p4_flow,
|
||||
node_h=node_line_port_2.h,
|
||||
connected_h=p4_primary_line.h,
|
||||
),
|
||||
port_4_mass_flow_g_s=pnl0003_to_p4_flow * 1.0e3,
|
||||
)
|
||||
p4_node_to_primary_line_flow = p4_balance.port_2_mass_flow_g_s * 1.0e-3
|
||||
|
||||
snapshot = TestMqlPn3P4NodeChamberSegmentSnapshot(
|
||||
inlet_line=inlet_line,
|
||||
chamber=chamber,
|
||||
outlet_line=outlet_line,
|
||||
node_line_port_1=node_line_port_1,
|
||||
node_line_port_2=node_line_port_2,
|
||||
p4_primary_line=p4_primary_line,
|
||||
p4_boundary=p4_primary_line,
|
||||
p4_port1_line=p4_port1_line,
|
||||
p4_port3_line=p4_port3_line,
|
||||
inlet_node=inlet_node,
|
||||
resistance_boundary=resistance_boundary,
|
||||
p4_primary_boundary=p4_primary_boundary,
|
||||
p4_port1_boundary=p4_port1_boundary,
|
||||
p4_port3_boundary=p4_port3_boundary,
|
||||
node_balance=node_balance,
|
||||
p4_balance=p4_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,
|
||||
outlet_line_to_chamber_flow=outlet_line_to_chamber_flow,
|
||||
node_to_resistance_flow=node_to_resistance_flow,
|
||||
node_to_pnl0003_flow=node_to_pnl0003_flow,
|
||||
pnl0003_center_flow=pnl0003_center_flow,
|
||||
pnl0003_to_p4_flow=pnl0003_to_p4_flow,
|
||||
p4_boundary_to_primary_line_flow=p4_boundary_to_primary_line_flow,
|
||||
p4_node_to_primary_line_flow=p4_node_to_primary_line_flow,
|
||||
p4_to_port1_line_flow=p4_to_port1_line_flow,
|
||||
p4_port1_boundary_to_line_flow=p4_port1_boundary_to_line_flow,
|
||||
p4_to_port3_line_flow=p4_to_port3_line_flow,
|
||||
p4_port3_boundary_to_line_flow=p4_port3_boundary_to_line_flow,
|
||||
)
|
||||
self._write_port_states(snapshot)
|
||||
return snapshot
|
||||
|
||||
@staticmethod
|
||||
def _line_to_chamber_flow(
|
||||
*,
|
||||
line: ThermodynamicProperties,
|
||||
chamber: ThermodynamicProperties,
|
||||
orifice: AmesimPneumaticOrifice,
|
||||
) -> float:
|
||||
return TestMqlPn3NodeChamberSegmentClosure._line_to_chamber_flow(
|
||||
line=line,
|
||||
chamber=chamber,
|
||||
orifice=orifice,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _line_to_p4_flow(
|
||||
*,
|
||||
line: ThermodynamicProperties,
|
||||
p4_boundary: ThermodynamicProperties,
|
||||
orifice: AmesimPneumaticOrifice,
|
||||
) -> float:
|
||||
return TestMqlPn3NodeChamberSegmentClosure._line_to_p4_flow(
|
||||
line=line,
|
||||
p4_boundary=p4_boundary,
|
||||
orifice=orifice,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _port(
|
||||
component: AmesimPneumaticVolume | AmesimPneumaticOrifice,
|
||||
port_name: str,
|
||||
) -> PortState:
|
||||
return TestMqlPn3NodeChamberSegmentClosure._port(component, port_name)
|
||||
|
||||
@staticmethod
|
||||
def _enthalpy_flow_from_node(
|
||||
*,
|
||||
flow_kg_s: float,
|
||||
node_h: float,
|
||||
connected_h: float,
|
||||
) -> float:
|
||||
return TestMqlPn3NodeChamberSegmentClosure._enthalpy_flow_from_node(
|
||||
flow_kg_s=flow_kg_s,
|
||||
node_h=node_h,
|
||||
connected_h=connected_h,
|
||||
)
|
||||
|
||||
def _write_port_states(
|
||||
self,
|
||||
snapshot: TestMqlPn3P4NodeChamberSegmentSnapshot,
|
||||
) -> None:
|
||||
TestMqlPn3NodeChamberSegmentClosure._write_port_states(self, snapshot)
|
||||
|
||||
p4_primary_line = self.components.p4_primary_line
|
||||
p4_primary_line.port_1.p = snapshot.p4_primary_boundary.p
|
||||
p4_primary_line.port_1.m_flow = snapshot.p4_boundary_to_primary_line_flow
|
||||
p4_primary_line.port_1.h_outflow = snapshot.p4_primary_line.h
|
||||
p4_primary_line.port_2.p = snapshot.p4_primary_line.p
|
||||
p4_primary_line.port_2.m_flow = snapshot.p4_node_to_primary_line_flow
|
||||
p4_primary_line.port_2.h_outflow = snapshot.p4_primary_line.h
|
||||
|
||||
p4_port1_line = self.components.p4_port1_line
|
||||
p4_port1_line.port_1.p = snapshot.p4_primary_line.p
|
||||
p4_port1_line.port_1.m_flow = snapshot.p4_to_port1_line_flow
|
||||
p4_port1_line.port_1.h_outflow = snapshot.p4_port1_line.h
|
||||
p4_port1_line.port_2.p = snapshot.p4_port1_boundary.p
|
||||
p4_port1_line.port_2.m_flow = snapshot.p4_port1_boundary_to_line_flow
|
||||
p4_port1_line.port_2.h_outflow = snapshot.p4_port1_line.h
|
||||
|
||||
p4_port3_line = self.components.p4_port3_line
|
||||
p4_port3_line.port_1.p = snapshot.p4_port3_boundary.p
|
||||
p4_port3_line.port_1.m_flow = snapshot.p4_port3_boundary_to_line_flow
|
||||
p4_port3_line.port_1.h_outflow = snapshot.p4_port3_line.h
|
||||
p4_port3_line.port_2.p = snapshot.p4_primary_line.p
|
||||
p4_port3_line.port_2.m_flow = snapshot.p4_to_port3_line_flow
|
||||
p4_port3_line.port_2.h_outflow = snapshot.p4_port3_line.h
|
||||
|
||||
def rhs(self, state_vector: list[float]) -> list[float]:
|
||||
snapshot = self.snapshot(state_vector)
|
||||
base_rhs = TestMqlPn3NodeChamberSegmentClosure.rhs(self, state_vector)[:10]
|
||||
p4_primary_derivative = (
|
||||
self.components.p4_primary_line.derivatives_from_connections(
|
||||
port_1_m_flow=snapshot.p4_boundary_to_primary_line_flow,
|
||||
connected_h_1=snapshot.p4_primary_boundary.h,
|
||||
port_2_m_flow=snapshot.p4_node_to_primary_line_flow,
|
||||
connected_h_2=snapshot.p4_primary_line.h,
|
||||
)
|
||||
)
|
||||
p4_port1_derivative = self.components.p4_port1_line.derivatives_from_connections(
|
||||
port_1_m_flow=snapshot.p4_to_port1_line_flow,
|
||||
connected_h_1=snapshot.p4_primary_line.h,
|
||||
port_2_m_flow=snapshot.p4_port1_boundary_to_line_flow,
|
||||
connected_h_2=snapshot.p4_port1_boundary.h,
|
||||
)
|
||||
p4_port3_derivative = self.components.p4_port3_line.derivatives_from_connections(
|
||||
port_1_m_flow=snapshot.p4_port3_boundary_to_line_flow,
|
||||
connected_h_1=snapshot.p4_port3_boundary.h,
|
||||
port_2_m_flow=snapshot.p4_to_port3_line_flow,
|
||||
connected_h_2=snapshot.p4_primary_line.h,
|
||||
)
|
||||
return [
|
||||
*base_rhs,
|
||||
*p4_primary_derivative.as_vector(),
|
||||
*p4_port1_derivative.as_vector(),
|
||||
*p4_port3_derivative.as_vector(),
|
||||
]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPneumaticBranchComponents:
|
||||
name: str
|
||||
|
||||
Reference in new issue
Block a user