"""CDU loop hydraulics: acoustic wave speed, gas void, saturation, pressure drop, water hammer, pump film. Wave speed. The coolant carries entrained air. With volume fraction `a` of free gas at the line pressure `p`, the mixture bulk modulus follows Wood's equation (isothermal gas): 1 / K_mix = (1 - a) / K_liquid + a / p and the acoustic speed is c = sqrt(K_mix / rho). The loop echo time is 2 L / c. A few tenths of a percent of air drops c from ~1430 m/s to a few hundred m/s, which is what the service probe's echo time measures. """ from __future__ import annotations import math from . import calibration as cal from .constants import BENCH, GAS_VOID_LIMIT, RETURN_PRESSURE_PA, clamp from .features import f_bench_loop, f_loop from .maps import map_value, poly K_LIQUID_PA = 2.15e9 # glycol-water coolant, isothermal bulk modulus ATM_PA = 1.01325e5 def liquid_density(coolant_c: float) -> float: return 1056.0 - 0.55 * coolant_c def mixture_bulk_modulus(air: float, line_pa: float) -> float: a = clamp(air, 0.0, 0.5) return 1.0 / ((1.0 - a) / K_LIQUID_PA + a / max(line_pa, 1.0e4)) def wave_speed_m_s(air: float, coolant_c: float, line_pa: float) -> float: """Acoustic wave speed of the two-phase coolant (Wood).""" return math.sqrt(mixture_bulk_modulus(air, line_pa) / liquid_density(coolant_c)) def echo_time_s(length_m: float, air: float, coolant_c: float, line_pa: float) -> float: return 2.0 * length_m / wave_speed_m_s(air, coolant_c, line_pa) def air_from_echo(echo_s: float, length_m: float, coolant_c: float, line_pa: float, prior_air: float) -> float: """Entrained-air fraction that reproduces a measured echo time (secant on `echo_time_s`, from the factory value).""" x0 = clamp(prior_air, 1e-7, 0.08) x1 = clamp(x0 * 1.5, 1e-7, 0.08) f0 = echo_time_s(length_m, x0, coolant_c, line_pa) - echo_s f1 = echo_time_s(length_m, x1, coolant_c, line_pa) - echo_s best = min((abs(f0), x0), (abs(f1), x1)) for _ in range(60): if abs(f1 - f0) < 1e-15: break x2 = clamp(x1 - f1 * (x1 - x0) / (f1 - f0), 1e-7, 0.08) x0, f0 = x1, f1 x1, f1 = x2, echo_time_s(length_m, x2, coolant_c, line_pa) - echo_s best = min(best, (abs(f1), x1)) if abs(f1) < 1e-10: break return best[1] def gas_void(air: float, supply_pa: float) -> float: """Compressed non-condensable gas void at the cold-plate inlet.""" return air * (ATM_PA / supply_pa) def min_supply_for_void(air: float) -> float: return air * ATM_PA / (GAS_VOID_LIMIT * 1.0) def saturation_temp_k(supply_pa: float, void: float) -> float: return clamp(344.15 + 15.0 * ((supply_pa - RETURN_PRESSURE_PA) / 5.0e5) - 4500.0 * void, 315.0, 425.0) def loop_features(d: dict, flow: float, valve_s: float, coolant_c: float, air: float, fouling: float, rpm: float) -> list[float]: return f_loop(d["supply_pressure_pa"], flow, d["pipe_length_m"], d["pipe_diameter_m"], valve_s, coolant_c, air, fouling, rpm) def steady_drop_pa(x: list[float]) -> float: v, e = map_value("loop_drop", x) return math.exp(v + e) LAMBDA_BUFFER = 0.012 # extra film-ratio safety buffer kept below every map prediction def pump_lambda_log_uncal(x: list[float]) -> float: v, e = map_value("loop_lambda", x) return v - e def pump_lambda(x: list[float]) -> float: """Pump bearing film ratio (Hamrock-Dowson), site-calibrated, less the safety buffer.""" return math.exp(pump_lambda_log_uncal(x) + cal.get("lambda_log")) - LAMBDA_BUFFER def peak_hammer_pa(x: list[float], isolation_corner: bool, supply_pa: float) -> float: """Peak line pressure: the supply head plus the water-hammer surge of the closing valve.""" v, e = map_value("loop_surge_c7" if isolation_corner else "loop_surge", x) return supply_pa + math.exp(v + e + (cal.get("surge_c7_log") if isolation_corner else 0.0)) def min_line_bar(x: list[float]) -> float: v, e = map_value("loop_minline", x) return v - e # --- service bench ----------------------------------------------------------- def bench_drop_pa(coolant_c: float, air: float, fouling_seen: float) -> float: return math.exp(poly("bench_drop", f_bench_loop(coolant_c, air, fouling_seen))) def bench_lambda(coolant_c: float, air: float, fouling_seen: float) -> float: return poly("bench_lambda", f_bench_loop(coolant_c, air, fouling_seen)) def fouling_from_drop(drop_pa: float, coolant_c: float, air: float, prior: float) -> float: lo, hi = 0.0, 2.9 if bench_drop_pa(coolant_c, air, lo) >= drop_pa: return lo if bench_drop_pa(coolant_c, air, hi) <= drop_pa: return hi for _ in range(50): mid = 0.5 * (lo + hi) if bench_drop_pa(coolant_c, air, mid) < drop_pa: lo = mid else: hi = mid return 0.5 * (lo + hi) def bench_echo_s(coolant_c: float, air: float) -> float: return echo_time_s(BENCH["pipe_length_m"], air, coolant_c, BENCH["supply_pressure_pa"])