XISING is a C program which illustrates a Monte Carlo simulation of a simple statistical mechanical system, by Michael Creutz.
The Ising model demonstrates ferromagnetism, displaying a second order phase transition from a disordered state at high temperature to an ordered state when cool. The program allows dynamical observation of this system under several simple Monte Carlo algorithms.
The system is a two dimensional array of spins, each of which is represented by a bit in a bit map displayed on the screen. Black and grey represent the two possible states of a given spin. The energy of the system is entirely determined by nearest neighbor pairs. If two neighbors are the same, then the energy has one value, and if they differ, it is higher by two units.
The display shows the spins in the image labeled "spins." This is above another bit map labeled "changes," representing the spins being changed under the current algorithm. The display has a thermometer to indicate the temperature and various buttons for controlling the updating. The inverse temperature, beta, is displayed above the thermometer. The critical value for beta is exactly known to be 0.5*log(1+sqrt(2))=.44068.... The critical temperature is marked on the thermometer.
One set of three buttons, labeled "run free," "heat," and "cool," are for adjusting the temperature. Normal running is with the energy/temperature conserved, but to heat or cool the system toggle the appropriate button. In a canonical mode (see below) the temperature can also be adjusted by clicking on the thermometer.
Another set of buttons controls the boundary conditions. The choices include "periodic," wherein the spin neighbors at an edge are those on the opposite edge, and "antiperiodic," which is similar but with the the wrapped neighbors inverted. The other two boundary choices are constant white or black. The latter two are not permitted when the cluster algorithm, discussed below, is in operation.
The algorithm button toggles between two alternatives. The program starts with a "local" updating scheme. This can be toggled into a variation of the "cluster" algorithm of R.H. Swendsen and J.-S. Wang, Physical Review Letters 58, 86 (1987), where a large block of spins is grown and then flipped in unison.
At the bottom of the display is a button that switches between a canonical and a microcanonical updating. The latter case is described in some detail in my paper Physical Review Letters 50, 1411 (1983). A set of "demons" circulates around the lattice trying to flip spins. Each carries a two bit sack of energy ranging from 0 to 16 units in steps of 4. Any energy change associated with a spin flip is compensated by a change in this sack. If the demon's sack cannot accommodate the change, the flip is rejected. In this mode the temperature is not fixed, but calculated from the average demon energy. Note the thermal fluctuations on the thermometer when in a microcanonical mode. The microcanonical version of the cluster algorithm is discussed in Physical Review Letters 69, 1002 (1992).
The program attains its speed by updating spins one word at a time using multispin coding and bit manipulation. The canonical modes are obtained by allowing the demons to be occasionally refreshed by visiting a heat bath. When in one of these, a mouse click near the thermometer will adjust the temperature to the value pointed at by the cursor. Clicking elsewhere in the main window when the system is paused with any algorithm does a single step. The remaining buttons, "quit" and "pause" should be self explanatory, as should the "speed" slider. The lattice dimensions can be adjusted by resizing the window.
After starting the program, press the heat button and observe how the domains get small and the acceptance, as shown in the "changes" display, gets large. Then press the cool button until the temperature, as displayed in the thermometer, is below the critical value. Watch the domains grow as the system magnetizes. Note how the acceptance is largest at the domain boundaries.
In many cases a single domain will grow to dominate the system. If, however, bands of different phases wrap around the lattice in either a horizontal or vertical direction, then the system can have a hard time deciding which phase will dominate and it can remain metastable for a long time.
Switching the boundary conditions to antiperiodic forces the system to have at least one domain wall. Switching between black and white edges allows one to create large included domains which gradually shrink away.
Returning the system to near the critical temperature, switch to the cluster algorithm. In this case a few iterations quickly give independent configurations. Heat the system and observe how the typical cluster size becomes quite small. Cooling the system below the critical temperature gives single clusters covering most of the system, which then flashes between dominantly spin up and down.
To illustrate the power of the cluster approach, use the local algorithm to heat the system to a high temperature and then rapidly quench it to somewhat below the critical value. Before the local approach has had time to have the smaller domains dissolve in the dominant one, change to the cluster approach. Note how quickly the cluster sweeps anneal out the included domains.
FOREST_FIRE_SIMULATION, a C program which models the occurrence of fires in a forest, and displays the status of the forest using X Windows, by Michael Creutz.
ISING_2D_SIMULATION, a C program which carries out a Monte Carlo simulation of an Ising model. a 2D array of positive and negative charges, each of which is likely to "flip" to be in agreement with neighbors.
MANDELBROT, a FORTRAN90 program which generates an ASCII PPM image of the Mandelbrot set;
REACTOR_SIMULATION, a FORTRAN90 program which is a simple Monte Carlo simulation of the shielding effect of a slab of a certain thickness in front of a neutron source. This program was provided as an example with the book "Numerical Methods and Software."
SHOWME, a C program which uses the X Window library to display triangulatons.
X_WINDOW_DISPLAY, a discussion of the issues involved when an X Window program on a remote machine needs to know how to get graphics information back to your local display.
XBOIDS, a C program which simulates the behavior of a flying flock of animals, displaying the results using X Windows, by Conrad Parker.
XWAVES, a C program which simulates the behavior of solution of certain forms of the wave equation, displaying the results using X Windows.
X_WINDOW, C++ programs which demonstrate some simple uses of the X Window library.
You can go up one level to the C source codes.