STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
cea.py
Go to the documentation of this file.
1"""CEA cache tables -> plain contiguous float64 arrays the njit kernels can read.
2
3Kept separate from kernels.py because this is the only place that touches the
4CEACache object model; the kernels below it see nothing but arrays.
5"""
6from __future__ import annotations
7
8import numpy as np
9
10
11def cea_arrays(cache):
12 """Grids + 7 property tables (float64, C-order), Cf_vac with the _ensure_cea fallback."""
13 assert getattr(cache, "use_3d", False), "cache is not a 3D grid"
14 Pc = np.ascontiguousarray(cache.Pc_grid, np.float64)
15 MR = np.ascontiguousarray(cache.MR_grid, np.float64)
16 eps = np.ascontiguousarray(cache.eps_grid, np.float64)
17 cf_vac = getattr(cache, "Cf_vac_table", None)
18 if cf_vac is None:
19 from engine.pipeline.cea_cache import _isentropic_cf_vac
20 gt = np.asarray(cache.gamma_table, np.float64)
21 cf_vac = np.empty_like(gt)
22 for k in range(gt.shape[2]):
23 ek = float(eps[k])
24 for i in range(gt.shape[0]):
25 for j in range(gt.shape[1]):
26 cf_vac[i, j, k] = _isentropic_cf_vac(gt[i, j, k], ek)
27 A = lambda t: np.ascontiguousarray(t, np.float64)
28 return (Pc, MR, eps, A(cache.cstar_table), A(cache.Cf_table), A(cache.Tc_table),
29 A(cache.gamma_table), A(cache.R_table), A(cache.M_table), A(cf_vac))
30
31
32
34 """Memoise cea_arrays for a cache, storing the result ON the cache object.
35
36 NOT keyed on id(cache): a freed cache's id can be reused, which would
37 silently serve a previous config's CEA tables in a multi-config process
38 (test sessions, GUI config switches). This is the same hazard
39 native_injector._ensure_cea documents and defends against with a token; tying
40 the memo to the object's own lifetime is simpler and cannot leak.
41 """
42 arr = getattr(cache, "_numba_cea_arrays", None)
43 if arr is None:
44 arr = cea_arrays(cache)
45 try:
46 cache._numba_cea_arrays = arr
47 except Exception:
48 pass # cache rejects attributes -> rebuild per call (correct, slower)
49 return arr
_cea_arrays_cached(cache)
Definition cea.py:33
cea_arrays(cache)
Definition cea.py:11