diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4468376 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.o +src/*.o +*.mod +src/*.mod +src/*.out + + 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/figures/mag_t1.jpg b/report/figures/mag_t1.jpg new file mode 100644 index 0000000..06a49dd Binary files /dev/null and b/report/figures/mag_t1.jpg differ diff --git a/report/figures/mag_t3.jpg b/report/figures/mag_t3.jpg new file mode 100644 index 0000000..4b0043d Binary files /dev/null and b/report/figures/mag_t3.jpg differ diff --git a/report/figures/mag_vs_temp.jpg b/report/figures/mag_vs_temp.jpg new file mode 100644 index 0000000..33cd002 Binary files /dev/null and b/report/figures/mag_vs_temp.jpg differ diff --git a/report/report.tex b/report/report.tex index 72d1253..b54725b 100644 --- a/report/report.tex +++ b/report/report.tex @@ -10,147 +10,69 @@ \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 +\title{Modeling Ising} +\author{Scott O'Connor} +\date{\today} \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}). + \begin{abstract} + The ising model is used in this program as a way to predict the behavior of magnetic material as it is effected by temperature. + \end{abstract} + +\section{Program Explained} + \subsection{} + The first thing this model does is calculate the Hamiltonian. + This is done by summing the states of each location in the Lattice + \begin{equation} + H(\sigma) = - \sum_{i=1} \sigma_i \sigma_j + \end{equation} + For a 2D case there are four possible nearest neighbor interations: the cell above, below, left and right. + The lattice currently implimented is zeropadded. This allows for the ability to sum over the non-zero padded portion of the lattice and not have to worry about the boundries. + + After the intial calacluaiton of the hamiltonian, a monte carlo simulation is performed on the lattice. In the monte carlo routine, random bits are selected, and a metropolis test is performed + The metropolis test will determined if a bit should be fliped or not. + + \begin{equation} + \Delta E = 2 \sigma_i (\sigma_{above} + \sigma_{below} + \sigma_{left} \sigma_{right}) + \end{equation} + + \begin{equation} + X \sim [(0,1)]< e^{-\beta \Delta E} + \end{equation} + + +\section{Plots} + %Plotting normalized magnetization vs various temperatures, the magnetization goes to zero around 2.2. This is consistant with how the model should perform + \begin{figure}[b] + \centering + \includegraphics{figures/mag_vs_temp.jpg} + \caption{\label{fig:mag_vs_temp}Normalize Magnetization and various temperatures} + \end{figure} + + %Plotting the magnetization over a million iterations in a 100 by 100 lattice when the temperature is temp=1, results in a net magnetization. + + \begin{figure}[b] + \centering + \includegraphics{figures/mag_t1.jpg} + \caption{\label{fig:mag_T1p} Magnetization over a million iterations at temp=1} + \end{figure} + +%Plotting the same simulation as above, except that temp=3 results in a zero net magnetization. + + \begin{figure}[b] + \centering + \includegraphics{figures/mag_t3.jpg} + \caption{\label{fig:mag_T3p} Magnetization over a million iterations at temp=3} + \end{figure} + +\section{Energy at Different Temperatures} + + \subsection{\label{sec:level2} Temperature at 2} + + \subsection{\label{sec:level2} Temperature at 3} + +\begin{conclusion} +The results of the ising model are as expected. The magnetization goes to zero when temp=2.2. When the temperature is below this mark, the magntization hovers above zero. When the temperature is above zero the net magnetization goes to zero. +\end{conclusion} \end{document} diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..51e8364 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,5 @@ +*.out +*.o +*.mod +*.exe +*.swp diff --git a/src/Makefile b/src/Makefile index eb24188..9c2487d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,15 +1,15 @@ 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 = +#FFLAGS += $(shell pkg-config --cflags plplotd-f95) +#LDFLAGS = $(shell pkg-config --libs plplotd-f95) +BINDIR := bin COMPILE = $(FC) $(FFLAGS) LINK = $(FC) $(LDFLAGS) TARGET = ising.exe # Name of final executable to produce -OBJS = plot.o ising.o # List of object dependencies +OBJS = global.o ising.o # List of object dependencies $(TARGET): $(OBJS) $(LINK) -o $@ $^ $(LIBS) diff --git a/src/dataread.m b/src/dataread.m new file mode 100644 index 0000000..416ffee --- /dev/null +++ b/src/dataread.m @@ -0,0 +1,17 @@ +%Plotting routine + +load /hfield.out + +data=hfield; +x=zeros(1,1000000); +y=zeros(1,1000000); +for i=1:1000000 + x(1,i) = data(i,1); + y(1,i) = data(i,2); +end + +figure(1); +plot(x,y) +title('Magnetization at temp=3') +xlabel('Iterations') +ylabel('Normalized Magnetization') diff --git a/src/global.f95 b/src/global.f95 new file mode 100644 index 0000000..c489fe6 --- /dev/null +++ b/src/global.f95 @@ -0,0 +1,22 @@ +module global + + implicit none + + integer :: t_avg,temp_points + integer :: latticeSize,iters,n1,n2 + integer, allocatable :: lattice(:,:) + real(8) :: rand_loc(2) + real(8) :: rand_temp + real(8) :: temp_prob + integer :: rand_loc_int(2) + real(8) :: del_e + real(8) :: h(2) + real(8) :: j !magnetic coefficients + real(8) :: min_temp,max_temp + real(8) :: k !boltzman constant + real(8) :: B !combination of temp and boltzman + + !Energy Variables + real(8) :: energy_sum !sum of total energy in lattice + +end module global diff --git a/src/ising.f95 b/src/ising.f95 new file mode 100644 index 0000000..86c5c75 --- /dev/null +++ b/src/ising.f95 @@ -0,0 +1,145 @@ +program ising + + use global + + implicit none + + !External Functions + real(8),external :: energy + integer,external :: hfield + + !Variables for main routine + integer :: ii,jj + integer :: tot_energy + real(8) :: energy_avg + real(8) :: hfeild_avg + real(8) :: temp + + !output files + open (unit = 1, file = 'energy.out', status = 'unknown') + open (unit = 2, file = 'hfield.out', status = 'unknown') + open (unit = 3, file = 'ising.inp', status = 'unknown') + open (unit = 4, file = 'hfield_avg.out', status = 'unknown') + open (unit = 5, file = 'energy_avg.out', status = 'unknown') + + !initializing variables + ii = 0 !Iteration Variable + jj = 0 !Averages Variables + energy_sum = 0 !Energy Sum + rand_loc = 2 !Init Random Location Variable + + call ReadInput + + allocate(lattice(0:latticeSize + 1,0:latticeSize + 1)) + lattice = 0 + lattice(1:latticeSize, 1:latticeSize) = 1 + + !main program + + do jj = 0,temp_points + print*, 'Current Temp Point:',jj + hfeild_avg=0 + energy_avg=0 + tot_energy=0 + temp=min_temp+((max_temp-min_temp)/temp_points)*jj + B = 1/(k*temp) !constant of temp and boltman + tot_energy = energy(lattice,latticeSize)!Calculate Chagnge total energy + do ii = 0,iters + !generate a random location + Call random_number(rand_loc) + rand_loc = rand_loc*(latticeSize) + rand_loc_int = ceiling(rand_loc) + + call del_energy !calculate change in energy + call flip_bit !Perform metropolis test + + !Write results to file + if (ii > iters-1) then + write (1,*),ii, energy_sum + write (2,*),ii, sum(lattice)/float(latticeSize**2) + end if + if (ii > iters-t_avg) then + hfeild_avg=hfeild_avg+(1/(float(ii)+1))*(sum(lattice)/float(latticeSize**2)-hfeild_avg) + energy_avg=energy_avg+(1/(float(ii)+1))*(tot_energy/float(latticeSize*2)-energy_avg) + end if + end do + + !writing averages to file + write(4,*),temp,hfeild_avg + write(5,*),temp,energy_avg + + end do +end program + +!------------------------------------------------------------------------------ +subroutine del_energy!{{{ + + use global, only: del_e,rand_loc_int,lattice + + integer :: spin,h1,h2,h3,h4 + + spin = lattice(rand_loc_int(1),rand_loc_int(2)) + h1 = lattice(rand_loc_int(1)+1,rand_loc_int(2)+1) + h2 = lattice(rand_loc_int(1)+1,rand_loc_int(2)-1) + h3 = lattice(rand_loc_int(1)-1,rand_loc_int(2)+1) + h4 = lattice(rand_loc_int(1)-1,rand_loc_int(2)-1) + del_e = 2*spin*(h1 + h2 + h3 + h4) + +end subroutine !}}} +!------------------------------------------------------------------------------ +subroutine flip_bit !{{{ + + use global, only: lattice,rand_loc_int,rand_temp,energy_sum,del_e,B + + integer :: spin + + spin = 0 + spin = lattice(rand_loc_int(1),rand_loc_int(2)) + call random_number(rand_temp) + if (exp(-B*del_e) .ge. rand_temp) then + lattice(rand_loc_int(1),rand_loc_int(2))=-spin + energy_sum=energy_sum+del_e + end if + +end subroutine !}}} +!------------------------------------------------------------------------------ +real(8) function energy(lattice1,latticeSize1) !{{{ + + integer :: latticeSize1 + integer,dimension(latticeSize1,latticeSize1) :: lattice1 + + integer :: ii,jj + integer :: spin,h1,h2,h3,h4 + + energy=0 + + do ii = 2,latticeSize1 - 1 + do jj = 2,latticeSize1 - 1 + spin = lattice1(ii,jj) + h1 = lattice1(ii + 1,jj + 1) + h2 = lattice1(ii + 1,jj - 1) + h3 = lattice1(ii - 1,jj + 1) + h4 = lattice1(ii - 1,jj - 1) + energy = energy+spin*(h1+h2*h3+h4) + end do + end do + +end function !}}} +!------------------------------------------------------------------------------ +subroutine ReadInput !{{{ + + use global, only: latticeSize,iters,k,min_temp,max_temp,temp_points, & + t_avg,k,j + + read(3,*) latticeSize + read(3,*) iters + read(3,*) min_temp,max_temp,temp_points + read(3,*) t_avg + read(3,*) k + read(3,*) j + + + close(3) + +end subroutine !}}} +!------------------------------------------------------------------------------ diff --git a/src/ising.inp b/src/ising.inp new file mode 100644 index 0000000..acb848f --- /dev/null +++ b/src/ising.inp @@ -0,0 +1,6 @@ +100 !Lattice Size +1000000 !Number of Iterations +1,5,10 !'Min Temperature','Max Temperature','Number of point between' +50000 !Number of Averages +1 !Boltzman constant +1 !j