update neighbor list library interface to use ID field in neighbor list to uniquely identify lists

This commit is contained in:
Axel Kohlmeyer
2021-04-02 13:50:50 -04:00
parent 366b49c581
commit 43735fd3f5

View File

@ -3914,40 +3914,43 @@ int lammps_create_atoms(void *handle, int n, tagint *id, int *type,
// Library functions for accessing neighbor lists
// ----------------------------------------------------------------------
/** Find neighbor list index of pair style neighbor list
/** Find index of a neighbor list requested by a pair style
*
* Try finding pair instance that matches style. If exact is set, the pair must
* match style exactly. If exact is 0, style must only be contained. If pair is
* of style pair/hybrid, style is instead matched the nsub-th hybrid sub-style.
* This function determines which of the available neighbor lists for
* pair styles matches the given conditions. It first matches the style
* name. If exact is 1 the name must match exactly, if exact is 0, a
* regular expression or substring match is done. If the pair style is
* hybrid or hybrid/overlay the style is matched against the sub styles
* instead.
* If a the same pair style is used multiple times as a sub-style, the
* nsub argument must be > 0 and represents the nth instance of the sub-style
* (same as for the pair_coeff command, for example). In that case
* nsub=0 will not produce a match and this function will return -1.
*
* Once the pair instance has been identified, multiple neighbor list requests
* may be found. Every neighbor list is uniquely identified by its request
* index. Thus, providing this request index ensures that the correct neighbor
* list index is returned.
* The final condition to be checked is the request ID (reqid). This
* will normally be 0, but some pair styles request multiple neighbor
* lists and set the request ID to a value > 0.
*
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
* \param style String used to search for pair style instance
* \param exact Flag to control whether style should match exactly or only
* must be contained in pair style name
* \param nsub match nsub-th hybrid sub-style
* \param request request index that specifies which neighbor list should be
* returned, in case there are multiple neighbor lists requests
* for the found pair style
* a regular expression / substring match is applied.
* \param nsub match nsub-th hybrid sub-style instance of the same style
* \param reqid request id to identify neighbor list in case there are
* multiple requests from the same pair style instance
* \return return neighbor list index if found, otherwise -1 */
int lammps_find_pair_neighlist(void* handle, char * style, int exact, int nsub, int request) {
LAMMPS * lmp = (LAMMPS *) handle;
Pair* pair = lmp->force->pair_match(style, exact, nsub);
int lammps_find_pair_neighlist(void *handle, char *style, int exact, int nsub, int reqid) {
LAMMPS *lmp = (LAMMPS *) handle;
Pair *pair = lmp->force->pair_match(style, exact, nsub);
if (pair != nullptr) {
// find neigh list
for (int i = 0; i < lmp->neighbor->nlist; i++) {
NeighList * list = lmp->neighbor->lists[i];
if (list->requestor_type != NeighList::PAIR || pair != list->requestor) continue;
if (list->index == request) {
return i;
}
NeighList *list = lmp->neighbor->lists[i];
if ( (list->requestor_type == NeighList::PAIR)
&& (pair == list->requestor)
&& (list->id == reqid) ) return i;
}
}
return -1;
@ -3955,74 +3958,60 @@ int lammps_find_pair_neighlist(void* handle, char * style, int exact, int nsub,
/* ---------------------------------------------------------------------- */
/** Find neighbor list index of fix neighbor list
/** Find index of a neighbor list requested by a fix
*
* The neighbor list request from a fix is identified by the fix ID and
* the request ID. The request ID is typically 0, but will be > 0 in
* case a fix has multiple neighbor list requests.
*
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
* \param id Identifier of fix instance
* \param request request index that specifies which request should be returned,
* in case there are multiple neighbor lists for this fix
* \param reqid request id to identify neighbor list in case there are
* multiple requests from the same fix
* \return return neighbor list index if found, otherwise -1 */
int lammps_find_fix_neighlist(void* handle, char *id, int request) {
LAMMPS * lmp = (LAMMPS *) handle;
Fix* fix = nullptr;
const int nfix = lmp->modify->nfix;
int lammps_find_fix_neighlist(void *handle, char *id, int reqid) {
LAMMPS *lmp = (LAMMPS *) handle;
const int ifix = lmp->modify->find_fix(id);
if (ifix < 0) return -1;
// find fix with name
for (int ifix = 0; ifix < nfix; ifix++) {
if (strcmp(lmp->modify->fix[ifix]->id, id) == 0) {
fix = lmp->modify->fix[ifix];
break;
}
}
if (fix != nullptr) {
// find neigh list
for (int i = 0; i < lmp->neighbor->nlist; i++) {
NeighList * list = lmp->neighbor->lists[i];
if (list->requestor_type != NeighList::FIX || fix != list->requestor) continue;
if (list->index == request) {
return i;
}
}
Fix *fix = lmp->modify->fix[ifix];
// find neigh list
for (int i = 0; i < lmp->neighbor->nlist; i++) {
NeighList *list = lmp->neighbor->lists[i];
if ( (list->requestor_type == NeighList::FIX)
&& (fix == list->requestor)
&& (list->id == reqid) ) return i;
}
return -1;
}
/* ---------------------------------------------------------------------- */
/** Find neighbor list index of compute neighbor list
/** Find index of a neighbor list requested by a compute
*
* The neighbor list request from a compute is identified by the compute
* ID and the request ID. 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 fix instance
* \param request request index that specifies which request should be returned,
* in case there are multiple neighbor lists for this fix
* \param id Identifier of compute instance
* \param reqid request id to identify neighbor list in case there are
* multiple requests from the same compute
* \return return neighbor list index if found, otherwise -1 */
int lammps_find_compute_neighlist(void* handle, char *id, int request) {
LAMMPS * lmp = (LAMMPS *) handle;
Compute* compute = nullptr;
const int ncompute = lmp->modify->ncompute;
int lammps_find_compute_neighlist(void* handle, char *id, int reqid) {
LAMMPS *lmp = (LAMMPS *) handle;
const int icompute = lmp->modify->find_compute(id);
if (icompute < 0) return -1;
// find compute with name
for (int icompute = 0; icompute < ncompute; icompute++) {
if (strcmp(lmp->modify->compute[icompute]->id, id) == 0) {
compute = lmp->modify->compute[icompute];
break;
}
}
if (compute != nullptr) {
// find neigh list
for (int i = 0; i < lmp->neighbor->nlist; i++) {
NeighList * list = lmp->neighbor->lists[i];
if (list->requestor_type != NeighList::COMPUTE || compute != list->requestor) continue;
if (list->index == request) {
return i;
}
}
Compute *compute = lmp->modify->compute[icompute];
// find neigh list
for (int i = 0; i < lmp->neighbor->nlist; i++) {
NeighList * list = lmp->neighbor->lists[i];
if ( (list->requestor_type == NeighList::COMPUTE)
&& (compute == list->requestor)
&& (list->id == reqid) ) return i;
}
return -1;
}