zoomy_core.kernel.kernel module#
Kernel — SymbolicRegistrar for backend-agnostic helper functions.
The Kernel holds basefunctions (safe_denominator, clamp_positive, etc.) that model and numerics expressions reference symbolically. Each backend (numpy, jax, C, UFL) provides concrete implementations during code transformation, using the same NumpyRuntimeSymbolic / JaxRuntimeSymbolic machinery that compiles Model and Numerics functions.
- After code transformation the user gets three compiled artifacts:
Model — physics (flux, source, eigenvalues)
Numerics — Riemann solver (numerical flux, fluctuations)
Kernel — helper functions shared by both
Usage:
kernel = Kernel(model)
runtime_kernel = NumpyRuntimeSymbolic(kernel)
# merge kernel functions into the module dict used by model/numerics
- class zoomy_core.kernel.kernel.Kernel(model=None, **params)#
Bases:
Parameterized,SymbolicRegistrarBackend-agnostic registry of numerical helper functions.
Mirrors the Model/Numerics pattern: each function is a
Functionbasefunction registered viaregister_symbolic_function. The symbolic definitions serve as blueprints; actual implementations are provided by the backend during compilation.- var(name)#
Get a model variable symbol by name.
- Parameters:
name (str) –
- Return type:
Symbol
- par(name)#
Get a model parameter symbol by name.
- Parameters:
name (str) –
- Return type:
Symbol
- safe_denominator()#
safe_denominator(x) → x regularized to avoid 1/0.
- clamp_positive()#
clamp_positive(x) → max(x, 0).
- conditional()#
conditional(c, t, f) → t if c else f.
- positive_variables()#
Return list of model variable symbols declared positive.
- static find_singular_denominators(expr, positive_vars)#
Find Pow(v, negative_exp) subexpressions for positive variables.
Walks the expression tree and collects every
Pow(v, e)wherevis a positive variable ande < 0. These are the terms that produce NaN whenv → 0(e.g. at dry cells).This is the detection function — swap this out to try different strategies (e.g. numerical probing, limit analysis).
- Return type:
list of (Pow_subexpr, variable) pairs
- name = 'Kernel'#
- regularize(obj)#
Regularize function definitions in-place (targeted).
Works on any object with a
functionsZstruct (Model, Numerics). For each function definition, findsPow(v, -n)wherevis a positive variable and replacesv → v + epsin that denominator only. Other occurrences ofv(e.g. ing*h) are untouched.