# Diffusion

## 2d Model

The example model single-compartment-diffusion is a single compartment that contains two species: ‘fast’ and ‘slow’, each with the same analytic initial distribution

The two species have different diffusion coefficients: \(D=1cm^2/s\) for species ‘slow’, and \(D=3cm^2/s\) for species ‘fast’, and the model contains no reactions.

## Analytic solution

For this system without reactions, we are simulating the two-dimensional diffusion equation,

where

\(c_s\) is the concentration of species \(s\) at position \((x, y)\) and time \(t\)

\(D_s\) is the diffusion constant for species \(s\)

For the initial condition \(c_s(t=0) = \delta(x)\delta(y)\), the analytic solution at time t of this equation is the heat kernel:

and a solution for our initial condition can then be found with an overall rescaling and a shift in t:

where \(t_0 = 9/D_s\). Note that this solution ignores boundary effects, so will not be valid at late times or close to the compartment boundary.

The total amount of species in the compartment is a conserved quantity,

and this is also valid at late times, since our zero flux Neumann boundary conditions also conserve the amount of species in the compartment.

## 3d Model

The example model single-compartment-diffusion-3d is a single compartment that contains two species: ‘fast’ and ‘slow’, each with the same analytic initial distribution.

Key differences from the 2d example above are that the origin of the geometry lies in the centre of a 100cm^3 cube, with initial species concentration given by:

and the heat kernel in 3d is given by:

which gives the solution at time t (again ignoring boundary effects):

where \(t_0 = 9/D_s\), with total amount of species in the compartment a conserved quantity: