# Simulating diffusion from bulk to individual particles

I have a 2 compartment simulation. The first compartment simulates reactions using ODEs. The second compartment uses Brownian motion. I want to be able to have molecules from the ODE compartment diffuse into the Brownian compartment.

It would seem I need to answer this question:

What physics/maths governs the rate of diffusion out of a volume? Can I simply use Fick's law?

In a volume $V$, a large number number of particles starting to move according to Brownian motion at time $t=0$ from the position $x_0\in V$ will exit from $V$ at a rate that depends on time, on the geometry of the volume $V$, and on the position $x_0$. For instance in one dimension, particles diffusing from $x_0>0$ will enter the region $x<0$ at time $t$ with probability density $$p(t)=\frac{x_0}{\sqrt{4\pi Dt^3}}\exp\left(-\frac{x_0^2}{4Dt}\right).\tag{1}$$ (1) is called Smirnov density.
Let us note $q(x, t; x_0,t_0)$ the probability of being at $x$ at time $t$, when we started in $x_0$ at time $t_0$. We are interested in $$Q(t; x_0,t_0)=\iiint_Vq(x,t;x_0,t_0)\mathrm d^3x$$ the probability of being in $V$ at time $t$. Starting from the diffusion equation $$\partial_tq(x,t;x_0,t_0)=D\Delta_xq(x,t;x_0,t_0)$$ we obtain after integration over $x$ and using the fact that $\Delta_{x_0} Q=\Delta_x Q$ and $\partial q/\partial t_0=-\partial q/\partial t$ $$\frac{\partial Q}{\partial t_0}=-D\,\Delta_{x_0}Q(t;x_0,t_0).$$ As it is a diffusion equation where the variable are the initial conditions, it is called a backward diffusion equation. We now can set $t_0=0$ for simplicity. The solution we want is obtained with the initial boundary condition $$Q(0;x_0)=\left\{\begin{array}{cc}1&\text{if x_0\in V},\\0&\text{otherwise}.\end{array}\right.$$ You can check that $$Q(t;x_0)=\iiint_V \frac{\mathrm d^3x}{(4\pi Dt)^{3/2}}\exp\left(-\frac{(x-x_0)^2}{4Dt}\right).$$ And the exit rate at time $t$ is $$p(t)=\frac{\partial Q}{\partial t}(t,x_0).$$