zoomy_core.kernel package#
Zoomy kernel: backend-agnostic helper functions for model and numerics.
- class zoomy_core.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.