spectral_galerkin_heat.core.property_expr ========================================= .. py:module:: spectral_galerkin_heat.core.property_expr .. autoapi-nested-parse:: Whitelisted math expressions of ``T`` for temperature-dependent properties. A property branch (e.g. ``k.solid``) is given in config as either a bare number (a constant) or a string expression of ``T`` such as ``"9.248 + 0.01571 * T"`` or ``"12.41 * exp(-T / 3000.0)"``. :class:`PropertyExpr` parses that string once against a small node/name/function whitelist using Python's ``ast`` module. It never calls ``eval`` or ``exec`` on the expression itself, so there is no sandbox-escape surface. (A restricted-namespace ``eval`` would be escapable through attribute access on any in-scope object.) The validated AST is then rendered to three targets, so the temperature-dependent hot path stays fully fused rather than falling back to a per-property Python callback: * :meth:`PropertyExpr.__call__`, a NumPy/CuPy-broadcasting evaluator that works on a scalar or a full field, on host or device; * :meth:`PropertyExpr.to_py_source`, a numba-``njit``-compatible Python source snippet using ``math.`` calls, which numba compiles natively, to build the fused CPU kernel; * :meth:`PropertyExpr.to_c_source`, a CUDA C expression, to build the fused GPU ``ElementwiseKernel``. Both source renderers take the target precision, since the literals they emit are what fixes the precision of the generated kernel. Classes ------- .. autoapisummary:: spectral_galerkin_heat.core.property_expr.PropertyExpr Module Contents --------------- .. py:class:: PropertyExpr(expr) A validated math expression of ``T`` (or a bare constant). ``str(expr)`` must either parse as a plain number (a constant) or as an expression using ``T``, ``+ - * / **``, the constants ``pi``/``e``, and calls to a fixed whitelist of math functions (``sqrt``, ``exp``, ``log``, trig/hyperbolic functions, and so on). Anything else raises ``ValueError`` at construction time: attribute access, subscripts, comprehensions, and unknown names or functions. .. py:method:: to_py_source(dtype=np.float32) Return numba-``njit``-compatible Python source with ``T`` free. :param dtype: Precision of the emitted literals, ``numpy.float32`` (default) or ``numpy.float64``. :type dtype: data-type, optional .. py:method:: to_c_source(dtype=np.float32) Return a CUDA C expression with ``T`` free. :param dtype: Precision of the emitted literals and intrinsics, ``numpy.float32`` (default) or ``numpy.float64``. :type dtype: data-type, optional