embedded3 S2-2b (host lever): narrow-band φ re-evaluation for moving bodies (max_surface_speed) — bit-identical, the flag body's ny 62 rebuild 3.54 → 0.30 s; the flag driver uses it
CI / Format Check (push) Failing after 4s
CI / Build (macos-latest) (push) Waiting to run
CI / Test (macos-latest) (push) Blocked by required conditions
CI / Test (ubuntu-latest) (push) Blocked by required conditions
CI / Python Bindings (maturin) (macos-latest) (push) Blocked by required conditions
CI / Python Bindings (maturin) (ubuntu-latest) (push) Blocked by required conditions
CI / WASM Build + Size Check (push) Blocked by required conditions
CI / Distributed Training Tests (push) Blocked by required conditions
CI / CI Success (push) Blocked by required conditions
CI / Clippy Check (push) Failing after 3s
CI / Build (ubuntu-latest) (push) Failing after 4s
Performance Benchmarks / Run Benchmarks (push) Failing after 5s
Documentation / Build User Guide (push) Successful in 6s
CI / Build CPU-Only (Explicit) (push) Failing after 1m5s
Documentation / Build API Documentation (push) Failing after 1m8s

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Omar Sobh
2026-09-17 19:30:54 -05:00
co-authored by Claude Fable 5.1
parent aa096465a6
commit c30e3dba34
5 changed files with 192 additions and 9 deletions
@@ -73,3 +73,127 @@ fn flag_body_builds_at_ny_62() {
assert!((closure[0].powi(2) + closure[1].powi(2) + closure[2].powi(2)).sqrt() < 1e-9);
}
}
/// Where the per-step host rebuild's time goes at ny 62 (S2-2b's target).
#[test]
#[ignore = "profile: the rebuild's parts at ny 62 (seconds)"]
fn rebuild_profile_at_ny_62() {
use rtx_cfd::solvers::incompressible::embedded3::CutGeometry;
let ny = 62;
let h = H / ny as f64;
let nx = (2.5 / h).round() as usize;
let g = Grid::cubic(nx, ny, ny, h);
let cyl = |x: f64, y: f64| ((x - 0.2_f64).powi(2) + (y - 0.2_f64).powi(2)).sqrt() - 0.05;
let body = Body::from_sdf(move |x, y, z, _t| cyl(x, y).min(flag_3d(x, y, z, 0.3, h)));
let b = Boundaries {
x1: Side::PressureOutlet,
..Boundaries::default()
};
let t0 = std::time::Instant::now();
let _cut = CutGeometry::build(&body, g, 0.0);
let t_cut = t0.elapsed().as_secs_f64();
let t1 = std::time::Instant::now();
let nodes = (nx + 1) * (ny + 1) * (ny + 1);
let mut acc = 0.0;
for n in 0..nodes {
let (k, j, i) = (
n / ((nx + 1) * (ny + 1)),
(n / (nx + 1)) % (ny + 1),
n % (nx + 1),
);
acc += body.phi(i as f64 * h, j as f64 * h, k as f64 * h, 0.0);
}
let t_phi = t1.elapsed().as_secs_f64();
let t2 = std::time::Instant::now();
let mask = Mask::build_cut(&body, g, 0.0, b).expect("mask");
let t_mask = t2.elapsed().as_secs_f64();
let t3 = std::time::Instant::now();
let (_table, _) = mask.wall_flux_table(&body, 0.0);
let t_flux = t3.elapsed().as_secs_f64();
println!(
" ny 62 rebuild parts: cut geometry {t_cut:.2} s (of which φ at {nodes} nodes {t_phi:.2} s), whole mask build {t_mask:.2} s, wall-flux table {t_flux:.2} s (Σφ {acc:.1})"
);
}
/// The narrow band is invisible to the solution: the moving circle
/// marched with and without `max_surface_speed` gives bit-identical
/// fields; the flag body's rebuild time at ny 62 with the band recorded.
#[test]
fn narrow_band_is_bit_identical_and_fast() {
use rtx_cfd::solvers::incompressible::ConvectionScheme;
use rtx_cfd::solvers::incompressible::embedded3::{
CutGeometry, Field, Fluid, Parameters, Solver, WallScheme,
};
let n = 76;
let h = 1.0 / n as f64;
let dt = 3.24e-4;
let run = |band: bool| {
let mut solver = Solver::new(
Fluid {
density: 1000.0,
viscosity: 1.0,
reference_velocity: 1.0,
reference_length: 0.1,
},
Parameters {
corrector_steps: 2,
tolerance: 1e-8,
convection_scheme: ConvectionScheme::Upwind,
wall_scheme: WallScheme::CutCell,
boundaries: Boundaries {
z0: Side::Periodic,
z1: Side::Periodic,
..Boundaries::default()
},
max_surface_speed: band.then_some(1.0),
..Parameters::default()
},
);
solver.set_boundary_velocity(|_, _, _, _| (0.0, 0.0, 0.0));
let yc = |t: f64| 0.5 + 0.08 * (t / 0.08).sin();
let vc = |t: f64| (t / 0.08).cos();
solver.set_moving_body(
Body::from_sdf(move |x, y, _z, t| {
((x - 0.5_f64).powi(2) + (y - yc(t)).powi(2)).sqrt() - 0.05
})
.with_surface_velocity(move |_, _, _, t| (0.0, vc(t), 0.0)),
);
let g = Grid::cubic(n, n, 4, h);
let mut f = Field::new(g);
solver.initialize(&mut f);
let start = std::time::Instant::now();
for _ in 0..40 {
solver.advance(&mut f, dt);
}
(f, start.elapsed().as_secs_f64())
};
let (full, t_full) = run(false);
let (band, t_band) = run(true);
let same = full.u == band.u && full.v == band.v && full.w == band.w && full.p == band.p;
println!(
" moving circle 76²×4, 40 steps: full {t_full:.2} s, band {t_band:.2} s; fields bit-identical: {same}"
);
assert!(same, "the narrow band changed the solution");
// The flag body at ny 62: a full build, then a banded rebuild after a small motion.
let ny = 62;
let hh = H / ny as f64;
let nx = (2.5 / hh).round() as usize;
let g = Grid::cubic(nx, ny, ny, hh);
let cyl = |x: f64, y: f64| ((x - 0.2_f64).powi(2) + (y - 0.2_f64).powi(2)).sqrt() - 0.05;
let body = Body::from_sdf(move |x, y, z, t| cyl(x, y).min(flag_3d(x, y, z, t, hh)));
let t0 = std::time::Instant::now();
let prev = CutGeometry::build(&body, g, 0.3);
let t_prev = t0.elapsed().as_secs_f64();
let t1 = std::time::Instant::now();
let next = CutGeometry::build_from(&body, g, 0.31, Some((&prev, 3.0 * hh, 1.0e-3)));
let t_next = t1.elapsed().as_secs_f64();
let exact = CutGeometry::build(&body, g, 0.31);
let vol_same = next.vol == exact.vol
&& next.a_u == exact.a_u
&& next.a_v == exact.a_v
&& next.a_w == exact.a_w;
println!(
" flag ny 62: full build {t_prev:.2} s, banded rebuild {t_next:.2} s; volumes and apertures identical to a full build: {vol_same}"
);
assert!(vol_same);
}
@@ -139,6 +139,8 @@ fn flag_wake_on_the_device() {
x1: Side::PressureOutlet,
..Boundaries::default()
},
// The narrow band: the flag's tip speed bounds the surface motion.
max_surface_speed: Some(2.0 * std::f64::consts::PI * FREQ * AMP * 1.05),
..Parameters::default()
},
);