28.01.2015 Views

Homework assignments (4,5 credits) in Computational Physics

Homework assignments (4,5 credits) in Computational Physics

Homework assignments (4,5 credits) in Computational Physics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Homework</strong> <strong>assignments</strong> (4,5 <strong>credits</strong>) <strong>in</strong> <strong>Computational</strong><br />

<strong>Physics</strong><br />

Olle Edholm and Mats Wall<strong>in</strong>, Department of Theoretical <strong>Physics</strong>, KTH<br />

December 6, 2007<br />

You are supposed to select ONE of the problems described below. It is important<br />

that the problem is solved <strong>in</strong>dividually, but some collaboration with other students is<br />

accepted. You are welcome to consult the <strong>in</strong>structors of the course and the literature if<br />

help is needed.<br />

The report should be written <strong>in</strong>dividually. The report should be typed on a computer<br />

and sectioned as a professional report, conta<strong>in</strong><strong>in</strong>g title, author, abstract, section headers,<br />

etc. Use spell checks. Computer produced plots should be <strong>in</strong>cluded with figure number<strong>in</strong>g<br />

and captions.<br />

You are supposed to write and run your own computer program. The programm<strong>in</strong>g<br />

language is supposed to be an efficient language, like fortran, C, C++, ... (but preferably<br />

not Maple, Matlab, or Mathematica). Include a short list<strong>in</strong>g of relevant parts of the<br />

computer code <strong>in</strong> the report.<br />

Some problems are easier and some are harder. You do not have to follow the <strong>in</strong>structions<br />

exactly, and it is allowed to skip or add steps if you want. For help and more<br />

<strong>in</strong>formation on the problem, please ask the <strong>in</strong>structors.<br />

Deadl<strong>in</strong>e for the reports extended until: Jan. 10. 2008<br />

1 Molecular dynamics of a hard sphere fluid<br />

Instructor: Olle Edholm<br />

Write the program. This has to be written differently than a program us<strong>in</strong>g cont<strong>in</strong>uous<br />

forces. This requires some fairly elaborate programm<strong>in</strong>g. In the hard sphere fluid the<br />

force is zero all the time except when two spheres collide. Then the force is <strong>in</strong>f<strong>in</strong>ite.<br />

Therefore, you should start by mak<strong>in</strong>g a table of the time for the next collision of each<br />

particle and the number of the particle it will collide with. Then you just assume that<br />

all particles will move along straight l<strong>in</strong>es (tak<strong>in</strong>g the periodic boundaries <strong>in</strong>to account)<br />

with their given (random) <strong>in</strong>itial velocities. Then you pick the shortest time <strong>in</strong> this table.<br />

Now, you subtract this time from all other times <strong>in</strong> the table. If it was particle i and j<br />

that collided, you have to calculate their new velocities from the rules of elastic collisions.<br />

It might be useful to consult a textbook <strong>in</strong> classical mechanics for this problem. Further<br />

you have to calculate the next time they will collide with all other particles and update<br />

the table accord<strong>in</strong>gly. F<strong>in</strong>ally you may iterate this procedure.<br />

Measure the density as the degree of close pack<strong>in</strong>g η = 4πNR 3 /3V . You may use<br />

dimensionless units (R = 1). The velocities should be random with an average zero. You<br />

1


can, however, use dimensionless velocities. Chose them for <strong>in</strong>stance <strong>in</strong> such a way that<br />

you will get the mean square velocity equal to 1. Use the program to calculate the pair<br />

correlation function of the hard sphere fluid at a couple of densities. You should get a<br />

pair correlation function that is zero for r less than 2 and has a couple of oscillations<br />

with a period <strong>in</strong> r that is of the order 2. Reasonable degrees of close pack<strong>in</strong>g should be<br />

<strong>in</strong> the <strong>in</strong>terval 0.1 up to maybe 0.5. (References: Allen and Tildesley, p. 102-108 or B.J.<br />

Berne, Statistical Mechanics part B p 1-40)<br />

2 Write a Monte Carlo program to simulate a LJfluid<br />

(argon)<br />

Instructor: Olle Edholm<br />

Use periodic boundary conditions and make the simulations at fixed N, V and T .<br />

Calculate energy and pressure. Use the same parameters, densities and temperatures as<br />

you used <strong>in</strong> the MD lab on argon. Check that you get similar energy and pressure as <strong>in</strong><br />

the MD-simulations. Don’t forget the k<strong>in</strong>etic part of energy and pressure. Experiment<br />

with different ways of sampl<strong>in</strong>g obey<strong>in</strong>g detailed balance (different maximum step lengths<br />

<strong>in</strong> the moves and mov<strong>in</strong>g one or several particles at the same time) and monitor how this<br />

affects the acceptance ratio. Start from a system equilibrated at wrong temperature and<br />

see how the choice of the moves affect convergence. Is there some correlation between<br />

acceptance ratio and rate of convergence (Reference: Allen and Tildesley, chapter 4.4)<br />

3 Temperature control <strong>in</strong> MD<br />

Instructor: Olle Edholm<br />

Program the Nose’-Hoover thermostat and compare it to the simple velocity scal<strong>in</strong>g<br />

with a time constant used <strong>in</strong> the argon computer lab. The equations of motion can be<br />

written on the follow<strong>in</strong>g form for both thermostats:<br />

d<br />

dt ¯p i = −∇ i U − ξ ¯p i<br />

i = 1, ....N<br />

The difference is <strong>in</strong> the equation of motion for the heat bath degree of freedom (ξ) which<br />

<strong>in</strong> the Berendsen scal<strong>in</strong>g method can be written:<br />

while it becomes:<br />

ξ = 1<br />

2τ [ 1<br />

3Nmk B T<br />

∑<br />

¯p 2 i − 1]<br />

i<br />

d<br />

dt ξ = 1 ∑<br />

ω2 [<br />

¯p 2 i − 1]<br />

3Nmk B T<br />

i<br />

<strong>in</strong> the Nose’-Hoover case. Both methods conta<strong>in</strong> a parameter τ or ω. Check for both<br />

methods, how the values of these parameters affect temperature stability, fluctuations<br />

and the responses of the system to small sudden changes <strong>in</strong> the temperature of the<br />

heat bath. Check also how well the velocities obey a Maxwellian distribution <strong>in</strong> the two<br />

cases. Calculate the heat capacity from the canonical ensemble equation based on energy<br />

fluctuations for both types of simulation. Compare the results with each other, with<br />

2


the heat capacity obta<strong>in</strong>ed from temperature fluctuations <strong>in</strong> a micro canonical (NVE)<br />

simulation and with experimental heat capacities. You may use the MD-program from,<br />

the argon computer lab as a template and make the changes there. (Reference, Frenkel<br />

& Smit p. 125-141.)<br />

4 Monte Carlo studies of simple <strong>in</strong>tegrals<br />

Instructors: Mats Wall<strong>in</strong> or Olle Edholm<br />

S<strong>in</strong>ce this problem is more elementary than the rest, the requirement on the report<br />

is higher <strong>in</strong> order to get grade higher than 3.<br />

Study various simulation methods for the simple test <strong>in</strong>tegral<br />

∫ ∞<br />

0<br />

∫ ∞<br />

0<br />

dx xe −x2<br />

dx e −x2<br />

Evaluate <strong>in</strong> four different ways: (1) Us<strong>in</strong>g a Metropolis method. (2) Simple Monte Carlo.<br />

(3) Simpson’s rule. (4) Exactly us<strong>in</strong>g analytic <strong>in</strong>tegration. In (1), experiment with the<br />

maximum step size δ. Beg<strong>in</strong> with δ = 1, then compare with δ = 0.1 and δ = 10.<br />

Study the statistical error <strong>in</strong> the MC methods by tak<strong>in</strong>g the average RMS error (error<br />

=result from (1) m<strong>in</strong>us result from (4)) as a function of the number of terms N (for<br />

example, N = 10, 100, 1000, 10000, ...) <strong>in</strong> the MC calculation. Is this a good measure of<br />

the statistical error <strong>in</strong> (1) and <strong>in</strong> (2) Why or why not Study the correlation time τ <strong>in</strong><br />

(1). In (1), it is necessary to repeat the calculation many times, and calculate the RMS<br />

errors from the results of these <strong>in</strong>dependent runs. Plot the RMS error vs. N <strong>in</strong> log-log<br />

plots. Compare the cpu times for (1)-(3) to reach a certa<strong>in</strong> error level. Also study the<br />

the more complicated oscillatory <strong>in</strong>tegral<br />

∫ ∞<br />

−∞<br />

dx s<strong>in</strong> 2 1 x<br />

5 Effects of frustration <strong>in</strong> the two-dimensional Is<strong>in</strong>g<br />

model on a triangular lattice<br />

Instructor: Mats Wall<strong>in</strong><br />

The two-dimensional Is<strong>in</strong>g model can also be def<strong>in</strong>ed on a triangular lattice, and then<br />

each sp<strong>in</strong> has six nearest neighbors. Study it <strong>in</strong> zero applied field. Simply add a coupl<strong>in</strong>g<br />

along one of the diagonals of each elementary square <strong>in</strong> the Monte Carlo code for the<br />

square lattice from the Is<strong>in</strong>g lab.<br />

Compute the B<strong>in</strong>der ratio and determ<strong>in</strong>e T c from it. Expla<strong>in</strong> why it is bigger or<br />

smaller than the value for the square lattice. Do a f<strong>in</strong>ite size scal<strong>in</strong>g analysis of g to<br />

determ<strong>in</strong>e ν. Is it smaller or bigger than for a square lattice Try to expla<strong>in</strong>!<br />

F<strong>in</strong>ally, change the sign of the coupl<strong>in</strong>g constant J to J = −1, which corresponds to an<br />

antiferromagnet. On a square lattice this can be transformed back to the ferromagnetic<br />

case J = +1 by flipp<strong>in</strong>g every other sp<strong>in</strong> <strong>in</strong> a checker board pattern. But for J = −1 a<br />

new phenomenon enters called frustration: no matter how the sp<strong>in</strong>s around an elementary<br />

triangular plaquette orient themselves, one of the three <strong>in</strong>teractions will be <strong>in</strong> the excited<br />

state. Do the same simulations as for the ferromagnetic case above.<br />

3


6 Monte Carlo simulation of the three dimensional<br />

classical xy-model<br />

Instructor: Mats Wall<strong>in</strong><br />

Repeat the same tasks as <strong>in</strong> the Is<strong>in</strong>g lab for the three dimensional classical xy-model.<br />

The energy is def<strong>in</strong>ed by:<br />

H = −J ∑<br />

cos(θ i − θ j )<br />

<br />

where θ i ∈ [0, 2π] is phase angle at lattice po<strong>in</strong>t i, and ∑ denotes nearest neighbor<br />

summation on a lattice with L 3 = N lattice po<strong>in</strong>ts. The temperature T enters through<br />

the partition function Z = Tr θi exp −H/T . Here Tr means that each θ i shall be <strong>in</strong>tegrated<br />

from 0 to 2π.<br />

Def<strong>in</strong>e the B<strong>in</strong>der ratio as<br />

R = 〈m4 〉<br />

〈m 2 〉 2<br />

where m is the absolute value of the volume average of the complex order parameter<br />

field, given by<br />

1 ∑<br />

m =<br />

e iθ j<br />

∣N<br />

∣<br />

Study the B<strong>in</strong>der ratio and the other thermodynamic quantities. Comment on the limits<br />

of the B<strong>in</strong>der ratio for low and high T . Determ<strong>in</strong>e the critical temperature and critical<br />

exponents. Study the equilibrium time near T c .<br />

(H<strong>in</strong>t: Do not bother to def<strong>in</strong>e a f<strong>in</strong>ite step length, ∆θ, for the maximum update<br />

of the phase angle. Instead simply draw the updated phase angle uniformly <strong>in</strong> [0, 2π].<br />

There is actually no ga<strong>in</strong> <strong>in</strong> the amount of uncorrelated data per CPU time <strong>in</strong> us<strong>in</strong>g a<br />

f<strong>in</strong>ite step length, even if the acceptance rate can be made larger. On the other hand,<br />

restrict<strong>in</strong>g θ to tak<strong>in</strong>g only, say, 1000 discrete values <strong>in</strong> [0, 2π], and us<strong>in</strong>g look-up tables<br />

for everyth<strong>in</strong>g, will speed up the code.)<br />

7 Monte Carlo simulation of the three dimensional<br />

classical Heisenberg model<br />

Instructor: Mats Wall<strong>in</strong><br />

Same as problem 3, but with xy sp<strong>in</strong>s replaced by 3-component classical Heisenberg<br />

sp<strong>in</strong>s. The Hamiltonian is then given by<br />

j<br />

H = −J ∑<br />

<br />

⃗S i · ⃗S j<br />

where ⃗ S i is a vector “sp<strong>in</strong>” lattice po<strong>in</strong>t i, and ∑ denote nearest neighbor summation.<br />

The Heisenberg sp<strong>in</strong>s have three components: S = (S x , S y , S z ). The length of the sp<strong>in</strong><br />

is S 2 = 1, and we can therefore use represented by their spherical polar angles (θ, φ) to<br />

specify the direction. Note that the <strong>in</strong>tegration volume element is s<strong>in</strong> θ dθ dφ, as usual <strong>in</strong><br />

spherical coord<strong>in</strong>ates. Repeat the same steps as <strong>in</strong> Problem 6.<br />

4


8 Self avoid<strong>in</strong>g random walks<br />

Instructors: Olle Edholm and Mats Wall<strong>in</strong><br />

An <strong>in</strong>terest<strong>in</strong>g and extensively studied problem <strong>in</strong> polymer physics is to model a<br />

polymer cha<strong>in</strong> <strong>in</strong> a good solvent as a self avoid<strong>in</strong>g random walk, where each step taken by<br />

the walker represents one segment of the polymer (one monomer). Crudely speak<strong>in</strong>g, the<br />

dist<strong>in</strong>ction between “good” and “poor” solvent is that <strong>in</strong> a good solvent the <strong>in</strong>teractions<br />

between the polymer and the solvent molecules is more important than the long-range<br />

<strong>in</strong>teractions between polymer molecules, and the latter can be ignored. You will study<br />

the average end-to-end distance <strong>in</strong> various spatial dimensions by Monte Carlo simulation<br />

of random walks on simple cubic lattices.<br />

(a) Free random walk. The ord<strong>in</strong>ary “free” random walk can be simulated by<br />

simple sampl<strong>in</strong>g of random steps on a simple “cubic” lattice <strong>in</strong> 1, 2, 3 and 4 dimensions).<br />

Start at the orig<strong>in</strong>. Take one step to any nearest neighbor lattice site at random, and<br />

from there take another step, etc. Calculate the exponent p = 2ν <strong>in</strong> 〈RN〉 2 ∼ N p <strong>in</strong> the<br />

limit of a large number of steps N, where R N is the end-to-end distance of the cha<strong>in</strong><br />

after N steps. It is useful to average the results over many walks, so the program should<br />

do at least 10 4 <strong>in</strong>dependent walks <strong>in</strong> one run. Derive the exact result p = 1 and compare<br />

with the simulation results.<br />

(b) Simple sampl<strong>in</strong>g of SAW. Modify your program to simulate a model of a<br />

polymer as a self avoid<strong>in</strong>g random walk on the lattice. Self avoid<strong>in</strong>g means that the<br />

walk cannot cross its previous path. This can be sampled as follows: Do an ord<strong>in</strong>ary<br />

walk, as <strong>in</strong> (a). Do not use moves that br<strong>in</strong>g the walker back to position occupied at the<br />

previous step, so <strong>in</strong> d dimensions use an equal probability to move <strong>in</strong> 2d − 1 directions.<br />

If the walker reaches a site where it has previously been, the walk term<strong>in</strong>ates. It is thus<br />

necessary to keep track of all the previous locations of the walker. This can be done by<br />

stor<strong>in</strong>g a vector with visited coord<strong>in</strong>ates (stor<strong>in</strong>g the whole lattice and tagg<strong>in</strong>g visited<br />

sites requires unnecessary memory usage). Calculate the exponent p = 2ν <strong>in</strong> 2, 3, and 4<br />

dimensions. How long cha<strong>in</strong>s can be reached with reasonable convergence Discuss the<br />

values of p and compare with the results from (a), and discuss why p goes up. Compare<br />

your result with the Flory mean field theory result ν = 3/(d + 2), which should be<br />

remarkably accurate <strong>in</strong> d = 2, 3 dimensions, and exact <strong>in</strong> d = 4 (d = 4 is the so called<br />

upper critical dimension for a self-avoid<strong>in</strong>g random walk, i.e. the dimension above which<br />

the self-avoid<strong>in</strong>g <strong>in</strong>teraction becomes irrelevant). What do you th<strong>in</strong>k would happen with p<br />

for self attract<strong>in</strong>g walks Compute the absolute dimensionless entropy per monomer from<br />

the equation: S/k B (N − 2) = ln Ω(N)/(N − 2). For the random walk Ω(N) = (2d) N−2<br />

which gives a constant entropy per monomer. For the SAW Ω(N) = W (N)(2d − 1) N−2<br />

were W (N) is the fraction of successful attempts. This gives an entropy per monomer<br />

that decreases with N. Determ<strong>in</strong>e the functional form of this decrease for large N.<br />

(c) SAW by biased sampl<strong>in</strong>g. There is an easy way to improve the poor acceptance<br />

rate at large N of the simple sampl<strong>in</strong>g method, by us<strong>in</strong>g biased sampl<strong>in</strong>g. For the trial<br />

move at “time step” N, keep track of the number of available, empty neighbour sites. Let<br />

a(N) be the number of available moves at time step N. Do one of the available moves<br />

at random, and compute R 2 (N)Π N j=1a(j). Repeat for many walks i = 1, ..., N w . The<br />

desired average is an average over walks: 〈R 2 (N)〉 = ∑ i Ri 2 (N)Π N j=1a i (j)/ ∑ i Π N j=1a i (j).<br />

Calculate ν, and study the statistics of the method and compare with (b).<br />

5


9 Write a Monte Carlo program to simulate the one<br />

component plasma (OCP)<br />

Instructor: Olle Edholm<br />

Use periodic boundary conditions and make the simulations at fixed N and Γ (see def<strong>in</strong>ition<br />

below). Calculate the energy and heat capacity per particle. Read first the second<br />

(classical) reference below (http://prola.aps.org/abstract/PRA/v8/i6/p3096_1). Try<br />

to reproduce some of the results of that article. You may first start with a cutoff method<br />

but you have to use the Ewald method (see the first reference) <strong>in</strong> the end. (Reference:<br />

Allen and Tildesley, and J.P. Hansen Phys. Rev A. 8 (1973) p. 3096-3109)<br />

The properties of the OCP do not depend separately on density and temperature,<br />

but these can be comb<strong>in</strong>ed <strong>in</strong>to one dimensionless parameter:<br />

Γ = 1<br />

4πɛ 0<br />

(Ze) 2<br />

k B T (4π 3 ρ)1/3<br />

If you use the dimensionless coord<strong>in</strong>ates: y i = x i (4πρ/3) 1/3 , the Coulomb energy between<br />

two particles may be written:<br />

u(r)<br />

k B T = Γ r ,<br />

with r be<strong>in</strong>g the <strong>in</strong>ter particle distance <strong>in</strong> the dimensionless units def<strong>in</strong>ed above. If Z = 1<br />

(protons) and T=300K, Γ = 1 corresponds to a low number density (about 10 21 protons<br />

per m 3 ) while Γ = 200 corresponds to more the k<strong>in</strong>d of densities one has <strong>in</strong> ord<strong>in</strong>ary<br />

matter (10 28 protons per m 3 ). Vary the parameter Γ <strong>in</strong> this range. In a typical plasma<br />

the temperature is usually much higher, but also the density. S<strong>in</strong>ce the density is taken<br />

to the power one third, even typical conditions <strong>in</strong>side a white dwarf star correspond to<br />

quite small values of Γ.<br />

Observe, f<strong>in</strong>ally that you have to <strong>in</strong>clude the attractive <strong>in</strong>teraction with the electrons<br />

as a uniform attractive background. This may be justified s<strong>in</strong>ce at typical plasma conditions<br />

the electrons can be treated as a quantum mechanical highly degenerate Fermi-Dirac<br />

gas. Us<strong>in</strong>g a cutoff, you may add this contribution (which can be calculated analytically)<br />

<strong>in</strong> the end. Us<strong>in</strong>g Ewald summation you have to <strong>in</strong>clude this when you calculate the electrostatic<br />

repulsion between the protons. If you do not do this each part of the <strong>in</strong>teractions<br />

will diverge separately.<br />

6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!