program n_particles_LJ_PBC_rand_dis parameter(n=3) 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 C Random position setup with preset separation / confirmation dis_limit = 1.0 call random_coord(x(1),y(1),x_range,y_range) i_count=1 do while(i_count=2)then call PBC_distance(x(i_count),y(i_count),x(i_count-1), & y(i_count-1),x2mx1,y2my1,dis,x_range,y_range) dis_min = dis end if do j=1,i_count call PBC_distance(x(j),y(j),x_temp,y_temp,x2mx1,y2my1,dis, & x_range,y_range) if(i_count==1) dis_min = dis write(*,*)'x and y and dis=',x_temp,y_temp,dis if(disx_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