6810: 1094 Activities 13

Online handout: Excerpt from Binder/Heermann

In this session, we'll extend our study of Monte Carlo methods. We'll compare importance sampling to ordinary random sampling and explore the two-dimensional Ising model. Please read the background notes for an introduction and then use the Biner/Heermann handout as you go.

Overview: Simulation of 2D Ising Model [HTML5 version]

To get started, we'll look at an applet that simulates the 2D Ising model. The goal is to visualize before looking at code; it is NOT expected that you will understand all of the physics now.

  1. Go to the HTML5 Ising model simulation linked on the 6810 page and read the short introduction.
  2. You will see a grid of blue and yellow squares, which represent up or down spins on a lattice. The magnetization is proportional to the net spin (count blue as +1 and yellow as −1). Below the grid you can read off the temperature and control it with a slide. There are also controls for the size of the grid and the steps per frame. Set the temperature to 10 by moving the slide all the way to the right and press start? What are the characteristics of the system? Are there any large areas of all blue or all yellow? How large is the magnetization per spin (roughly)? Is it constant?

  3. Now rapidly bring the temperature to zero and let it settle down. Repeat the cycle of rapid heating and cooling several times. Does it always end up in a uniform ferromagnetic state? If not, why not? Estimate the magnetization per spin in each case.

  4. Next change the temperature by increments of about 1 (you have to release the slide for the change to take affect). Characterize the behavior of the system as it heats through the critical temperature to high temperature. What happens at 2.27 (restart the page to get there exactly)? Make a sketch of the magnetization as a function of temperature.

  5. Play with changing the cell size (by the Size pull down) to very large and very small. What differences do you observe in the size of the fluctuations and the behavior of the magnetization?

Monte Carlo Sampling

In the sampling_test.cpp code, three distributions of energy for a one-dimensional Ising model [equation (2.1.1) in the handout] are generated. The first is the exact distribution at temperature kT in the canonical ensemble; that is, the distribution of energies considering every possible configuration of spins weighted by a normalized Boltzmann factor. The second is the energy distribution if a large number of spin configurations are chosen at random. The third is the energy distribution from a Metropolis Markov process.

  1. Here are some questions to get you familiar with the model and its implementation in the code sampling_test.cpp:
  2. Compile and link sampling_test.cpp (using make_sampling_test) and run it to see what the output looks like. Did you get the correct answer above for the number of configurations and the possible energies? (If not, rethink!)

  3. Generate and attach a gnuplot graph of the probability of energy E [called P(E)] vs. the energy (this is what is output to the screen) for kT = 10. and kT = 1. [You'll need to get the results into data files somehow. There is a plot file sampling_test.plt to help with the plot, but you have to put the results in files with these names. Cutting and pasting is fine.]
  4. Verify that the transition probabilities in (2.1.39a) and (2.1.39b) both satisfy the condition (2.1.38). Which one is implemented in the code? Bonus: Switch to the other and check that it works.

  5. How do you calculate the average energy at a given temperature? Modify the code to calculate the average energy at kT = 1. and kT = 10. using the Metropolis sampling methods and compare to the exact average energy (according to the canonical Boltzmann distribution).

The Two-D Ising Model

In this section, we explore some aspects of Monte Carlo simulations that are discussed in section 2.2 of the handout. We use the two-dimensional Ising model first with a ferromagnetic interaction (J > 0) and then with an "anti-ferromagnetic" interaction as our example.

  1. Take a look at ising_model.cpp and note that one can switch between the one-d and two-d Ising models by commenting and uncommenting some lines. The default is the two-d model. What are the differences between the one-d and two-d versions?

  2. Equilibration. Compile and link ising_model.cpp (use make_ising_model) and run for several temperatures.
  3. Modify the code to change it from ferromagnetic to anti-ferromagnetic (only one line needs to be changed!). What did you change?

  4. Cooling. At present, the code starts from a random configuration. Modify the code to implement "cooling" by looping through temperatures kT = 2.0, 1.0, then 0.5 but start the simulation at each successive temperature using the final configuration of the higher temperature as the initial configuration of the lower temperature. Generate a gnuplot graph of the energy vs. time for each of the temperatures and compare to your previous results. Conclusions?

  5. Efficiency. The code at present has several inefficiencies. Here are some ways to speed it up:
    1. The current approach compares energies of new and old configurations by calculating the full energy of each and subtracting. Can you devise a (much) more efficient approach? (You don't need to implement it here.)

    2. During one MCS, we can update each spin sequentially, which saves random number calls but also leads to shorter equilibration times.
    3. We can reduce the random number calls when deciding if a spin flips or not.
    4. We can use a table of nearest neighbors of each spins to save calculation time.
    These optimizations speed up the code by a factor of about six! A new version is ising_opt.cpp (with make_ising_opt). Look at how the optimizations were implemented.
  6. Phase Transition

6810: 1094 Session 13. Last modified: .