接入test_mql PNVO孔口边界

This commit is contained in:
huojiarong committed 2026-07-17 09:16:35 +00:00
1 parent 78013b25c9
commit 5c3ad50090
3 files changed
+89 -39

No files matched your search

+27 -16
View File
@@ -3940,14 +3940,18 @@ class TestMqlSystem:
def typed_node3_count(self) -> int:
return len(self.node3_assembly)
def _pnl0003_line_for_node_port(self, node_alias: str, port_name: str):
def _pnl0003_spec_for_node_port(self, node_alias: str, port_name: str):
for spec in self.pnl0003_assembly.specs:
if spec.source_component == node_alias and spec.source_port == port_name:
return self.pnl0003_assembly.lines[spec.alias]
return spec
if spec.target_component == node_alias and spec.target_port == port_name:
return self.pnl0003_assembly.lines[spec.alias]
return spec
raise KeyError(f"No PNL0003 line attached to {node_alias}.{port_name}")
def _pnl0003_line_for_node_port(self, node_alias: str, port_name: str):
spec = self._pnl0003_spec_for_node_port(node_alias, port_name)
return self.pnl0003_assembly.lines[spec.alias]
def _pnl00r_line_for_node_port(self, node_alias: str, port_name: str):
for spec in self.pnl00r_assembly.specs:
if spec.source_component == node_alias and spec.source_port == port_name:
@@ -4300,14 +4304,14 @@ class TestMqlSystem:
resistance_boundary_pressure_pa: float,
inlet_node_temperature_k: float = 293.15,
resistance_boundary_temperature_k: float = 293.15,
pnl0003_port_2_mass_flow_kg_s: float = 0.0,
pnl0003_port_2_temperature_k: float = 293.15,
p4_boundary_pressure_pa: float = 15.3e6,
p4_boundary_temperature_k: float = 293.15,
):
"""Close a PNL0001 chamber segment with the real outlet PN3 node.
The PN3 primary pressure/temperature is taken from the attached PNL0003
port-1 compliance. The PNL0003 port-2 side and the far side of PNL00R
remain prescribed boundaries until PNVO/P4 semantics are inserted.
port-1 compliance. The PNL0003 port-2 side is connected through the
real PNVO001 orifice to a prescribed P4 pressure boundary.
"""
from PythonModels.components.amesim_pneumatic import (
AmesimPneumaticOrifice,
@@ -4315,14 +4319,20 @@ class TestMqlSystem:
)
from PythonModels.systems.test_mql_closure import (
TestMqlPneumaticBoundaryCondition,
TestMqlPneumaticFlowBoundaryCondition,
TestMqlPn3NodeChamberSegmentClosure,
TestMqlPn3NodeChamberSegmentComponents,
)
inlet_line = self.pnl0001_assembly.lines[spec.inlet_line_alias]
outlet_line = self.pnl0001_assembly.lines[spec.outlet_line_alias]
node_line = self._pnl0003_line_for_node_port(spec.outlet_node_alias, "port_2")
node_line_spec = self._pnl0003_spec_for_node_port(spec.outlet_node_alias, "port_2")
node_line = self.pnl0003_assembly.lines[node_line_spec.alias]
node_orifice_alias = (
node_line_spec.target_component
if node_line_spec.source_component == spec.outlet_node_alias
else node_line_spec.source_component
)
node_orifice = self.pneumatic_assembly.variable_orifices[node_orifice_alias]
node_resistance = self._pnl00r_line_for_node_port(
spec.outlet_node_alias, "port_1"
)
@@ -4346,6 +4356,7 @@ class TestMqlSystem:
outlet_line=outlet_line,
node_line=node_line,
node_resistance=node_resistance,
node_orifice=node_orifice,
node=node,
volume=volume,
inlet_orifice=inlet_orifice,
@@ -4360,9 +4371,9 @@ class TestMqlSystem:
pressure_pa=resistance_boundary_pressure_pa,
temperature_k=resistance_boundary_temperature_k,
),
pnl0003_port_2_flow=TestMqlPneumaticFlowBoundaryCondition(
mass_flow_kg_s=pnl0003_port_2_mass_flow_kg_s,
temperature_k=pnl0003_port_2_temperature_k,
p4_boundary=TestMqlPneumaticBoundaryCondition(
pressure_pa=p4_boundary_pressure_pa,
temperature_k=p4_boundary_temperature_k,
),
)
@@ -4374,8 +4385,8 @@ class TestMqlSystem:
resistance_boundary_pressure_pa: float,
inlet_node_temperature_k: float = 293.15,
resistance_boundary_temperature_k: float = 293.15,
pnl0003_port_2_mass_flow_kg_s: float = 0.0,
pnl0003_port_2_temperature_k: float = 293.15,
p4_boundary_pressure_pa: float = 15.3e6,
p4_boundary_temperature_k: float = 293.15,
config: SolveIVPConfig | None = None,
t_eval: list[float] | None = None,
):
@@ -4385,8 +4396,8 @@ class TestMqlSystem:
resistance_boundary_pressure_pa=resistance_boundary_pressure_pa,
inlet_node_temperature_k=inlet_node_temperature_k,
resistance_boundary_temperature_k=resistance_boundary_temperature_k,
pnl0003_port_2_mass_flow_kg_s=pnl0003_port_2_mass_flow_kg_s,
pnl0003_port_2_temperature_k=pnl0003_port_2_temperature_k,
p4_boundary_pressure_pa=p4_boundary_pressure_pa,
p4_boundary_temperature_k=p4_boundary_temperature_k,
)
run_config = config or SolveIVPConfig(t_stop=1.0e-4, max_step=1.0e-5)
return integrate_ode(
+53 -22
View File
@@ -90,17 +90,6 @@ 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
@@ -167,6 +156,7 @@ class TestMqlPn3NodeChamberSegmentComponents:
outlet_line: AmesimPnl0001Pipe
node_line: AmesimPnl0003Pipe
node_resistance: AmesimPnl00rPipe
node_orifice: AmesimPneumaticOrifice
node: TestMqlPneumaticNode3
volume: AmesimPneumaticVolume
inlet_orifice: AmesimPneumaticOrifice
@@ -183,6 +173,7 @@ class TestMqlPn3NodeChamberSegmentSnapshot:
node_line_port_2: ThermodynamicProperties
inlet_node: ThermodynamicProperties
resistance_boundary: ThermodynamicProperties
p4_boundary: ThermodynamicProperties
node_balance: TestMqlPneumaticNode3Balance
inlet_node_to_line_flow: float
inlet_line_to_chamber_flow: float
@@ -191,8 +182,7 @@ class TestMqlPn3NodeChamberSegmentSnapshot:
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
pnl0003_to_p4_flow: float
@dataclass(frozen=True)
@@ -550,6 +540,16 @@ class TestMqlPnl0001ChamberSegmentClosure:
self._write_port_states(snapshot)
return snapshot
@staticmethod
def _line_to_p4_flow(
*,
line: ThermodynamicProperties,
p4_boundary: ThermodynamicProperties,
orifice: AmesimPneumaticOrifice,
) -> float:
upstream_temperature = line.T if line.p >= p4_boundary.p else p4_boundary.T
return orifice.mass_flow(line.p, p4_boundary.p, upstream_temperature)
@staticmethod
def _port(
component: AmesimPneumaticVolume | AmesimPneumaticOrifice,
@@ -720,6 +720,16 @@ class TestMqlPnl0001PairChamberSegmentClosure:
upstream_temperature = line.T if line.p >= chamber.p else chamber.T
return orifice.mass_flow(line.p, chamber.p, upstream_temperature)
@staticmethod
def _line_to_p4_flow(
*,
line: ThermodynamicProperties,
p4_boundary: ThermodynamicProperties,
orifice: AmesimPneumaticOrifice,
) -> float:
upstream_temperature = line.T if line.p >= p4_boundary.p else p4_boundary.T
return orifice.mass_flow(line.p, p4_boundary.p, upstream_temperature)
@staticmethod
def _port(
component: AmesimPneumaticVolume | AmesimPneumaticOrifice,
@@ -844,12 +854,12 @@ class TestMqlPn3NodeChamberSegmentClosure:
components: TestMqlPn3NodeChamberSegmentComponents,
inlet_node: TestMqlPneumaticBoundaryCondition,
resistance_boundary: TestMqlPneumaticBoundaryCondition,
pnl0003_port_2_flow: TestMqlPneumaticFlowBoundaryCondition,
p4_boundary: TestMqlPneumaticBoundaryCondition,
) -> None:
self.components = components
self.inlet_node = inlet_node
self.resistance_boundary = resistance_boundary
self.pnl0003_port_2_flow = pnl0003_port_2_flow
self.p4_boundary = p4_boundary
def initial_state_vector(self) -> list[float]:
return [
@@ -882,6 +892,7 @@ class TestMqlPn3NodeChamberSegmentClosure:
resistance_boundary = self.resistance_boundary.properties(
self.components.node_resistance.gas
)
p4_boundary = self.p4_boundary.properties(self.components.node_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,
@@ -924,8 +935,10 @@ class TestMqlPn3NodeChamberSegmentClosure:
)
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
pnl0003_to_p4_flow = self._line_to_p4_flow(
line=node_line_port_2,
p4_boundary=p4_boundary,
orifice=self.components.node_orifice,
)
snapshot = TestMqlPn3NodeChamberSegmentSnapshot(
inlet_line=inlet_line,
@@ -935,6 +948,7 @@ class TestMqlPn3NodeChamberSegmentClosure:
node_line_port_2=node_line_port_2,
inlet_node=inlet_node,
resistance_boundary=resistance_boundary,
p4_boundary=p4_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,
@@ -943,8 +957,7 @@ class TestMqlPn3NodeChamberSegmentClosure:
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,
pnl0003_to_p4_flow=pnl0003_to_p4_flow,
)
self._write_port_states(snapshot)
return snapshot
@@ -962,6 +975,16 @@ class TestMqlPn3NodeChamberSegmentClosure:
orifice=orifice,
)
@staticmethod
def _line_to_p4_flow(
*,
line: ThermodynamicProperties,
p4_boundary: ThermodynamicProperties,
orifice: AmesimPneumaticOrifice,
) -> float:
upstream_temperature = line.T if line.p >= p4_boundary.p else p4_boundary.T
return orifice.mass_flow(line.p, p4_boundary.p, upstream_temperature)
@staticmethod
def _port(
component: AmesimPneumaticVolume | AmesimPneumaticOrifice,
@@ -1018,9 +1041,17 @@ class TestMqlPn3NodeChamberSegmentClosure:
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.m_flow = -snapshot.pnl0003_to_p4_flow
node_line.port_2.h_outflow = snapshot.node_line_port_2.h
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_boundary.p
node_orifice.port_b.m_flow = -snapshot.pnl0003_to_p4_flow
node_orifice.port_b.h_outflow = snapshot.p4_boundary.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
@@ -1064,8 +1095,8 @@ class TestMqlPn3NodeChamberSegmentClosure:
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,
port_2_m_flow=-snapshot.pnl0003_to_p4_flow,
connected_h_2=snapshot.p4_boundary.h,
)
)
return [
+9 -1
View File
@@ -168,6 +168,7 @@ class TestMqlPn3NodeChamberSegmentTests(unittest.TestCase):
self.assertEqual(closure.components.outlet_line.name, "pneumatic_97")
self.assertEqual(closure.components.node_line.name, "pneumatic_88")
self.assertEqual(closure.components.node_resistance.name, "pneumatic_100")
self.assertEqual(closure.components.node_orifice.name, "pn_morifice_9")
self.assertEqual(closure.components.node.alias, "pn_node3_9")
self.assertEqual(len(closure.initial_state_vector()), 10)
self.assertEqual(len(rhs), 10)
@@ -185,6 +186,7 @@ class TestMqlPn3NodeChamberSegmentTests(unittest.TestCase):
self.spec,
inlet_node_pressure_pa=15.3e6,
resistance_boundary_pressure_pa=15.0e6,
p4_boundary_pressure_pa=15.0e6,
)
state = closure.initial_state_vector()
state[4] *= 0.99
@@ -204,16 +206,21 @@ class TestMqlPn3NodeChamberSegmentTests(unittest.TestCase):
snapshot.node_to_pnl0003_flow,
-(snapshot.outlet_node_to_line_flow + snapshot.node_to_resistance_flow),
)
self.assertGreater(snapshot.pnl0003_to_p4_flow, 0.0)
self.assertAlmostEqual(
closure.components.node_line.port_1.m_flow,
snapshot.node_to_pnl0003_flow,
)
self.assertAlmostEqual(
closure.components.node_line.port_2.m_flow,
-snapshot.pnl0003_to_p4_flow,
)
mass_derivative_sum = rhs[0] + rhs[2] + rhs[4] + rhs[6] + rhs[8]
self.assertAlmostEqual(
mass_derivative_sum,
(
snapshot.inlet_node_to_line_flow
+ snapshot.pnl0003_port_2_flow
- snapshot.pnl0003_to_p4_flow
- snapshot.node_to_resistance_flow
),
delta=1.0e-12,
@@ -224,6 +231,7 @@ class TestMqlPn3NodeChamberSegmentTests(unittest.TestCase):
self.spec,
inlet_node_pressure_pa=15.31e6,
resistance_boundary_pressure_pa=15.29e6,
p4_boundary_pressure_pa=15.29e6,
config=SolveIVPConfig(
t_start=0.0,
t_stop=1.0e-8,