!----------------------! module systemvariables implicit none integer :: l ! system length integer :: n ! number of spins (n=l*l) real(8) :: pflip(-1:1,-4:4) ! flip probabilities integer, allocatable :: spin(:) ! spin array end module systemvariables !--------------------------! !-------------------------------------------------------------------! !Metropolis-algorithm simulation of the two-dimensional Ising model.! !Reads the following from a file 'ising.in': ! ! l,t,h = system length, temperature (T/J), field (h.J) ! ! bins, binsteps = number of bins, MC steps per bin ! !Writes these bin averages to the file 'bindata.dat': ! ! /N, /N**2, <|M|>/N, /N**2 ! !These results should be processed by the program average.f90. ! !A single random numbers seeds (3) are read from a file 'seed.in'. !-------------------------------------------------------------------! program ising2d !----------------------------------! use systemvariables; implicit none integer :: i,j,bins,binsteps,seed real(8) :: t,h open(10,file='ising.in',status='old') read(10,*)l,t,h read(10,*)bins,binsteps close(10) call initialize(t,h) do i=1,binsteps call mcstep end do do j=1,bins call resetdatasums do i=1,binsteps call mcstep call measure(h) end do call writebindata(binsteps) end do deallocate(spin) !-------------------! end program ising2d !-------------------! !--------------------------------------------! !Carries out one Monte Carlo step, defined as! !n flip attempts of randomly selected spins. ! !--------------------------------------------! subroutine mcstep !----------------------------------! use systemvariables; implicit none integer :: i,s,x,y,s1,s2,s3,s4 real(8), external :: ran do i=1,n s=int(ran()*n) x=mod(s,l); y=s/l s1=spin(mod(x+1,l)+y*l) s2=spin(x+mod(y+1,l)*l) s3=spin(mod(x-1+l,l)+y*l) s4=spin(x+mod(y-1+l,l)*l) if (ran()