GPU-accelerated simulation of a reaction-diffusion system in Rust, using wgpu.
The simulation can be run natively, or it can be compiled to WebAssembly and executed in a browser supporting WebGPU.
👉 Click here to run the simulation in your browser!
Reaction-diffusion systems model the concentration in space and time of chemical substances. As the name implies, the reagents can diffuse through space and react with each other.
The Gray Scott model is a specific reaction-diffusion system that simulates the behaviour of the following chemical reactions:
The concentration of reagents
The system is described by the following equations:
where:
-
$D_a$ and$D_b$ are the diffusion rates -
$f$ is the feed rate of substance$A$ -
$k$ is the kill rate of substance$B$
In particular:
- The term
$D_x \nabla^2 x$ describes how the substances diffuse - The terms
$-ab^2$ and$ab^2$ describe the decrement of substance$A$ and the increment of substance$B$ due to the reaction$A + 2B \rightarrow 3B$ - The term
$f(1-a)$ describes the replenishment of substance$A$ , as otherwise it would eventually all be consumed by the first reaction - The term
$(k+f)b$ describes the diminishment of substance$B$ due to the reaction$B \rightarrow C$
This system of equations is then discretised so that it can be simulated on a grid of cells, where each cell has specific concentrations of