Simulation Library

It is not very hard to numerically simulate interacting particle systems. There are pages on the internet where you can run some chosen systems. I quite like this applet. Code (in python) for simulating a stochastic Ising model and pictures can be found here.

I myself use Octave for simulating interacting particle systems. I have collected a number of executable scripts in this library. If you want to use my scripts, then download the libary, save it in a directory where you want to do your simulations and run "tar -xf library.tar" to unpack the archive. You will also need to have Octave installed on your computer. It is possible that the scripts also function under Matlab, which is a very similar program (but not freeware). Here is a list of the main scripts in the library with a short description.

  • voter1 Simulates a one dimensional voter model.
  • voter2 Simulates a two dimensional voter model.
  • voter3 Simulates a three dimensional voter model.
  • contact1 Simulates a one dimensional contact process.
  • contact2 Simulates a two dimensional contact process.
  • Potts1 Simulates a one dimensional Potts model with Glauber dynamics.
  • Potts2 Simulates a two dimensional Potts model with Glauber dynamics.
  • coop1 Simulates a one dimensional system of particles performing coalescing random walks with cooperative branching.
  • rebel1 Simulates a rebellious voter model.
  • disIsing2 Simulates a dissipative Ising model in two dimensions.
  • disIsing3 Simulates a dissipative Ising model in three dimensions.
  • spinflip2 Simulates a general class of two dimensional spin flip models.
  • spinflip3 Simulates a general class of three dimensional spin flip models.
  • If you run the script of a one dimensional model you will see a space-time picture with space plotted horizontally and time running upwards. If you run the script of a two dimensional model you will see the initial state. To move forward or backward in time, you should run the scripts:

  • filmforward Jumps to the next time.
  • filmbackward Jumps to the previous time.
  • If you run the script of a three dimensional model you will see the the upper, left and front side of a cube. You can again use the scripts filmforward and filmbackward to move forward or backward in time. All systems are simulated on a lattice with periodic boundary conditions.

    The library also contains a few other scripts that are functions that are called from the other scripts. These are:

  • fliprates Called from spinflip2 and spinflip3. Edit this script to simulate general spin flip systems where the flip rates at a given site are a function of the type of that site and the number of neighbors of each type. The default setting is for the voter model.
  • makepic Used for creating the colorful pictures.
  • neigh Used to calculate the neighbors of a site (with periodic boundary conditions).
  • choose Used to pick a site in a one dimensional lattice according to a given probability distribution.
  • choose2 Used to pick a site in a two dimensional lattice according to a given probability distribution.
  • choose3 Used to pick a site in a three dimensional lattice according to a given probability distribution.
  • If you want to change the parameters of the model or change the initial state, then open the scripts in a text editor and change the appropriate lines. If your favorite interacting particle system is not included in the scripts, then you can write your own script, using one of the scripts above as a template. For spin flip systems, it suffices to define the rates of your choice in fliprates.

    Octave pictures can be exported as pdf files that can then be included in Latex. For three dimensional systems I use Tikz to give the simulation results a three dimensional appearance. Running Latex on the example document cube.tex will produce a 3D visualization of the pdf file voter3.pdf.

    Exporting a lot of Octave figures is a tedious job. Octave moreover exports these figures including surrounding white space which has to be removed in an image editing program before it can be used in Latex. For Linux users, I have written three scripts that make it easier to export pictures. After running a simulation, in Octave run the script present. This produces a number of files with the extension .pre. Running the script pre2pict in a terminal will convert these into pdf files. This last step works only under Linux, unfortunately. Make sure to save both pre2pict and pre2ppm (which is called from pre2pict) as executable files in your bin directory.


    Jan Swart, Last update: 29.9.2021.