Mud Crack
Submitted by rec on Tue, 2006-02-28 21:02. :: 9-12 | Physics | Standard 1: Physical Science
WHAT IS IT?
Information coming soon....
Turtle procedures
to random-float :num
output (random 1e9) * 1e-9 * :num
end
to random-x
output (random screen-width)
end
to random-y
output (random screen-height)
end
to sum-neighbors
ask-patch-at 0 0 [
set nliquid (liquid-at 0 -1) + (liquid-at 1 0) + (liquid-at 0 1) + (liquid-at -1 0)
set nparticle (particle-at 0 -1) + (particle-at 1 0) + (particle-at 0 1) + (particle-at 0 -1)
]
end
to try-moving-particle
seth (90 * (random 4))
fd 1
if is-liquid? [
sum-neighbors
let [:tmp energy-as-particle-moving - energy-as-liquid]
fd -1
sum-neighbors
if accept energy-of-motion :tmp [
make-liquid
fd 1
make-particle
]
]
end
to try-evaporate-liquid
sum-neighbors
if accept energy-of-evaporation [ make-vapor ]
end
to try-condense-vapor
sum-neighbors
if accept energy-of-condensation [ make-liquid ]
end
to accept :deltaH
output (random-float 1.0) < (min 1 (exp (-1 * :deltaH)))
end
to energy-of-evaporation
output energy-as-vapor - energy-as-liquid
end
to energy-of-condensation
output energy-as-liquid - energy-as-vapor
end
to energy-of-motion :tmp
output ((energy-as-liquid-moving - energy-as-particle) + :tmp)
end
to energy-as-vapor
output 0
end
to energy-as-liquid
output (-1 * eps-ll * nliquid) - (eps-nl * nparticle) - mu
end
to energy-as-particle
output (-1 * eps-nn * nparticle) - (eps-nl * nliquid)
end
to energy-as-liquid-moving
;; this cell is a particle trying to move into an adjacent liquid cell,
;; so when we evaluate the energy as a liquid we assume that one of
;; the neighboring liquid cells has become a particle,
;; hence nliquid is 1 too big, and nparticle is 1 too small
output (-1 * eps-ll * (nliquid - 1)) - (eps-nl * (nparticle + 1)) - mu
end
to energy-as-particle-moving
;; this cell is a liquid trying to be displaced by a particle
;; hence nliquid is 1 too small and nparticle is 1 too big
output (-1 * eps-nn * (nparticle - 1)) - (eps-nl * (nliquid + 1))
end
to make-liquid
set liquid 1
set particle 0
stamp liquid-color
end
to is-liquid?
output liquid = 1
end
to make-particle
set liquid 0
set particle 1
stamp particle-color
end
to is-particle?
output particle = 1
end
to make-vapor
set liquid 0
set particle 0
stamp vapor-color
end
to is-vapor?
output liquid = 0 and particle = 0
end
Observer procedures
;;
;; mudcrack, Copyright (c) 2005 by Roger E Critchlow Jr, Santa Fe, New Mexico, USA
;; This program is free software, licensed under the terms of the Gnu Public License.
;;
;; See Nature, 426: 271-274, November 20, 2003 for details
;;
turtles-own [
tmp
]
patches-own [
liquid
particle
nliquid
nparticle
]
globals [
clock ;; count the iterations
coverage ;; cell fraction of particles
eps-ll ;; strength of liquid-liquid attraction
eps-nn ;; strength of particle-particle attraction
eps-nl ;; strength of particle-liquid attraction
mu ;; chemical potential of liquid-vapor transition
pmovement ;; ratio of phase transition steps per diffusion step
particle-color
liquid-color
vapor-color
report-velocity
velocity
nsamples
]
;;
;; convert integer sliders to float values
;;
to convert-sliders
set coverage icoverage / 1000.0
set eps-ll ieps-ll / 100.0
set eps-nn ieps-nn / 100.0
set eps-nl ieps-nl / 100.0
set mu imu / 100.0
set pmovement ipmovement / 1000.0
end
to default
set icoverage 0.4 * 1000
set ieps-ll 2 * 100
set ieps-nl 1.5 * ieps-ll
set ieps-nn 2 * ieps-ll
set imu -2.25 * ieps-ll
set ipmovement 100
convert-sliders
end
to setup
clear-all
convert-sliders
set clock 0
set particle-color 34
set liquid-color 36
set vapor-color 32
set report-velocity true
set velocity 0
set nsamples 0
create-turtles-and-do 2 [
hide-turtle
setheading 0
]
ask-patches [
ifelse (random 1000000000) < (coverage * 1000000000) [
set liquid 0
set particle 1
setpc particle-color
] [
set liquid 1
set particle 0
setpc liquid-color
]
]
end
to go
convert-sliders
reset-timer
let [:chunk 10000]
repeat :chunk [
set clock (clock + 1)
ask-turtle 0 [
setxy random-x random-y
ifelse is-particle? [
if (random-float 1.0) < pmovement [ try-moving-particle ]
] [
ifelse is-liquid? [ try-evaporate-liquid ] [ try-condense-vapor ]
]
]
]
if report-velocity [
set velocity (nsamples * velocity + (:chunk / timer)) / (nsamples + 1)
set nsamples nsamples + 1
show (se (se (round velocity) " steps/second over ") (se nsamples " samples"))
]
end
4546 reads
