接入PNL0001事件窗口RHS诊断

This commit is contained in:
huojiarong committed 2026-07-22 04:21:38 +00:00
1 parent 2120901909
commit f0f8f40c7a
4 files changed
+597 -11

No files matched your search

+121 -9
View File
@@ -3874,6 +3874,23 @@ class TestMqlVariableChamberRhsDiagnostic:
energy_derivative_w: float
@dataclass(frozen=True)
class TestMqlPnl0001LineRhsDiagnostic:
line_alias: str
chamber_alias: str
line_pressure_pa: float
line_temperature_k: float
chamber_pressure_pa: float
chamber_temperature_k: float
chamber_to_line_flow_kg_s: float
node_to_line_flow_kg_s: float
mass_derivative_kg_s: float
port_1_energy_flow_w: float
port_2_energy_flow_w: float
thermal_energy_flow_w: float
energy_derivative_w: float
_PISTON_FORCE_BINDINGS = (
("mass_friction_endstops_10", "pn_brp2_8", "p4_port3_remote_primary_chamber"),
("mass_friction_endstops_11", "pn_brp2_9", "p4_primary_chamber"),
@@ -3977,8 +3994,13 @@ _PRIMARY_CHAMBER_DIAGNOSTIC_FIELDS = {
}
_PNL0001_MASS_FLOW_DIAGNOSTIC_FIELDS = {
"pneumatic_69": "p4_port3_remote_chamber_to_line_flow",
_PNL0001_LINE_DIAGNOSTIC_FIELDS = {
"pneumatic_69": (
"p4_port3_remote_primary_line",
"p4_port3_remote_primary_chamber",
"p4_port3_remote_chamber_to_line_flow",
"p4_port3_remote_node_to_primary_line_flow",
),
}
_VARIABLE_ORIFICE_MASS_FLOW_DIAGNOSTIC_FIELDS = {
@@ -4146,6 +4168,65 @@ class TestMqlFullStateClosure:
),
)
def pnl0001_line_rhs_diagnostic(
self,
*,
line_alias: str,
state_vector: list[float],
time_s: float = 0.0,
) -> TestMqlPnl0001LineRhsDiagnostic:
if line_alias not in _PNL0001_LINE_DIAGNOSTIC_FIELDS:
raise KeyError(line_alias)
(
line_field,
chamber_field,
chamber_flow_field,
node_flow_field,
) = _PNL0001_LINE_DIAGNOSTIC_FIELDS[line_alias]
chamber_alias = _PNCH012_ALIAS_BY_SNAPSHOT_FIELD[chamber_field]
snapshot = self.snapshot_at(time_s, state_vector)
line = getattr(self.pneumatic_closure.components, line_field)
line_properties = getattr(snapshot.pneumatic, line_field)
chamber_properties = getattr(snapshot.pneumatic, chamber_field)
chamber_to_line_flow = getattr(snapshot.pneumatic, chamber_flow_field)
node_to_line_flow = getattr(snapshot.pneumatic, node_flow_field)
line_derivative = line.derivatives_from_connections(
port_1_m_flow=chamber_to_line_flow,
connected_h_1=chamber_properties.h,
port_2_m_flow=node_to_line_flow,
connected_h_2=line_properties.h,
)
port_1_inlet_u = (
chamber_properties.h / line.gas.gamma
if chamber_to_line_flow > 0.0
else line_properties.u
)
port_2_inlet_u = (
line_properties.h / line.gas.gamma
if node_to_line_flow > 0.0
else line_properties.u
)
thermal_energy_flow = (
line.heat_transfer_coefficient
* line.heat_transfer_area
* (line.external_temperature - line_properties.T)
)
return TestMqlPnl0001LineRhsDiagnostic(
line_alias=line_alias,
chamber_alias=chamber_alias,
line_pressure_pa=line_properties.p,
line_temperature_k=line_properties.T,
chamber_pressure_pa=chamber_properties.p,
chamber_temperature_k=chamber_properties.T,
chamber_to_line_flow_kg_s=chamber_to_line_flow,
node_to_line_flow_kg_s=node_to_line_flow,
mass_derivative_kg_s=line_derivative.m,
port_1_energy_flow_w=chamber_to_line_flow * port_1_inlet_u,
port_2_energy_flow_w=node_to_line_flow * port_2_inlet_u,
thermal_energy_flow_w=thermal_energy_flow,
energy_derivative_w=line_derivative.U,
)
def data_path_values(
self,
*,
@@ -4173,14 +4254,43 @@ class TestMqlFullStateClosure:
values_by_data_path = {}
for data_path in selected_paths:
signal, alias = self._split_data_path(data_path)
if alias in _PNL0001_MASS_FLOW_DIAGNOSTIC_FIELDS:
if signal != "dm1":
if alias in _PNL0001_LINE_DIAGNOSTIC_FIELDS:
(
line_field,
_chamber_field,
chamber_flow_field,
_node_flow_field,
) = _PNL0001_LINE_DIAGNOSTIC_FIELDS[alias]
if signal == "dm1":
canonical_flow_kg_s = getattr(snapshot.pneumatic, chamber_flow_field)
values_by_data_path[data_path] = -canonical_flow_kg_s * 1.0e3
elif signal == "p2":
line_properties = getattr(snapshot.pneumatic, line_field)
values_by_data_path[data_path] = pressure_to_amesim_gauge_pa(
line_properties.p
)
elif signal == "t2":
line_properties = getattr(snapshot.pneumatic, line_field)
values_by_data_path[data_path] = line_properties.T
elif signal == "mgas":
line = getattr(self.pneumatic_closure.components, line_field)
values_by_data_path[data_path] = line.gas_mass_g()
elif signal in {"re", "v", "ff"}:
line = getattr(self.pneumatic_closure.components, line_field)
line_properties = getattr(snapshot.pneumatic, line_field)
canonical_flow_kg_s = getattr(snapshot.pneumatic, chamber_flow_field)
diagnostics = line.diagnostics(
mass_flow_kg_s=-canonical_flow_kg_s,
temperature_k=line_properties.T,
)
if signal == "re":
values_by_data_path[data_path] = diagnostics.reynolds_number
elif signal == "v":
values_by_data_path[data_path] = diagnostics.gas_velocity_m_s
else:
values_by_data_path[data_path] = diagnostics.friction_factor
else:
raise KeyError(data_path)
canonical_flow_kg_s = getattr(
snapshot.pneumatic,
_PNL0001_MASS_FLOW_DIAGNOSTIC_FIELDS[alias],
)
values_by_data_path[data_path] = -canonical_flow_kg_s * 1.0e3
elif alias in self.pneumatic_assembly.variable_orifices:
orifice = self.pneumatic_assembly.variable_orifices[alias]
if signal == "xv":
@@ -4207,6 +4317,8 @@ class TestMqlFullStateClosure:
values_by_data_path[data_path] = chamber_properties.T
elif signal == "vol":
values_by_data_path[data_path] = chamber.volume_cm3()
elif signal in {"mgas", "mgas1"}:
values_by_data_path[data_path] = chamber.gas_mass_g()
else:
raise KeyError(data_path)
elif alias in self.mechanical_closure.assembly.pistons: