Skip to content

Commit

Permalink
implements preserve_lists option
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Nov 25, 2022
1 parent 6656888 commit e16ae36
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CellListMap"
uuid = "69e1c6dd-3888-40e6-b3c8-31ac5f578864"
authors = ["Leandro Martinez <[email protected]> and contributors"]
version = "0.8.7-DEV"
version = "0.8.7"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand Down
10 changes: 8 additions & 2 deletions docs/src/PeriodicSystems.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ using CellListMap.PeriodicSystems
- [Two sets of particles](@ref)
- [Particle simulation](@ref)



## The mapped function

The function to be mapped for every pair of particles within the cutoff follows the same interface as the standard interface. It must be of the form
Expand Down Expand Up @@ -51,6 +49,14 @@ const masses = # ... some masses
u = map_pairwise((x,y,i,j,d2,u) -> energy(d2,u,masses), system)
```

To compute a different property from the same coordinates and cell lists, use `preserve_lists=true`, for example,
```julia
u = map_pairwise((x,y,i,j,d2,u) -> u += sqrt(d2), system; preserve_lists = true)
```
in which case we are computing the sum of distances from the same cell lists used to compute the energy in the previous example
(requires version 0.8.7). Specifically, this will skip the updatding of the cell lists, thus be careful to not use this
option if the cutoff, unitcell, or any other property of the system changed.

## Potential energy example

!!! note
Expand Down
9 changes: 7 additions & 2 deletions src/PeriodicSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ end
"""
```
map_pairwise!(f::Function, system; show_progress = true)
map_pairwise!(f::Function, system; show_progress = true, preserve_lists = false)
```
Function that maps the `f` function into all pairs of particles of
Expand All @@ -848,6 +848,10 @@ Thread-safety is taken care automatically in parallel executions.
`map_pairwise` is an alias to `map_pairwise!` for syntax consistency
when the `output` variable is immutable.
If `preserve_lists` is `true`, the cell lists will not be recomputed,
this may be useful for computing a different function from the same
coordinates.
# Example
In this example we compute the sum of `1/(1+d)` where `d` is the
Expand All @@ -869,10 +873,11 @@ julia> map_pairwise((x,y,i,j,d2,output) -> output += 1 / (1 + sqrt(d2)), sys)
function map_pairwise!(
f::F,
sys::AbstractPeriodicSystem;
preserve_lists::Bool=false,
show_progress::Bool=false
) where {F<:Function}
sys.output = _reset_all_output!(sys.output, sys._output_threaded)
UpdatePeriodicSystem!(sys)
preserve_lists || UpdatePeriodicSystem!(sys)
sys.output = CellListMap.map_pairwise!(
f, sys.output, sys._box, sys._cell_list;
output_threaded=sys._output_threaded,
Expand Down
4 changes: 4 additions & 0 deletions test/BasicForPeriodicSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ end
naive = CellListMap.map_pairwise!((x, y, i, j, d2, u) -> potential(i, j, d2, u, mass), 0.0, box, cl)
system = PeriodicSystem(xpositions=x, cutoff=cutoff, unitcell=sides, output=0.0)
@test PeriodicSystems.map_pairwise!((x, y, i, j, d2, u) -> potential(i, j, d2, u, mass), system) naive

# Check the functionality of computing a different function from the same coordinates (new_coordinates=false)
naive = CellListMap.map_pairwise!((x, y, i, j, d2, u) -> u += d2, 0.0, box, cl)
@test PeriodicSystems.map_pairwise!((x, y, i, j, d2, u) -> u += d2, system; preserve_lists = true) naive

# Function to be evalulated for each pair: gravitational force
function calc_forces!(x, y, i, j, d2, mass, forces)
Expand Down

2 comments on commit e16ae36

@lmiq
Copy link
Member Author

@lmiq lmiq commented on e16ae36 Nov 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72887

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.7 -m "<description of version>" e16ae36b357ed91d49918f4f8437c9796cef49eb
git push origin v0.8.7

Please sign in to comment.