zoomy_core.systemmodel.operations

zoomy_core.systemmodel.operations#

Reusable SystemModel.apply operations (op(sm) callables) that rewrite operator slots: aux registration, 1/h regularization, eigenvalue guards. They run on the way from SystemModel to NumericalSystemModel; sweeping operations cover every slot of OPERATOR_SLOTS unless a slot is explicitly excluded.

Module Contents#

Functions#

map_operator_slots

Apply rewrite(expr) -> expr to every slot of OPERATOR_SLOTS except exclude, freezing the lazy quasilinear_matrix from the clean primaries first.

normalize_face_normal

Operation: impose |n| = 1 on every slot (default scope OPERATOR_SLOTS), which separates the SWE celerity from the 1/h of the momentum terms. It is a NumericalSystemModel default (normalize_normal=True).

kp_hinv

Kurganov-Petrova desingularized inverse depth sqrt(2) h / sqrt(h^4 + max(h, eps)^4), equal to 1/h for h >= eps and tending to 0 as h -> 0. The numerator is bare h (no clamp), so a negative depth gives a negative hinv and the failure stays visible.

register_aux

Operation: add the algebraic aux variable name = formula to aux_state and update_aux_variables (identity on existing rows) and refresh the derived operators. **assumptions go to the new Symbol (default real=True).

wave_speed_inverse_depth

The 1/h of every wave speed, 1/max(1e-14, h), never the KP hinv: large but finite at a wet/dry front (REQ-82). Used by regularize_pow and the numerical spectral radius.

regularize_pow

Operation: replace every field**(-n) in the physical, derived and reconstruction operators by aux_name**n; eigenvalues get a floored plain 1/max(1e-14, h) instead. The lazy derived operators are frozen from the clean primaries first, so the exact d(q^2/h)/dh term survives the substitution.

equilibrate_constraint_rows

Operation: multiply each algebraic (zero mass-matrix) row by the minimal power of h that clears its negative powers of h. This changes the conditioning of the elliptic block, not the constraint manifold, wherever ``h

desingularize_hinv

Operation: register the hinv aux with the Kurganov-Petrova inverse depth (eps = wet_dry_eps) and rewrite every h**(-n) to hinv**n; mode is True or "kp", falsy is a no-op. Legacy NSM depth default; the depth-law study uses regularize_depth_direct / regularize_depth_aux.

symbolic_spectrum

Operation: derive the closed-form spectrum of the normal-projected quasilinear matrix into sm.eigenvalues; opt-in because it is expensive for high moment levels.

regularize_depth_direct

Operation: substitute the Kurganov-Petrova reciprocal inline for every field**(-n) in every slot (the DIRECT path); no aux row is added. Mutually exclusive with regularize_depth_aux.

regularize_depth_aux

Operation: register the aux name whose update row is the Kurganov-Petrova reciprocal and rewrite every field**(-n) to name**n in every slot (the AUX path). Mutually exclusive with regularize_depth_direct; takes the same eps / eigenvalues / exclude arguments, and the row defining name is not rewritten.

desingularize_positivity

Operation: replace the base of each negative or fractional power in the source that involves a positive_state symbol by sqrt(base**2 + floor**2) and re-derive the source Jacobians. A no-op if the model declares no positive_state.

guard_eigenvalue_powers

Operation: wrap every fractional power of the depth in sm.eigenvalues in Max(., 0) so wave speeds stay real at a transient h < 0 (no dry zeroing). Half A of the guard/gate split; gate_eigenvalues_dry is half B.

cfl_wave_speed_bound

The dt spectrum of a system without closed-form eigenvalues, shape (n_eq, 1): the wave-speed bound of A_n in the face’s normal frame (system_model.wave_speed_bound, the Riemann speeds’ bound) in row 0, zeros below (the consumers take max |.|), or with SpectralRadius.eig the numerical eigenvalues of A_n; subs replaces aux symbols first (the CFL inverse depth).

bound_wave_speed

Operation: publish cfl_wave_speed_bound into sm.eigenvalues_cfl for a system without closed-form eigenvalues whose dt spectrum no dry gate published (no depth, or no gate guard), so the cells rule takes the same bound as the Riemann speeds; a no-op with a closed form or a published dt spectrum.

gate_eigenvalues_dry

Operation: publish a timestep-only spectrum conditional(h <= eps, 0, e) into sm.eigenvalues_cfl, leaving sm.eigenvalues physical (with its power guard) for the Riemann dissipation. eps defaults to 0: a cell without water (h <= 0) has no wave speed, but every cell with h > 0 moves mass with its own velocity (the Audusse states keep it), so its speed bounds the step however thin it is (ANALYSIS 52). The dry gate carries the power guard because a branchless backend evaluates both arms; without a closed form e is the Riemann speeds’ bound (cfl_wave_speed_bound) of A_n with hinv -> 1/max(1e-14, h) (wave_speed_inverse_depth). Idempotent.

regularize_fractional_powers

Operation: shift the base of every fractional power by eps**2 (b**r -> (b + eps**2)**r) so the operators stay differentiable at b = 0 under AD. Opt-in and idempotent; eps must be positive, and the value changes by O(eps**2) away from b = 0.

norm_derivative_at_zero

Operation (default, before the source linearization): every S**r in the source slots with S >= 0 a scaled squared Euclidean norm (_nonnegative) and rational r >= 1/2 not an integer (|u| = (u.u)**(1/2) of a friction law) becomes conditional(S > 0, conditional(S > 0, S, 1)**r, S): the same value, and the derivative 0 at S = 0 (S has its minimum there, dS = 0) instead of dS / (2 sqrt(S)) = 0/0 = NaN. That is the derivative of S**r for r > 1/2 and the least-norm subgradient for r = 1/2; the Newton Jacobian of an implicit friction source (JAX: AD) and the point-implicit source_jacobian_* stay finite at rest. No regularization: values are unchanged.

Data#

API#

zoomy_core.systemmodel.operations.OPERATOR_SLOTS#

(‘flux’, ‘hydrostatic_pressure’, ‘nonconservative_matrix’, ‘source’, ‘source_explicit’, ‘mass_matrix…

zoomy_core.systemmodel.operations.KERNEL_SLOTS#

(‘boundary_conditions’, ‘aux_boundary_conditions’, ‘boundary_gradients’)

zoomy_core.systemmodel.operations.map_operator_slots(sm, rewrite, *, exclude=(), skip_rows=None) → dict#

Apply rewrite(expr) -> expr to every slot of OPERATOR_SLOTS except exclude, freezing the lazy quasilinear_matrix from the clean primaries first.

Args

  • exclude: slot names to leave alone; a name outside OPERATOR_SLOTS raises KeyError.

  • skip_rows: {slot: rows} left untouched inside a swept slot.

Returns

{slot: "rewritten" | "unchanged" | "absent" | "excluded"}.

zoomy_core.systemmodel.operations.normalize_face_normal(*, exclude=())#

Operation: impose |n| = 1 on every slot (default scope OPERATOR_SLOTS), which separates the SWE celerity from the 1/h of the momentum terms. It is a NumericalSystemModel default (normalize_normal=True).

zoomy_core.systemmodel.operations.kp_hinv(h, eps)#

Kurganov-Petrova desingularized inverse depth sqrt(2) h / sqrt(h^4 + max(h, eps)^4), equal to 1/h for h >= eps and tending to 0 as h -> 0. The numerator is bare h (no clamp), so a negative depth gives a negative hinv and the failure stays visible.

Args

  • h: depth, sympy expression or numpy/jax array.

  • eps: regularization scale.

References

zoomy_core.systemmodel.operations.register_aux(name: str, formula, **assumptions)#

Operation: add the algebraic aux variable name = formula to aux_state and update_aux_variables (identity on existing rows) and refresh the derived operators. **assumptions go to the new Symbol (default real=True).

zoomy_core.systemmodel.operations.wave_speed_inverse_depth(h)#

The 1/h of every wave speed, 1/max(1e-14, h), never the KP hinv: large but finite at a wet/dry front (REQ-82). Used by regularize_pow and the numerical spectral radius.

zoomy_core.systemmodel.operations.regularize_pow(field: Union[str, sympy.Symbol], aux_name: str)#

Operation: replace every field**(-n) in the physical, derived and reconstruction operators by aux_name**n; eigenvalues get a floored plain 1/max(1e-14, h) instead. The lazy derived operators are frozen from the clean primaries first, so the exact d(q^2/h)/dh term survives the substitution.

zoomy_core.systemmodel.operations.equilibrate_constraint_rows(mode=True)#

Operation: multiply each algebraic (zero mass-matrix) row by the minimal power of h that clears its negative powers of h. This changes the conditioning of the elliptic block, not the constraint manifold, wherever ``h

0``.

zoomy_core.systemmodel.operations.desingularize_hinv(mode='kp')#

Operation: register the hinv aux with the Kurganov-Petrova inverse depth (eps = wet_dry_eps) and rewrite every h**(-n) to hinv**n; mode is True or "kp", falsy is a no-op. Legacy NSM depth default; the depth-law study uses regularize_depth_direct / regularize_depth_aux.

References

zoomy_core.systemmodel.operations.symbolic_spectrum()#

Operation: derive the closed-form spectrum of the normal-projected quasilinear matrix into sm.eigenvalues; opt-in because it is expensive for high moment levels.

zoomy_core.systemmodel.operations.regularize_depth_direct(eps=None, *, field: str = 'h', eigenvalues: str = 'regularize', exclude=())#

Operation: substitute the Kurganov-Petrova reciprocal inline for every field**(-n) in every slot (the DIRECT path); no aux row is added. Mutually exclusive with regularize_depth_aux.

Args

  • eps: regularization scale (not wet_dry_eps).

  • eigenvalues: "regularize" sweeps the spectrum, "exclude" keeps the exact 1/h.

  • exclude: further slots to leave alone (opt out, never opt in).

References

zoomy_core.systemmodel.operations.regularize_depth_aux(eps=None, *, name: str = 'hinv', field: str = 'h', eigenvalues: str = 'regularize', exclude=())#

Operation: register the aux name whose update row is the Kurganov-Petrova reciprocal and rewrite every field**(-n) to name**n in every slot (the AUX path). Mutually exclusive with regularize_depth_direct; takes the same eps / eigenvalues / exclude arguments, and the row defining name is not rewritten.

References

zoomy_core.systemmodel.operations.desingularize_positivity(floor)#

Operation: replace the base of each negative or fractional power in the source that involves a positive_state symbol by sqrt(base**2 + floor**2) and re-derive the source Jacobians. A no-op if the model declares no positive_state.

zoomy_core.systemmodel.operations.guard_eigenvalue_powers()#

Operation: wrap every fractional power of the depth in sm.eigenvalues in Max(., 0) so wave speeds stay real at a transient h < 0 (no dry zeroing). Half A of the guard/gate split; gate_eigenvalues_dry is half B.

zoomy_core.systemmodel.operations.cfl_wave_speed_bound(sm, subs=None)#

The dt spectrum of a system without closed-form eigenvalues, shape (n_eq, 1): the wave-speed bound of A_n in the face’s normal frame (system_model.wave_speed_bound, the Riemann speeds’ bound) in row 0, zeros below (the consumers take max |.|), or with SpectralRadius.eig the numerical eigenvalues of A_n; subs replaces aux symbols first (the CFL inverse depth).

zoomy_core.systemmodel.operations.bound_wave_speed()#

Operation: publish cfl_wave_speed_bound into sm.eigenvalues_cfl for a system without closed-form eigenvalues whose dt spectrum no dry gate published (no depth, or no gate guard), so the cells rule takes the same bound as the Riemann speeds; a no-op with a closed form or a published dt spectrum.

zoomy_core.systemmodel.operations.gate_eigenvalues_dry(eps=None)#

Operation: publish a timestep-only spectrum conditional(h <= eps, 0, e) into sm.eigenvalues_cfl, leaving sm.eigenvalues physical (with its power guard) for the Riemann dissipation. eps defaults to 0: a cell without water (h <= 0) has no wave speed, but every cell with h > 0 moves mass with its own velocity (the Audusse states keep it), so its speed bounds the step however thin it is (ANALYSIS 52). The dry gate carries the power guard because a branchless backend evaluates both arms; without a closed form e is the Riemann speeds’ bound (cfl_wave_speed_bound) of A_n with hinv -> 1/max(1e-14, h) (wave_speed_inverse_depth). Idempotent.

zoomy_core.systemmodel.operations.regularize_fractional_powers(eps, *, exclude=())#

Operation: shift the base of every fractional power by eps**2 (b**r -> (b + eps**2)**r) so the operators stay differentiable at b = 0 under AD. Opt-in and idempotent; eps must be positive, and the value changes by O(eps**2) away from b = 0.

zoomy_core.systemmodel.operations.norm_derivative_at_zero()#

Operation (default, before the source linearization): every S**r in the source slots with S >= 0 a scaled squared Euclidean norm (_nonnegative) and rational r >= 1/2 not an integer (|u| = (u.u)**(1/2) of a friction law) becomes conditional(S > 0, conditional(S > 0, S, 1)**r, S): the same value, and the derivative 0 at S = 0 (S has its minimum there, dS = 0) instead of dS / (2 sqrt(S)) = 0/0 = NaN. That is the derivative of S**r for r > 1/2 and the least-norm subgradient for r = 1/2; the Newton Jacobian of an implicit friction source (JAX: AD) and the point-implicit source_jacobian_* stay finite at rest. No regularization: values are unchanged.