implement function to add request for single occasional neighbor list
This commit is contained in:
@ -43,6 +43,7 @@
|
|||||||
#include "molecule.h"
|
#include "molecule.h"
|
||||||
#include "neigh_list.h"
|
#include "neigh_list.h"
|
||||||
#include "neighbor.h"
|
#include "neighbor.h"
|
||||||
|
#include "neigh_request.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
#include "pair.h"
|
#include "pair.h"
|
||||||
#if defined(LMP_PLUGIN)
|
#if defined(LMP_PLUGIN)
|
||||||
@ -6122,18 +6123,57 @@ int lammps_find_compute_neighlist(void *handle, const char *id, int reqid) {
|
|||||||
|
|
||||||
// helper Command class for a single neighbor list build
|
// helper Command class for a single neighbor list build
|
||||||
|
|
||||||
class NeighProxy : protected Command
|
namespace LAMMPS_NS {
|
||||||
{
|
class NeighProxy : protected Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
NeighProxy(class LAMMPS *lmp) : Command(lmp), neigh_idx(-1) {};
|
NeighProxy(class LAMMPS *lmp) : Command(lmp), neigh_idx(-1) {};
|
||||||
|
|
||||||
void command(int, char **) override {
|
void command(int, char **) override;
|
||||||
fprintf(stderr, "called NeighProxy::command()\n");
|
|
||||||
}
|
|
||||||
int get_index() const { return neigh_idx; }
|
int get_index() const { return neigh_idx; }
|
||||||
protected:
|
protected:
|
||||||
int neigh_idx;
|
int neigh_idx;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void NeighProxy::command(int narg, char **arg)
|
||||||
|
{
|
||||||
|
neigh_idx = -1;
|
||||||
|
if (narg != 3) return;
|
||||||
|
auto *req = neighbor->add_request(this, arg[0]);
|
||||||
|
int flags = atoi(arg[1]);
|
||||||
|
double cutoff = atof(arg[2]);
|
||||||
|
req->apply_flags(flags);
|
||||||
|
if (cutoff > 0.0) req->set_cutoff(cutoff);
|
||||||
|
lmp->init();
|
||||||
|
|
||||||
|
// setup domain, communication and neighboring
|
||||||
|
// acquire ghosts and build standard neighbor lists
|
||||||
|
|
||||||
|
if (domain->triclinic) domain->x2lamda(atom->nlocal);
|
||||||
|
domain->pbc();
|
||||||
|
domain->reset_box();
|
||||||
|
comm->setup();
|
||||||
|
if (neighbor->style) neighbor->setup_bins();
|
||||||
|
comm->exchange();
|
||||||
|
comm->borders();
|
||||||
|
if (domain->triclinic) domain->lamda2x(atom->nlocal + atom->nghost);
|
||||||
|
neighbor->build(1);
|
||||||
|
|
||||||
|
// build neighbor list this command needs based on earlier request
|
||||||
|
|
||||||
|
auto list = neighbor->find_list(this);
|
||||||
|
neighbor->build_one(list);
|
||||||
|
|
||||||
|
// find neigh list
|
||||||
|
for (int i = 0; i < neighbor->nlist; i++) {
|
||||||
|
NeighList *list = neighbor->lists[i];
|
||||||
|
if (this == list->requestor) {
|
||||||
|
neigh_idx = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Build a single neighbor list in between runs and return its index
|
/** Build a single neighbor list in between runs and return its index
|
||||||
*
|
*
|
||||||
@ -6158,8 +6198,15 @@ int lammps_request_single_neighlist(void *handle, const char *id, int flags, dou
|
|||||||
BEGIN_CAPTURE
|
BEGIN_CAPTURE
|
||||||
{
|
{
|
||||||
NeighProxy proxy(lmp);
|
NeighProxy proxy(lmp);
|
||||||
proxy.command(0, nullptr);
|
char *args[3];
|
||||||
|
args[0] = utils::strdup(id);
|
||||||
|
args[1] = utils::strdup(std::to_string(flags));
|
||||||
|
args[2] = utils::strdup(std::to_string(cutoff));
|
||||||
|
proxy.command(3, args);
|
||||||
idx = proxy.get_index();
|
idx = proxy.get_index();
|
||||||
|
delete[] args[0];
|
||||||
|
delete[] args[1];
|
||||||
|
delete[] args[2];
|
||||||
}
|
}
|
||||||
END_CAPTURE
|
END_CAPTURE
|
||||||
return idx;
|
return idx;
|
||||||
|
|||||||
@ -109,6 +109,17 @@ enum _LMP_VAR_CONST {
|
|||||||
LMP_VAR_STRING = 3 /*!< return value will be a string (catch-all) */
|
LMP_VAR_STRING = 3 /*!< return value will be a string (catch-all) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Neighbor list settings constants
|
||||||
|
*
|
||||||
|
* Must be kept in sync with the equivalent constants in ``python/lammps/constants.py``,
|
||||||
|
* ``fortran/lammps.f90``, ``tools/swig/lammps.i``, and
|
||||||
|
* ``examples/COUPLE/plugin/liblammpsplugin.h`` */
|
||||||
|
|
||||||
|
enum _LMP_NEIGH_CONST {
|
||||||
|
LMP_NEIGH_HALF = 0, /*!< request (default) half neighbor list */
|
||||||
|
LMP_NEIGH_FULL = 1, /*!< request full neighbor list */
|
||||||
|
};
|
||||||
|
|
||||||
/* Ifdefs to allow this file to be included in C and C++ programs */
|
/* Ifdefs to allow this file to be included in C and C++ programs */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -235,7 +246,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_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_fix_neighlist(void *handle, const char *id, int request);
|
||||||
int lammps_find_compute_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_request_single_neighlist(void *handle, const char *id, int flags, double cutoff);
|
||||||
int lammps_neighlist_num_elements(void *handle, int idx);
|
int lammps_neighlist_num_elements(void *handle, int idx);
|
||||||
void lammps_neighlist_element_neighbors(void *handle, int idx, int element, int *iatom,
|
void lammps_neighlist_element_neighbors(void *handle, int idx, int element, int *iatom,
|
||||||
int *numneigh, int **neighbors);
|
int *numneigh, int **neighbors);
|
||||||
|
|||||||
Reference in New Issue
Block a user