use alice_physics::fluid::{Fluid, FluidConfig};
use alice_physics::math::{Fix128, Vec3Fix};
fn main() {
let spacing = Fix128::from_ratio(1, 10);
let min = Vec3Fix::ZERO;
let max = Vec3Fix::new(
Fix128::from_ratio(3, 10),
Fix128::from_ratio(5, 10),
Fix128::from_ratio(3, 10),
);
let mut fluid = Fluid::new_block(min, max, spacing, FluidConfig::default());
let (nx, ny, nz) = (4usize, 6usize, 4usize);
println!(
"particles: {} (closed form {})",
fluid.particle_count(),
nx * ny * nz
);
assert_eq!(fluid.particle_count(), nx * ny * nz);
let probe = (2 * ny + 3) * nz + 1;
let p = fluid.positions[probe];
println!(
"particle {probe} sits at ({:.3}, {:.3}, {:.3})",
p.x.to_f64(),
p.y.to_f64(),
p.z.to_f64()
);
assert!(
(p.x.to_f64() - 0.2).abs() < 1e-12
&& (p.y.to_f64() - 0.3).abs() < 1e-12
&& (p.z.to_f64() - 0.1).abs() < 1e-12
);
let com = |f: &Fluid| {
f.positions.iter().map(|q| q.y.to_f64()).sum::<f64>() / f.particle_count() as f64
};
let y0 = com(&fluid);
let dt = Fix128::from_ratio(1, 60);
for _ in 0..15 {
fluid.step(dt);
}
let fall = y0 - com(&fluid);
let free_fall = 0.5 * 10.0 * 0.25 * 0.25;
println!("centre of mass fell {fall:.4} m in 0.25 s (free fall would be {free_fall:.4} m)");
assert!(fall > 0.0 && fall < free_fall);
}