merge/model-development-into-main #2

Merged
lujingze merged 126 commits from merge/model-development-into-main into main 2026-07-31 09:52:44 +08:00
2 changed files with 88 additions and 1 deletions
Showing only changes of commit d67fb251d2 - Show all commits

No files matched your search

@@ -379,8 +379,13 @@ class TestMqlP4NodeEnthalpyBreakdownDiagnostic:
python_reference_port_3_enthalpy_flow_w: float
python_reference_port_4_enthalpy_flow_w: float
python_reference_port_2_enthalpy_flow_w: float
python_real_gas_reference_port_1_enthalpy_flow_w: float
python_real_gas_reference_port_3_enthalpy_flow_w: float
python_real_gas_reference_port_4_enthalpy_flow_w: float
python_real_gas_reference_port_2_enthalpy_flow_w: float
python_port_2_enthalpy_error_w: float
python_reference_port_2_enthalpy_error_w: float
python_real_gas_reference_port_2_enthalpy_error_w: float
@dataclass(frozen=True)
@@ -1013,6 +1018,30 @@ def _reference_enthalpy_flow_for_node_port(
return port_mass_flow_kg_s * reference_h
def _real_gas_reference_enthalpy_flow_for_node_port(
*,
gas: AmesimPneumaticGas,
reference_temperature_k: float,
flow_kg_s: float,
node_pressure_pa: float,
node_temperature_k: float,
connected_pressure_pa: float,
connected_temperature_k: float,
port_mass_flow_kg_s: float,
) -> float:
stream_pressure_pa = node_pressure_pa if flow_kg_s >= 0.0 else connected_pressure_pa
stream_temperature_k = (
node_temperature_k if flow_kg_s >= 0.0 else connected_temperature_k
)
reference_h = gas.pressure_reference_enthalpy(
stream_pressure_pa,
stream_temperature_k,
reference_pressure=AMESIM_REFERENCE_PRESSURE_PA,
reference_temperature=reference_temperature_k,
)
return port_mass_flow_kg_s * reference_h
def _pnl0001_energy_flow_diagnostic(
*,
closure: object,
@@ -1308,6 +1337,41 @@ def _p4_node_enthalpy_breakdown_diagnostic(
port_mass_flow_kg_s=snapshot.p4_port3_remote_orifice_to_node_flow,
)
reference_port_2 = reference_port_1 + reference_port_3 + reference_port_4
real_gas_reference_port_1 = _real_gas_reference_enthalpy_flow_for_node_port(
gas=line.gas,
reference_temperature_k=reference_temperature_k,
flow_kg_s=snapshot.p4_port3_remote_node_to_line_flow,
node_pressure_pa=snapshot.p4_port3_remote_primary_line.p,
node_temperature_k=snapshot.p4_port3_remote_primary_line.T,
connected_pressure_pa=snapshot.p4_port3_line.p,
connected_temperature_k=snapshot.p4_port3_line.T,
port_mass_flow_kg_s=-snapshot.p4_port3_remote_node_to_line_flow,
)
real_gas_reference_port_3 = _real_gas_reference_enthalpy_flow_for_node_port(
gas=line.gas,
reference_temperature_k=reference_temperature_k,
flow_kg_s=snapshot.p4_port3_remote_to_port3_line_flow,
node_pressure_pa=snapshot.p4_port3_remote_primary_line.p,
node_temperature_k=snapshot.p4_port3_remote_primary_line.T,
connected_pressure_pa=snapshot.p4_port3_remote_port3_line.p,
connected_temperature_k=snapshot.p4_port3_remote_port3_line.T,
port_mass_flow_kg_s=-snapshot.p4_port3_remote_to_port3_line_flow,
)
real_gas_reference_port_4 = _real_gas_reference_enthalpy_flow_for_node_port(
gas=line.gas,
reference_temperature_k=reference_temperature_k,
flow_kg_s=snapshot.p4_port3_remote_orifice_to_node_flow,
node_pressure_pa=snapshot.p4_port3_remote_orifice_line_port_2.p,
node_temperature_k=snapshot.p4_port3_remote_orifice_line_port_2.T,
connected_pressure_pa=snapshot.p4_port3_remote_primary_line.p,
connected_temperature_k=snapshot.p4_port3_remote_primary_line.T,
port_mass_flow_kg_s=snapshot.p4_port3_remote_orifice_to_node_flow,
)
real_gas_reference_port_2 = (
real_gas_reference_port_1
+ real_gas_reference_port_3
+ real_gas_reference_port_4
)
return TestMqlP4NodeEnthalpyBreakdownDiagnostic(
node_alias=node_alias,
@@ -1332,12 +1396,19 @@ def _p4_node_enthalpy_breakdown_diagnostic(
python_reference_port_3_enthalpy_flow_w=reference_port_3,
python_reference_port_4_enthalpy_flow_w=reference_port_4,
python_reference_port_2_enthalpy_flow_w=reference_port_2,
python_real_gas_reference_port_1_enthalpy_flow_w=real_gas_reference_port_1,
python_real_gas_reference_port_3_enthalpy_flow_w=real_gas_reference_port_3,
python_real_gas_reference_port_4_enthalpy_flow_w=real_gas_reference_port_4,
python_real_gas_reference_port_2_enthalpy_flow_w=real_gas_reference_port_2,
python_port_2_enthalpy_error_w=(
balance.port_2_enthalpy_flow_w - amesim_port_2_enthalpy
),
python_reference_port_2_enthalpy_error_w=(
reference_port_2 - amesim_port_2_enthalpy
),
python_real_gas_reference_port_2_enthalpy_error_w=(
real_gas_reference_port_2 - amesim_port_2_enthalpy
),
)
@@ -2587,10 +2658,20 @@ def format_test_mql_pnvo_event_window_summary(
f"{p4_node.python_reference_port_4_enthalpy_flow_w}, "
f"python_ref_p2_dh="
f"{p4_node.python_reference_port_2_enthalpy_flow_w}, "
f"python_real_ref_p1_dh="
f"{p4_node.python_real_gas_reference_port_1_enthalpy_flow_w}, "
f"python_real_ref_p3_dh="
f"{p4_node.python_real_gas_reference_port_3_enthalpy_flow_w}, "
f"python_real_ref_p4_dh="
f"{p4_node.python_real_gas_reference_port_4_enthalpy_flow_w}, "
f"python_real_ref_p2_dh="
f"{p4_node.python_real_gas_reference_port_2_enthalpy_flow_w}, "
f"python_p2_dh_error="
f"{p4_node.python_port_2_enthalpy_error_w}, "
f"python_ref_p2_dh_error="
f"{p4_node.python_reference_port_2_enthalpy_error_w}"
f"{p4_node.python_reference_port_2_enthalpy_error_w}, "
f"python_real_ref_p2_dh_error="
f"{p4_node.python_real_gas_reference_port_2_enthalpy_error_w}"
)
for chamber_energy in sample.pnch012_energy_equation_diagnostics:
lines.append(
@@ -489,8 +489,13 @@ class RunTestMqlFullStateComparisonScriptTests(unittest.TestCase):
python_reference_port_3_enthalpy_flow_w=-1700.0,
python_reference_port_4_enthalpy_flow_w=-16000.0,
python_reference_port_2_enthalpy_flow_w=-18500.0,
python_real_gas_reference_port_1_enthalpy_flow_w=-790.0,
python_real_gas_reference_port_3_enthalpy_flow_w=-1685.0,
python_real_gas_reference_port_4_enthalpy_flow_w=-15750.0,
python_real_gas_reference_port_2_enthalpy_flow_w=-18225.0,
python_port_2_enthalpy_error_w=658664.2,
python_reference_port_2_enthalpy_error_w=164.2,
python_real_gas_reference_port_2_enthalpy_error_w=439.2,
),
),
pnch012_energy_equation_diagnostics=(
@@ -621,6 +626,7 @@ class RunTestMqlFullStateComparisonScriptTests(unittest.TestCase):
self.assertIn("amesim_pn2vol2_dT_node_plus_dh1=-9000.0", summary)
self.assertIn("python_ref_pn2vol2_dT_node_minus_dh1=-11200.0", summary)
self.assertIn("p4_node_enthalpy@pnnode4_16", summary)
self.assertIn("python_real_ref_p2_dh_error=439.2", summary)
self.assertIn("amesim_p4_dh=-15664.2", summary)
self.assertIn("python_p4_dh=643000.0", summary)
self.assertIn("python_ref_p2_dh=-18500.0", summary)