Programming a 2D Ising Model/The effect of temperature
This is the fifth section of the Ising model experiment. You can return to the previous page, Accelerating the code, or jump ahead to the next section, The effect of system size.
We now have enough code to start to investigate the phase behaviour of our model. In the first instance, we are going to make plots of the average energy and magnetisation of the system as a function of temperature, to get an idea of where the change between energetic and entropic domination takes place, but we first have to make a small change to the code that averages the energy and magnetisation.
Correcting the Averaging Code
As you saw in the previous part of the experiment, when we begin from a random configuration, it takes a few Monte Carlo cycles to reach the equilibrium state of the system at a particular temperature. This manifests itself as a relatively sharp drop in the energy of the system in the first few hundred or thousand steps, before the energy starts to fluctuate around a constant value. If we want our average properties to be correct, we should only average in the region where the average energy and magnetisation are constant.
TASK 5a: The script ILfinalframe.py runs for a given number of cycles at a given temperature, then plots a depiction of the final lattice state as well as graphs of the energy and magnetisation as a function of cycle number. This is much quicker than animating every frame! Experiment with a few different temperatures and lattice sizes. Approximately how many cycles (remember, a cycle is steps) are needed for the system to go from its random starting position to the equilibrium state? Modify your __init__()
, statistics()
and montecarlostep()
methods so that the first cycles of the simulation are ignored when calculating the averages. Be careful of off-by-one errors. You should state in your report what period you chose to ignore, and include graphs from ILfinalframe.py to illustrate your motivation in choosing this number.
Running over a range of temperatures
The script ILtemperaturerange.py performs simulations of a given length over a range of temperatures. The temperature range is determined by the parameters given to the np.arange function near the top of the file. Starting from a uniformly aligned lattice, a simulation of length n_steps will be performed at temperature T_cold, and the average energy and magnetisation will be recorded. A new simulation of length n_steps will then be performed at temperature T_cold + dT, and so on until all temperatures in the range have been simulated. This results in a NumPy array of five columns: the temperature, then the four statistical quantities: ave_energies, ave_sqenergies (squared energies), ave_magnetisations, ave_sqmagnetisations (squared magnetisations).
TASK 5b: Use ILtemperaturerange.py to plot the average energy and magnetisation for each temperature, with error bars, for an 8 × 8 lattice. Use multiple repeats to calculate these error bars. Use your intuition and results from the script ILfinalframe.py to estimate how many cycles each simulation should be. The temperature range 0.25 to 5.0 is sufficient. Use as many temperature points as you feel necessary to illustrate the behaviour, but do not use a temperature spacing larger than 0.5. The NumPy function savetxt() stores your array of output data on disk — you will need it later. Save the file as 8x8.dat so that you know which lattice size it came from.
This is the fifth section of the Ising model experiment. You can return to the previous page, Accelerating the code, or jump ahead to the next section, The effect of system size.