zoomy_core.kernel package

Contents

zoomy_core.kernel package#

Zoomy kernel: backend-agnostic helper functions for model and numerics.

class zoomy_core.kernel.Kernel(model=None, **params)#

Bases: Parameterized, SymbolicRegistrar

Backend-agnostic registry of numerical helper functions.

Mirrors the Model/Numerics pattern: each function is a Function basefunction registered via register_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).

clamp_momentum()#

clamp_momentum(hu, h, u_max) → sign(hu) * min(|hu|, h * u_max).

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) where v is a positive variable and e < 0. These are the terms that produce NaN when v 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 functions Zstruct (Model, Numerics). For each function definition, finds Pow(v, -n) where v is a positive variable and replaces v v + eps in that denominator only. Other occurrences of v (e.g. in g*h) are untouched.

Submodules#