embedded3 S2-5: the cut wall sat ½(1−α)h inside the body — cross diffusion over the open-part centroid spacing (RTX_E3_DIFFUSION_CENTROID; host + e3_cut.cu, shift tables, point-implicit excess); flat-wall effective-position instrument; DFG 2D-1 ladder tests (device + host); knobs tried and refuted along the way (oblique distance, axis exchange, centroid pressure gradient)
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 / Build (macos-latest) (push) Waiting to run
Documentation / Build API Documentation (push) Failing after 4s
Documentation / Build User Guide (push) Successful in 4s
CI / Clippy Check (push) Failing after 2m24s
CI / Build CPU-Only (Explicit) (push) Failing after 3s
CI / Format Check (push) Failing after 11s
CI / Build (ubuntu-latest) (push) Failing after 1m58s
Performance Benchmarks / Run Benchmarks (push) Successful in 2m44s

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Omar Sobh
2026-09-18 10:54:52 -05:00
co-authored by Claude Fable 5.1
parent 4c3e58fa27
commit fdfb6da769
12 changed files with 667 additions and 22 deletions
@@ -80,7 +80,11 @@ fn dfg_2d_1_on_the_device() {
// The cylinder extruded across the width, with samples for the
// traction route (S2-1).
solver.set_body(Body::extruded(
rtx_cfd::solvers::incompressible::EmbeddedBody::circle(CX, CY, 0.5 * D),
rtx_cfd::solvers::incompressible::EmbeddedBody::circle(
CX,
CY,
0.5 * D + env_f("RTX_E3_DFG_DR", 0.0) * h,
),
lz,
));
let g = Grid::cubic(nx, ny, nz, h);
@@ -0,0 +1,140 @@
//! S2-5 host ladder: DFG 2D-1 (Re 20) on a periodic-z slab of 4 cells with
//! every knob of the cut wall read from the environment — the instrument
//! for host-only prototypes (`RTX_E3_PRESSURE_CENTROID=1`). Reference
//! c_D 5.57954, c_L 0.010619, Δp 0.117520. `RTX_E3_DFG_NY` (default 62).
use rtx_cfd::solvers::incompressible::ConvectionScheme;
use rtx_cfd::solvers::incompressible::embedded3::{
Body, Boundaries, Field, Fluid, Grid, Parameters, Side, Solver, WallScheme,
};
const H: f64 = 0.41;
const L: f64 = 2.2;
const D: f64 = 0.1;
const CX: f64 = 0.2;
const CY: f64 = 0.2;
const U_M: f64 = 0.3;
const U_BAR: f64 = 2.0 / 3.0 * U_M;
const RHO: f64 = 1.0;
const NU: f64 = 1e-3;
fn inflow(y: f64, _z: f64) -> f64 {
4.0 * U_M * y * (H - y) / (H * H)
}
#[test]
#[ignore = "host DFG at ny 31 with the routes split (about half an hour)"]
fn dfg_2d1_on_the_host() {
let ny: usize = std::env::var("RTX_E3_DFG_NY")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(62);
let h = H / ny as f64;
let nx = (L / h).round() as usize;
let nz = 4;
let lz = nz as f64 * h;
let dt = (0.3 * h / U_M).min(0.5 * h * h / (6.0 * NU));
let mut solver = Solver::new(
Fluid {
density: RHO,
viscosity: RHO * NU,
reference_velocity: U_BAR,
reference_length: D,
},
Parameters {
corrector_steps: 2,
tolerance: 1e-8,
convection_scheme: ConvectionScheme::TvdVanAlbada,
wall_scheme: WallScheme::CutCell,
boundaries: Boundaries {
x1: Side::PressureOutlet,
z0: Side::Periodic,
z1: Side::Periodic,
..Boundaries::default()
},
..Parameters::default()
},
);
solver.set_boundary_velocity(|x, y, z, _t| {
if x <= 0.0 {
(inflow(y, z), 0.0, 0.0)
} else {
(0.0, 0.0, 0.0)
}
});
solver.set_body(Body::extruded(
rtx_cfd::solvers::incompressible::EmbeddedBody::circle(CX, CY, 0.5 * D),
lz,
));
let g = Grid::cubic(nx, ny, nz, h);
let mut field = Field::new(g);
for k in 0..nz {
for j in 0..ny {
let u0 = inflow((j as f64 + 0.5) * h, (k as f64 + 0.5) * h);
for i in 0..=nx {
field.u[g.uface(k, j, i)] = u0;
}
}
}
solver.initialize(&mut field);
let coef = 2.0 / (RHO * U_BAR * U_BAR * D * lz);
let steps = (12.0 / dt).ceil() as usize;
let start = std::time::Instant::now();
let mut last = (0.0, 0.0);
for step in 0..steps {
let r = solver.advance(&mut field, dt);
if (step + 1) % (steps / 20).max(1) == 0 || step + 1 == steps {
let t = solver.time();
let mask = solver.mask().unwrap();
let body = solver.body().unwrap();
let mu = RHO * NU;
let (po, so) = mask.cut_wall_force_parts(body, &field, mu, t).unwrap();
let ex = mask
.cut_wall_exchange_force(body, &field, mu, RHO, t, None)
.unwrap();
let (pr, sr) = mask
.cut_wall_force_reconstructed_parts(body, &field, mu, t, None)
.unwrap();
let margin = 1.5 * D;
let ci = |x: f64| ((x / h).round() as usize).clamp(2, nx - 2);
let cj = |y: f64| ((y / h).round() as usize).clamp(2, ny - 2);
let bx = (
ci(CX - margin),
ci(CX + margin),
cj(CY - 0.15),
cj(CY + 0.15),
0,
nz,
);
let fcv = mask.control_volume_force_with_walls(&field, dt, RHO, mu, None, bx, false);
let cd = |f: [f64; 3]| coef * f[0];
println!(
" t {t:7.3}: c_D operator {:.4} (p {:.4} + s {:.4} + exchange {:.4}) | reconstructed {:.4} (p {:.4} + s {:.4}) | box {:.4} c_L {:.5} Δp {:.5}; residual {:.1e} [{:.0} s]",
cd(po) + cd(so) + cd(ex),
cd(po),
cd(so),
cd(ex),
cd(pr) + cd(sr),
cd(pr),
cd(sr),
cd(fcv),
coef * (po[1] + so[1] + ex[1]),
mask.pressure_at(&field.p, CX - 0.5 * D, CY, 0.5 * lz)
.unwrap_or(f64::NAN)
- mask
.pressure_at(&field.p, CX + 0.5 * D, CY, 0.5 * lz)
.unwrap_or(f64::NAN),
r.final_residual,
start.elapsed().as_secs_f64()
);
let now = (cd(po) + cd(so) + cd(ex), cd(fcv));
if (now.0 - last.0).abs() < 1e-4 * now.0.abs()
&& (now.1 - last.1).abs() < 1e-4 * now.1.abs()
&& t > 2.0
{
println!(" settled");
break;
}
last = now;
}
}
}
@@ -0,0 +1,102 @@
//! S2-5 instrument: where does the cut wall sit? Poiseuille flow along z
//! (periodic, body force `f`) between an EMBEDDED flat wall at `y = y_w`
//! (cut at a chosen fraction θ of a cell) and the domain's top wall. The
//! flow rate per unit width is `f (H y_w)³ / (12 μ)`, so the measured
//! rate gives the effective wall position `y_eff`; the offset
//! `(y_eff y_w)/h` must vanish at second order and is the number the
//! DFG ladder reads as an effective radius ≈ 0.2 h short.
use rtx_cfd::solvers::incompressible::ConvectionScheme;
use rtx_cfd::solvers::incompressible::embedded3::{
Body, Boundaries, Field, Fluid, Grid, Parameters, Side, Solver, WallScheme,
};
const MU: f64 = 0.1;
const F: f64 = 1.0;
const HY: f64 = 1.0;
fn offset(ny: usize, theta: f64) -> (f64, Vec<(f64, f64, f64)>) {
let h = HY / ny as f64;
let (nx, nz) = (3 * ny, 2);
let y_w = (ny as f64 / 4.0).floor() * h + theta * h;
let exact = move |y: f64| {
if y > y_w {
F / (2.0 * MU) * (y - y_w) * (HY - y)
} else {
0.0
}
};
let mut solver = Solver::new(
Fluid {
density: 1.0,
viscosity: MU,
reference_velocity: 1.0,
reference_length: 1.0,
},
Parameters {
corrector_steps: 2,
tolerance: 1e-10,
convection_scheme: ConvectionScheme::Upwind,
wall_scheme: WallScheme::CutCell,
boundaries: Boundaries {
z0: Side::Periodic,
z1: Side::Periodic,
..Boundaries::default()
},
..Parameters::default()
},
);
solver.set_boundary_velocity(move |_x, y, _z, _t| (0.0, 0.0, exact(y)));
solver.set_momentum_source(|_, _, _, _| (0.0, 0.0, F));
solver.set_body(Body::from_sdf(move |_x, y, _z, _t| y - y_w));
let g = Grid::cubic(nx, ny, nz, h);
let mut field = Field::new(g);
for k in 0..=nz {
for j in 0..ny {
for i in 0..nx {
if k < nz || true {
let idx = g.wface(k.min(nz), j, i);
field.w[idx] = exact((j as f64 + 0.5) * h);
}
}
}
}
solver.initialize(&mut field);
let dt = 0.5 * h * h / (6.0 * MU);
let steps = (3.0 / dt).ceil() as usize;
for _ in 0..steps {
solver.advance(&mut field, dt);
}
let mask = solver.mask().expect("mask");
let i = nx / 2;
let mut q = 0.0;
let mut profile = Vec::new();
for j in 0..ny {
let f = g.wface(0, j, i);
let a = mask.a_w(f);
q += a * field.w[f] * h;
let y = (j as f64 + 0.5) * h;
if a > 0.0 && profile.len() < 4 {
profile.push((a, field.w[f], exact(y)));
}
}
let y_eff = HY - (12.0 * MU * q / F).cbrt();
((y_eff - y_w) / h, profile)
}
#[test]
#[ignore = "S2-5 instrument: the cut wall's effective position on a flat wall (a minute on the host)"]
fn flat_wall_effective_position() {
for ny in [16usize, 32] {
for theta in [0.05, 0.25, 0.5, 0.75, 0.95] {
let (off, profile) = offset(ny, theta);
let p: Vec<String> = profile
.iter()
.map(|(a, w, e)| format!("α {a:.2} w {w:.5} (exact at the face centre {e:.5})"))
.collect();
println!(
" ny {ny} θ {theta:.2}: effective wall offset {off:+.4} h (positive = the wall sits inside the fluid); first open faces: {}",
p.join("; ")
);
}
}
}