program n_particles_LJ_PBC_rand_TP parameter(n=8) real x(n),y(n),x_old(n),y_old(n),vx(n),vy(n) real force_x(n),force_y(n),force_x_old(n),force_y_old(n) integer pgopen do i=1,n call random_number(r) vx(i)=2*(r-0.5) write(*,*)'The initial vx of particle',i,'is',vx(i) call random_number(r) vy(i)=2*(r-0.5) write(*,*)'The initial vy of particle',i,'is',vy(i) c write(*,*)'What is initial vx of particle',i,'of',n,'?' c read(*,*) vx(i) c write(*,*)'What is initial vy of particle',i,'of',n,'?' c read(*,*) vy(i) end do x_range = 10.0 y_range = 10.0 C In this code, n must be >= 2. C Diagonal line-up type inital position do i=1,n x(i) = 8.0*(i-1)/(n-1) y(i) = 8.0*(i-1)/(n-1) write(*,*)'position of particle',i,'is (',x(i),y(i),')' end do C Cheker board line-up type initial position do i=1,n x(i) = (x_range/3)*mod(i,3) y(i) = (y_range/3)*(i/3) end do dis_limit = 1.0 c goto 200 call random_coord(x(1),y(1),x_range,y_range) i_count=1 do while(i_count T=Ek/(nk) (d=2, unit 1/k) c ek=ek/n area=x_range*y_range c P=(n*k*T + 0.5*virial)/area ek_cum = ek_cum + ek V_cum = V_cum + Virial T = ek_cum/i_step P = T + 0.5*V_cum/i_step P = P/area if ( mod(i_step,1000) == 0 ) write(*,*)'T=',T,'P=',P 1000 continue call pgclos end subroutine lj_force(x1,y1,x2,y2,force_x,force_y,x_range,y_range, &x2mx1,y2my1,pot) sigma = 1.0 epsilon = 1.0 c r = sqrt( (x2-x1)**2 + (y2-y1)**2 ) call PBC_distance(x1,y1,x2,y2,x2mx1,y2my1,dis,x_range,y_range) r=dis s_o_r = sigma /r force = (-1)*24*epsilon*(2*s_o_r**12-s_o_r**6)/r force_x = force*(x2mx1)/r force_y = force*(y2my1)/r pot=4*epsilon*(s_o_r**12-s_o_r**6) end subroutine subroutine PBC_distance(x1,y1,x2,y2,x2mx1,y2my1,dis,x_range, &y_range) dis_min=sqrt( (0.5*x_range)**2 + (0.5*y_range)**2 ) do i=-1,1 do j=-1,1 x2mx1_temp=i*x_range+x2-x1 y2my1_temp=j*y_range+y2-y1 r=sqrt( (x2mx1_temp)**2 + (y2my1_temp)**2 ) if(r < dis_min)then dis_min = r x2mx1=x2mx1_temp y2my1=y2my1_temp dis=r endif end do end do end subroutine subroutine wall_reflect(x,y,vx,vy,x_range,y_range) if(x>x_range) vx = (-1)*vx if(x<0.0) vx = (-1)*vx if(y>y_range) vy = (-1)*vy if(y<0.0) vy = (-1)*vy end subroutine subroutine PBC(x,y,x_range,y_range) if(x>x_range) x = x - x_range if(x<0.0) x = x + x_range if(y>y_range) y = y - y_range if(y<0.0) y = y + y_range end subroutine subroutine random_coord(x1,y1,x_range,y_range) call random_number(temp) c x1=x_range*(temp-0.5) x1=x_range*(temp) call random_number(temp) c y1=y_range*(temp-0.5) y1=y_range*(temp) end subroutine subroutine strong_PBC(x,y,x_range,y_range) 201 if(x>x_range) x = x - x_range if(x>x_range) goto 201 202 if(x<0.0) x = x + x_range if(x<0.0) goto 202 203 if(y>y_range) y = y - y_range if(y>y_range) goto 203 204 if(y<0.0) y = y + y_range if(y<0.0) goto 204 end subroutine