Advertisement
Guest User

Untitled

a guest
Jun 11th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        program LennardJonesLiquid
  2.        implicit none
  3.        integer L,N,MCS,i,j,k,d, sim_time, check_time, m
  4.        parameter (L=20, MCS=230000, sim_time = 30000, check_time = 100)
  5.        real r_c, x_step, y_step,r_step, ran1, P, dr, ro, PI, T
  6.        parameter (r_c = 2.5, x_step = 0.01,y_step = 0.01,r_step = 0.02,
  7.      &                  dr = 0.05 ,PI = 3.141592653, ro = 0.95, T = 0.7)
  8.        ! 0.8 - liquid & 0.93 - solid
  9.        real xnew, ynew, dx, dy, r_ij2, Rnew2, dU, r, Probability, Rmax
  10.        real dx_new, dy_new
  11.        integer counter, r_size, mcs_size
  12.        real, allocatable:: x(:), y(:), Prob(:,:)
  13.        d =-1
  14.        Rmax = L/3.0 - 1.0
  15.        !--------
  16.        r_size = int( Rmax/r_step + 1.0 )
  17.        mcs_size = int( (mcs-sim_time)/check_time + 1.0)
  18.        !---------- matrix places
  19.        N = int( ro*L**2 + 0.0)
  20.        write(*,*) 'N = ', N
  21.        allocate (x(N), y(N), Prob(r_size,mcs_size) )
  22.        call Liquid(L,N,x,y)
  23.        do i=1, r_size
  24.          do j=1, mcs_size
  25.             Prob(i,j) = 0.0
  26.          enddo
  27.        enddo
  28.        call showmatrix(N,x,y)
  29.        write(*,*) 'MCS'
  30.         counter = 1
  31.         do k=1, MCS
  32.           do i=1, N
  33.              dU = 0
  34.              xnew = x(i) + (ran1(d)-0.5)*x_step
  35.              ynew = y(i) + (ran1(d)-0.5)*y_step
  36.              if(xnew.gt.L) xnew = xnew - L
  37.              if(ynew.gt.L) ynew = ynew - L
  38.              if(xnew.lt.0.) xnew = xnew + L
  39.              if(ynew.lt.0.) ynew = ynew + L
  40.               do j=1, N
  41.                if(j.ne.i) then
  42.                   dx = abs( x(i) - x(j) )
  43.                   dy = abs( y(i) - y(j) )
  44.                   if(dx.gt.L/2.) dx = L - dx
  45.                   if(dy.gt.L/2.) dy = L - dy
  46.                   r_ij2 = dx**2 + dy**2
  47.                  
  48.                   dx_new = abs( xnew-x(j) )
  49.                   dy_new = abs( ynew-y(j) )
  50.                   if(dx_new.gt.L/2.) dx_new = L - dx_new
  51.                   if(dy_new.gt.L/2.) dy_new = L - dy_new
  52.                   Rnew2 = dx_new**2 + dy_new**2
  53.                   if(Rnew2.le.1.0) goto 7
  54.                   !r^2<=1 then r<=1, sqrt() not needed
  55.                  
  56.                   if(r_ij2.le.r_c.and.Rnew2.le.r_c) then
  57.                      dU = dU + 4.0*(1/Rnew2**6 - 1/r_ij2**6)
  58.                   endif
  59.                endif
  60.               enddo
  61.               if(ran1(d).le.min(1.0,exp(-dU/T))) then
  62.                   x(i) = xnew
  63.                   y(i) = ynew
  64.               endif
  65. 7           continue
  66.           enddo
  67.           if(k.ge.sim_time.and.mod(k,check_time).eq.0) then
  68.              r = 1.0
  69.              m = INT(1/r_step - 1.0)
  70. 33           continue
  71.                 Prob(m,counter) = Prob(m,counter) +
  72.      &                   Probability(r,dr,N,L,ro,x,y) !probabilistic matrix
  73.                 r = r + r_step
  74.                 m = m + 1
  75.              if(r.le.Rmax) goto 33
  76.              counter = counter + 1
  77.           endif
  78.           write(*,*) k
  79.         enddo
  80.         write(*,*) '----------------------------------'
  81.         write(*,*) 'Probability', '     ', 'r'
  82.         call save_prob(Prob,r_size,mcs_size,r_step)
  83.         call showmatrix(N,x,y)
  84.         pause
  85.         !call showmatrix(N,x,y)
  86.        
  87.        end program
  88.  
  89.        function Probability(r,dr,N,L,ro,x,y)
  90.         integer i, N, j, L
  91.         real dr, deltaR2, r, x(N), y(N)
  92.         real P, Probability, PI, ro, dx, dy
  93.         PI = 3.141592653
  94.         P = 0
  95.         Probability = P
  96.         if(r.le.dr) return
  97.         do j=1, N
  98.           M = 0
  99.           do i=1, N
  100.           dx = abs( x(i) - x(j) )
  101.           dy = abs( y(i) - y(j) )
  102.           if(dx.gt.L/2.) dx = L - dx
  103.           if(dy.gt.L/2.) dy = L - dy
  104.           deltaR2 = sqrt( dx**2 + dy**2 )
  105.           if(deltaR2.gt.r-dr.and.deltaR2.le.r) then
  106.                 M = M + 1
  107.           endif
  108.           enddo
  109.           P = P + M/(2.0*PI*r*dr*ro)
  110.           !ring width: r-dr to r
  111.         enddo
  112.         Probability = P/(N+0.0)
  113.         return
  114.         end
  115.        
  116.        subroutine Liquid(L,N,x,y)
  117.         integer L, N, M, k
  118.         real x(N), y(N), d, free_space
  119.         x(1) = 0.5
  120.         y(1) = 0.5
  121.         M = (L-1)*(L-2)
  122.         k = int(sqrt(N+0.0))
  123.         free_space = (L-1.0)/(k+0.0) - 1.0
  124.         if(N.ge.M) then
  125.            d = 1.0
  126.         else
  127.            d = 1.0 + free_space
  128.         endif
  129.         write (*,*) 'd = ',d
  130.         do i=2, N
  131.           y(i) = y(i-1)
  132.           x(i) = x(i-1) + d
  133.           if(x(i).gt.L-0.5) then
  134.              y(i) = y(i) + d
  135.              x(i) = 0.5
  136.           endif
  137.         enddo
  138.        end
  139.        
  140.        subroutine showmatrix(n,x,y)
  141.        integer n
  142.        real x(n), y(n)
  143.        open(99,file='matrix-0.95.txt')
  144.        do i=1, n
  145.           write(99,*) x(i), y(i)
  146.        enddo
  147.        close(99)
  148.        end
  149.        
  150.        subroutine save_prob(Prob, A, B, dr)
  151.         integer A,B, i, j
  152.         real Prob(A,B), P
  153.         open(13,file='prob-solid.txt')
  154.         do i=1, A
  155.            P = 0.0
  156.            do j=1, B
  157.               P = P + Prob(i,j)
  158.            enddo
  159.            P = P/(B+0.0)
  160.            write(13,*) i*dr, P
  161.            write(*,*) i*dr, P
  162.         enddo
  163.         close(13)
  164.        end
  165.        
  166.        FUNCTION ran1(idum)
  167.       INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV
  168.       REAL ran1,AM,EPS,RNMX
  169.       PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,
  170.      *NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
  171.       INTEGER j,k,iv(NTAB),iy
  172.       SAVE iv,iy
  173.       DATA iv /NTAB*0/, iy /0/
  174.       if (idum.le.0.or.iy.eq.0) then
  175.         idum=max(-idum,1)
  176.         do 11 j=NTAB+8,1,-1
  177.           k=idum/IQ
  178.           idum=IA*(idum-k*IQ)-IR*k
  179.           if (idum.lt.0) idum=idum+IM
  180.           if (j.le.NTAB) iv(j)=idum
  181. 11      continue
  182.         iy=iv(1)
  183.       endif
  184.       k=idum/IQ
  185.       idum=IA*(idum-k*IQ)-IR*k
  186.       if (idum.lt.0) idum=idum+IM
  187.  
  188.       j=1+iy/NDIV
  189.       iy=iv(j)
  190.       iv(j)=idum
  191.       ran1=min(AM*iy,RNMX)
  192.       return
  193.       END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement