Skip to content

Commit

Permalink
use gather scatter API
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Jun 23, 2024
1 parent 13e2294 commit 5ba4d36
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/external_pair.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using LAMMPS
using Test

lmp_native = LMP()
lmp_julia = LMP()
lmp_native = LMP(["-screen", "none"])
lmp_julia = LMP(["-screen", "none"])

for lmp in (lmp_native, lmp_julia)
command(lmp, "units lj")
Expand All @@ -24,13 +24,13 @@ command(lmp_julia, "fix julia_lj all external pf/callback 1 1")
command(lmp_native, "pair_style lj/cut $cutoff")
command(lmp_native, "pair_coeff * * 1 1")

const coefficients = Dict(
1 => Dict(
1 => [48.0, 24.0, 4.0,4.0]
const coefficients = Base.ImmutableDict(
1 => Base.ImmutableDict(
1 => [48.0, 24.0, 4.0, 4.0]
)
)

function compute_force(rsq, itype, jtype)
@inline function compute_force(rsq, itype, jtype)
coeff = coefficients[itype][jtype]
r2inv = 1.0/rsq
r6inv = r2inv^3
Expand All @@ -39,7 +39,7 @@ function compute_force(rsq, itype, jtype)
return (r6inv * (lj1*r6inv - lj2))*r2inv
end

function compute_energy(rsq, itype, jtype)
@inline function compute_energy(rsq, itype, jtype)
coeff = coefficients[itype][jtype]
r2inv = 1.0/rsq
r6inv = r2inv^3
Expand All @@ -58,14 +58,14 @@ for lmp in (lmp_native, lmp_julia)
command(lmp, "create_atoms 1 random $natoms 1 NULL")
command(lmp, "mass 1 1.0")

LAMMPS.API.lammps_scatter_atoms(lmp, "x", 1, 3, positions)
scatter!(lmp, "x", positions)

command(lmp, "run 0")
end

# extract forces
forces_native = extract_atom(lmp_native, "f")
forces_julia = extract_atom(lmp_julia, "f")
forces_native = gather(lmp_native, "f", Float64)
forces_julia = gather(lmp_julia, "f", Float64)

@testset "External Pair" begin
@test forces_native == forces_julia
Expand Down

0 comments on commit 5ba4d36

Please sign in to comment.