拆解test_mql变容气室RHS
This commit is contained in:
1 parent
a6e1faa2d8
commit
2c2952cff1
4 files changed
+205
No files matched your search
@@ -53,6 +53,7 @@ class TestMqlFullStateSignalDiagnostic:
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlFullStateComparisonRun:
|
||||
system: TestMqlSystem
|
||||
closure: object
|
||||
amesim_results: AmesimResults
|
||||
output_schema: TestMqlOutputSchema
|
||||
result: TestMqlSimulationResult
|
||||
@@ -128,6 +129,13 @@ class TestMqlFullStateComparisonRun:
|
||||
diagnostics = self.diagnostics_by_final_abs_error()
|
||||
return diagnostics[0] if diagnostics else None
|
||||
|
||||
def chamber_rhs_diagnostic(self, chamber_alias: str, sample_index: int = -1):
|
||||
state_vector = [row[sample_index] for row in self.result.y]
|
||||
return self.closure.variable_chamber_rhs_diagnostic(
|
||||
chamber_alias=chamber_alias,
|
||||
state_vector=state_vector,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TestMqlFullStateComparisonPathConfig:
|
||||
@@ -193,6 +201,17 @@ def run_test_mql_full_state_comparison(
|
||||
t_eval=list(config.execution.t_eval) if config.execution.t_eval is not None else None,
|
||||
data_paths=selected_paths,
|
||||
)
|
||||
closure = system.full_state_closure_from_spec(
|
||||
spec,
|
||||
inlet_node_pressure_pa=config.execution.inlet_node_pressure_pa,
|
||||
resistance_boundary_pressure_pa=(
|
||||
config.execution.resistance_boundary_pressure_pa
|
||||
),
|
||||
inlet_node_temperature_k=config.execution.inlet_node_temperature_k,
|
||||
resistance_boundary_temperature_k=(
|
||||
config.execution.resistance_boundary_temperature_k
|
||||
),
|
||||
)
|
||||
series_by_data_path = {
|
||||
data_path: result.series[data_path]
|
||||
for data_path in result.series
|
||||
@@ -213,6 +232,7 @@ def run_test_mql_full_state_comparison(
|
||||
)
|
||||
run = TestMqlFullStateComparisonRun(
|
||||
system=system,
|
||||
closure=closure,
|
||||
amesim_results=amesim_results,
|
||||
output_schema=output_schema,
|
||||
result=result,
|
||||
@@ -278,9 +298,38 @@ def format_test_mql_full_state_comparison_summary(
|
||||
f"final_amesim={diagnostic.final_amesim_value}, "
|
||||
f"final_abs_error={diagnostic.final_abs_error}"
|
||||
)
|
||||
chamber_diagnostic = _largest_chamber_rhs_diagnostic(run)
|
||||
if chamber_diagnostic is not None:
|
||||
lines.append(
|
||||
"Largest endpoint chamber RHS breakdown: "
|
||||
f"{chamber_diagnostic.chamber_alias}"
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
f" - piston_alias={chamber_diagnostic.piston_alias}",
|
||||
f" - pressure_pa={chamber_diagnostic.chamber_pressure_pa}",
|
||||
f" - volume_m3={chamber_diagnostic.chamber_volume_m3}",
|
||||
f" - volume_rate_m3_s={chamber_diagnostic.chamber_volume_rate_m3_s}",
|
||||
f" - mass_derivative_kg_s={chamber_diagnostic.mass_derivative_kg_s}",
|
||||
f" - port_a_energy_flow_w={chamber_diagnostic.port_a_energy_flow_w}",
|
||||
f" - boundary_work_w={chamber_diagnostic.boundary_work_w}",
|
||||
f" - energy_derivative_w={chamber_diagnostic.energy_derivative_w}",
|
||||
]
|
||||
)
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
def _largest_chamber_rhs_diagnostic(run: TestMqlFullStateComparisonRun):
|
||||
diagnostic = run.largest_final_abs_error_diagnostic
|
||||
if diagnostic is None or "@" not in diagnostic.data_path:
|
||||
return None
|
||||
_signal, alias = diagnostic.data_path.split("@", 1)
|
||||
try:
|
||||
return run.chamber_rhs_diagnostic(alias)
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
|
||||
def main() -> None:
|
||||
run, output_dir = run_test_mql_full_state_comparison()
|
||||
print(format_test_mql_full_state_comparison_summary(run), end="")
|
||||
|
||||
Reference in new issue
Block a user