Excluded volume¶
This module implements a method to place a number of spheres that have no overlap.
This example shows use of the excluded volume with the placement of 1000 particles
at random positions with a diameter of 1
in a cubic box with each edge being
50
:
local random = math.random
math.randomseed(os.time())
local edge = 50
local box = mdsim.box{length = {edge, edge, edge}}
local excluded = mdsim.positions.excluded_volume{box = box, cell_length = 1}
local obstacles = {}
local diameter = 1
local repeats = 50
for i = 1, 1000 do
for j = 1, repeats do
local r = {edge * random(), edge * random(), edge * random()}
if excluded:place_sphere(r, diameter) then
obstacles[i] = r
excluded:exclude_sphere(r, diameter)
break
end
end
if not obstacles[i] then
error(("cannot place obstacle %d after %d repeats"):format(i, repeats))
end
end
local particle = mdsim.particle{dimension = box.dimension, particles = #obstacles}
particle.data["position"] = obstacles
Note
If one uses the random number generator from Lua , this should be done in
conjunction with LuaJIT, only. Standard Lua uses the OS-dependent rand()
function.
- class halmd.mdsim.positions.excluded_volume(args)¶
Construct excluded volume instance
- Parameters:
args (table) – keyword arguments
args.box (number) – instance of
halmd.mdsim.box
args.cell_length (number) – cell length for internal binning (must not be smaller than largest sphere diameter)
- exclude_sphere(centre, diameter)¶
Place a single sphere at
centre
with a diameter ofdiameter
- exclude_spheres(centres, diameters)¶
Place a set of spheres with their respective centres and diameters
- place_spheres(centre, diameter)¶
Test if a sphere at
centre
with diameterdiameter
can be placed without overlap with any other previously set sphere