Create initial state of a fluid mixture

For fluid mixtures, which have the same interaction laws for each component (but different coefficients), all fluid particles are collected in a single instance of particle. The different components are distinguished by their value for species, particles of the same species form a contiguous range in tag (which is given by the index in the particle array). This allows for the efficient selection of each component from a range of tags.

The setup procedure has the following steps:

  • create system state
  • sequentially assign particle species
  • sequentially place particles on an fcc lattice
  • randomly shuffle the positions
  • assign random velocities according to a Maxwell–Boltzmann distribution
local mdsim   = halmd.mdsim
local numeric = halmd.numeric
local random  = halmd.random

local nparticle = {8000, 2000} -- particle numbers for each component
local length = {20, 20, 20}    -- cubic simulation box
local temperature = 1.5        -- temperature of Maxwell–Boltzmann distribution

-- create system state
local box ={length = length})
local particle = mdsim.particle({dimension = #length, particles = numeric.sum(nparticle), species = #nparticle})

-- assign particle species
local species = {}
for s = 1, #nparticle do
    for i = 1, nparticle[s] do
        table.insert(species, s - 1)    -- species values are 0-based 
end["species"] = species

-- set particle positions sequentially on an fcc lattice
mdsim.positions.lattice({box = box, particle = particle}):set()

-- shuffle positions randomly (shuffling is available in the host backend only)
local r =["position"]
r = random.generator({memory = "host"}):shuffle(r)["position"] = r

-- set initial particle velocities
mdsim.velocities.boltzmann({particle = particle, temperature = temperature}):set()


The approach to randomly shuffle the particle positions is not very efficient performance-wise: in the current implementation, it involves 6 deep copies of the position array (assuming that the GPU is the compute device).