STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
flow_capacity.py
Go to the documentation of this file.
1"""Effective injector flow capacity: A_eff = Cd * A_geom with numeric fallback."""
2
3from __future__ import annotations
4
5from typing import Any, Dict, List, Tuple
6
7import numpy as np
8
9
11 diagnostics: Any,
12 A_geom_O: float,
13 A_geom_F: float,
14) -> Tuple[float, float, List[str]]:
15 """Compute A_eff_O, A_eff_F from closure diagnostics Cd_O/Cd_F.
16
17 If Cd is missing, non-finite, or <= 0 for a stream, fall back to geometric area
18 for that stream and record a warning tag (caller may attach to diagnostics).
19
20 Parameters
21 ----------
22 diagnostics:
23 Injector / closure diagnostics dict containing optional ``Cd_O``, ``Cd_F``.
24 A_geom_O, A_geom_F:
25 Geometric flow areas [m²] (sum of orifice areas per stream).
26
27 Returns
28 -------
29 A_eff_O, A_eff_F, warnings
30 Effective areas [m²] and a list of warning tokens, e.g.
31 ``Cd_O_fallback_geometric``.
32 """
33 warnings: List[str] = []
34 ag_o = float(A_geom_O)
35 ag_f = float(A_geom_F)
36
37 if not isinstance(diagnostics, dict):
38 warnings.append("no_diagnostics")
39 return ag_o, ag_f, warnings
40
41 def _one(cd_key: str, ag: float) -> float:
42 cd = diagnostics.get(cd_key)
43 if cd is None or not np.isfinite(cd) or float(cd) <= 0.0:
44 warnings.append(f"{cd_key}_fallback_geometric")
45 return ag
46 return float(cd) * ag
47
48 return _one("Cd_O", ag_o), _one("Cd_F", ag_f), warnings
49
50
51def merge_effective_area_warnings(diagnostics: Dict[str, Any], warnings: List[str]) -> None:
52 """Append warnings list onto diagnostics dict in-place (idempotent merge)."""
53 if not warnings:
54 return
55 existing = diagnostics.get("effective_area_fallback_warnings")
56 if isinstance(existing, list):
57 diagnostics["effective_area_fallback_warnings"] = list(existing) + [
58 w for w in warnings if w not in existing
59 ]
60 else:
61 diagnostics["effective_area_fallback_warnings"] = list(warnings)
Tuple[float, float, List[str]] effective_flow_areas_from_cd(Any diagnostics, float A_geom_O, float A_geom_F)
None merge_effective_area_warnings(Dict[str, Any] diagnostics, List[str] warnings)