Phys 4 Project solutions. November 4, 7 Note the model and units Quantities The D Ising model has the total energy E written in terms of the spins σ i = ± site i, E = σ i σ j (.) <ij> where < ij > indicates we should take the sum over nearest neighbour sites. Like in the D case we will be calculating the energy per site E and the magnetisation M, Units E E = (number of sites) = E N (.) i M = σ i (number of sites) = i σ i N. (.3) In the code we have set = at k B =. has units of energy and so does k B T. So these choices are equivalent to measuring all energies in units of (so that E is a dimensionless quantity) and all temperatures in units of k B (so that k BT is a dimensionless quantity). M is naturally dimensionless as it is the average value of the difference of two integers. There will be a dimensionfull factor which depends on the gyromagnetic ratio that relates M in the Ising model to the magnetisation field studied in electrodynamics. Part : The solutions to each of the parts -4b has their own script all of which call the function isingd which implements a Monte Carlo simulation of the D Ising model. A minimal list of changes that need to be made to the code on the website for the one dimensional Ising model (the file isingd.m) are as follows (line numbers here refere to those in the original isingd.m): line 5: should be modified so that the initial grid is N N ( rand(n,) rand(n,n)). line 9: calculation of initial energy should be adjusted now that grid is an N N array (sum(grid.*circshift(grid,)), sum(sum(grid.*circshift(grid,[,])))). line : likewise for the magnetisation (Magnet=sum(grid); Magnet=sum(sum(grid));) line : trials should be a N t array ( randi(n,t,) randi(n,t,) ). line 4: s now has two components ( trials(i) randi(trials(i,:) ). lines 5 and 6:The code that implements the periodic boundary conditions need to be modified. We need to specify the row and column of all sites and we need to include the neighbours above and below a given site (see code for this modification). line 7: de must include contributions from neighbours above and below. line 36: normalise vectors by the total number of spins N instead of N. line 46: the 5*N is the themalisation time and will need to be changed later on. The code in the solutions has the following additional modifications:
The total number of of Monte Carlo (MC) steps (t) and the number of steps required for thermalisation (nthrm) are now inputs. In the code Elist and Mlist only stores values from MC steps after nthm (this means nthm should be set to zero when studying thermalisation). There is an optional input (grid) and function outputs the final grid. This allows you to input the initial configuration of the spins and output the final configuration. This can be used to break long up runs into multiple small runs if memory is an issue. It will also allow us to use simulated annealing to speed up the thermalisation in part 3. The variable plot_flag can now be,, or. When plot_flag is the function outputs the average energy, the average magnetisation, the averaged magnetic susceptibility, and the average heat capacity (with averages only taken over the thermalised configurations). When plot_flag its the function out puts two arrays giving a time series of the magnetisation (Mlistout) and energy (Elistout) which will be used for determining thermalisation. Part : The solution to part can be run by running the script part.m which requires the function isingd.m and the graphing script GraphsP.m. Warning: all the scripts in the solution take 3 min to about an hour to run on the TA s laptop. Method and results When thermalisation has occurred the energy per spin and magnetisation should reach stable values with some random fluctuations. To eliminate the fluctuations the script script averages the M vs time and E vs time curves at k B T/ = 3 over nav= different runs for each different value of N. Scaling with N and graphs The results are shown in figure. in which we have plotted the energy per spin and magnetisation plotted against the number of Monte Carlo steps scaled by N. The curves for the energy per spin collapse to one curve indicating that the thermalisation time is scaling like N and show the decrease of the energy from its initial value close to (for random initial conditions) to a final energy which is less than zero. The magnetisation curve just shows small random fluctuations around zero (one would expect this as T = 3/k B is a relatively high here so the magnetisations should fluctuate around zero and as it starts at approximately zero all we see is fluctuations). We can understand why the thermalisation time might scale like N as follows. To reach a valid thermal configuration we might expect to have to flip a fixed percentage of the spins the time required will scale with the number of spins N. Determining thermalisation We can see from figure. that the average energy has definitely reached its final equilibrium value after 8N Monte Carlo steps so that 8N Monte Carlo steps is a sufficient thermalisation time at this temperature (in fact N would be sufficient in this case). 3 Part 3: The solution to part 3 can be run by running the script part3.m which requires the function isingd.m and the graphing script GraphsP3.m.
-. -. -.3 -.4 -.5 N= 4 5.3.. -.6 -.7 -.8 -. -. -.9 4 N 8 N -.3 4 N 8 N Figure.: Thermalisation when k B T/ = 3. The legend on the left hand plot gives the value for N and applies to both figures. The left hand plot shows the average energy per spin vs the number of Monte Carlo steps (note the scaled x axis). The right hand plot shows the average magnetisation vs the number of Monte Carlo steps (note the scaled x axis). Methods The script calculates the average magnetisation (of the absolute value, see below) M, the average energy per spin E, the heat capacity per spin C v, and the magnetic susceptibility χ M from 5 5 N configurations taken after 8N thermalisation Monte Carlo steps for configurations with N =,, and 5 for temperatures. k BT.6. Speeding up the thermalisation. We use the scheme known as simulated annealing to speed up the thermalisation where the highest temperature is run first then the final state of the system is kept and used as the starting point for the next (lower) temperature. The idea is that a thermalised state with k BT =.6 is closer to a thermalised state at k BT =.58 than a random initial state is (and so on). Calculating the susceptibility and heat capacity. The correct formula for calculating the magnetic susceptibility is the following ( ) χ M = k B T N σ i σ i. (3.) i From this expression we can see that the magnetic susceptability has the dimensions of (energy) in our units. For calculating the heat capacity per spin { E C v = k B T N E } (3.) where E is the total energy. We see that heat capacity has the same dimensions as k B. Note that in terms of E and M these quantities are χ M = N { M M } (3.3) k B T and for calculating the heat capacity per spin i C v = N k B T { E E }. (3.4) 3
Also the question didn t specify whether you should calculate the heat capacity per spin or the total heat capacity so it was equally valid to give the total heat capacity Cv total which can be calculated by the following formulae, There where two common mistakes here: C total v = k B T { E E } = N 4 k B T { E E }. (3.5). If the absolute value of of calculating M M instead of M M (in practice you had to be careful about when the absolute value of mlist in the code).. Getting the factors involving with N wrong, note that the D code for the tutorial included correct calculations for the above quantities. Here you needed to be careful about when you normalised Elist and Elist in the code. A note on the magnetisation. For a finite system even at low tempertures if the simulation time is large enough the magnetisation will always average to zero. This is because if we leave the Monte Carlo algorithm running long enough eventually the unlikely event of all the spins reversing direction will occur so the configurations {σ i } and { σ i } (where all the spins are flipped) are equal likely. To get around this we plot the mean of the absolute value of the magnetisation. Results and explanation Plots of the results are shown in figure 3.. We now descibe the physical significance of what is happening in these plots. The magnetisation. We see that the magnetisation (actually the absolute value of the magnetisation) per spin is close to one at the lowest temperature here the spins are almost all aligned as the thermal energy required to anti align them is not available. As temperature increases the magentisation decreases, at first the decrease is the same for all values of N then the magnetisation starts drop off more rapidly for the larger systems this is where the phase transition occurs. The energy per spin. The energy increases as we increase the temperature because of thermal fluctuations. Fluctuations in the energy per spin are bigger for the smaller system which results in our energy curve being messier for the N = case. The magnetic susceptibility. The magnetic susceptibility curves for the larger samples have a sharp peak. In the N = 5 case we can see clearly that this peak occurs when the magnetisation starts to drop off this signifies the phase transition. Note also that at high temperatures when the system is well into the paramagnetic phase the magnetic susceptibility is approximately independent of N. The heat capacity The heat capacity curves all have a peak the peak is sharper and more pronounced with a larger N this marks the position of the phase transition. At low temperature the heat cappacity is approximatly independent of N. How things change with N We can see in 3. that the signatures of the phase transition, the rapid drop-off of M and the peaks in χ M and C v are more pronounced when N is higher. Strictly the phase transistion is a property of a system in the thermodynamic limit N. As N we expect each of the curves M (T ), E (T ), χ M (T ), and C V (T ) to converge to a fixed curve. The N curves for M (T ) and E (T ) have a sharp but continuous change at the critical point. The N curves for χ M (T ) and C V (T ) will have singularities at the critical point. So the behaviour we see is 4
.9.8 -.3 -.4.7.6.5.4.3.....3.4.5.6 -.5 -.6 -.7 -.8 -.9...3.4.5.6 45 4 35 3 5 5 5..8.6.4..8...3.4.5.6.6...3.4.5.6 Figure 3.: The results of the Monte Carlo simulation for the D Ising model described in part 3. In plots figures the results for the square lattice of length N = are marked with s, with N = are marked with s, and with N = 5 are marked with s. In the top left we have the magnetisation, in the top right we have the energy per spin, in the bottom left we have the magnetic susceptibility, and in the bottom right we have the heat capacity per spin. to be expected. A rough physical explanation is as follows. The critical point marks a balance between the energetic preference to align and the entropic term in the free energy which favours configurations when they aren t aligned. So the system is right on the edge and can support large fluctuations which leads to χ M and C V (these are proportional to fluctuations in the magnetisation and energy respectively) being vary large. 4 Part 4: Part four can be divided into two parts: (i) determining a thermalisation time which is sufficient to thermalise the system close to the phase transistion (ii) use the thermalisation time to improve the plots in part 3 and use these plots to obtain a good estimate for the phase transition. I consider these two parts separately. Thermalising the system close to the critical point. The solution to part 4a can be run by running the script part4a.m which requires the function isingd.m and the graphing script GraphsP4a.m. The code just repeats the calculation from part but at a temperature k B T/ =.3 which is close to the critical temperature estimated by picking the peak of the χ M curve. As thermalisation takes a lot longer here. The code 5
- -.5 -. -.5 -. -.5 -.3 -.35 -.4 -.45 - -. -. -.3 -.4 N= 5 -.5 4 N 8 N.8.6.4. -. -.4 -.6 -.5 5 N 5 N -.8 5 N 5 N Figure 4.: Testing the thermalisation of the system described in part 4. The legend left hand plot gives the value for N and applies to both figures. The left hand plot shows the average energy per spin vs the number of Monte Carlo steps (note the scaled x axis) up to 5N steps. The right hand plot shows the average magnetisation vs the number of Monte Carlo steps (note the scaled x axis). averages over 5 realisations (half the number used in part ) of the Monte Carlo algorithm. The resulting plots of average magnetisation and average energy per site vs number of MC steps are shown in figure 4.. We see that the system takes a lot longer to for the energy per site (the left hand graph in figure 4.) to reach its equilibrium value at this temperature than at T = 3. The curves on the scaled axes do not collapse like they did in part and the curves for larger N take longer to reach equilibrium. This indicates that the thermalisation time is increasing with N faster than O(N ) (the thermalisation time is probably scaling something like N +a where a > ). The curves for both E and M display a large amount of fluctuation (again fluctuations are be bigger close to the critical point). It appears that all of the energy curves have reached equilibrium after 5N MC steps but it is hard to tell without doing more averaging so to be safe I have used 5 4 N MC steps for thermalisation in the next part. Determining the Curie temperature The solution to part 4b can be run using the script part4b.m which requires the function isingd.m and the graphing script GraphsP4b.m. Method and results: This script repeats the the calculation from part 3 but with a thermalisation time of 5 4 N and for each data point it averages over two realisations of the Monte Carlo algorithm (it would be better with more but that would take longer). The results are plotted in figure 4. and we see the same trend with some of the noise smoothed out (again we could do better by doing more averaging or running the script for more MC steps). Finding the critical temperature. At the critical (Curie) temperature (T C ) the magnetic susceptibility and heat capacity diverge and the the magnetisation drops to zero. In a finite system the magnetic susceptibility and heat capacity plots in figure 4. have a peak and the magnetisation plot has a rapid drop. It is somewhat ambiguous where exactly the drop in magnetisation occurs so we look at the peaks of the heat capacity and magnetic susceptibility curves. The critical temperature is a quantity that should be considered in the thermodynamic (N ) limit so we look at the largest system (N = 5). The magnetic susceptibility and heat capacity are both at their maximum values when k BT temperature is k BT C (99) =.8 so our estimate for the critical.69 which =.8 ±.. The exact value for the critical temperature is k BT C = log(+ ) See for example the discussion and references in: Lectures on phase transitions and the renormalization group, N. Goldenfeld, Addison-Wesley, 6
.9.8.7.6.5.4.3.. -.3 -.4 -.5 -.6 -.7 -.8...3.4.5.6 -.9...3.4.5.6 35 3 5 5 5...3.4.5.6.7.4..8.6.4..8.6...3.4.5.6.7 Figure 4.: The results of the Monte Carlo simulation for the D Ising model described in part 4b. In plots figures the results for the square lattice of length N = are marked with s, with N = are marked with s, and with N = 5 are marked with s. In the top left we have the magnetisation, in the top right we have the energy per spin, in the bottom left we have the magnetic susceptibility, and in the bottom right we have the heat capacity per spin. 7
is in agreement with our value (if we looked at a finer temperatures scale we would find that our value was slightly different from the exact value as we have studied a finite lattice). Efficacy: The following things that can be done to optimise the code (this is not an exhaustive list): Implement simulated annealing when varying the temperature as described in part 3 above. If you have a computer with multiple cores some of the for loops in the scripts (not in the MC algorithm itself) can be run in parallel on different cores using the parfor. I have done this in the solutions, if you have trouble running these loops you can just replace with regular for loops. In the initialisation part of the Monte Carlo algorithm you can pre-calculate the different probabilities e 8β, e 4β (the other probabilities are ) and use an if loop instead of calculating the exponential every MC step (I have not done this in the solutions). 8