Gravity between particles: Downward gravity: van der Waals strength: Electrostatic strength: Cooling: Cooling on walls: Heating: Heating on walls: Wall Width (pixels): Wall Force Constant: Closed Top:
Width: Height: Generate at bottom:
Particle Type 1: Number Mass Charge Radius Polarizability Maximum initial velocity Colour Border Colour
Particle Type 2: Number Mass Charge Radius Polarizability Maximum initial velocity Colour Border Colour
Particle Type 3: Number Mass Charge Radius Polarizability Maximum initial velocity Colour Border Colour
Time Step per cycle: Cycles per frame:
A little HTML 5 experiment with some 2D physics, using Verlet integration to track the motions of particles.
In this version, particles can be influenced by three forces - gravity, electrostatic forces, and simulated van der Waals forces (as simulated by the Lennard-Jones potential). This latter force allows particles to repel each other at close range (the force is inversely proportional to the twelfth power of the distance between the centres of particles) and attract each other (force is proportional to the sixth power). Electrostatic interactions obey the inverse square law; you can also set the particles up to attract each other by gravity. There is also a downwards gravitational attraction. The particles also bounce off the walls, as if the walls were covered in perfectly bouncy springs.
This has been tested on Internet Explorer 11, Firefox 26, Chrome 31. I have got this working on Internet Explorer 11 on my Windows 8 machine, but not on my Windows 7 machine. It occasionally gets slow on Firefox - with some effort I have been able to stop it doing this most of the time, but not always.
Note the at the simulation is not always "numerically stable" - sometimes the calculations get wild, the error snowball at each step and particles fly out of the arena. There are various things you can do to avoid this, these will be explained with the parameters.
Various parameters can be tweaked. The time step per cycle and cycles per frame control how fast the simulation runs. Lower values of the time step make the simulation more accurate, and less prone to numerical instability - try turning this down if the simulation explodes. Cycles per frame affects how often the display updates.
You can adjust the overall strength of the various forces - stronger forces make numerical instability more likely. Also, you can add "heating" and "cooling", which can apply in general, or just to particles that are bouncing off the walls. "Cooling" removes a little bit of the velocity from each particle during each cycle - this gradually removes energy from the simulation, allowing structures to form. This generally should be kept low (e.g. 0.001 is considered "high"), although cooling on the walls can be higher - 0.5 is a good value. Heating makes a random tweak to the velocity on each cycle, simulating the addition of random thermal motion to each particle. Heating often requires higher values than cooling - 1.0 is a good value - it's often worth setting this after the simulation has come to rest. Another way to cool the simulation is to allow "evaporation" - turn "closed top" off, and high-energy particles will be able to fly out of the arena, reducing the amount of energy in the simulation.
When you change a runtime parameter, click away to another parameter, or press enter, and the change will take effect immediately.
Setup - the current version allows for three types of particle - those with a little programming knowledge and cunning should be able to add more. The number of particles per type is important, as the simulation slows down if there are too many. Try running in Google Chrome if you find it painfully slow. If there are far too many particles, the simulation might not start - try making the arena larger. It's generally good to balance the charge on the particles if you don't want the simulation to explode (either that, or use a lot of cooling and see the effect). "Polarizability" affects the strength of the van der Waals forces - the higher, the stronger.
You can also tell the setup to generate particles at the bottom of the arena - this is useful if you're trying to start a simulation without too much energy in it.
The overall code base allows for more advanced features - such as particles connected by springs. However, this is the basic version, and does not include these.
Get the code from my github page. See also my blog post introducing the thing.
Peter Corbett, 2013-2014
Back to ptc24 labs.