Validation-first Python/NumPy implementation of a 2D incompressible MAC grid fluid simulator.
Included in v1:
- Row-major
[j, i]MAC grid arrays. - Closed-wall normal velocity boundaries.
- Bilinear sampling for cell and face fields.
- Divergence, Jacobi pressure solve, and pressure projection.
- Semi-Lagrangian dye and velocity advection.
- Deterministic mouse force and dye injection APIs.
- Headless dye renderer.
Excluded from v1: viscosity, vorticity confinement, obstacles, free surfaces, FLIP/PIC, buoyancy, turbulence, adaptive meshes, advanced UI, and real-time performance targets.
python -m pytest
python -m macfluid.render --steps 10 --out smoke.png
python -m macfluid.interactiveThe renderer writes a PNG file without requiring a display server.
python -m macfluid.interactive- Drag with the left mouse button to inject velocity and dye.
- Press
spaceto clear the simulation. - Press
sto save the current dye image toartifacts/interactive-screenshot.png. - Press
qorescto quit.
Useful options:
python -m macfluid.interactive --nx 96 --ny 96 --scale 6 --pressure-iterations 220The interactive viewer uses Python's standard tkinter window toolkit, so it does not add a runtime dependency beyond NumPy.