接入test_mql PN3节点管路闭合
This commit is contained in:
1 parent
568be2e632
commit
78013b25c9
3 files changed
+511
-1
No files matched your search
@@ -8,10 +8,18 @@ from PythonModels.components.amesim_pneumatic import (
|
||||
AmesimPneumaticOrifice,
|
||||
AmesimPneumaticVolume,
|
||||
)
|
||||
from PythonModels.components.amesim_pneumatic_line import AmesimPnl0001Pipe
|
||||
from PythonModels.components.amesim_pneumatic_line import (
|
||||
AmesimPnl0001Pipe,
|
||||
AmesimPnl0003Pipe,
|
||||
AmesimPnl00rPipe,
|
||||
)
|
||||
from PythonModels.core.medium import ThermodynamicProperties
|
||||
from PythonModels.core.ports import PortState
|
||||
from PythonModels.core.state import VolumeState
|
||||
from PythonModels.systems.test_mql_nodes import (
|
||||
TestMqlPneumaticNode3,
|
||||
TestMqlPneumaticNode3Balance,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -82,6 +90,17 @@ class TestMqlPneumaticBoundaryCondition:
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPneumaticFlowBoundaryCondition:
|
||||
mass_flow_kg_s: float
|
||||
temperature_k: float = 293.15
|
||||
|
||||
def connected_enthalpy(self, gas: AmesimPneumaticGas) -> float:
|
||||
if self.temperature_k <= 0.0:
|
||||
raise ValueError("flow boundary temperature must be positive")
|
||||
return gas.specific_enthalpy(self.temperature_k)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPneumaticChamberSegmentComponents:
|
||||
volume: AmesimPneumaticVolume
|
||||
@@ -142,6 +161,40 @@ class TestMqlPnl0001PairChamberSegmentSnapshot:
|
||||
outlet_line_to_chamber_flow: float
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPn3NodeChamberSegmentComponents:
|
||||
inlet_line: AmesimPnl0001Pipe
|
||||
outlet_line: AmesimPnl0001Pipe
|
||||
node_line: AmesimPnl0003Pipe
|
||||
node_resistance: AmesimPnl00rPipe
|
||||
node: TestMqlPneumaticNode3
|
||||
volume: AmesimPneumaticVolume
|
||||
inlet_orifice: AmesimPneumaticOrifice
|
||||
outlet_orifice: AmesimPneumaticOrifice
|
||||
spec: TestMqlPneumaticChamberSegmentSpec
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPn3NodeChamberSegmentSnapshot:
|
||||
inlet_line: ThermodynamicProperties
|
||||
chamber: ThermodynamicProperties
|
||||
outlet_line: ThermodynamicProperties
|
||||
node_line_port_1: ThermodynamicProperties
|
||||
node_line_port_2: ThermodynamicProperties
|
||||
inlet_node: ThermodynamicProperties
|
||||
resistance_boundary: ThermodynamicProperties
|
||||
node_balance: TestMqlPneumaticNode3Balance
|
||||
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_port_2_flow: float
|
||||
pnl0003_port_2_connected_h: float
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlPneumaticBranchComponents:
|
||||
name: str
|
||||
@@ -774,3 +827,251 @@ class TestMqlPnl0001PairChamberSegmentClosure:
|
||||
*chamber_derivative.as_vector(),
|
||||
*outlet_derivative.as_vector(),
|
||||
]
|
||||
|
||||
|
||||
class TestMqlPn3NodeChamberSegmentClosure:
|
||||
"""Boundary-reduced chamber segment closed by one real PN3 node.
|
||||
|
||||
``pneumatic_88`` supplies the PN3 primary pressure/temperature from its
|
||||
port-1 compliance. The node has no storage, so the sum of the port-1
|
||||
PNL00R flow and port-3 PNL0001 flow is written as the opposite port-1
|
||||
flow into the PNL0003 state.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
components: TestMqlPn3NodeChamberSegmentComponents,
|
||||
inlet_node: TestMqlPneumaticBoundaryCondition,
|
||||
resistance_boundary: TestMqlPneumaticBoundaryCondition,
|
||||
pnl0003_port_2_flow: TestMqlPneumaticFlowBoundaryCondition,
|
||||
) -> None:
|
||||
self.components = components
|
||||
self.inlet_node = inlet_node
|
||||
self.resistance_boundary = resistance_boundary
|
||||
self.pnl0003_port_2_flow = pnl0003_port_2_flow
|
||||
|
||||
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(),
|
||||
]
|
||||
|
||||
def apply_state_vector(self, values: list[float]) -> None:
|
||||
if len(values) != 10:
|
||||
raise ValueError("PN3 node/chamber segment state vector requires ten 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:])
|
||||
|
||||
def snapshot(
|
||||
self,
|
||||
state_vector: list[float] | None = None,
|
||||
) -> TestMqlPn3NodeChamberSegmentSnapshot:
|
||||
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()
|
||||
inlet_node = self.inlet_node.properties(self.components.inlet_line.gas)
|
||||
resistance_boundary = self.resistance_boundary.properties(
|
||||
self.components.node_resistance.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_port_2_connected_h = self.pnl0003_port_2_flow.connected_enthalpy(
|
||||
self.components.node_line.gas
|
||||
)
|
||||
snapshot = TestMqlPn3NodeChamberSegmentSnapshot(
|
||||
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,
|
||||
inlet_node=inlet_node,
|
||||
resistance_boundary=resistance_boundary,
|
||||
node_balance=node_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_port_2_flow=self.pnl0003_port_2_flow.mass_flow_kg_s,
|
||||
pnl0003_port_2_connected_h=pnl0003_port_2_connected_h,
|
||||
)
|
||||
self._write_port_states(snapshot)
|
||||
return snapshot
|
||||
|
||||
@staticmethod
|
||||
def _line_to_chamber_flow(
|
||||
*,
|
||||
line: ThermodynamicProperties,
|
||||
chamber: ThermodynamicProperties,
|
||||
orifice: AmesimPneumaticOrifice,
|
||||
) -> float:
|
||||
return TestMqlPnl0001PairChamberSegmentClosure._line_to_chamber_flow(
|
||||
line=line,
|
||||
chamber=chamber,
|
||||
orifice=orifice,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _port(
|
||||
component: AmesimPneumaticVolume | AmesimPneumaticOrifice,
|
||||
port_name: str,
|
||||
) -> PortState:
|
||||
return TestMqlPneumaticChamberSegmentClosure._port(component, port_name)
|
||||
|
||||
@staticmethod
|
||||
def _enthalpy_flow_from_node(
|
||||
*,
|
||||
flow_kg_s: float,
|
||||
node_h: float,
|
||||
connected_h: float,
|
||||
) -> float:
|
||||
return flow_kg_s * (node_h if flow_kg_s >= 0.0 else connected_h)
|
||||
|
||||
def _write_port_states(
|
||||
self,
|
||||
snapshot: TestMqlPn3NodeChamberSegmentSnapshot,
|
||||
) -> None:
|
||||
spec = self.components.spec
|
||||
chamber = self.components.volume
|
||||
chamber_inlet_port = self._port(chamber, spec.volume_inlet_port)
|
||||
chamber_outlet_port = self._port(chamber, spec.volume_outlet_port)
|
||||
|
||||
TestMqlPnl0001PairChamberSegmentClosure._write_line_side(
|
||||
self,
|
||||
line=self.components.inlet_line,
|
||||
line_properties=snapshot.inlet_line,
|
||||
node_properties=snapshot.inlet_node,
|
||||
node_to_line_flow=snapshot.inlet_node_to_line_flow,
|
||||
line_to_chamber_flow=snapshot.inlet_line_to_chamber_flow,
|
||||
orifice=self.components.inlet_orifice,
|
||||
orifice_boundary_port=spec.inlet_orifice_boundary_port,
|
||||
orifice_volume_port=spec.inlet_orifice_volume_port,
|
||||
chamber_port=chamber_inlet_port,
|
||||
chamber_properties=snapshot.chamber,
|
||||
)
|
||||
TestMqlPnl0001PairChamberSegmentClosure._write_line_side(
|
||||
self,
|
||||
line=self.components.outlet_line,
|
||||
line_properties=snapshot.outlet_line,
|
||||
node_properties=snapshot.node_line_port_1,
|
||||
node_to_line_flow=snapshot.outlet_node_to_line_flow,
|
||||
line_to_chamber_flow=snapshot.outlet_line_to_chamber_flow,
|
||||
orifice=self.components.outlet_orifice,
|
||||
orifice_boundary_port=spec.outlet_orifice_boundary_port,
|
||||
orifice_volume_port=spec.outlet_orifice_volume_port,
|
||||
chamber_port=chamber_outlet_port,
|
||||
chamber_properties=snapshot.chamber,
|
||||
)
|
||||
node_line = self.components.node_line
|
||||
node_line.port_1.p = snapshot.node_line_port_1.p
|
||||
node_line.port_1.m_flow = snapshot.node_to_pnl0003_flow
|
||||
node_line.port_1.h_outflow = snapshot.node_line_port_1.h
|
||||
node_line.port_2.p = snapshot.node_line_port_2.p
|
||||
node_line.port_2.m_flow = snapshot.pnl0003_port_2_flow
|
||||
node_line.port_2.h_outflow = snapshot.node_line_port_2.h
|
||||
|
||||
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.resistance_boundary.p
|
||||
resistance.port_2.m_flow = -snapshot.node_to_resistance_flow
|
||||
resistance.port_2.h_outflow = snapshot.resistance_boundary.h
|
||||
|
||||
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.inlet_node.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,
|
||||
)
|
||||
node_line_derivative_1, node_line_derivative_2 = (
|
||||
self.components.node_line.derivatives_from_connections(
|
||||
port_1_m_flow=snapshot.node_to_pnl0003_flow,
|
||||
connected_h_1=snapshot.node_line_port_1.h,
|
||||
port_2_m_flow=snapshot.pnl0003_port_2_flow,
|
||||
connected_h_2=snapshot.pnl0003_port_2_connected_h,
|
||||
)
|
||||
)
|
||||
return [
|
||||
*inlet_derivative.as_vector(),
|
||||
*chamber_derivative.as_vector(),
|
||||
*outlet_derivative.as_vector(),
|
||||
*node_line_derivative_1.as_vector(),
|
||||
*node_line_derivative_2.as_vector(),
|
||||
]
|
||||
Reference in new issue
Block a user