Compare commits

...
3 Commits
Author SHA1 Message Date
ClaudeandClaude Opus 5.5 99ddb5fc27 Test: fine jet ownership uses remapped physical owners
Caller obj_id 99 spanning 2x2 fine blocks: driven rows carry the single
remapped owner 0 across several block ids, accepted; source id unchanged.
Caller ids (99, 7) under one tube are rejected at amplitude 0 and .002
on the 32x24 fixture; source ids unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 02:42:04 +00:00
ClaudeandClaude Opus 5.5 bf0adda45f Test: jet ownership is set membership, not row adjacency
Synthetic rows: one jet over non-contiguous rows of one body is accepted;
the same rows with a second body id are rejected (Grok case 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 02:41:15 +00:00
ClaudeandClaude Opus 5.5 64d54ab23e Jets: one jet may drive links of only one body
surface_link_velocity (the shared host check used by CurvedLinkSoA,
ObjectManager sync, prepare_fine_boundary and FixedPatchStepper) now
rejects a jet whose selected cut links carry more than one body id, at
any amplitude, before uploads. Identity is the scene-wide body id of the
physical cut-link list, so one body spanning storage blocks stays valid.
No body selector; empty-selection semantics unchanged.

Tests: two bodies under one jet rejected (amplitude 2e-3 and 0) on the
Simulation/manager path and on the fine path; separate jets on separate
bodies accepted on both; one fine body crossing 2x2 block seams accepted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 02:39:58 +00:00
3 changed files with 110 additions and 2 deletions

No files matched your search

+7 -1
View File
@@ -6,7 +6,8 @@ packing), over every link in the scene; it carries no body association.
Per-link velocity = amplitude * profile(s) * field(hit), where ``s`` in [-1, 1]
is the region's lateral coordinate. Velocities are lattice units of the level
whose links are evaluated; callers convert frames/units before evaluation.
One physical link (receiver, direction) may be driven by at most one jet.
One physical link (receiver, direction) may be driven by at most one jet, and
one jet may drive the links of only one body (checked at assignment, any amplitude).
Edge rule: the lateral bound |s| < 1 is exclusive (the profile vanishes
there for parabolic/quartic); Sector r_min/r_max and Tube 0 <= along <= length
@@ -222,6 +223,11 @@ def surface_link_velocity(objects, cfg, flags, fluid_idx, dir, body_id, rx, ry,
raise ValueError("Jets require D2Q9/FP32/unshifted/double_buffer")
shape, jet_id = jet_link_shapes(jets, hits)
driven = jet_id >= 0
for j in range(len(jets)): # scene-wide body identity, independent of storage blocks
bodies = np.unique(body_id[jet_id == j])
if len(bodies) > 1:
raise ValueError(f"Jet {j} selects cut links of bodies {bodies.tolist()}; "
"one jet may drive only one body")
owners = {obj.obj_id: obj for obj in objects}
for bid in np.unique(body_id[driven]):
state = vars(owners[int(bid)].state)
+63
View File
@@ -293,6 +293,16 @@ def test_fine_boundary_keeps_edge_frame_hits_and_checks_jets():
refinement.prepare_fine_boundary(cfg, patch, [body], jets=[jet, jet])
with pytest.raises(ValueError, match="need fine boundary objects"):
refinement.prepare_fine_boundary(cfg, patch, [], jets=[jet])
# One fine jet over two physical bodies is rejected; one per body is accepted.
A, B = (8.75, 12.25), (15.75, 12.25)
pair = [SimObject(i, geometry=CircleGeometry(*c, 1.5), center=c, radius=1.5)
for i, c in enumerate((A, B))]
span = Jet(Tube((4.5, 12.25), 0., 15., .5), Parallel(0.))
with pytest.raises(ValueError, match="one jet may drive only one body"):
refinement.prepare_fine_boundary(cfg, patch, pair, jets=[span])
refinement.prepare_fine_boundary(cfg, patch, pair, jets=[
Jet(Sector(A, 0., .5, 2.), Radial(A, inward=False)),
Jet(Sector(B, math.pi, .5, 2.), Radial(B, inward=False))])
# Jet vs legacy SurfaceActuation overlap on the fine level (root's case).
legacy = SimObject(0, geometry=CircleGeometry(*C, R), center=C, radius=R,
surface_actuation=SurfaceActuation(0., .5, .002))
@@ -310,3 +320,56 @@ def test_action_upload_keeps_cfg_none_fallback(device):
bodies._upload_action_async(stream)
bodies.add(circle(radius=2.))
bodies._upload_action_async(stream)
def two_body_case(device, jets):
field = make_field(device)
bodies = manager(field, [circle(center=(3., 5.), radius=1.6),
circle(center=(8.5, 5.), radius=1.6)])
bodies.jets.extend(jets)
bodies.sync_to_gpu(field)
return field, bodies
@pytest.mark.parametrize("amplitude", [2e-3, 0.0]) # geometry checked even at zero amplitude
def test_one_jet_spanning_two_bodies_rejected(device, amplitude):
both = Jet(Tube((0., 5.), 0., 12., .5), Parallel(0.), amplitude=amplitude)
with pytest.raises(ValueError, match="one jet may drive only one body"):
two_body_case(device, [both])
def test_separate_jets_on_separate_bodies_accepted(device):
left = Jet(Sector((3., 5.), 0., .6, 2.), Radial((3., 5.), inward=False), amplitude=1e-3)
right = Jet(Sector((8.5, 5.), math.pi, .6, 2.), Radial((8.5, 5.), inward=False), amplitude=-1e-3)
field, _ = two_body_case(device, [left, right])
cl = field.curved
for j in (0, 1):
assert len(np.unique(cl.body_id[cl.jet_id == j])) == 1
assert cl.body_id[cl.jet_id == 0][0] != cl.body_id[cl.jet_id == 1][0]
def test_one_body_with_noncontiguous_rows_accepted_and_mixed_rejected():
# Synthetic rows: ownership is set membership over body_id, not row adjacency.
from CelerisLab.body.geometry.circle import CircleGeometry
from CelerisLab.body.objects import SimObject
from CelerisLab.config import LBMConfig
from CelerisLab.lbm.descriptors import FLUID
cfg = LBMConfig(nx=12, ny=10, viscosity=.1)
cfg.validate()
objs = [SimObject(i, geometry=CircleGeometry(3. + 5*i, 5., 1.), center=(3. + 5*i, 5.), radius=1.)
for i in (0, 1)]
flags = np.full(cfg.nx*cfg.ny, FLUID, np.uint16)
fluid_idx = np.array([10, 20, 30], np.uint32)
dirs = np.array([1, 1, 1], np.uint8)
zeros = np.zeros(3, np.float32)
hits = np.array([[0., 0.], [5., 5.], [0., 1.]])
jet = Jet(Tube((0., -.5), math.pi/2, 2., .5), Parallel(0.)) # selects rows 0 and 2
for body_id, ok in ((np.array([0, 1, 0], np.int32), True), (np.array([0, 1, 1], np.int32), False)):
call = lambda: surface_link_velocity(objs, cfg, flags, fluid_idx, dirs, body_id,
zeros, zeros, jets=[jet], hits=hits)
if ok:
_, aperture = call()
assert aperture.tolist() == [True, False, True]
else:
with pytest.raises(ValueError, match="one jet may drive only one body"):
call()
@@ -18,7 +18,7 @@ import pycuda.driver as cuda
from CelerisLab.cuda import compiler_v2 as compiler
from CelerisLab.lbm.descriptors import SOLID
from CelerisLab.lbm.refinement import ACTIVE, FixedPatch2D
from CelerisLab.lbm.refinement import ACTIVE, FixedPatch2D, prepare_fine_boundary
from CelerisLab.lbm.refinement_stepper import FixedPatchStepper
from test_refinement_blocked_fine import (BOUNDS, FINE_BLOCKS, NX, NY, STEPS, actuation,
circle, config, fine_circle, raw, state)
@@ -47,6 +47,45 @@ def mocked(objects, jets, fine_block):
class JetStepperCPU(unittest.TestCase):
def test_one_body_across_blocks_accepted(self):
# Fine circle (19.5, 15.5) R4.3 crosses the 2x2 block seams; one body, one jet.
import math
from CelerisLab.body.jets import Jet, Radial, Sector
C = (16.0, 12.0)
whole = Jet(Sector(C, .1, math.pi, 3.), Radial(C, inward=False), amplitude=0.)
backend, _ = mocked([circle()], [whole], FINE_BLOCKS[1])
_, jet_id = backend._jet_cache
self.assertGreater(len(np.unique(backend._fine_tables["block"][jet_id == 0])), 1)
backend.close()
def test_fine_ownership_uses_remapped_physical_owner(self):
# Caller ids (99, 7) are remapped to fine owners (0, 1); block ids never count.
import math
from CelerisLab.body.geometry.circle import CircleGeometry
from CelerisLab.body.jets import Jet, Parallel, Radial, Sector, Tube
from CelerisLab.body.objects import SimObject
C = (16.0, 12.0)
source = SimObject(99, geometry=CircleGeometry(*C, 2.15), center=C, radius=2.15)
whole = Jet(Sector(C, .1, math.pi, 3.), Radial(C, inward=False), amplitude=0.)
backend, _ = mocked([source], [whole], FINE_BLOCKS[1])
_, jet_id = backend._jet_cache
owners = backend.fine_boundary.curved_host[3][jet_id == 0]
self.assertEqual(np.unique(owners).tolist(), [0])
self.assertGreater(len(np.unique(backend._fine_tables["block"][jet_id == 0])), 1)
self.assertEqual(source.obj_id, 99)
backend.close()
cfg = config("periodic")
patch_ = FixedPatch2D.from_config(cfg, BOUNDS)
A, B = (12.5, 12.0), (19.5, 12.0)
pair = [SimObject(i, geometry=CircleGeometry(*c, 1.5), center=c, radius=1.5)
for i, c in ((99, A), (7, B))]
for amplitude in (0., .002):
with self.assertRaisesRegex(ValueError, "one jet may drive only one body"):
prepare_fine_boundary(cfg, patch_, pair,
jets=[Jet(Tube((9., 12.), 0., 14., .5), Parallel(0.),
amplitude=amplitude)])
self.assertEqual([o.obj_id for o in pair], [99, 7])
def test_blocked_jet_velocity_matches_legacy_rows(self):
legacy, _ = mocked([circle(actuation(SPEED))], (), FINE_BLOCKS[1])
driven, _ = mocked([circle()], [jet()], FINE_BLOCKS[1])