vicflow
GPU-accelerated 2D vortex-in-cell fluid simulator for generative art. High-Reynolds flows on CUDA, ROCm and Apple Silicon. Based on Mark J. Stock's vic2d.
Status: early development. What exists today is the solver on periodic domains and between no-slip walls, with density, buoyancy and color, validated against vic2d, with a NumPy reference backend and a PyTorch backend (CUDA, Apple Silicon, CPU) whose advection runs as a fused native kernel on GPUs (Triton, Metal). Obstacles, open boundaries and scene files come next.
Installation
pip install vicflow # NumPy backend (CPU)
pip install "vicflow[torch]" # adds the PyTorch backend: CUDA, Apple Silicon (MPS), CPU
vicflow needs Python 3.11 or later. With an NVIDIA driver older than 580 (CUDA 12.x), install PyTorch from https://download.pytorch.org/whl/cu126 before vicflow: the PyTorch wheels on PyPI need CUDA 13.
Method
The flow is described by its vorticity ω. Each time step:
- diffuses ω (explicit 5-point scheme),
- advects it semi-Lagrangially: every grid node traces its fluid back with RK4 and interpolates ω there with the 4th-order M4′ kernel,
- recovers the velocity by solving ∇²ψ = −ω with FFTs, u = ∂ψ/∂y, v = −∂ψ/∂x.
Each axis is periodic or bounded by no-slip walls. Walls carry ψ = 0 (a sine transform, done as an FFT of the odd extension), and create vorticity: at every step the wall vorticity is set from the slip velocity next to it, then diffuses into the fluid.
This is vic2d's scheme; its low numerical diffusion is what makes Reynolds numbers in the millions possible.
Example
import numpy as np
from vicflow import Grid, Simulation
grid = Grid.square(256)
x, y = grid.coords()
vorticity = np.sin(2 * np.pi * x) * np.sin(2 * np.pi * y)
sim = Simulation(grid, vorticity, viscosity=1e-4, dt=0.01)
sim.run(100)
print(sim.time, sim.kinetic_energy())
Fields have shape (nx, ny) and are indexed [ix, iy], with y pointing up,
like vic2d. Images and matplotlib put rows (y) first and y down, so plot a
field transposed: plt.imshow(sim.vorticity.T, origin="lower"). The domain's
longest side has length 1.
Fields can be replaced between steps, e.g. to add a vortex in the middle of a
run: sim.vorticity = sim.vorticity + extra. The velocity is recomputed from
the new vorticity. Changing a field in place (sim.vorticity[...] += ...)
does not update the velocity: assign the whole field.
A box with walls all round, or a channel periodic in x:
box = Grid.square(256, "wall") # 257 x 257 nodes, wall nodes included
channel = Grid(512, 128, "periodic", "wall") # 512 x 129 nodes
A density field is carried by the flow and drives it through buoyancy
(Boussinesq); with the default gravity, pointing down, heavy fluid sinks
(vic2d's points up).
At a sharp interface the M4′ interpolation overshoots and leaves grid-scale
ripples; the default limiter="scalars" clips the advected density and color
to their local range, and leaves the vorticity alone.
Rayleigh-Taylor instability, heavy fluid over light:
grid = Grid(512, 256, "periodic", "wall")
x, y = grid.coords()
density = np.tanh((y - 0.25 - 0.01 * np.cos(2 * np.pi * 4 * x)) / 0.01)
sim = Simulation(
grid,
np.zeros(grid.shape),
viscosity=1e-5,
dt=0.002,
density=density,
diffusivity=1e-5,
buoyancy=1.0,
)
Color is a stack of passive scalars of shape (channels, nx, ny), usually
RGB, carried and diffused (color_diffusivity) in the same advection pass.
vicflow.image reads and writes PNGs (8 or 16 bits per channel) with y
pointing up, like vic2d; the image needs one pixel per node:
from vicflow.image import read_color, write_image
color = read_color("start.png") # (3, width, height), values in [0, 1]
sim = Simulation(
grid,
vorticity,
viscosity=1e-5,
dt=0.002,
color=color,
color_diffusivity=1e-6,
)
sim.run(500)
write_image("frame.png", sim.color, bits=16)
On a GPU, install the torch extra (pip install "vicflow[torch]") and pick
the PyTorch backend; it uses CUDA or Apple's MPS when available, in float32,
with a fused advection kernel (Triton on NVIDIA, Metal on Apple Silicon; AMD/ROCm
should work through Triton but is untested).
sim = Simulation(grid, vorticity, viscosity=1e-4, dt=0.01, backend="torch")
sim.run(100)
w = sim.to_numpy(sim.vorticity)
Replaying a vic2d run
vicflow's defaults favour stable, artefact-free runs over matching vic2d bit for bit. To reproduce a vic2d run, pass its conventions explicitly:
sim = Simulation(
grid,
vorticity,
viscosity=1e-4,
dt=0.01,
density=density,
gravity=(0, 1), # vic2d's gravity points up (only with a density field)
vic2d_mean_flow=True, # its mean-velocity convention, which depends on the grid origin
time_order=1, # velocity frozen during the backtrace (default 2: extrapolated)
limiter="none", # no limiter (default "scalars")
)
time_order=1 is about 20 % faster, but its kinetic energy drifts upwards at
large time steps and it can blow up next to walls.
Public API
Grid, Simulation and the vicflow.image module. The other modules
(vicflow.poisson, vicflow.advect, vicflow.backends, ...) are internal and
may change between versions.
Development
Needs uv.
uv sync # create the environment
uv run pytest # tests, including the comparison with vic2d
uv run ruff check . # lint
uv run ruff format . # format
uv run python benchmarks/step_time.py # ms per step for every available backend
Work happens on dev; main only receives stable, tagged versions.
tests/reference/
holds the vic2d runs used as an oracle and the scripts that regenerate them.
validation/turbulence_vs_legacy.py runs a larger
case (decaying turbulence, 1024²) with both codes and draws them side by side.
Citing
If you use vicflow in your work, please cite it:
@misc{vicflow2026,
author = {Quentin Petit},
title = {vicflow: a {GPU}-accelerated {2D} vortex-in-cell fluid simulator for generative art},
howpublished = {\url{https://github.com/petitquentin/vicflow}},
year = {2026}
}
Credits
The numerical method comes from vic2d by Mark J. Stock. If you use vicflow, please also cite it:
@Misc{vic2d2004,
author = {Mark J.~Stock},
title = {vic2d: A command-line two-dimensional fluid simulator using a novel semi-Lagrangian advection technique},
howpublished = {\url{https://github.com/markstock/vic2d}},
year = {2004}
}
License
GPL-3.0-or-later, like vic2d. See LICENSE.
Metadata
Release files for vicflow 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vicflow-0.1.0.tar.gz | 41.2 kB | With provenance | Details for vicflow-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vicflow-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for vicflow-0.1.0-py3-none-any.whl |
Total release size: 86.4 kB
Release files / vicflow-0.1.0.tar.gz
| Download URL | vicflow-0.1.0.tar.gz |
|---|---|
| Size | 41.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a83aea501a06c33dd2a59249dbbb5f433e97df2c609a07811349de1be07ea2f3
|
|
BLAKE2b-256 checksum How to use checksums |
377a8d7d8a034173d454a4d083b0e96c048a9f913455731ce1830991dbfb830c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / vicflow-0.1.0-py3-none-any.whl
| Download URL | vicflow-0.1.0-py3-none-any.whl |
|---|---|
| Size | 45.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d94effc7fe4805a971fd642b2c3c7b0c8da5c55d89f9249c8a39a565dff7c86f
|
|
BLAKE2b-256 checksum How to use checksums |
70310295ca3a303b3c440a4e88ec3446e44754105128daeddf2eb171a508716d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logSecurity for vicflow 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for vicflow-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.