Hi, I am using CellListMap in one of my ABM simulations (using Agents.jl). It suits very well what I want to do: There some active agents and some static obstacles.
CellListMap finds collisions between agents and obstacles and calculates desired forces and torques. Since positions of obstacles are fixed, it makes sense to not build the CellList every step, but update it using
UpdateCellList!. It gives 2x boost in the speed of the simulation.
However, there is a problem that I couldn’t resolve yet: if the number of obstacles is smaller than the number of agents, the cell list doesn’t get updated (fresh construction of the cell list work)! I was wondering if somebody has already used
Ageints.jl framework and knows something about this problem.
My setup is straightforward: I create the cell list and give it as property to the
Agents.jl model in a
box_sides = [extent...] box = CellListMap.Box(box_sides, 2rcut) if n_obs > 0 # checking number of obstacles # rods_pos : vector of agents positions # obs_pos: vector of obstacles positions cl = CellListMap.CellList(rods_pos, obs_pos, box) else cl = CellListMap.CellList(rods_pos, box) end aux = CellListMap.AuxThreaded(cl) # model parameters as a mutable struct. properties = Parameters(dt, va, λ⁰, γ, l, d, ζ, n_obs, obs_pos, obs_radius, [forces, torque], rcut, rcut^2, # here are the cell-list related stuff box, cl, aux) # define the model model = ABM(ActiveRod, space2d, rng=rng, properties = properties )
model_step! function, the time evolution of the model is implemented and the cell list should be updated:
function model_step!(model::ABM) # get the vector of rods positions rods_pos = [[model[id].pos...] for id in 1:model.agents.count] obs_pos = [[model.obs_pos[id]...] for id in 1:model.n_obs] # reset forces and torques for id in 1:model.agents.count model.force_torque[id] = [0.0, 0.0] model.force_torque[id] = 0.0 end if model.n_obs > 0 # update the cell list model.cell_list = CellListMap.UpdateCellList!(rods_pos, model.obs_pos, model.box, model.cell_list, model.cl_aux) # calculate pairwise forces and torques CellListMap.map_pairwise!( (x, y, i, j, d2, force_torque) -> calc_forces_torque!(x, y, i, j, d2, model, force_torque), model.force_torque, model.box, model.cell_list) end end
As soon as the number of obstacles are larger than the number of agents, updating the cell-list works perfectly.