m3g / CellListMap.jl

Flexible implementation of cell lists to map the calculations of particle-pair dependent functions, such as forces, energies, neighbor lists, etc.
https://m3g.github.io/CellListMap.jl/
MIT License
87 stars 4 forks source link

Error when creating PeriodicSystem with empty positions #75

Closed nhz2 closed 1 year ago

nhz2 commented 1 year ago

Thank you for creating the high-level PeriodicSystems interface, it has simplified my simulation code.

My simulations typically start without particles and more get added at random times. This makes it tricky to use with PeriodicSystems because currently, it errors if I make a system without particles, see below.

Currently, I am constructing the PeriodicSystem with a few junk particles, and separately keeping track of if it is valid or not. It would simplify my code if PeriodicSystem could properly handle the case of no particles.

using StaticArrays
using CellListMap.PeriodicSystems
Vec2D = SVector{2,Float64}
system = PeriodicSystem(;
    positions=Vec2D[],
    cutoff=0.1,
    unitcell=[1.0, 1.0],
    output=0.0,
)
ERROR: DivideError: integer division error
Stacktrace:
 [1] rem
   @ ./int.jl:289 [inlined]
 [2] set_idxs!(idxs::Vector{UnitRange{Int64}}, n_particles::Int64, nbatches::Int64)
   @ CellListMap ~/.julia/packages/CellListMap/A9riF/src/CellLists.jl:414
 [3] CellListMap.AuxThreaded(cl::CellListMap.CellList{2, Float64}; particles_per_batch::Int64)
   @ CellListMap ~/.julia/packages/CellListMap/A9riF/src/CellLists.jl:392
 [4] AuxThreaded
   @ ~/.julia/packages/CellListMap/A9riF/src/CellLists.jl:373 [inlined]
 [5] #UpdateCellList!#52
   @ ~/.julia/packages/CellListMap/A9riF/src/CellLists.jl:687 [inlined]
 [6] CellListMap.CellList(x::Vector{SVector{2, Float64}}, box::CellListMap.Box{CellListMap.OrthorhombicCell, 2, Float64, Float64, 4}; parallel::Bool, nbatches::Tuple{Int64, Int64})
   @ CellListMap ~/.julia/packages/CellListMap/A9riF/src/CellLists.jl:506
 [7] PeriodicSystem(; positions::Vector{SVector{2, Float64}}, xpositions::Nothing, ypositions::Nothing, unitcell::Vector{Float64}, cutoff::Float64, output::Float64, output_name::Symbol, parallel::Bool, nbatches::Tuple{Int64, Int64}, lcell::Int64)
   @ CellListMap.PeriodicSystems ~/.julia/packages/CellListMap/A9riF/src/PeriodicSystems.jl:165
 [8] top-level scope
   @ REPL[10]:1
lmiq commented 1 year ago

This is fixed in 0.8.5 to be available at any moment.