diff --git a/README.md b/README.md deleted file mode 100644 index acd7ca5..0000000 --- a/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Milestones - -## Day 0 -### Introduction to GNU/Linux, Fortran, Github, and LaTeX. -* Register for an account on [Github](https://www.github.com) -* Login to the HPC computing platform, clone the [ICCP/coding notes](https://github.com/ICCP/coding-notes) repository, and compile the example code -* Fork the [ICCP/ising](https://github.com/ICCP/ising) repository with your github account. Clone your fork to the HPC and/or your local computer. - -## Milestone 1 -* Lay out program - * Write up the physics as you understand it in a LaTeX document (to eventually become a paper) - * Determine figures-of-interest to include in final report -* Implement the 2D square Ising model for a constant temperature - * Commit regularly and push changes to your fork! - -## Milestone 2 -* Refine the model with periodic boundary conditions, varied initial conditions -* Implement a sweep through a temperature range to determine the critical Curie temperature - * Average several equilibrium systems at each temperature to better your statistics -* Begin collecting data - -## Milestone 3 -* Finalize data collection -* Write and typeset a short report with your results, making use of your initial layout -* Submit assignment by creating a pull request on the original [ICCP/ising](https://github.com/ICCP/ising) repository diff --git a/Readme b/Readme new file mode 100644 index 0000000..bd2f1eb --- /dev/null +++ b/Readme @@ -0,0 +1,4 @@ +Cd into source direction and type + +./run_ising.sh + diff --git a/Readme~ b/Readme~ new file mode 100644 index 0000000..e69de29 diff --git a/report/Animation_Images/SpinData00001.png b/report/Animation_Images/SpinData00001.png new file mode 100644 index 0000000..263236a Binary files /dev/null and b/report/Animation_Images/SpinData00001.png differ diff --git a/report/Animation_Images/SpinData00002.png b/report/Animation_Images/SpinData00002.png new file mode 100644 index 0000000..51520d3 Binary files /dev/null and b/report/Animation_Images/SpinData00002.png differ diff --git a/report/Animation_Images/SpinData00003.png b/report/Animation_Images/SpinData00003.png new file mode 100644 index 0000000..2326e10 Binary files /dev/null and b/report/Animation_Images/SpinData00003.png differ diff --git a/report/Animation_Images/SpinData00004.png b/report/Animation_Images/SpinData00004.png new file mode 100644 index 0000000..09945e5 Binary files /dev/null and b/report/Animation_Images/SpinData00004.png differ diff --git a/report/Animation_Images/SpinData00005.png b/report/Animation_Images/SpinData00005.png new file mode 100644 index 0000000..3c5542e Binary files /dev/null and b/report/Animation_Images/SpinData00005.png differ diff --git a/report/Animation_Images/SpinData00006.png b/report/Animation_Images/SpinData00006.png new file mode 100644 index 0000000..d44d54e Binary files /dev/null and b/report/Animation_Images/SpinData00006.png differ diff --git a/report/Animation_Images/SpinData00007.png b/report/Animation_Images/SpinData00007.png new file mode 100644 index 0000000..547e655 Binary files /dev/null and b/report/Animation_Images/SpinData00007.png differ diff --git a/report/Animation_Images/SpinData00008.png b/report/Animation_Images/SpinData00008.png new file mode 100644 index 0000000..1a10a28 Binary files /dev/null and b/report/Animation_Images/SpinData00008.png differ diff --git a/report/Animation_Images/SpinData00009.png b/report/Animation_Images/SpinData00009.png new file mode 100644 index 0000000..8ba66ee Binary files /dev/null and b/report/Animation_Images/SpinData00009.png differ diff --git a/report/Animation_Images/SpinData00010.png b/report/Animation_Images/SpinData00010.png new file mode 100644 index 0000000..6223160 Binary files /dev/null and b/report/Animation_Images/SpinData00010.png differ diff --git a/report/Animation_Images/SpinData00011.png b/report/Animation_Images/SpinData00011.png new file mode 100644 index 0000000..191d21b Binary files /dev/null and b/report/Animation_Images/SpinData00011.png differ diff --git a/report/Animation_Images/SpinData00012.png b/report/Animation_Images/SpinData00012.png new file mode 100644 index 0000000..cd44cc5 Binary files /dev/null and b/report/Animation_Images/SpinData00012.png differ diff --git a/report/Animation_Images/SpinData00013.png b/report/Animation_Images/SpinData00013.png new file mode 100644 index 0000000..d1cde53 Binary files /dev/null and b/report/Animation_Images/SpinData00013.png differ diff --git a/report/Animation_Images/SpinData00014.png b/report/Animation_Images/SpinData00014.png new file mode 100644 index 0000000..6d08aa1 Binary files /dev/null and b/report/Animation_Images/SpinData00014.png differ diff --git a/report/Animation_Images/SpinData00015.png b/report/Animation_Images/SpinData00015.png new file mode 100644 index 0000000..94f30c5 Binary files /dev/null and b/report/Animation_Images/SpinData00015.png differ diff --git a/report/Animation_Images/SpinData00016.png b/report/Animation_Images/SpinData00016.png new file mode 100644 index 0000000..fb8172b Binary files /dev/null and b/report/Animation_Images/SpinData00016.png differ diff --git a/report/Animation_Images/SpinData00017.png b/report/Animation_Images/SpinData00017.png new file mode 100644 index 0000000..f5eb9fd Binary files /dev/null and b/report/Animation_Images/SpinData00017.png differ diff --git a/report/Animation_Images/SpinData00018.png b/report/Animation_Images/SpinData00018.png new file mode 100644 index 0000000..a180c98 Binary files /dev/null and b/report/Animation_Images/SpinData00018.png differ diff --git a/report/Animation_Images/SpinData00019.png b/report/Animation_Images/SpinData00019.png new file mode 100644 index 0000000..0481f74 Binary files /dev/null and b/report/Animation_Images/SpinData00019.png differ diff --git a/report/Animation_Images/SpinData00020.png b/report/Animation_Images/SpinData00020.png new file mode 100644 index 0000000..2dc9d5a Binary files /dev/null and b/report/Animation_Images/SpinData00020.png differ diff --git a/report/Animation_Images/SpinData00021.png b/report/Animation_Images/SpinData00021.png new file mode 100644 index 0000000..e566777 Binary files /dev/null and b/report/Animation_Images/SpinData00021.png differ diff --git a/report/Animation_Images/SpinData00022.png b/report/Animation_Images/SpinData00022.png new file mode 100644 index 0000000..80d9135 Binary files /dev/null and b/report/Animation_Images/SpinData00022.png differ diff --git a/report/Animation_Images/SpinData00023.png b/report/Animation_Images/SpinData00023.png new file mode 100644 index 0000000..bd9756e Binary files /dev/null and b/report/Animation_Images/SpinData00023.png differ diff --git a/report/Animation_Images/SpinData00024.png b/report/Animation_Images/SpinData00024.png new file mode 100644 index 0000000..155e6eb Binary files /dev/null and b/report/Animation_Images/SpinData00024.png differ diff --git a/report/Animation_Images/SpinData00025.png b/report/Animation_Images/SpinData00025.png new file mode 100644 index 0000000..c95c2ae Binary files /dev/null and b/report/Animation_Images/SpinData00025.png differ diff --git a/report/Animation_Images/SpinData00026.png b/report/Animation_Images/SpinData00026.png new file mode 100644 index 0000000..bacba46 Binary files /dev/null and b/report/Animation_Images/SpinData00026.png differ diff --git a/report/Animation_Images/SpinData00027.png b/report/Animation_Images/SpinData00027.png new file mode 100644 index 0000000..6106729 Binary files /dev/null and b/report/Animation_Images/SpinData00027.png differ diff --git a/report/Animation_Images/SpinData00028.png b/report/Animation_Images/SpinData00028.png new file mode 100644 index 0000000..b7817fc Binary files /dev/null and b/report/Animation_Images/SpinData00028.png differ diff --git a/report/Animation_Images/SpinData00029.png b/report/Animation_Images/SpinData00029.png new file mode 100644 index 0000000..a3866c6 Binary files /dev/null and b/report/Animation_Images/SpinData00029.png differ diff --git a/report/Animation_Images/SpinData00030.png b/report/Animation_Images/SpinData00030.png new file mode 100644 index 0000000..75de001 Binary files /dev/null and b/report/Animation_Images/SpinData00030.png differ diff --git a/report/Animation_Images/SpinData00031.png b/report/Animation_Images/SpinData00031.png new file mode 100644 index 0000000..eeda8a0 Binary files /dev/null and b/report/Animation_Images/SpinData00031.png differ diff --git a/report/Animation_Images/SpinData00032.png b/report/Animation_Images/SpinData00032.png new file mode 100644 index 0000000..6740cf4 Binary files /dev/null and b/report/Animation_Images/SpinData00032.png differ diff --git a/report/Animation_Images/SpinData00033.png b/report/Animation_Images/SpinData00033.png new file mode 100644 index 0000000..2cae8e3 Binary files /dev/null and b/report/Animation_Images/SpinData00033.png differ diff --git a/report/Animation_Images/SpinData00034.png b/report/Animation_Images/SpinData00034.png new file mode 100644 index 0000000..6ab0090 Binary files /dev/null and b/report/Animation_Images/SpinData00034.png differ diff --git a/report/Animation_Images/SpinData00035.png b/report/Animation_Images/SpinData00035.png new file mode 100644 index 0000000..67f3a7c Binary files /dev/null and b/report/Animation_Images/SpinData00035.png differ diff --git a/report/Animation_Images/SpinData00036.png b/report/Animation_Images/SpinData00036.png new file mode 100644 index 0000000..467dba9 Binary files /dev/null and b/report/Animation_Images/SpinData00036.png differ diff --git a/report/Animation_Images/SpinData00037.png b/report/Animation_Images/SpinData00037.png new file mode 100644 index 0000000..c12d56c Binary files /dev/null and b/report/Animation_Images/SpinData00037.png differ diff --git a/report/Animation_Images/SpinData00038.png b/report/Animation_Images/SpinData00038.png new file mode 100644 index 0000000..321db73 Binary files /dev/null and b/report/Animation_Images/SpinData00038.png differ diff --git a/report/Animation_Images/SpinData00039.png b/report/Animation_Images/SpinData00039.png new file mode 100644 index 0000000..dccbdda Binary files /dev/null and b/report/Animation_Images/SpinData00039.png differ diff --git a/report/Animation_Images/SpinData00040.png b/report/Animation_Images/SpinData00040.png new file mode 100644 index 0000000..8c18ebc Binary files /dev/null and b/report/Animation_Images/SpinData00040.png differ diff --git a/report/Animation_Images/SpinData00041.png b/report/Animation_Images/SpinData00041.png new file mode 100644 index 0000000..dc3a0e2 Binary files /dev/null and b/report/Animation_Images/SpinData00041.png differ diff --git a/report/Animation_Images/SpinData00042.png b/report/Animation_Images/SpinData00042.png new file mode 100644 index 0000000..6b510cb Binary files /dev/null and b/report/Animation_Images/SpinData00042.png differ diff --git a/report/Animation_Images/SpinData00043.png b/report/Animation_Images/SpinData00043.png new file mode 100644 index 0000000..3d5823c Binary files /dev/null and b/report/Animation_Images/SpinData00043.png differ diff --git a/report/Animation_Images/SpinData00044.png b/report/Animation_Images/SpinData00044.png new file mode 100644 index 0000000..fb10ce9 Binary files /dev/null and b/report/Animation_Images/SpinData00044.png differ diff --git a/report/Animation_Images/SpinData00045.png b/report/Animation_Images/SpinData00045.png new file mode 100644 index 0000000..8c78768 Binary files /dev/null and b/report/Animation_Images/SpinData00045.png differ diff --git a/report/Animation_Images/SpinData00046.png b/report/Animation_Images/SpinData00046.png new file mode 100644 index 0000000..90bc7b0 Binary files /dev/null and b/report/Animation_Images/SpinData00046.png differ diff --git a/report/Animation_Images/SpinData00047.png b/report/Animation_Images/SpinData00047.png new file mode 100644 index 0000000..be6bd19 Binary files /dev/null and b/report/Animation_Images/SpinData00047.png differ diff --git a/report/Animation_Images/SpinData00048.png b/report/Animation_Images/SpinData00048.png new file mode 100644 index 0000000..a8d58fa Binary files /dev/null and b/report/Animation_Images/SpinData00048.png differ diff --git a/report/Animation_Images/SpinData00049.png b/report/Animation_Images/SpinData00049.png new file mode 100644 index 0000000..4d239e4 Binary files /dev/null and b/report/Animation_Images/SpinData00049.png differ diff --git a/report/Animation_Images/SpinData00050.png b/report/Animation_Images/SpinData00050.png new file mode 100644 index 0000000..c0ea320 Binary files /dev/null and b/report/Animation_Images/SpinData00050.png differ diff --git a/report/Animation_Images/SpinData00051.png b/report/Animation_Images/SpinData00051.png new file mode 100644 index 0000000..43efe53 Binary files /dev/null and b/report/Animation_Images/SpinData00051.png differ diff --git a/report/Internal_Energy_v_Temp.png b/report/Internal_Energy_v_Temp.png new file mode 100644 index 0000000..3c56e69 Binary files /dev/null and b/report/Internal_Energy_v_Temp.png differ diff --git a/report/Ising2Report.tex b/report/Ising2Report.tex new file mode 100644 index 0000000..e843e54 --- /dev/null +++ b/report/Ising2Report.tex @@ -0,0 +1,220 @@ +\documentclass[10pt]{article} +\usepackage[utf8]{inputenc} + +%%% PAGE DIMENSIONS +\usepackage{geometry} +\geometry{a4paper} +\geometry{margin=.75in} + +%%% PACKAGES +\usepackage{booktabs} +\usepackage{array} +\usepackage{paralist} +\usepackage{verbatim} +\usepackage{subfig} +\usepackage{caption} +\usepackage{amsmath} +\usepackage{float} +\usepackage{color} +\usepackage[pdftex]{graphicx} + +%%% HEADERS & FOOTERS +\usepackage{fancyhdr} +\pagestyle{fancy} +\renewcommand{\headrulewidth}{0pt} +\lhead{}\chead{}\rhead{} +\lfoot{}\cfoot{\thepage}\rfoot{} + +%%% ANIMATIONS +\usepackage{animate} + +%%% SECTION TITLE APPEARANCE +\usepackage{sectsty} +\allsectionsfont{\sffamily\mdseries\upshape} + + +%%% ToC (table of contents) APPEARANCE +\usepackage[nottoc,notlof,notlot]{tocbibind} +\usepackage[titles,subfigure]{tocloft} +\renewcommand{\cftsecfont}{\rmfamily\mdseries\upshape} +\renewcommand{\cftsecpagefont}{\rmfamily\mdseries\upshape} + +\title{Monte Carlo Methodology and the Wolff Algorithm: \newline The Ising Model Revisited} +\author{Mark Wittekind \& Drew Murray} + +%\date{} % Remove the '%' before '\date{}' to display a given date or no date (if empty), + % otherwise leave the '%' and the current date is printed + +\newcommand{\beq}{\begin{equation}} +\newcommand{\eeq}{\end{equation}} +\newcommand{\n}{\noindent} + + +\begin{document} +\maketitle +\section{Introduction} + +The Ising model consists of a collection of particles arranged in a lattice. Each particle can have one of two spins, up or down, making a binary system. The Wolff algorithm uses clustering to pseudo-randomly update the spins in a manner that resembles temperature demagnetization of physical binary systems. By simulating the lattice's response to temperature for many different temperatures, many physical phenomena can be observed. + + +\section{Initial Conditions} + +A periodic, 2D lattice of size 100x100 particles, evenly spaced and with identical spins, was initialized. The simulation was then run for a range of pre-specified temperatures. For each temperature, the lattice was reinitialized and the Wolff algorithm was subsequently run a large number of timesteps to ensure steady-state magnetization. + +\beq +\label{eqn:equation1} +Timesteps = \frac{Tn}{2} +\eeq + +where n is the number of particles in the system. + +Although we do not know the explicit functional dependence of accuracy on temperature we do know the runtime depends exponentially on T. Therefore a simple method to reduce runtime at lower temperatures while maintaining a reasonable degree of accuracy at higher temperatures is to vary the timesteps as a linear function of temperature. + +\section{Runtime} + +The Wolff algorithm creates clusters and flips the spin of all constituent particles. It adds particles to the cluster semi-randomly dependent on temperature. + +\subsection{Wolff Algorithm} + +1) Choose a particle at random and flip its spin +2) Consider all nearest neighbors, add each neighbor with the same spin as the original particle to a queue with probability +\beq +\label{eqn:equation2} +P(T)=1-e^{\frac{-2J}{K_{b}T}} +\eeq +3) If the particle was added to the queue, flip its spin +4) Repeat from step 2 with the first particle in the queue as the 'chosen' particle + +\subsection{Temperature Range} +We chose two temperature ranges to observe due to limitations on computation time: + +\subsection{Magnetization versus Temperature} +We selected a relatively large range of temperatures (1-5) to explore when interested in the behavior of magnetization as a function of temperature. Due to the larger range of temperatures we had to reduce the resolution in temperature steps to a delta T of .002 to hit a target runtime. + +\subsection{Critical Temperature} +In looking for the critical temperature $T_c$ we could explore a smaller temperature range (2.2-2.4) with a higher resolution delta T of .00015. + +\section{Results \& Analysis} +\subsection{Magnetization} +\subsubsection{Calculation} +Magnetization was normalized on the number of spin states in our lattice as follows: + +\beq +\label{eqn:equation3} +m=|\frac{1}{n}\sum\limits_{i,j} s_{i,j}| +\eeq + +\subsubsection{Behavior} +At temperatures far below $T_c$ we observe rapid oscillation of spin across the whole system. This agrees with our expectations due to the lack of an external field establishing a distinction between spin up and down. + + +Near $T_c$ we observe a rapid drop in magnetization from 1 to zero. + +At temperatures above $T_c$ we observe random spin states leading to an overall magnetization of approximately zero. These observations are illustrated. + +\begin{figure}[H] +\centering +\begin{minipage}{.75\textwidth} +\centering +\includegraphics[width= \linewidth]{Mag_v_Temp.png} +\end{minipage}\hfill +\caption{Plot of magnetization versus temperature.} +\label{fig:figure1} +\end{figure} +\n +\subsection{Susceptibility} +Susceptibility is calculated as follows: + +\beq +\label{eqn:equation4} +\chi=\frac{\partial \bar{m}}{\partial t} +\eeq + +We utilized this calculation to find $T_c$ = 2.285 by locating the minimum of this plot. This agrees with our expectations of a $T_c$ of around 2.2. + +\begin{figure}[H] +\centering +\begin{minipage}{.75\textwidth} +\centering +\includegraphics[width= \linewidth]{Sus_v_Temp.png} +\end{minipage}\hfill +\caption{Plot of susceptibility versus temperature.} +\label{fig:figure2} +\end{figure} +\n +\subsection{Internal Energy} +Internal energy is calculated as follows: + +\beq +\label{eqn:equation5} +U=-J\sum\limits_{} s_is_j +\eeq + +This behaves similarly to m(T) as expected. + +\begin{figure}[H] +\centering +\begin{minipage}{.75\textwidth} +\centering +\includegraphics[width= \linewidth]{Internal_Energy_v_Temp.png} +\end{minipage}\hfill +\caption{Plot of internal energy versus temperature.} +\label{fig:figure3} +\end{figure} +\n +\subsection{Specific Heat} +Specific heat is calculated as follows: + +\beq +\label{eqn:equation6} +\chi=\frac{\partial U}{\partial t} +\eeq + +This behaves similar to $\chi(T)$ and centers on $T_c$. + +\begin{figure}[H] +\centering +\begin{minipage}{.75\textwidth} +\centering +\includegraphics[width= \linewidth]{Specific_Heat_v_Temp.png} +\end{minipage}\hfill +\caption{Plot of specific heat versus temperature.} +\label{fig:figure4} +\end{figure} +\n +\n +\subsection{Critical Exponent} +The critical exponent $\gamma$ is defined as follows: + + +\beq +\label{eqn:equation7} +m\approx |T-T_c|^{\gamma} +\eeq + +Using logarithms we can solve for $\gamma$: + +\beq +\label{eqn:equation8} +\gamma \approx log(m-|T-T_c|) +\eeq + +\begin{figure}[H] +\centering +\begin{minipage}{.75\textwidth} +\centering +\includegraphics[width= \linewidth]{log_mag_v_log_tmtc.png} +\end{minipage}\hfill +\caption{Plot of log(m) versus log(abs(T-Tc)).} +\label{fig:figure5} +\end{figure} +\n + +\section{Conclusion} +Using the Wolff algorithm on a finite, periodic lattice, the temperature dependence of magnetization, susceptibility, internal energy, and heat capacity can be found. The critical temperature was found to be 2.285 (in natural units) which is the temperature at which susceptibility is minimal. The critical exponent $\gamma$ was found to be 0.1 which is close to the expected 0.125. + + + + + +\end{document} diff --git a/report/Mag_v_Temp.png b/report/Mag_v_Temp.png new file mode 100644 index 0000000..df374a3 Binary files /dev/null and b/report/Mag_v_Temp.png differ diff --git a/report/Specific_Heat_v_Temp.png b/report/Specific_Heat_v_Temp.png new file mode 100644 index 0000000..d53feec Binary files /dev/null and b/report/Specific_Heat_v_Temp.png differ diff --git a/report/Sus_v_Temp.png b/report/Sus_v_Temp.png new file mode 100644 index 0000000..4d2dd3b Binary files /dev/null and b/report/Sus_v_Temp.png differ diff --git a/report/figures/fig_1.pdf b/report/figures/fig_1.pdf deleted file mode 100644 index 629164b..0000000 Binary files a/report/figures/fig_1.pdf and /dev/null differ diff --git a/report/log_mag_v_log_tmtc.png b/report/log_mag_v_log_tmtc.png new file mode 100644 index 0000000..e7b4989 Binary files /dev/null and b/report/log_mag_v_log_tmtc.png differ diff --git a/report/report.tex b/report/report.tex deleted file mode 100644 index 72d1253..0000000 --- a/report/report.tex +++ /dev/null @@ -1,156 +0,0 @@ -\documentclass[]{article} - -\usepackage{amsmath} % AMS math package -\usepackage{amssymb} % AMS symbol package -\usepackage{bm} % bold math -\usepackage{graphicx} % Include figure files -\usepackage{dcolumn} % Align table columns on decimal point -\usepackage{multirow} % Multirow/column tables -\usepackage{hyperref} % Hyperlinks - -\begin{document} - -\title{Manuscript Title:\\with Forced Linebreak}% Force line breaks with \\ -\author{Ann Author} -\date{\today}% It is always \today, today, but you can specify other dates manually -\maketitle - -\begin{abstract} -An article usually includes an abstract, a concise summary of the work -covered at length in the main body of the article. -\end{abstract} - - -\section{First-level heading} %Title for the section -\label{sec:level1} %Label for the section, to be used for referencing in other parts of the document - -This sample document demonstrates some common uses of \LaTeX\ in documents you'll write for ICCP. Further information can be found online at the \href{http://en.wikibooks.org/wiki/LaTeX}{\LaTeX\ wikibook} or in the distribution documentation. - -When we refer to commands in this example file, they always have their required formal arguments in normal \TeX{} format. In this format, \verb+#1+, \verb+#2+, etc. stand for required author-supplied arguments to commands. For example, in \verb+\section{#1}+ the \verb+#1+ stands for the title text of the author's section heading, and in \verb+\title{#1}+ the \verb+#1+ stands for the title text of the paper. - -Line breaks in section headings at all levels can be introduced using \textbackslash\textbackslash. A blank input line tells \TeX\ that the paragraph has ended. - -\subsection{\label{sec:level2} Second-level heading: Formatting} - -This file may be formatted in either the \texttt{preprint} or \texttt{reprint} style. \texttt{reprint} format mimics final journal output. The paper size may be specified with the option \texttt{letter}. These options are inserted in the square brackets inside the \texttt{\textbackslash documentclass[]\{article\}} command. - -\section{Math and Equations} -Inline math may be typeset using the \verb+$+ delimiters. Bold math symbols may be achieved using the \verb+bm+ package and the \verb+\bm{#1}+ command it supplies. For instance, a bold $\alpha$ can be typeset as \verb+$\bm{\alpha}$+ giving $\bm{\alpha}$. Fraktur and Blackboard (or open face or double struck) characters should be typeset using the \verb+\mathfrak{#1}+ and \verb+\mathbb{#1}+ commands respectively. Both are supplied by the \texttt{amssymb} package. For -example, \verb+$\mathbb{R}$+ gives $\mathbb{R}$ and \verb+$\mathfrak{G}$+ gives $\mathfrak{G}$ - -In \LaTeX\ there are many different ways to display equations, and a few preferred ways are noted below. Displayed math will center by default. Use the class option \verb+fleqn+ to flush equations left. - -Below we have numbered single-line equations; this is generally the most common type of equation in \LaTeX: -\begin{equation} -\label{eq:one} %Label for the equation, to be used for referencing in other parts of the document - i \hbar \frac{\partial \Psi}{\partial t} = -\frac{\hbar^2}{2m}\nabla^2 \psi + U(\mathbf{x}) \psi -\end{equation} - -When the \verb+\label{#1}+ command is used [cf. input for Eq.~(\ref{eq:one})], the equation can be referred to in text without knowing the equation number that \TeX\ will assign to it. Just use \verb+\ref{#1}+, where \verb+#1+ is the same name that was used in the \verb+\label{#1}+ command. - -Unnumbered single-line equations can be typeset using the \verb+equation*+ environment: -\begin{equation*} - \hat{f}(\xi) = \int_{-\infty}^\infty f(x) e^{-2\pi i x \xi} \, \mathrm{d}x -\end{equation*} - -\subsection{Multiline equations} - -You'll generally want to use the \verb+align+ environment for multiline equations. Use the \verb+\nonumber+ command at the end of each line (again denoted with \textbackslash\textbackslash) to avoid assigning a number, or \verb+align*+ to disable numbering entirely: -\begin{align} - \sin(2\theta) &= 2 \sin(\theta) \cos(\theta) \nonumber \\ - &= \frac{2\tan(\theta)}{1 + \tan^2(\theta)} -\end{align} -Note how alignment occurs at the (unprinted) \verb+&+ character. - -Do not use \verb+\label{#1}+ on a line of a multiline equation if \verb+\nonumber+ is also used on that line. Incorrect cross-referencing will result. Notice the use \verb+\text{#1}+ for using a Roman font within a math environment. - -\section{Cross-referencing} -\LaTeX\ will automatically number such things as sections, footnotes, equations, figure captions, and table captions for you. In order to reference them in text, use the \verb+\label{#1}+ and \verb+\ref{#1}+ commands\footnote{Check out the \texttt{cleveref} (one r) package, too!}. To reference a particular page, use the \verb+\pageref{#1}+ command. - -The \verb+\label{#1}+ should appear within the section heading (or immediately after), within the footnote text, within the equation, or within the table or figure caption. The \verb+\ref{#1}+ command is used in text at the point where the reference is to be displayed. Some examples: Section~\ref{sec:level1} on page~\pageref{sec:level1}, Table~\ref{tab:table1}, and Fig.~\ref{fig:epsart}. -\begin{figure}[b] - \centering - \includegraphics{figures/fig_1}% Imports a figure - does not automatically scale - \caption{\label{fig:epsart} A figure caption. The figure captions are automatically numbered.} -\end{figure} - -\section{Floats: Figures, Tables, etc.} -Figures (images) and tables are usually allowed to ``float'', which means that their placement is determined by \LaTeX, while the document is being typeset. - -Use the \texttt{figure} environment for a figure, the \texttt{table} environment for a table. In each case, use the \verb+\caption+ command within to give the text of the figure or table caption along with the \verb+\label+ command to provide a key for referring to this figure or table. Insert an image using either the \texttt{graphics} or \texttt{graphix} packages, which define the \verb+\includegraphics{#1}+ command. (The two packages differ in respect of the optional arguments used to specify the orientation, scaling, and translation of the image.) To create an alignment, use the \texttt{tabular} environment. - -\begin{table} - \centering - \begin{tabular}{ |l|l|l| } - \hline - \multicolumn{3}{ |c| }{Team sheet} \\ - \hline - Goalkeeper & GK & Paul Robinson \\ \hline - \multirow{4}{*}{Defenders} & LB & Lucus Radebe \\ - & DC & Michael Duburry \\ - & DC & Dominic Matteo \\ - & RB & Didier Domi \\ \hline - \multirow{3}{*}{Midfielders} & MC & David Batty \\ - & MC & Eirik Bakke \\ - & MC & Jody Morris \\ \hline - Forward & FW & Jamie McMaster \\ \hline - \multirow{2}{*}{Strikers} & ST & Alan Smith \\ - & ST & Mark Viduka \\ - \hline - \end{tabular} - \caption{\label{tab:table1}A table, demonstrating the use of the \texttt{multirow} package for spanning rows and columns.} -\end{table} - -The best place for the \texttt{figure} or \texttt{table} environment is immediately following its first reference in text; this sample document illustrates this practice for Fig.~\ref{fig:epsart}, which shows a figure that is small enough to fit in a single column. In exceptional cases, you will need to move the float earlier in the document: \LaTeX's float placement algorithms need to know about a full-page-width float sooner. - -The content of a table is typically a \texttt{tabular} environment, giving rows of type in aligned columns. Column entries separated by \verb+&+'s, and -each row ends with \textbackslash\textbackslash. The required argument for the \texttt{tabular} environment specifies how data are aligned in the columns. -For instance, entries may be centered, left-justified, right-justified, aligned on a decimal point. - -Extra column-spacing may be be specified as well, although \LaTeX sets this spacing so that the columns fill the width of the table. Horizontal rules are typeset using the \verb+\hline+ command. Rows with that columns span multiple columns can be typeset using the \verb+\multicolumn{#1}{#2}{#3}+ command (for example, see the first row of Table~\ref{tab:table1}). - -\appendix - -\section{Appendixes} - -To start the appendixes, use the \verb+\appendix+ command. This signals that all following section commands refer to appendixes instead of regular sections. Therefore, the \verb+\appendix+ command should be used only once---to setup the section commands to act as appendixes. Thereafter normal section commands are used. The heading for a section can be left empty. For example, -\begin{verbatim} -\appendix -\section{} -\end{verbatim} -will produce an appendix heading that says ``APPENDIX A'' and -\begin{verbatim} -\appendix -\section{Background} -\end{verbatim} -will produce an appendix heading that says ``APPENDIX A: BACKGROUND'' (note that the colon is set automatically). - -If there is only one appendix, then the letter ``A'' should not appear. This is suppressed by using the star version of the appendix command (\verb+\appendix*+ in the place of \verb+\appendix+). - -\section{A little more on appendixes} - -Observe that this appendix was started by using -\begin{verbatim} -\section{A little more on appendixes} -\end{verbatim} - -Note the equation number in an appendix: -\begin{equation} - E^2=p^2c^2 + m^2c^4. -\end{equation} - -\subsection{\label{app:subsec}A subsection in an appendix} - -You can use a subsection or subsubsection in an appendix. Note the numbering: we are now in Appendix~\ref{app:subsec}. - -Note the equation numbers in this appendix, produced with the subequations environment: -\begin{subequations} -\begin{align} - E^2 &= m^2c^4 \quad \text{(rest)}, \label{appa} \\ - E^2 &= m^2c^4 + p^2 c^2 \quad \text{(relativistic)}, \label{appb} \\ - E^2 &\approx p^2 c^2 \quad \text{(ultrarelativistic)} \label{appc} -\end{align} -\end{subequations} -They turn out to be Eqs.~(\ref{appa}), (\ref{appb}), and (\ref{appc}). - -\end{document} diff --git a/report/spins.gif b/report/spins.gif new file mode 100644 index 0000000..6f5d671 Binary files /dev/null and b/report/spins.gif differ diff --git a/src/CLattice.cpp b/src/CLattice.cpp new file mode 100644 index 0000000..6cf57fb --- /dev/null +++ b/src/CLattice.cpp @@ -0,0 +1,190 @@ +/* + * File: CLattice.cpp + * Author: Mark Wittekind and Drew Murray + * + * Created on March 6, 2015, 11:51 AM + */ + +#include "CLattice.h" + +#include +#include +#include +#include + +using namespace std; + +CLattice::CLattice(const unsigned short h, const unsigned short w, + const float j) : + CObject() { + m_height = h; + m_width = w; + m_COUPLING_CONSTANT = j; + // Fill lattice with initial values + for (unsigned short i = 0; i <= m_height; i++) { + m_lattice.push_back(vector()); + for (unsigned short j = 0; j <= m_width; j++) { + m_lattice[i].push_back(false); + } + } + +} + +CLattice::~CLattice() { +} + +void CLattice::update(SimulationParameters* SimPar) { + + unsigned short y = rand() % m_height; + unsigned short x = rand() % m_width; + bool old_spin = m_lattice[y][x]; + m_lattice[y][x] = !old_spin; + vector temp = { y, x }; + m_queue.push(temp); + while (!m_queue.empty()) { + y = m_queue.front()[0]; + x = m_queue.front()[1]; + m_queue.pop(); + unsigned short newy, newx; + for (short i = 0; i < 4; i++) { + switch (i) { + case 0: + newy = y; + if (x == 0) + newx = m_width - 1; + else + newx = x - 1; + break; + case 1: + newy = y; + newx = (x + 1) % m_width; + break; + case 2: + if (y == 0) + newy = m_height - 1; + else + newy = y - 1; + newx = x; + break; + case 3: + newy = (y + 1) % m_height; + newx = x; + break; + } + if (m_lattice[newy][newx] == old_spin + && float(rand()) / float(RAND_MAX) + < (1 + - exp( + -2.0 * SimPar->COUPLING_CONSTANT + / (SimPar->BOLTZMAN_CONSTANT + * SimPar->temperature)))) { + m_lattice[newy][newx] = !old_spin; + temp.clear(); + temp.push_back(newy); + temp.push_back(newx); + m_queue.push(temp); + } + } + + } + return; +} + +float CLattice::calcMag() { + float s = 0; + for (unsigned short i = 0; i < m_height; i++) { + for (unsigned short j = 0; j < m_width; j++) { + if (m_lattice[i][j]) + s++; + else + s--; + } + } + s /= float(m_width * m_height); + return abs(s); +} + +float CLattice::calcEnergy() { + signed short Energy = 0; + for (unsigned short y = 0; y < m_height; y++) { + for (unsigned short x = 0; x < m_width; x++) { + for (short i = 0; i < 2; i++) { + unsigned short newy = 0; + unsigned short newx = 0; + switch (i) { + case 0: + newy = y; + if (x == 0) + newx = m_width - 1; + else + newx = x - 1; + break; + case 1: + if (y == 0) + newy = m_height - 1; + else + newy = y - 1; + newx = x; + break; + } + signed short s[2] = { -1, -1 }; + if (m_lattice[newy][newx]) + s[0] = 1; + if (m_lattice[y][x]) + s[1] = 1; + Energy += (s[0] * s[1]); + } + } + } + return abs(2.0 * Energy * m_COUPLING_CONSTANT); +} + +void CLattice::print_all(ostream& pos_stream, ostream& mag_stream, SimulationParameters* SimPar) { + const string TRUE_CHAR = "1"; + const string FALSE_CHAR = "0"; + const bool labels = false; + + mag_stream << calcMag() << " "; + + for(unsigned short i = 1; i< m_height+1; i++) { + string newstring = ""; + if(labels) { + string adjust = ""; + + if (i< 10)adjust = " "; + string newstring = adjust + to_string(i); + } + string header(" "); + if (i==1) + { + for(unsigned short j = 1; j +#include +#include +#include +#include "SimulationParametersStruct.cpp" + +#include "CObject.h" + +using namespace std; + +class CLattice : public CObject{ +public: + CLattice(const unsigned short h, const unsigned short w, const float j); + ~CLattice(); + void print_all(ostream& pos_stream, ostream& mag_stream, SimulationParameters* SimPar); + void update(SimulationParameters* SimPar); + float calcMag(); + float calcEnergy(); +private: + vector > m_lattice; + unsigned short m_height; + unsigned short m_width; + float m_COUPLING_CONSTANT; + queue> m_queue; + +}; + +#endif /* CLATTICE_H */ diff --git a/src/CObject.cpp b/src/CObject.cpp new file mode 100644 index 0000000..45ab179 --- /dev/null +++ b/src/CObject.cpp @@ -0,0 +1,34 @@ +/* + * File: CObject.cpp + * Author: Mark Wittekind and Drew Murray + * + * Created on March 6, 2015, 11:53 AM + */ + +#include "CObject.h" + +CObject::CObject() { +} + + +CObject::~CObject() { +} + +void CObject::update(SimulationParameters* SimPar){ + cout << "Called CObject update (bad)\n"; + return; +} + +void CObject::print_all(ostream& pos_stream, ostream& mag_stream, SimulationParameters* SimPar){ + cout << "Called CObject print_all (bad)\n"; + return; +} +float CObject::calcMag(){ + cout << "Called CObject calcMag (bad)\n"; + return 0.0; +} +float CObject::calcEnergy(){ + cout << "Called CObject calcEnergy (bad)\n"; + return 0.0; +} + diff --git a/src/CObject.h b/src/CObject.h new file mode 100644 index 0000000..c84512d --- /dev/null +++ b/src/CObject.h @@ -0,0 +1,28 @@ +/* + * File: CObject.h + * Author: Mark Wittekind and Drew Murray + * + * Created on March 6, 2015, 11:53 AM + */ + +#ifndef COBJECT_H +#define COBJECT_H +#include +#include +#include +#include "SimulationParametersStruct.cpp" +using namespace std; + +class CObject { +public: + CObject(); + virtual ~CObject(); + virtual void update(SimulationParameters* SimPar); + virtual void print_all(ostream& pos_stream, ostream& mag_stream, SimulationParameters* SimPar); + virtual float calcMag(); + virtual float calcEnergy(); +private: + +}; + +#endif /* COBJECT_H */ diff --git a/src/CSimulation.cpp b/src/CSimulation.cpp new file mode 100644 index 0000000..bb0b254 --- /dev/null +++ b/src/CSimulation.cpp @@ -0,0 +1,66 @@ +/* + * File: CSimulation.cpp + * Author: Mark Wittekind and Drew Murray + * + * Created on March 6, 2015, 11:33 AM + */ + +#include "CSimulation.h" +#include "CObject.h" +#include "SimulationParametersStruct.cpp" + +CSimulation::CSimulation(SimulationParameters *SimPar) { + m_simPar = SimPar; +} + +void CSimulation::addObject(CObject* obj){ + m_objects.push_back(obj); +} + + +CSimulation::~CSimulation() { +} + +float CSimulation::calcMag(){ + float magTot = 0.0; + for (vector::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){ + magTot += (*it2)->calcMag(); + } + return magTot; +} + +float CSimulation::calcEnergy(){ + float enTot = 0.0; + for (vector::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){ + enTot += (*it2)->calcEnergy(); + } + return enTot; +} + +void CSimulation::run(ostream& pos_stream, ostream& mag_stream, SimulationParameters *SimPar){ + + //mystery line to allow virtual functions to work as they should (this variable is never used) + //CLattice uselessvariable(m_simPar->WIDTH,m_simPar->HEIGHT); + + for (vector::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){ + mag_stream << m_simPar->temperature << "\n"; + (*it2)->print_all(pos_stream, mag_stream, m_simPar); + } + + for(unsigned int t = 0; tMAXTIMESTEPS;t++) + { + for (vector::iterator it = m_objects.begin(); it != m_objects.end(); it++){ + (*it)->update(m_simPar); + } + if((t%SimPar->PRINT_FREQ==m_simPar->PRINT_FREQ-1) || ((t+1)>=(m_simPar->MAXTIMESTEPS))) + { + cout << "printing timestep " << t << " of " << SimPar->MAXTIMESTEPS << "\n"; + for (vector::iterator it2 = m_objects.begin(); it2 != m_objects.end(); it2++){ + (*it2)->print_all(pos_stream,mag_stream, m_simPar); + } + } + } + mag_stream<<"\n"; + pos_stream<<"TEMP CHANGED\n"; + return; + } diff --git a/src/CSimulation.h b/src/CSimulation.h new file mode 100644 index 0000000..ed4ba89 --- /dev/null +++ b/src/CSimulation.h @@ -0,0 +1,32 @@ +/* + * File: CSimulation.h + * Author: Mark Wittekind and Drew Murray + * + * Created on March 6, 2015, 11:33 AM + */ + +#ifndef CSIMULATION_H +#define CSIMULATION_H +#include +#include "CObject.h" +#include "SimulationParametersStruct.cpp" +#include "CLattice.h" +using namespace std; + + +class CSimulation { +public: + CSimulation(SimulationParameters *SimPar); + virtual ~CSimulation(); + void run(ostream& pos_stream, ostream& mag_stream, SimulationParameters *SimPar); + void addObject(CObject* obj); + float calcMag(); + float calcEnergy(); + +private: + SimulationParameters* m_simPar; + vector m_objects; + +}; + +#endif /* CSIMULATION_H */ diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index eb24188..0000000 --- a/src/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -FC = gfortran -FFLAGS = -Wall -Wextra -march=native -O3 -fimplicit-none -#FFLAGS += -pedantic -fbounds-check -fmax-errors=1 -g -FFLAGS += $(shell pkg-config --cflags plplotd-f95) -LDFLAGS = $(shell pkg-config --libs plplotd-f95) -LIBS = - -COMPILE = $(FC) $(FFLAGS) -LINK = $(FC) $(LDFLAGS) - -TARGET = ising.exe # Name of final executable to produce -OBJS = plot.o ising.o # List of object dependencies - -$(TARGET): $(OBJS) - $(LINK) -o $@ $^ $(LIBS) - -%.o:%.f95 - $(COMPILE) -c $< - -.PHONY:clean -clean: - rm *.exe *.o *.mod diff --git a/src/R_code/mag_critical.R b/src/R_code/mag_critical.R deleted file mode 100644 index 4a4878b..0000000 --- a/src/R_code/mag_critical.R +++ /dev/null @@ -1,51 +0,0 @@ -wolff <- read.table("temperature_sweep.dat",header=T) -attach(wolff) - -steps = 14 - -mag.crit <- which.max(Susceptibility) - -x1 = log(abs(Temperature - Temperature[mag.crit])) -y1 = log(Magnetization - Magnetization[mag.crit]) - -plot(x1,y1,type="n", - xlim=c(-3.5,-1), - ylim=c(-1,0), - xlab = "Log(Temperature - Tc)", - ylab ="Log(Magnetization)", - main = expression(paste("Magnetic Exponent ",beta,sep=" "))) - -grid() - -bound = c(120,120) -tc.guesses = Temperature[seq(mag.crit - bound[1], mag.crit + bound[2], - length.out = steps)] - -mag.guesses= Magnetization[seq(mag.crit - bound[1], mag.crit + bound[2], - length.out = steps)] - -colors = rainbow(steps) -colors[7] = "black" - -for(i in 1:steps ){ - d1 = log(-Temperature + tc.guesses[i]) - d2 = log(Magnetization) - - lines(d1,d2,col = colors[i]) - - fitrange = which(-3.5 < d1 & d1 < -2) - - fit = lm(d2[fitrange]~d1[fitrange]) - print(fit) - - if (i == 7) abline(fit, col = colors[i],lty = 4) - print(paste(i,tc.guesses[i])) -} - - - -lines(log(-Temperature + tc.guesses[7]),d2) -fit <- lm(d2[fitrange] ~ log(-Temperature + tc.guesses[7])[fitrange]) -abline(fit,lty = 4) - -detach(wolff) diff --git a/src/R_code/make_plots.R b/src/R_code/make_plots.R deleted file mode 100644 index 4780b30..0000000 --- a/src/R_code/make_plots.R +++ /dev/null @@ -1,39 +0,0 @@ -wolff <- read.table("temperature_sweep.dat",header=T) -attach(wolff) #Attaches wolff to R search path; wolff$Value becomes Value - - -sus.max = which.max(Susceptibility) -cv.max = which.max(Cv) -print(paste("Susceptibility max occurs at:",Temperature[sus.max]) ,sep = " ") -print(paste("Cv max occurs at:",Temperature[cv.max]) ,sep = " ") - -par(mfrow = c(2,2), oma = c(0,0,2,0), mar = c(5,5,2,2) - .3) -#opens graphics device with 2x2 matrix for plots, 2 line outer margin - -plot(Temperature,Magnetization,type="l", - xlab="Temperature",ylab="") -abline(v = Temperature[sus.max],col = "red",lty = 3) -abline(v = Temperature[cv.max],col = "green",lty = 3) - -plot(Temperature,Susceptibility,type="l", - xlab="Temperature",ylab="Susceptibility") -abline(v = Temperature[sus.max],col = "red",lty = 3) -abline(v = Temperature[cv.max],col = "green",lty = 3) - -plot(Temperature,Energy,type="l", - xlab="Temperature",ylab="") -abline(v = Temperature[sus.max],col = "red",lty = 3) -abline(v = Temperature[cv.max],col = "green",lty = 3) - -plot(Temperature,Cv,type="l", - xlab="Temperature",ylab="") -abline(v = Temperature[sus.max],col = "red",lty = 3) -abline(v = Temperature[cv.max],col = "green",lty = 3) - - -mtext("Wolff Algorithm", line = .5, outer = T) - - -detach(wolff) - -#dev.copy2eps(file="system_plots.eps") diff --git a/src/R_code/sus_critical.R b/src/R_code/sus_critical.R deleted file mode 100644 index bccbbee..0000000 --- a/src/R_code/sus_critical.R +++ /dev/null @@ -1,33 +0,0 @@ -wolff <- read.table("temperature_sweep.dat",header=T) -attach(wolff) - -steps = 14 - -sus.crit <- which.max(Susceptibility) - -x1 = log(Temperature - Temperature[sus.crit]) -y1 = log(Susceptibility) - -plot(x1,y1,type="n", - ylim = c(-20,-12), - xlab = "Log(Temperature - Tc)", - ylab = "Log(Susceptibility)", - main = expression(paste("Susceptibility Exponent ",gamma," (tail)"))) - -grid() - -colors = rainbow(steps) -tmps = seq(2, 3, length.out = steps) -for( i in steps:1 ){ - lines(log(Temperature - tmps[i]),log(Susceptibility),col=colors[i]) - } -#plots warm colors first, warm colors represent "guesses" < t_c -lines(x1,y1) - -pow.rng <- which(-3 < x1 & x1 < -1) - -sus.fit <- lm(y1[pow.rng] ~ x1[pow.rng]) - -abline(sus.fit,lty = 4) - -detach(wolff) diff --git a/src/R_code/visualize_lattice.R b/src/R_code/visualize_lattice.R deleted file mode 100644 index 53c2f73..0000000 --- a/src/R_code/visualize_lattice.R +++ /dev/null @@ -1,15 +0,0 @@ -spin.file <- "array.dat" -#change to path of spin output file - -spin.colors <- c("purple","red","green") #downspin, upspin -spin.matrix <- as.matrix(read.table(spin.file)) - -par(mar=c(1,1,3,1)+.1) - -image(spin.matrix,col=spin.colors,axes=FALSE) -title(main="Wolff Cluster Algorithm") - -#axis(1,at=seq(0,1,by=(1/(dim(spin.matrix)[1]-1))*1),labels=F) -#axis(2,at=seq(0,1,by=(1/(dim(spin.matrix)[2]-1))*1),labels=F) -box() -dev.copy2pdf(file="vis_lattice.pdf") #uncomment to generate output file diff --git a/src/SimulationParametersStruct.cpp b/src/SimulationParametersStruct.cpp new file mode 100644 index 0000000..b6c7360 --- /dev/null +++ b/src/SimulationParametersStruct.cpp @@ -0,0 +1,35 @@ +/* + * SimulationParametersStruct.cpp + * + * Created on: Mar 13, 2015 + * Author: Mark Wittekind and Drew Murray + */ +#ifndef SIM_PARAMS_UNIQUE +#define SIM_PARAMS_UNIQUE + +struct SimulationParameters +{ + const unsigned short WIDTH = 50; + const unsigned short HEIGHT = 50; + unsigned short MAXTIME = 50; + float TIMESTEP = 1; + unsigned int MAXTIMESTEPS = short(MAXTIME/TIMESTEP); + float COUPLING_CONSTANT = 1; + float temperature = 2; + float BOLTZMAN_CONSTANT = 1; + unsigned int PRINT_FREQ = 1; + float MIN_TEMP = 1; + float MAX_TEMP = 3; + float TEMP_STEP = .25; + bool CRIT_MODE = false; + unsigned short CRIT_REPEATS = 10; + bool var_timestep = true; + + //TODO + // Critical exponents: + // log(X) vs log(T) + // log(mag) vs log(T) +}; + +#endif + diff --git a/src/UtilityFunctions.cpp b/src/UtilityFunctions.cpp new file mode 100644 index 0000000..5b19296 --- /dev/null +++ b/src/UtilityFunctions.cpp @@ -0,0 +1,18 @@ +/* + * UtilityFunctions.cpp + * + * Created on: Mar 13, 2015 + * Author: Mark Wittekind and Drew Murray + */ + +#include "UtilityFunctions.h" + +Utility_Functions::Utility_Functions() { + // TODO Auto-generated constructor stub + +} + +Utility_Functions::~Utility_Functions() { + // TODO Auto-generated destructor stub +} + diff --git a/src/UtilityFunctions.h b/src/UtilityFunctions.h new file mode 100644 index 0000000..d7005c5 --- /dev/null +++ b/src/UtilityFunctions.h @@ -0,0 +1,17 @@ +/* + * UtilityFunctions.h + * + * Created on: Mar 13, 2015 + * Author: Mark Wittekind and Drew Murray + */ + +#ifndef UTILITYFUNCTIONS_H_ +#define UTILITYFUNCTIONS_H_ + +class Utility_Functions { +public: + Utility_Functions(); + virtual ~Utility_Functions(); +}; + +#endif /* UTILITYFUNCTIONS_H_ */ diff --git a/src/ising_makefile b/src/ising_makefile new file mode 100644 index 0000000..e1b2fdb --- /dev/null +++ b/src/ising_makefile @@ -0,0 +1,29 @@ +CC = g++ +CFLAGS = -Wall -g -std=c++11 +LDFLAGS = -lm +EXENAME = ising2.exe +OBJS = main.o SimulationParametersStruct.o CSimulation.o UtilityFunctions.o CLattice.o CObject.o + +$(EXENAME) : $(OBJS) + ${CC} ${CFLAGS} ${LDFLAGS} $(OBJS) -o $(EXENAME) + +CLattice.o : CLattice.cpp CLattice.h CObject.h + ${CC} ${CFLAGS} -c CLattice.cpp + +CSimulation.o : CSimulation.cpp CSimulation.h CLattice.h SimulationParametersStruct.cpp CObject.h + ${CC} ${CFLAGS} -c CSimulation.cpp + +CObject.o : CObject.cpp CObject.h + ${CC} ${CFLAGS} -c CObject.cpp + +SimulationParametersStruct.o : SimulationParametersStruct.cpp + ${CC} ${CFLAGS} -c SimulationParametersStruct.cpp + +UtilityFunctions.o : UtilityFunctions.cpp UtilityFunctions.h + ${CC} ${CFLAGS} -c UtilityFunctions.cpp + +main.o : main.cpp CSimulation.h SimulationParametersStruct.cpp + ${CC} ${CFLAGS} -c main.cpp + +clean : + rm -f *.o $(EXENAME) diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..cf41216 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,165 @@ +/* + * File: main.cpp + * Author: Mark Wittekind and Drew Murray + * + * Created on March 5, 2015, 6:03 PM + */ + +#include +#include "SimulationParametersStruct.cpp" +#include "CSimulation.h" +#include +#include +#include +#include +#include +#include + +using namespace std; +/* + * + */ + +unsigned int calc_timesteps(SimulationParameters *SimPar) +{ + unsigned int t = 1; + t *= SimPar->HEIGHT; + t *= SimPar->WIDTH; + t *= SimPar->temperature; + t /= 2; + return t; +} + +void print_header(SimulationParameters *SimPar, ostream &head_stream) +{ + head_stream << "Simulation Parameters\n"; + head_stream << SimPar->WIDTH << " WIDTH \n"; + head_stream << SimPar->HEIGHT << " HEIGHT \n"; + head_stream << SimPar->MAXTIME << " MAXTIME\n"; + head_stream << SimPar->TIMESTEP << " TIMESTEP\n"; + head_stream << SimPar->MAXTIMESTEPS << " MAXTIMESTEPS\n"; + head_stream << SimPar->COUPLING_CONSTANT << " COUPLING_CONSTANT\n"; + head_stream << SimPar->temperature << " temperature\n"; + head_stream << SimPar->BOLTZMAN_CONSTANT << " BOLTZMAN_CONSTANT\n"; + head_stream << SimPar->PRINT_FREQ << " PRINT_FREQ\n"; + head_stream << SimPar->MIN_TEMP << " MIN_TEMP\n"; + head_stream << SimPar->MAX_TEMP << " MAX_TEMP\n"; + head_stream << SimPar->TEMP_STEP << " TEMP_STEP\n"; + head_stream << SimPar->CRIT_MODE << " CRIT_MODE\n"; + head_stream << SimPar->CRIT_REPEATS << " CRIT_REPEATS\n"; + head_stream << SimPar->var_timestep << " var_timestep\n"; + return; +} + +int main(int argc, char** argv) { + srand (time(NULL)); + //output stream for position + streambuf * pos_buf; + ofstream pos_of; + streambuf * mag_buf; + ofstream mag_of; + streambuf * en_buf; + ofstream en_of; + streambuf * head_buf; + ofstream head_of; + if (false){ + //set to cout + pos_buf = cout.rdbuf(); + mag_buf = cout.rdbuf(); + en_buf = cout.rdbuf(); + head_buf = cout.rdbuf(); + } + else{ + //set to filename + pos_of.open("data/raw_positions.txt"); + pos_buf = pos_of.rdbuf(); + mag_of.open("data/mag.txt"); + mag_buf = mag_of.rdbuf(); + en_of.open("data/energy.txt"); + en_buf = en_of.rdbuf(); + head_of.open("data/parameters.txt"); + head_buf = head_of.rdbuf(); + } + + + ostream pos_stream(pos_buf); + ostream mag_stream(mag_buf); + ostream en_stream(en_buf); + ostream head_stream(head_buf); + //TODO allow for outputting to file + //TODO allow for command line parameters + + + SimulationParameters* SimPar = new SimulationParameters(); + + print_header(SimPar, head_stream); + head_of.close(); + + if(SimPar->CRIT_MODE){ + float TempCritsAvg; + for(unsigned short r =0;rCRIT_REPEATS;r++){ + cout << "\nRepeat: " << r << "/" << SimPar->CRIT_REPEATS << "\n"; + vector mags; + for(float T = SimPar->MIN_TEMP;TMAX_TEMP;T+=SimPar->TEMP_STEP){ + cout << "Temperature: " << T << endl; + SimPar->temperature = T; + + //TODO SimPar->MAXTIMESTEPS=calc_timesteps(SimPar); + cout << "MAXTIMESTEPS = " << SimPar->MAXTIMESTEPS << "\n"; + CSimulation Simulation(SimPar); + CLattice lattice(SimPar->HEIGHT,SimPar->WIDTH, SimPar->COUPLING_CONSTANT); + CObject *lattice2 = &lattice; + Simulation.addObject(lattice2); + + Simulation.run(pos_stream,mag_stream, SimPar); + pos_of.flush(); + mag_of.flush(); + en_of.flush(); + mags.push_back(Simulation.calcMag()); + //cout << "Final Energy: " << Simulation.calcEnergy() << "\n"; + + } + + //calculate crit temp + unsigned short min_sus_idx = 0;//index in terms of mag + float min_sus = numeric_limits::infinity(); + for(unsigned short i = 1; iTEMP_STEP); + if(new_sus < min_sus){ + min_sus = new_sus; + min_sus_idx = i; + } + } + TempCritsAvg+=(SimPar->MIN_TEMP+SimPar->TEMP_STEP*min_sus_idx); + cout << (SimPar->MIN_TEMP+SimPar->TEMP_STEP*min_sus_idx) << "\n"; + } + TempCritsAvg/=SimPar->CRIT_REPEATS; + cout << "Final Average Critical Temp: " << TempCritsAvg << endl; + + } + else{ + for(float T = SimPar->MIN_TEMP;TMAX_TEMP;T+=SimPar->TEMP_STEP) + { + SimPar->temperature = T; + cout << "\nTemperature: " << T << endl; + en_stream << T << "\n"; + + //TODO SimPar->MAXTIMESTEPS=calc_timesteps(SimPar); + cout << "MAXTIMESTEPS = " << SimPar->MAXTIMESTEPS << "\n"; + CSimulation Simulation(SimPar); + CLattice lattice(SimPar->HEIGHT,SimPar->WIDTH, SimPar->COUPLING_CONSTANT); + CObject *lattice2 = &lattice; + Simulation.addObject(lattice2); + + Simulation.run(pos_stream,mag_stream, SimPar); + pos_of.flush(); + mag_of.flush(); + en_of.flush(); + float energy = Simulation.calcEnergy(); + cout << "Final Energy: " << energy << "\n"; + en_stream << energy << "\n"; + } + } + delete SimPar; + return 0; +} diff --git a/src/plot.f95 b/src/plot.f95 deleted file mode 100644 index 1fa8c67..0000000 --- a/src/plot.f95 +++ /dev/null @@ -1,64 +0,0 @@ -module plot - use plplot - implicit none - private - - public plot_init, plot_close, plot_lattice - -contains - - subroutine plot_init(latticeSize) - integer, intent(in) :: latticeSize - call plsdev("xcairo") - call plinit() - - !You can find default colors at - !http://plplot.sourceforge.net/docbook-manual/plplot-html-5.9.9/plcol0.html - - !call plscol0(0, 255, 255, 255) ! white - !call plscol0(1, 255, 0, 0) ! red - !call plscol0(2, 255, 77, 0) ! orange - !call plscol0(3, 255, 255, 0) ! yellow - !call plscol0(4, 0, 255, 0) ! green - !call plscol0(5, 0, 0, 255) ! blue - !call plscol0(6, 0, 255, 255) ! cyan - !call plscol0(7, 255, 0, 255) ! magenta - !call plscol0(8, 128, 128, 128) ! gray - !call plscol0(9, 0, 0, 0) ! black - - call plenv(0d0, latticeSize + 1d0, 0d0, latticeSize + 1d0, 0, 0) - end subroutine plot_init - - subroutine plot_close() - call plspause(.false.) - call plend() - end subroutine plot_close - - subroutine plot_lattice(lattice) - ! Draw a rectangular grid of up- and down-arrows corresponding to Ising - ! states. Because this redraws the entire screen, it is *very* slow for - ! Metropolis models - instead, consider a routine that only redraws the - ! sites that change. - integer, intent(in) :: lattice(:,:) - integer :: i, j - real(8) :: x, y - !Assumes 1 corresponds to up-spin, -1 to down-spin. - - call plclear() - do i = 1, size(lattice, 1) - do j = 1, size(lattice, 2) - x = i; y = j - if (lattice(i, j) .eq. 1) then - call plcol0(1) !default red - call plpoin([x], [y], 30) !30 denotes up-arrow glyph - else ! Comment out the else clauses to speed drawing - call plcol0(11) !default cyan - call plpoin([x], [y], 31) !31 denotes down-arrow glyph - end if - end do - end do - - call plflush() - end subroutine plot_lattice - -end module plot diff --git a/src/run_ising.sh b/src/run_ising.sh new file mode 100755 index 0000000..a51cb06 --- /dev/null +++ b/src/run_ising.sh @@ -0,0 +1,8 @@ +rm data/* +rm images/* +rm spins.gif +make clean -f ising_makefile +make ising2.exe -f ising_makefile +./ising2.exe +python3 plot_spins.py +convert -delay 10 -loop 0 images/SpinData*.png spins.gif