Professional Documents
Culture Documents
equations: Practice
Warm-up Codlets:
Sauro Succi
Burgers codlet
if(mod(it,10).eq.1) then
do j=1,nx
write(36,*) j,u(j)
write(37,*) it,j,u(j)
end do
write(36,'(bn)')
write(36,'(bn)')
write(37,'(bn)')
endif
write(6,*) 'max velocity, dt',umax,dt
end do
stop
end
Kardar-Parisi-Zhang
end do
KPZ.f: 4
c advance to next time step
t = t+dt
do i=1,nx
h(i) = hnew(i)
end do
c diagnostics ----------------------------------------------
htot = 0.
hvar = 0.
hlen = 0.
do i=1,nx
g = 0.5*(h(i+1)-h(i-1))/dx
htot = htot + h(i)
hvar = hvar + h(i)*h(i)
hlen = hlen + sqrt(1.0+g*g)*dx
end do
aveh = htot/nx
wid = sqrt(hvar/nx-aveh*aveh)
write(6,*) 'it,t,aveh,width,length',it,t,aveh,wid,hlen
write(9,*) t,aveh,wid,hlen
KPZ.f: 5
c movie for postproc
if(mod(it,nout).eq.0) then
do i=1,nx
write(50,*) i,h(i)
end do
write(50,'(bn)')
write(50,'(bn)')
endif
c -----------------------------------------------------
end do ! end evolution
c end realizations
write(6,*) 'Final time of realization ', ir, t
end do
stop
end
KPZ.f: 6
function ranpang(iseed)
c random number generator, from Pang, p.47
implicit double precision (a-h,o-z)
i2e30 = 2**30
ia=16807
ic=i2e30-1 ! ic=2**31-1, but 2**31 is a overflow
ic=ic+i2e30
iq=ic/ia
ir=mod(ic,ia)
ih=iseed/iq
il=mod(iseed,iq)
it=ia*il-ir*ih
if(it.gt.0) then
iseed=it
else
iseed=it+ic
endif
ranpang=iseed/float(ic)
return
end
Sandpile cellular automaton
Nsteps = 100
hrain = 2 ! play with it
c initial configuration: empty, play wit it
do j=0,ny+1
do i=0,nx+1
h(i,j)=int(0*rand())
end do
end do
Sand.f: 3
c time evolution
do it=1,Nsteps
c load the central site (you may want to load a site at random)
ir = nx/2
jr = ny/2
h(ir,jr)=h(ir,jr)+hrain
c the boundary buffers collect the outgoing flux from the bulk
do j=1,ny
do i=1,nx
if(h(i,j).gt.4) then
h(i,j) = h(i,j)-4
h(i+1,j)=h(i+1,j)+1
h(i-1,j)=h(i-1,j)+1
h(i,j+1)=h(i,j+1)+1
h(i,j-1)=h(i,j-1)+1
endif
end do
end do
Sand.f: 4
c diagnostic
htot = 0
do j=0,ny+1
do i=0,nx+1
htot = htot + h(i,j)
write(36,*) i,j,h(i,j)
end do
write(36,'(bn)')
end do
write(36,'(bn)')
write(36,'(bn)’)
write(6,*), it,htot,ir,jr,h(ir,jr)
write(9,*), it,htot,h(ir,jr)
end do
stop
end
End of the Lecture