Merge r8h-flat-capsule (R8/R7 phase 2 round 1; default-off, verified)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Omar Sobh
2026-09-26 04:52:30 -05:00
co-authored by Claude Opus 5.5
9 changed files with 401 additions and 69 deletions
@@ -229,17 +229,9 @@ impl E3Fluid {
}));
VERSION.fetch_add(1, Ordering::AcqRel);
let (l1, l2, l3) = (lines.clone(), lines.clone(), lines.clone());
let body = Body::from_sdf(move |x, y, _z, t| cylinder(x, y).min(capsule(&l1, x, y, t).0))
.with_surface_velocity(move |x, y, _z, t| {
let (df, (vx, vy)) = capsule(&l2, x, y, t);
if df <= cylinder(x, y) {
(vx, vy, 0.0)
} else {
(0.0, 0.0, 0.0)
}
});
let width = nz as f64 * h;
let body = body.with_device_sdf(move |t| {
let tip_corner = super::flat_tip();
let device_sdf = move |t: f64| {
let line = l3.read().expect("lines").at(t);
DeviceSdf {
cyl: [CX, CY, R_CYL],
@@ -250,12 +242,48 @@ impl E3Fluid {
r_edge: h,
half: HALF,
fillet: 0.0,
tip_corner,
poly: line.pts,
vel: line.vel,
// R8-c's plate body (merged alongside): the span-uniform harness keeps the polyline.
plate: None,
}
});
};
let body = if tip_corner.is_some() {
// R8-h: the flat tip's host φ and velocity are the device form's
// (the kernel's arithmetic), cached per thread, time and lines.
let ds = device_sdf.clone();
let sdf_at = move |t: f64| -> Arc<DeviceSdf> {
thread_local! {
static SDF: RefCell<(u64, u64, Option<Arc<DeviceSdf>>)> =
const { RefCell::new((u64::MAX, u64::MAX, None)) };
}
let ver = VERSION.load(Ordering::Acquire);
SDF.with(|cell| {
let mut c = cell.borrow_mut();
if c.0 != t.to_bits() || c.1 != ver || c.2.is_none() {
c.2 = Some(Arc::new(ds(t)));
c.0 = t.to_bits();
c.1 = ver;
}
c.2.clone().expect("sdf")
})
};
let sdf_v = sdf_at.clone();
Body::from_sdf(move |x, y, z, t| sdf_at(t).phi_host(x, y, z))
.with_surface_velocity(move |x, y, z, t| sdf_v(t).velocity_host(x, y, z))
} else {
Body::from_sdf(move |x, y, _z, t| cylinder(x, y).min(capsule(&l1, x, y, t).0))
.with_surface_velocity(move |x, y, _z, t| {
let (df, (vx, vy)) = capsule(&l2, x, y, t);
if df <= cylinder(x, y) {
(vx, vy, 0.0)
} else {
(0.0, 0.0, 0.0)
}
})
};
let body = body.with_device_sdf(device_sdf);
solver.set_moving_body(body);
let g = Grid::cubic(nx, ny, nz, h);
let mut field = Field::new(g);