Intermolecular forces condensation simulation



I modeled it off of the Lennard-Jones potential (wikipedia)


Each sphere is basically one atom or molecule and it's potential energy is the sum of its Lennards-Jones potential relative to every other atom

E(r)=4ϵ[(σr)12(σr)6]E(r) = 4\epsilon [\left(\dfrac{\sigma}{r}\right)^{12} - \left(\dfrac{\sigma}{r}\right)^{6}]

whereE(r)E(r) is the potential energy for that distance
rr is the distance between particles
ϵ\epsilon is the depth of the potential well, basically the potential energy at the minimum or most stable
σ\sigma is where potential energy is zero, basically the size of the particle.

Note that particles won't go to the distance where potential energy is zero, but will go to the bottom of the potential well where potential energy is negative, slightly before the edge of the particle where potential energy is zero.


The bottom of the energy well is r=21/6σr = {2^{1/6}}\sigma

A more accurate simulation would put the potential energy into the potential energy function in Schrödinger's equation at every point to model the change in the probability waves of atoms. But that is really hard to program since it uses derivatives of vector fields. Instead, it can be approximated for a worse but way faster and easier numerical solution.


vv = change in distance of nuclei, like velocity but only the direction toward the other nuclei
rr = distance between nuclei
KK = kinetic energy of vv


v=drdtv = \dfrac{dr}{dt}
K=12v2K = \dfrac{1}{2}v^2
taking the derivative of KK with respect to tt
dKdt=vdvdt\dfrac{dK}{dt} = v\dfrac{dv}{dt}
dividing both sides by vv
dKdt1v=dvdt\dfrac{dK}{dt}\dfrac{1}{v} = \dfrac{dv}{dt}
substitute vv for drdt\dfrac{dr}{dt}
dKdt1drdt=dvdt\dfrac{dK}{dt}\dfrac{1}{\frac{dr}{dt}} = \dfrac{dv}{dt}
simplify to
dKdtdtdr=dvdt\dfrac{dK}{dt}\dfrac{dt}{dr} = \dfrac{dv}{dt}
the dtdt's cancel to become
dKdr=dvdt\dfrac{dK}{dr} = \dfrac{dv}{dt}
The change in velocity over the change in time is just acceleration so
acceleration = dKdr\dfrac{dK}{dr}
Now let's assume that kinetic energy is the only energy exchanged with potential energy, ignoring electron levels, etc. So the only place a drop in potential energy can go is into kinetic energy, so
acceleration = dKdr=dE(r)dr\dfrac{dK}{dr} = -\dfrac{dE(r)}{dr}
Taking the derivative of the Lennards-Jones potential gives
dE(r)dr=4ϵ[12(σr)13σ+6(σr)7σ]\dfrac{dE(r)}{dr} = 4\epsilon [-12\dfrac{(\dfrac{\sigma}{r})^{13}}{\sigma} + 6\dfrac{(\dfrac{\sigma}{r})^{7}}{\sigma}]
So finally an easily implementable numeric solution
acceleration = 4ϵ[12(σr)13σ+6(σr)7σ]4\epsilon [-12\dfrac{(\dfrac{\sigma}{r})^{13}}{\sigma} + 6\dfrac{(\dfrac{\sigma}{r})^{7}}{\sigma}]

where the accelation is directly towards the other atom


In the simulation above this exact equation is implemented except when rr approaches very close to σ\sigma because the Lennards-Jones potential has an extremely steep incline, so the derivative makes an extremely large acceleration. Because the simulation only does one physics tick in a set time frame it can't simulate sharp changes. Realistically the atoms would be pushed apart before it reaches that close the simulation does have atoms get that close due to a large enought dtdt causing innaccuraccies in each time tick. To compensate the equation is disabled for when r<1.07σr < 1.07\sigma, and instead applies an elastic collission which is closer to real life than the numerical solution. The elastic collision equation in 3D is taken from here


There are still glitches in the elastic collision detection since each sphere is only allowed one collision with every other sphere. When around a lot of other spheres it is pulled in harder than the elastic collisions push it out. The solution would to keep colliding a sphere with its neightbor until the velocity vectors are moving apart within the same physics tick. But that uses a lot of computing power and the simulation already doesn't run well, but the basic concept of IMF simulation is still there