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]

whereE(r) is the potential energy for that distance
r is the distance between particles
ϵ is the depth of the potential well, basically the potential energy at the minimum or most stable
σ 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σ

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.


v = change in distance of nuclei, like velocity but only the direction toward the other nuclei
r = distance between nuclei
K = kinetic energy of v


v=drdt
K=12v2
taking the derivative of K with respect to t
dKdt=vdvdt
dividing both sides by v
dKdt1v=dvdt
substitute v for drdt
dKdt1drdt=dvdt
simplify to
dKdtdtdr=dvdt
the dt's cancel to become
dKdr=dvdt
The change in velocity over the change in time is just acceleration so
acceleration = dKdr
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
Taking the derivative of the Lennards-Jones potential gives
dE(r)dr=4ϵ[12(σr)13σ+6(σr)7σ]
So finally an easily implementable numeric solution
acceleration=4ϵ[12(σr)13σ+6(σr)7σ]

where the accelation is directly towards the other atom


In the simulation above this exact equation is implemented except when r approaches very close to σ 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 dt causing innaccuraccies in each time tick. To compensate the equation is disabled for when r<1.07σ, 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