补充pn2pipefr候选流量诊断
This commit is contained in:
1 parent
84d1675292
commit
1602e0dc51
4 files changed
+108
No files matched your search
@@ -6,6 +6,7 @@ from math import log10, pi, sqrt
|
||||
from PythonModels.components.amesim_pneumatic import (
|
||||
HELIUM_PNEUMATIC_GAS,
|
||||
AmesimPneumaticGas,
|
||||
compressible_orifice_mass_flow,
|
||||
diameter_mm_to_area_m2,
|
||||
)
|
||||
from PythonModels.core.base import AlgebraicComponent, DynamicComponent
|
||||
@@ -60,6 +61,61 @@ class _DarcyPipeResistanceMixin:
|
||||
upper = middle
|
||||
return 0.5 * (lower + upper)
|
||||
|
||||
def pn2pipefr_mass_flow(
|
||||
self,
|
||||
*,
|
||||
port_1_pressure_pa: float,
|
||||
port_1_temperature_k: float,
|
||||
port_2_pressure_pa: float,
|
||||
port_2_temperature_k: float,
|
||||
length: float | None = None,
|
||||
) -> float:
|
||||
pressure_difference = port_1_pressure_pa - port_2_pressure_pa
|
||||
if pressure_difference == 0.0:
|
||||
return 0.0
|
||||
upstream_pressure = max(port_1_pressure_pa, port_2_pressure_pa)
|
||||
downstream_pressure = min(port_1_pressure_pa, port_2_pressure_pa)
|
||||
upstream_temperature = (
|
||||
port_1_temperature_k
|
||||
if pressure_difference > 0.0
|
||||
else port_2_temperature_k
|
||||
)
|
||||
resistance_length = self.length if length is None else length
|
||||
if resistance_length <= 0.0:
|
||||
raise ValueError("length must be positive")
|
||||
|
||||
def target_flow(mass_flow_kg_s: float) -> float:
|
||||
reynolds = self._reynolds_number(mass_flow_kg_s, upstream_temperature)
|
||||
friction_factor = self._friction_factor(reynolds)
|
||||
flow_coefficient = sqrt(
|
||||
self.diameter / (resistance_length * friction_factor)
|
||||
)
|
||||
return compressible_orifice_mass_flow(
|
||||
upstream_pressure=upstream_pressure,
|
||||
downstream_pressure=downstream_pressure,
|
||||
upstream_temperature=upstream_temperature,
|
||||
area=self.area,
|
||||
flow_coefficient=flow_coefficient,
|
||||
gas=self.gas,
|
||||
)
|
||||
|
||||
flow_coefficient = sqrt(self.diameter / (resistance_length * 0.02))
|
||||
magnitude = compressible_orifice_mass_flow(
|
||||
upstream_pressure=upstream_pressure,
|
||||
downstream_pressure=downstream_pressure,
|
||||
upstream_temperature=upstream_temperature,
|
||||
area=self.area,
|
||||
flow_coefficient=flow_coefficient,
|
||||
gas=self.gas,
|
||||
)
|
||||
for _ in range(12):
|
||||
next_magnitude = target_flow(magnitude)
|
||||
if abs(next_magnitude - magnitude) <= max(1.0e-12, abs(magnitude) * 1.0e-9):
|
||||
magnitude = next_magnitude
|
||||
break
|
||||
magnitude = 0.5 * (magnitude + next_magnitude)
|
||||
return magnitude if pressure_difference > 0.0 else -magnitude
|
||||
|
||||
def _darcy_pressure_drop(
|
||||
self,
|
||||
mass_flow_kg_s: float,
|
||||
|
||||
@@ -280,6 +280,8 @@ class TestMqlPnl0001PressureLossCalibrationDiagnostic:
|
||||
amesim_pressure_drop_pa: float
|
||||
current_darcy_pressure_drop_pa: float
|
||||
pressure_drop_multiplier: float
|
||||
candidate_pn2pipefr_dm1_g_s: float
|
||||
candidate_pn2pipefr_to_amesim_dm1_ratio: float
|
||||
amesim_linear_conductance_kg_s_sqrt_k_per_pa: float
|
||||
python_linear_conductance_kg_s_sqrt_k_per_pa: float
|
||||
python_to_amesim_linear_conductance_ratio: float
|
||||
@@ -580,6 +582,7 @@ def _pnl0001_pressure_loss_calibration_diagnostic(
|
||||
amesim_line_gauge_pressure_pa = amesim_value(f"p2@{line_alias}")
|
||||
amesim_chamber_gauge_pressure_pa = amesim_value(f"press@{chamber_alias}")
|
||||
amesim_line_temperature_k = amesim_value(f"t2@{line_alias}")
|
||||
amesim_chamber_temperature_k = amesim_value(f"temp@{chamber_alias}")
|
||||
mass_flow_magnitude_kg_s = abs(amesim_dm1_g_s) * 1.0e-3
|
||||
amesim_pressure_drop_pa = abs(
|
||||
amesim_line_gauge_pressure_pa - amesim_chamber_gauge_pressure_pa
|
||||
@@ -601,6 +604,25 @@ def _pnl0001_pressure_loss_calibration_diagnostic(
|
||||
pressure_drop_multiplier = (
|
||||
float("inf") if amesim_pressure_drop_pa > 0.0 else 1.0
|
||||
)
|
||||
candidate_port1_to_port2_kg_s = line.pn2pipefr_mass_flow(
|
||||
port_1_pressure_pa=(
|
||||
amesim_chamber_gauge_pressure_pa + AMESIM_REFERENCE_PRESSURE_PA
|
||||
),
|
||||
port_1_temperature_k=amesim_chamber_temperature_k,
|
||||
port_2_pressure_pa=(
|
||||
amesim_line_gauge_pressure_pa + AMESIM_REFERENCE_PRESSURE_PA
|
||||
),
|
||||
port_2_temperature_k=amesim_line_temperature_k,
|
||||
)
|
||||
candidate_pn2pipefr_dm1_g_s = -candidate_port1_to_port2_kg_s * 1.0e3
|
||||
if amesim_dm1_g_s != 0.0:
|
||||
candidate_pn2pipefr_to_amesim_dm1_ratio = (
|
||||
candidate_pn2pipefr_dm1_g_s / amesim_dm1_g_s
|
||||
)
|
||||
else:
|
||||
candidate_pn2pipefr_to_amesim_dm1_ratio = (
|
||||
float("inf") if candidate_pn2pipefr_dm1_g_s != 0.0 else 1.0
|
||||
)
|
||||
amesim_linear_conductance = _pnl0001_linear_conductance(
|
||||
dm1_g_s=amesim_dm1_g_s,
|
||||
temperature_k=amesim_line_temperature_k,
|
||||
@@ -634,6 +656,10 @@ def _pnl0001_pressure_loss_calibration_diagnostic(
|
||||
amesim_pressure_drop_pa=amesim_pressure_drop_pa,
|
||||
current_darcy_pressure_drop_pa=current_darcy_pressure_drop_pa,
|
||||
pressure_drop_multiplier=pressure_drop_multiplier,
|
||||
candidate_pn2pipefr_dm1_g_s=candidate_pn2pipefr_dm1_g_s,
|
||||
candidate_pn2pipefr_to_amesim_dm1_ratio=(
|
||||
candidate_pn2pipefr_to_amesim_dm1_ratio
|
||||
),
|
||||
amesim_linear_conductance_kg_s_sqrt_k_per_pa=(
|
||||
amesim_linear_conductance
|
||||
),
|
||||
@@ -984,6 +1010,10 @@ def format_test_mql_pnvo_event_window_summary(
|
||||
f"amesim_dp={pressure_loss.amesim_pressure_drop_pa}, "
|
||||
f"darcy_dp={pressure_loss.current_darcy_pressure_drop_pa}, "
|
||||
f"dp_multiplier={pressure_loss.pressure_drop_multiplier}, "
|
||||
f"candidate_pn2pipefr_dm1="
|
||||
f"{pressure_loss.candidate_pn2pipefr_dm1_g_s}, "
|
||||
f"candidate_pn2pipefr_ratio="
|
||||
f"{pressure_loss.candidate_pn2pipefr_to_amesim_dm1_ratio}, "
|
||||
f"amesim_linear_k="
|
||||
f"{pressure_loss.amesim_linear_conductance_kg_s_sqrt_k_per_pa}, "
|
||||
f"python_linear_k="
|
||||
|
||||
Reference in new issue
Block a user