Files
CelerisLab/src/CelerisLab/lbm/channel.py
T
ClaudeandClaude Opus 5.5 00d7a54829 feat: opt-in MRT collision for blocked/refined stepping
Additive compile-time COLLISION_MODEL == 2 branches in BlockStep,
BlockChannelStep and patch_collide repeat the uniform collide_dispatch
MRT sequence (zero forcing, omega clamp, collide_mrt_no_force). SRT
statements, including the shifted retained-delta/direct-momentum path,
are unchanged under the alternate branch. Guards accept SRT or MRT only;
TRT, LES, non-FP32, non-double-buffer and shifted dense/mixed refinement
stay rejected. Transfers, subcycling, BFL, raw ledgers, channel closures,
shifted-Jet SRT guard and PeriodicBlockStepper are untouched. Existing
MRT operator, shifted representation and fixed kinetic rates are reused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 10:26:55 +00:00

55 lines
2.4 KiB
Python

"""Host contract for the blocked root's uniform SRT/MRT channel boundary.
Boundary ghosts are evolved state, but are not physical fluid leaves. Halo
ownership remains periodic to reproduce the uniform kernel's wrapped pulls.
No boundary closure is applied on a fine level.
"""
import numpy as np
def channel_masks(shape):
"""Physical fluid and bulk-transfer masks in GLOBAL root coordinates."""
ny, nx = shape
fluid = np.zeros(shape, bool)
fluid[1:ny - 1, 1:nx - 1] = True
bulk = fluid.copy()
bulk[[1, ny - 2]] = False
return fluid, bulk
def validate_channel_config(cfg, blocks):
if any(block is None for block in blocks):
raise ValueError("channel requires all-blocked levels")
if (cfg.inlet_scheme != "zou_he_local" or cfg.outlet_mode != "neq_extrap"
or cfg.y_wall_bc != "bounce_back" or cfg.top_wall_bc != "velocity"
or cfg.wall_slot_width != 0 or cfg.wall_normal_velocity != 0):
raise ValueError("channel requires Zou-He inlet, pressure NEQ outlet and stationary bounce-back y walls")
def validate_channel_transfers(pair, layout, targets):
"""Reject actual exchange/closure overlap, not a padded geometric envelope.
Explosion donors and restriction receivers must use ordinary bulk collision
semantics. Restriction writes receiver-local source slots; these may not
overwrite the channel's extra immutable-input reads (pressure donor and
same-node halfway-wall corrections). The slot check deliberately respects
block seams, rather than treating different halo images as the same slot.
"""
ny, nx = pair.coarse_shape
_, bulk = channel_masks(pair.coarse_shape)
legal = bulk.ravel() & ~pair.covered.ravel()
receivers = pair.coalesce_coarse % (ny * nx)
if not legal[pair.ghost_coarse].all() or not legal[receivers].all():
raise ValueError("channel transfer donors and receivers must be uncovered bulk fluid")
owner = layout.owner
reads = []
# Outlet closes from the full previous-step state at its left neighbor.
donor = owner[1:-1, -1].astype(np.int64) - 1
for q in range(9):
reads.append(layout.slot(donor, q))
for y, directions in ((1, (4, 6, 7)), (ny - 2, (3, 5, 8))):
for q in directions:
reads.append(layout.slot(owner[y, 1:-1], q))
if np.intersect1d(targets, np.concatenate(reads)).size:
raise ValueError("channel restriction writes overlap immutable boundary closure reads")