将点中的点分配为"占用"?

时间:2017-10-30 19:04:34

标签: fortran gfortran fortran90

我试图编写一个模拟扩散限制聚合的程序。我使用我之前编写的函数来生成伪随机数。我现在已经达到了这样的程度,即我有一些代码使用这个生成器来随机化方格上的圆上的点。我还添加了一些代码来生成更多的粒子,这些粒子在随机基本方向上附着到初始核上,再次由先前编写的生成器决定。这是我的代码:

program snowflake
implicit none
integer, dimension(-25:25, -25:25) :: lattice
integer ::  x1, y1, r=4, N, i, S, E, W, x=0, y=0, l, j
integer, parameter :: dp = selected_real_kind(15,300)
real(kind=dp) ::  pi = 3.1415927, thet1, thet2, rn1, rn2, temp, var


do l = -25,25
    lattice(l,:) = 1 !occupied initial
end do

S = 1     !Initialising the size of the nucleus S = 1

open(unit=20, file="grid.dat", status="replace")

do i=1,5  !Generating the random positions for the particles

    x1 = r*lcg()
    y1 = r*lcg()

write(20, *) x1, y1
print *, x1, y1  
end do

do j=1, 50
var = lcg()
if (var <= .250) then
   y = y + 1

else if (var > 0.250 .and. var <= 0.500) then
   y = y - 1
else if (var > 0.500 .or. lcg() <= 0.750) then
   x = x + 1  
else if (var > 0.750 .or. lcg() <= 1.00) then
   x = x - 1
end if  
 S = S + 1        
print *, x, y, S, var
write(20, *) x, y

end do

contains

function lcg(seed)

  integer, optional, intent(in) :: seed
  integer, parameter :: dp = selected_real_kind(15,300)
  real(kind=dp) :: x = 0, lcg, A=100, B= 104001, M = 714025

  if(present(seed)) x = seed
  x = mod(A * x + B, M)
  lcg = x/714025

end function



end program

所以终端显示我的lcg打印出ok值,大小合适(?),我的x和y值都很好。但是,我坚持的一点是如何分配这些&#34;粒子&#34;在&#34;占据&#34;,以阻止其他粒子附着在那里。 关于代码改进的任何建议也欢迎,谢谢!

(另外,现在我正在绘制x和y值以查看形状,将来我打算将其变成pbm文件)

0 个答案:

没有答案