\documentclass[11pt,a4wide]{article}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{a4wide}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[dvips]{epsfig}
\usepackage[T1]{fontenc}
\usepackage{cite} % [2,3,4] --> [2--4]
\usepackage{shadow}
\usepackage{hyperref}

\setcounter{tocdepth}{2}

\lstset{language=c++}
\lstset{alsolanguage=[90]Fortran}
\lstset{basicstyle=\small}
\lstset{backgroundcolor=\color{white}}
\lstset{frame=single}
\lstset{stringstyle=\ttfamily}
\lstset{keywordstyle=\color{red}\bfseries}
\lstset{commentstyle=\itshape\color{blue}}
\lstset{showspaces=false}
\lstset{showstringspaces=false}
\lstset{showtabs=false}
\lstset{breaklines}
\begin{document}
\section*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.
\begin{itemize}
\item Give a short description of the nature of the problem and the eventual 
numerical methods you have used.
\item Describe the algorithm you have used and/or developed. Here you may find it convenient
to use pseudocoding. In many cases you can describe the algorithm
in the program itself.

\item Include the source code of your program. Comment your program properly.
\item If possible, try to find analytic solutions, or known limits
in order to test your program when developing the code.
\item Include your results either in figure form or in a table. Remember to
       label your results. All tables and figures should have relevant captions
       and labels on the axes.
\item Try to evaluate the reliabilty and numerical stability/precision
of your results. If possible, include a qualitative and/or quantitative
discussion of the numerical stability, eventual loss of precision etc. 

\item Try to give an interpretation of you results in your answers to 
the problems.
\item Critique: if possible include your comments and reflections about the 
exercise, whether you felt you learnt something, ideas for improvements and 
other thoughts you've made when solving the exercise.
We wish to keep this course at the interactive level and your comments can help
us improve it.
\item Try to establish a practice where you log your work at the 
computerlab. You may find such a logbook very handy at later stages
in your work, especially when you don't properly remember 
what a previous test version 
of your program did. Here you could also record 
the time spent on solving the exercise, various algorithms you may have tested
or other topics which you feel worthy of mentioning.
\end{itemize}



\section*{Format for electronic delivery of report and programs}
%
This project counts 1/3 of the final mark. The feedback will, in addition to our comments contain a final score, where 100 is the maximum. Project 5 counts also 1/3 of the final mark. The final exam stands for the remaining 1/3 of the final mark.
We have set up devilry so that you can use your candidate number only. Please mark your project with the candidate number. If you prefer to not use the candidate number, we will need it anyway in order to correlate with the final written exam. 

The preferred format for the report is a PDF file. You can also
use DOC or postscript formats or as an ipython notebook file. 
As programming language we prefer that you choose between C/C++, Fortran2008 or Python.
The following prescription should be followed when preparing the report:
\begin{itemize}
\item Use Devilry to hand in your projects, log in  at 
\url{ http://devilry.ifi.uio.no} with your normal UiO username and password
and choose either '<PASSWORD>' or '<PASSWORD>'. This time however you should use your candidate number only. You are free to use your name as well, but we need the candidate number for the final mark. 
\item You can upload the report file as well as your program files to devilry!  For the source code file(s) you have developed you can also place these at  a github domain, or eventually upload all program files to devilry.  
The report file should include all of your discussions and a list of the codes you have developed. 
\item You should include tests and/or unit tests of your code(s).
\item Comments  from us on your projects, with final score
will be available under
your Devilry domain and are only visible to you and the teachers of the course.

\end{itemize}

Finally, even though this project counts 1/3 of the final mark, 
we encourage you to work two and two together. Optimal working groups consist of 
2-3 students. You can then hand in a common report. 


\section*{Project 4, numerical integration, deadline  Friday November 13}


The project deals with the Ising model in two dimensions, without an external magnetic 
field. In its simplest form
the energy is expressed as
\begin{equation}
  E=-J\sum_{<kl>}^{N}s_ks_l
\end{equation}
with  $s_k=\pm 1$, $N$ is the total number of spins and
$J$ is a coupling constant expressing the strength of the interaction
between neighboring spins.
The symbol $<kl>$ indicates that we sum over nearest
neighbors only. We will assume that we have a ferromagnetic ordering, viz $J> 0$.
We will use periodic boundary conditions and the Metropolis algorithm only. 
\begin{enumerate}

\item[a)] Assume we have only two spins in each dimension, that is $L=2$.
Find the closed form expression for the partition function and the corresponding
expectations values for
for $E$, $|{\cal M}|$, the specific heat $C_V$ and the susceptibility $\chi$ 
as functions of  $T$ using periodic boundary conditions.



\item[b)] 
Write now a code for the Ising model which computes the mean energy 
$E$, mean magnetization 
$|{\cal M}|$, the specific heat $C_V$ and the susceptibility $\chi$ 
as functions of  $T$ using periodic boundary conditions for 
$L=2$ in the $x$ and $y$ directions. 
Compare your results with the expressions from a)
for  a  temperature $T=1.0$ (in units of $kT/J$). 

How many Monte Carlo cycles do you need in order to achieve a good agreeement?


\item[c)]
 
We choose now a square lattice with $L=20$ spins in the $x$ and $y$ directions. 

In [b) we did not study carefully how many Monte Carlo cycles were needed in order to reach the most likely state. Here
we want to perform a study of the time (here it corresponds to the number 
of Monte Carlo cycles) one needs before one reaches an equilibrium situation 
and can start computing various expectations values. Our 
first attempt is a rough and plain graphical
one, where we plot various expectations values as functions of the number of Monte Carlo cycles.

Choose first a temperature of $T=1.0$ (in units of $kT/J$) and study the 
mean energy and magnetisation (absolute value) as functions of the number of Monte Carlo cycles.
Use both an ordered (all spins pointing in one direction) and a random
spin orientation as starting configuration. 
How many Monte Carlo cycles do you need before you reach an equilibrium situation?
Repeat this analysis for $T=2.4$. 

Make also a plot of the total number of accepted configurations 
as function of the total number of Monte Carlo cycles. How does the number of
accepted configurations behave as function of temperature $T$?


\item[d)] Compute thereafter the probability 
$P(E)$ for the previous system with $L=20$ and the same temperatures.
You compute this probability by simply counting the number of times a 
given energy appears in your computation. Start the computation after 
the steady state situation has been reached.
Compare your results with the computed variance in energy 
$\sigma^2_E$ and discuss the behavior you observe. 
\end{enumerate}

Near $T_C$ we can characterize the behavior of many physical quantities
by a power law behavior.
As an example the mean magnetization is given by
\begin{equation}
  \langle {\cal M}(T) \rangle \sim \left(T-T_C\right)^{\beta},
\end{equation}
where $\beta=1/8$ is a so-called critical exponent. A similar relation
applies to the heat capacity 
\begin{equation}
  C_V(T) \sim \left|T_C-T\right|^{\alpha},
\end{equation}
and the susceptibility
\begin{equation}
  \chi(T) \sim \left|T_C-T\right|^{\gamma},
\end{equation}
with $\alpha = 0$ and $\gamma = 7/4$.
Another important quantity is the correlation length, which is expected
to be of the order of the lattice spacing for $T>> T_C$. Because the spins
become more and more correlated as $T$ approaches $T_C$, the correlation
length increases as we get closer to the critical temperature. The divergent
behavior of $\xi$ near $T_C$ 
is
\begin{equation}
  \xi(T) \sim \left|T_C-T\right|^{-\nu}.
  \label{eq:xi}
\end{equation}
A second-order phase transition is characterized by a
correlation length which spans the whole system.
Since we are always limited to a finite lattice, $\xi$ will
be proportional with the size of the lattice. 
Through so-called finite size scaling relations
it is possible to relate the behavior at finite lattices with the 
results for an infinitely large lattice.
The critical temperature scales then as
\begin{equation}
 T_C(L)-T_C(L=\infty) = aL^{-1/\nu},
 \label{eq:tc}
\end{equation}
with  $a$ a constant and  $\nu$ defined in Eq.~(\ref{eq:xi}).
We set $T=T_C$ and obtain a mean magnetisation
\begin{equation}
  \langle {\cal M}(T) \rangle \sim \left(T-T_C\right)^{\beta}
  \rightarrow L^{-\beta/\nu},
  \label{eq:scale1}
\end{equation}
a heat capacity
\begin{equation}
  C_V(T) \sim \left|T_C-T\right|^{-\gamma} \rightarrow L^{\alpha/\nu},
  \label{eq:scale2}
\end{equation}
and susceptibility
\begin{equation}
  \chi(T) \sim \left|T_C-T\right|^{-\alpha} \rightarrow L^{\gamma/\nu}.
  \label{eq:scale3}
\end{equation}

\begin{enumerate}
\item [e)]  We wish to study the behavior of the Ising model in two dimensions close to the 
critical temperature as a function of the lattice size $L\times L$.
Calculate the expectation values 
for $\langle E\rangle$ and $\langle |{\cal M}|\rangle$,
the specific heat $C_V$ and the susceptibility $\chi$
as functions  of $T$ for $L=20$, $L=40$, $L=60$ and $L=80$ for $T\in [2.0,2.4]$
with a step in temperature $\Delta T=0.05$ or smaller. 
Plot  $\langle E\rangle$, $\langle 1{\cal M}1\rangle$, $C_V$ and $\chi$ 
as functions of $T$. Can you see an indication of a phase transition?

Use the absolute value $\langle |{\cal M}|\rangle$ when you evaluate $\chi$.

You should parallelize the code using either OpenMP or MPI.
\item[f)]  Use Eq.~(\ref{eq:tc}) and the exact result
$\nu=1$ in order to estimate $T_C$ in the thermodynamic limit $L\rightarrow \infty$
using your simulations with $L=20$, $L=40$, $L=60$ and $L=80$
The exact result for the critical temperature (after Lars Onsager) is
$kT_C/J=2/ln(1+\sqrt{2})\approx 2.269$ with $\nu=1$.
\end{enumerate}

\section*{Background literature}
If you wish to read more about the Ising model and statistical physics here are two suggestions.
\begin{enumerate}
\item M.~Plischke and B.~Bergersen, Equilibrium Statistical Physics,
Prentice-Hall, see chapters 5 and 6.
\item M.~E.~J.~Newman and T.~Barkema, Monte Carlo methods in statistical physics, Oxford, see chapters 3 and 4.

\end{enumerate}
\end{document}






