Newton’s XPBD solver now treats selected particles as fluids using position-based density constraints, bounded cohesion, viscosity, optional vorticity confinement, grouped neighborhoods, and two-way particle–rigid contact. A render-only path fits smoothed anisotropic particles and reconstructs an optically shaded surface in ViewerGL without changing the simulated state. Nine examples cover free surfaces, pumping, multiple fluids and worlds, buoyancy, SDF containers, articulated manipulation, waves, foam, and spray. At approximately 100,000 particles, the measured dam-break simulation reaches a median 90.2 frames per second on an RTX 4090.
1. Scope
The branch adds a fluid particle type to the existing XPBD solver and a corresponding surface representation for ViewerGL.
Fluids use the same particle state and timestep
Particles marked ACTIVE | FLUID participate in a density projection inside SolverXPBD.step(). Cloth, granular particles, rigid contacts, and fluid particles can therefore advance through the same state pair and collision pipeline.
The physical and visual representations are separate
The solver owns particle positions, velocities, density data, and optional diffuse particles. Rendering may smooth positions and fit ellipsoids, but those derived arrays never feed back into the simulation.
Fluid–rigid coupling is two-way
Shape contacts constrain fluid particles while the equal-and-opposite correction is accumulated onto dynamic bodies. The Archimedes screw example uses this coupling to transfer simulated water momentum to a freely rotating wheel.
Nine runnable examples define the supported surface area
The examples exercise containers, pumps, manipulators, mixed fluids, multiple isolated worlds, buoyant objects, wave forcing, and diffuse spray. Each example is registered with an end-state stability check.
2. XPBD fluid simulation
A position-based fluids solve is embedded in each XPBD substep. The implementation uses the same particle arrays, inverse masses, contacts, and state update as Newton’s other XPBD constraints.
Density constraint
For every active fluid particle \(i\), a grouped hash-grid query finds same-world neighbors inside the smoothing radius \(h\). The poly6 kernel estimates density and a unilateral constraint removes compression while allowing a free surface to remain under-dense:
fluid_relaxation scales this density correction and a particle-scale bound limits each iteration. A deterministic separation direction resolves coincident samples. The neighbor cap is optional; setting fluid_max_neighbors=0 processes the complete neighborhood.
Substep sequence
Predict. External forces advance particle and body velocities and predict new positions.
Collide.CollisionPipeline generates particle–shape contacts. Texture SDFs provide smooth confinement for mesh containers and pump surfaces.
Project. Each XPBD iteration solves fluid density, particle contacts, rigid contacts, joints, and deformable constraints. Fluid contact corrections can transfer momentum to dynamic bodies.
Update velocity. Corrected positions determine particle velocity; a kernel-weighted neighborhood blend applies viscosity, while optional vorticity confinement restores rotational detail.
Emit diffuse particles. When enabled, low-density crest and trapped-air candidates spawn finite-lifetime foam and spray that advect with the resolved velocity field.
Cohesion and viscosity
Free-surface attraction is a bounded Akinci-style pair bias rather than the negative branch of the density constraint. This keeps isolated particles stable while still forming droplets and strands. Viscosity is applied after projection as a per-substep blend toward the mass- and density-weighted neighborhood velocity:
ViewerGL derives a smooth surface from the solved particle state. All smoothing and anisotropy are visual outputs; they do not alter density, contacts, or the next simulation step.
Render-particle fit
SolverXPBD.update_render_particles() computes a weighted neighborhood center and blends it with the simulated position. A regularized covariance fit supplies three clamped ellipsoid axes, allowing sheets and strands to connect without inflating the simulation radius:
DepthRay-cast anisotropic ellipsoids into linear eye-space depth.
ThicknessAccumulate depth-tested optical thickness from enlarged splats.
SmoothApply a separable depth-aware bilateral filter at framebuffer resolution.
ShadeRecover normals from depth and evaluate refraction, reflection, shadow, and specular light.
DiffuseComposite optional velocity-stretched foam and spray against the fluid depth.
Optical model
Thickness controls Beer–Lambert transmission, while Schlick’s approximation blends the transmitted scene with reflection at grazing angles. The public material parameters expose absorption, index of refraction, normal-incidence reflectance, and specular response:
Depth, thickness, and bilateral-filter targets use the native framebuffer size. This preserves thin sheets and curved silhouettes in the 1280×720 recordings below.
4. User-level API
Fluid simulation is configured on SolverXPBD; surface generation and optical material settings are explicit rendering calls.
Listing 1. Mark particles as fluid and advance XPBD
Particle spacing at which a regular lattice is calibrated to rest density.
fluid_smoothing_length
Neighbor-kernel support radius; defaults to 1.8 times rest distance.
fluid_rest_density
Target density in kg/m³; may be inferred from particle mass and rest spacing.
fluid_cohesion
Bounded free-surface attraction in the range [0, 1].
fluid_viscosity
Per-substep blend toward neighborhood velocity in the range [0, 1].
fluid_relaxation
Scale applied to each density-projection correction.
fluid_max_neighbors
Optional work bound for over-compressed neighborhoods; zero disables the cap.
max_diffuse_particles
Capacity for visual foam and spray; zero disables diffuse emission.
5. Example simulations
Six runnable XPBD examples are shown at 1280×720 and 30 fps. Every clip contains ten seconds of simulation using the branch’s native ViewerGL fluid surface.
Figure 1. Archimedes screw, 130,001 particles. Fluid–rigid contact carries water upslope through the helical channel; discharged water transfers momentum to a freely rotating paddle wheel before returning to the reservoir.Figure 2. Dam break, 99,960 particles. A collapsing column impacts two rigid obstacles, testing incompressibility, free-surface cohesion, splashing, and contact response.Figure 3. Interactive tank, 100,300 particles. Rigid bodies with different densities float, settle, and sink under two-way particle contact.Figure 4. Three-fluid tank, 94,518 particles. Three independently configured particle groups share one container and interact with buoyant rigid bodies.Figure 5. Wave pool, 100,491 particles. A kinematic paddle drives sustained waves across a sloped beach while mixed-density bodies test buoyancy and contact stability.Figure 6. Robot cup transfer, 100,548 particles. A Franka arm carries an SDF-confined fluid through an 8.8-second manipulation trajectory without losing containment.
6. Performance
Measurements use Warp 1.17, CUDA Toolkit 12.9, driver 13.2, and an RTX 4090. Solver trials exclude ViewerGL; capture trials include two 60 Hz simulation steps, rendering, readback, and H.264 encoding per 30 Hz output frame.
The cup-transfer result is dominated by twelve inverse-kinematics iterations on each 60 Hz simulation frame and should not be interpreted as raw fluid-solver throughput. JSON sidecars beside each video retain the exact capture metadata.
7. Correctness and stability
Focused coverage spans density projection, fluid material terms, coupling, world isolation, surface generation, diffuse particles, and end-to-end examples.
Table 3. Validation performed on the integrated branch.
Area
Result
Coverage
XPBD fluid solver
61 pass · 1 expected skip
CPU and CUDA density, cohesion, viscosity, diffuse particles, SDF confinement, world isolation, capture, reordering, momentum, and non-finite recovery.
Fluid surface API
5 pass
Render-particle fitting, material grouping, lifecycle, visibility, and point fallback.
Fluid examples
9 pass
Nine CUDA examples with reduced test particle counts and their built-in physical assertions.
Archimedes screw
240 frames pass
Finite particle and body state, water lift, passive wheel rotation, basin containment, and revolute-bearing integrity.
Report captures
6 pass
Six H.264 simulations at 1280×720, 30 fps, and ten seconds each.
Representative commands
uv run --extra dev -m newton.tests -k test_solver_xpbd_fluid
uv run --extra dev -m newton.tests -k test_viewer_fluid
uv run --extra dev -m newton.tests -k test_viewer_layers
uv run --extra dev -m newton.tests -k test_shape_colors
uv run --extra dev -m newton.tests -k test_viewer_picking
uv run --extra dev -m newton.tests -k TestFluidExamples
uv run -m newton.examples fluid_xpbd_archimedes_screw --viewer gl --headless --num-frames 10
uvx pre-commit run -a
8. Conclusion
The branch adds a position-based fluid model directly to SolverXPBD, including density projection, cohesion, viscosity, vorticity, diffuse particles, multi-world isolation, and two-way rigid coupling. ViewerGL converts the solved particles into a native-resolution anisotropic surface through an explicit public API. Nine examples—including the Archimedes screw pump—exercise the implementation, while the measured dam break sustains a median 90.2 simulation fps at approximately 100,000 particles.