Skip to content

Commit

Permalink
add ability to extract ghosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Joroks committed Aug 27, 2024
1 parent 2eae971 commit 947f357
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/LAMMPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function extract_global_datatype(lmp::LMP, name)
end

"""
extract_atom(lmp::LMP, name::String, lmp_type::_LMP_DATATYPE; copy=false)
extract_atom(lmp::LMP, name::String, lmp_type::_LMP_DATATYPE; copy=false, with_ghosts=false)
Extract per-atom data from the lammps instance.
Expand All @@ -484,9 +484,7 @@ Extract per-atom data from the lammps instance.
| `LAMMPS_INT64` | `Vector{Int64}` |
| `LAMMPS_INT64_2D` | `Matrix{Int64}` |
the kwarg `copy`, which defaults to true, determies wheter a copy of the underlying data is made.
As the pointer to the underlying data is not persistent, it's highly recommended to only disable this,
if you wish to modify the internal state of the LAMMPS instance.
`with_ghosts` determines wheter entries for ghost atoms are included. This is ignored for "mass".
!!! info
The returned data may become invalid if a re-neighboring operation
Expand All @@ -496,7 +494,7 @@ if you wish to modify the internal state of the LAMMPS instance.
A table with suported name keywords can be found here: <https://docs.lammps.org/Classes_atom.html#_CPPv4N9LAMMPS_NS4Atom7extractEPKc>
"""
function extract_atom(lmp::LMP, name::String, lmp_type::_LMP_DATATYPE; copy=false)
function extract_atom(lmp::LMP, name::String, lmp_type::_LMP_DATATYPE; copy=false, with_ghosts=false)
void_ptr = API.lammps_extract_atom(lmp, name)
void_ptr == C_NULL && throw(KeyError("Unknown per-atom variable $name"))

Expand All @@ -512,7 +510,7 @@ function extract_atom(lmp::LMP, name::String, lmp_type::_LMP_DATATYPE; copy=fals
return _extract(ptr, length; copy=copy)
end

length = extract_setting(lmp, "nlocal")
length = extract_setting(lmp, with_ghosts ? "nall" : "nlocal")

if _is_2D_datatype(lmp_type)
# only Quaternions have 4 entries
Expand Down
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ end
@test extract_atom(lmp, "mass", LAMMPS_DOUBLE) isa Vector{Float64}
@test extract_atom(lmp, "mass", LAMMPS_DOUBLE) == [1]

x = extract_atom(lmp, "x", LAMMPS_DOUBLE_2D)
@test size(x) == (3, 27)
x1 = extract_atom(lmp, "x", LAMMPS_DOUBLE_2D)
@test size(x1) == (3, 27)

x2 = extract_atom(lmp, "x", LAMMPS_DOUBLE_2D; with_ghosts=true)
@test size(x2) == (3, 27)

@test extract_atom(lmp, "image", LAMMPS_INT) isa Vector{Int32}

Expand Down

0 comments on commit 947f357

Please sign in to comment.