Below the Curie temperature,
The energy of the configuration is:
Where
The magnetization is the average of the spin values:
This program follows these steps to simulate the gradual transition to magnetization:
1. A 2D square arraylist with random values of 1 and -1 is created according to desired size. These values represent the spin up and spin down.
2. To visually represent this grid, a JFrame is displayed with panels of blue and orange corresponding to 1 and -1, respectively.
3. A value in the arraylist is chosen at random and has its sign flipped. This represents the flip in spin.
4. The energy of the old and new configuration is calculated and compared.
5. If the energy of the new configuration is greater, a random number between 0 and 1 is generated. This random number is then compared to
6. The JFrame is updated in real time as an animation.
7. Returns to step 3 until either the amount of desired iterations is reached or the system reaches uniform spin.
The total energy and average magnetization of the system is stored and exported as a csv file (ising.csv). Run the ising.py file to generate plots of these quantities if desired.
For more reading regarding the physics see the wikipedia articles on Ising model, ferromagnetism, spin magnetic moment, and Monte Carlo methods.
Here is a video of a run with a 20x20 grid.
Below is the corresponding python plot for the energy and magnetization. The system completes with a uniform spin up configuration as can be seen by the magnetization of 1.
Here a run finishes with uniform spin down.
A run with a temperature above