Hover over the menu bar to pick a physics animation.

Having already solved the diffusion equation

`(deln)/(delt)=alpha(del^2n)/(delx^2)\ \ \ \ \ (0)`

for analog temperature or density diffusion, this will be the discrete particle version of the same physical behavior. Here we will concentrate on demonstrating the diffusion of particles and matching their computed density to the density expected from the diffusion equation. We've already demonstrated particle diffusion where the starting condition is with particles of type 1 on the left side of the container and type 2 on the right side. Here, instead, we will have a narrow swath of "dopant" particles centered in the container and immersed in a sea of host particles. Assuming that the initial dopant particle very time dependence of the dopant particle density, `n`, should then follow the expression (see Appendix 0) Assuming that the initial width of the dopant particle swath is very narrow, time dependence of the dopant particle density, `n`, should then follow the expression`n(x,t)=sqrt(1/(4pialphat))exp(-x^2/(4alphat))\ \ \ \ (1)`

where `t` is time and `alpha` is the diffusivity of the combined dopant and host particle seas. So the program objective is to fit the actual spread of the dopant particle distribution to equation 1 by computing an appropriate value for `alpha` using least squares fitting of the dopant density to the time varying density of the dopant.The diffusing particles (dopant spheres) are initially located in a very narrow band (swath) at the horizontal (x) center of the container. The blue dopant spheres start with three dimensional (3D) random velocity directions. The dopant spheres collide with other spheres of their own family as well as a much larger family of red host spheres. The blue dopant spheres progress away from the center band is by random walk and therefore follows the laws of diffusion. The x density numerical distribution (histogram) of the blue dop[ant pheres should form a gaussian as expressed by equation 1. The program fits this numerical distribution to an analog gaussian by minimizing the least squared deviation of the analog gaussian relative to the numerical density distribution. From the `sigma` of the fitted gaussian, the numerically derived diffusivity is computed.

This diffusivity is to be compared with the expected diffusivity (see Appendix 3):

`alpha=lambda/3 sqrt((v^2)_(avg)) `

where `(v^2)_(avg)=1/Nsum_1^N(v_i^2)` and `lambda` is the mean free path and is to be computed from`lambda=1/(n*4pi r^2) `

where N is the total number of host+dopant spheres per unit volume and r is the radius of the both sphere colors.It is not unusual to use least squares fitting to find the coefficient for an exponential like

`f(x)=a exp(-x/lambda)`

where `lambda` is the parameter that we need to find. For equation 1, however, we need to find the corresponding value for`n(x)=n_(max) exp(-x^2/sigma^2)`

So we need to use the arrays of data
`NA_i=n_i`

and

`XA_i=x_i^2`

`sum_1^Nn_i^2-[n_(max)exp(-x_i^2/(sigma^2))]^2`

and from `sigma^2` we can compute `alpha` as`alpha=sigma^2/(4t)`

where time is the time elapsed since the start button was pushed.For the computation of hard sphere velocities after collision see Appendix 1 below the Canvas. Also see Appendix 2 for a discussion of the rationale for equation 0. For the derivation of equation 1 see Appendix 0.

Since equation 1 assumes an infinite span in the x direction, the usual separation of variables method will not work. Instead we can use Fourier transforms to handle the second derivative with respect to x:

`u(x,t)=1/(2pi)int_-oo^ooU(k,t)exp(ikx)dk\ \ \ \ \ (A0.1`

where U(k,t) is the Fourier transform of a generic version of the dependent variable, u(x,t) in equation 0. The Fourier Integral Transform of `u(x,t)` is:`U(k,t)=int_-oo^oou(x,t)exp(-ikx)dx`

Taking the second derivative of U(k,t) with respect to x we have:`(del^2U(k,t))/(delx^2)=-k^2alpha(delU(k,t))/(delt)`

`U(k,t)=-alpha k^2(delU(k,t))/(delt)`

Then re-writing equation`(delU(k,t))/(U(k,t))=-k^2alpha(delt)`

with solution`ln((U(k,t))/U_0)=ln(-k^2alpha(t-t_0))`

so taking exponential of both sides and letting `U_0=1` and `t_0=0` we have:`U(k,t)=exp(-k^2alphat)\ \ \ \ \(A0.2)`

Finally we use equation A0.1 to convert `U(k,t)` back to `u(x,t)``u(x,t)=1/(2pi)int_-oo^ooU(k,t)exp(ikx)dk\ \ \ \ \ (A-0-1)`

Inserting the expression for `U(k,t)` we have:`u(x,t)=1/(2pi)int_-oo^ooexp(-k^2alphat)exp(ikx)dk\ \ \ \ \ (A0.3)`

This equation is solved by completing the square of the exponential's `k` terms. A similar integral, where we have completed the square, to the one in equation A0.3 is:`int_-oo^ooe^(-(ak^2+bk))dk=sqrt(pi/a)e^(-b^2/(4a))\ \ \ \ \ (A0.4)`

The exponent in equation A0.3 is:
`-alpha t k^2+ ik(x)`

so:
`a=-alphat`

and:
`b=i(x)`

and the term to subtract from the completed square is:
`b^2/(4a)=-(x^2)/(4alphat))`

Then the exponent can be written:

`-alpha t k^2+ ik(x)=
-alpha t (k-i(x)/(2alphat))^2-(x)^2/(4alphat)`

`1/(2pi)int_-oo^ooexp(-k^2alphat)exp(ikx)dk=sqrt(1/(4pialphat))e^(-x^2/(4alphat))\ \ \ \ \ (A0.5)`

For hard sphere collisions, we need to use both momentum and energy conservation to find the final velocities of particles. The change of momentum of one particle is the negative of the change of momentum of the other:

`m_1deltabb"v"_1=Mdeltavbbhat"u"=-m_2deltabb"v"_2\ \ \ \ \(A1.1)`

where bold characters indicate vectors and where `M` and `deltav` are presently unknown and `bbhat"u"` is a unit vector pointing between the centers of the particles. Now we'll insert equation A1.1 into an expression for the conservation of kinetic energy.`((m_1bb"v"_1+Mdeltavbbhat"u")cdot (m_1bb"v"_1+Mdeltavbbhat"u"))/m_1+ ((m_2bb"v"_2-Mdeltavbbhat"u")cdot (m_2bb"v"_2-Mdeltavbbhat"u"))/m_2= m_1bb"v"_1cdotbb"v"_1+m_2bb"v"_2cdotbb"v"_2`

Here the centered dot between vector quantities indicates the dot or inner product defined as follows:`bb"a"cdot bb"b"=a_xb_x+a_yb_y+a_zb_z`

where the subscripts `x y z` indicate the cartesian components of the `a` and `b` vectors. Cancelling the terms on the left with the terms on the right we obtain:`2bb"v"_1cdot(Mdeltav bbhat"u")-2bb"v"_2cdot(Mdeltav bbhat"u")+ (Mdeltav)^2/m_1+ (Mdeltav)^2/m_2=0`

`2(Mdeltav bbhat"u")cdot(bb"v"_1-bb"v"_2)+(Mdeltav)^2(m_2+m_1)/(m_1m_2)=0`

Solving for `Mdeltav` we obtain:`Mdeltav=-2(m_1m_2)/(m_1+m_2)bb hat "u"cdot(bb"v"_1-bb"v"_2)`

So the results for `M` and `deltav` are:`M=(2m_1m_2)/(m_1+m_2)`

and`deltav=-"u"cdot(bb"v"_1-bb"v"_2)`

Thus `bb"v'"_1` becomes:`m_1bb"v'"_1=m_1bb"v"_1+Mdeltavbbhat"u"\ \ \ \ \(A1.2)`

and `bb"v'"_2` becomes:`m_1bb"v'"_2=m_2bb"v"_2-Mdeltavbbhat"u"\ \ \ \ \(A1.3)`

where `bb"v"'` indicates the value of the velocity vectorIsaac Newton expressed the equation for heat flow across a very thin layer as the difference between temperatures from one side of the layer to the other divided by the layer thickness:

`(dq)/(dt)=-K (T_2-T_1)/(deltax)=-K(delT)/(delx)\ \ \ \ \ \(A2-1)`

where `(dq)/dt` is the heat flux (`("watts")/(m^2)`), `t` is time, `K` is the conductivity (`W/(m-K)`) of the layer. (It was Fourier who much later (1822) converted the discrete verion of the law to the analog version seen on the right.) If instead of heat flow, we had particle transport in a medium, it would follow the analogous equation. The important concept to understand is that, if the temperature gradient or the particle density gradient is constant throughout the thickness of the medium, then the temperature or density therein remains constant.If the gradient at a certain level of the thickness is reduced, then the temperature or concentration beyond that level can increase. This is where the diffusion equation with its second derivative with respect to x comes into play. Let's consider a bell shaped (gaussian) density distribution function: At the top the second derivative is negative so equation 0 says that the density will be declining there. At the left or right sides, the second derivative is positive so, according to equation 0, the density will be increasing there and, considering that all diffusion is the result of random walk, that is what we expect. So in conclusion we can just say that equation 0 is equation A2-1 converted to non-constant gradients.

`(deltan)/(deltat)=-(deln)/(delx)(v_x)_(avg)\ \ \ \ \ A3.1`

where This equation is really the equation for the gradient-induced drift (like heat conductivity) rather than the diffusion. It is not quite right because it does not take into account that half of the steps result in backward motion by an average of distance `lambda`. The number of steps per unit time that a particle makes is:`(dS)/dt=v_(avg)/lambda`

We want to convert equation A3-1 so that the right side has the`(deltan)/(deltat)=-(del^2n)/(delx^2)v_(avg)lambda\ \ \ \ \ A3.2`

From equation A3.2 we conclude that`alpha=1/3 v_(avg)lambda`

where the `1/3` factor comes from the fact that we `(v_x)_(avg)=1/3 v_(avg)`.