From 9e9caf7d1408ac4a9233ac7d695c232d29ac7836 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 22 Apr 2025 16:02:51 -0400 Subject: [PATCH] dummy implementation of single neighbor list build --- src/library.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/library.h | 1 + 2 files changed, 49 insertions(+) diff --git a/src/library.cpp b/src/library.cpp index 74186922ec..a609ab5bee 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -24,6 +24,7 @@ #include "atom.h" #include "atom_vec.h" #include "comm.h" +#include "command.h" #include "compute.h" #include "domain.h" #include "dump.h" @@ -6119,6 +6120,53 @@ int lammps_find_compute_neighlist(void *handle, const char *id, int reqid) { /* ---------------------------------------------------------------------- */ +// helper Command class for a single neighbor list build + +class NeighProxy : protected Command +{ + public: + NeighProxy(class LAMMPS *lmp) : Command(lmp), neigh_idx(-1) {}; + + void command(int, char **) override { + fprintf(stderr, "called NeighProxy::command()\n"); + } + int get_index() const { return neigh_idx; } + protected: + int neigh_idx; +}; + +/** Build a single neighbor list in between runs and return its index + * + * A neighbor list request is created and the neighbor list built from a + * proxy command. The request ID is typically 0, but will be + * > 0 in case a compute has multiple neighbor list requests. + * + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param id Identifier of neighbor list request + * \param flags Neighbor list flags + * \param cutoff Custom neighbor list cutoff if > 0, use default cutoff if < 0 + * \return return neighbor list index if valid, otherwise -1 */ + +int lammps_request_single_neighlist(void *handle, const char *id, int flags, double cutoff) { + auto lmp = (LAMMPS *)handle; + int idx = -1; + if (!lmp || !lmp->error || !lmp->neighbor) { + lammps_last_global_errormessage = fmt::format("ERROR: {}(): Invalid LAMMPS handle\n", FNERR); + return -1; + } + + BEGIN_CAPTURE + { + NeighProxy proxy(lmp); + proxy.command(0, nullptr); + idx = proxy.get_index(); + } + END_CAPTURE + return idx; +} + +/* ---------------------------------------------------------------------- */ + /** Return the number of entries in the neighbor list with given index * * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. diff --git a/src/library.h b/src/library.h index 0d57fdaf78..079ae48828 100644 --- a/src/library.h +++ b/src/library.h @@ -235,6 +235,7 @@ int lammps_create_atoms(void *handle, int n, const int64_t *id, const int *type, int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int nsub, int request); int lammps_find_fix_neighlist(void *handle, const char *id, int request); int lammps_find_compute_neighlist(void *handle, const char *id, int request); +int lammps_request_single_neighlist(void *handle, const char *id, int request, int flags, double cutoff); int lammps_neighlist_num_elements(void *handle, int idx); void lammps_neighlist_element_neighbors(void *handle, int idx, int element, int *iatom, int *numneigh, int **neighbors);