update fork
This commit is contained in:
303
src/library.cpp
303
src/library.cpp
@ -14,14 +14,12 @@
|
||||
// C or Fortran style library interface to LAMMPS
|
||||
// customize by adding new LAMMPS-specific functions
|
||||
|
||||
#include "library.h"
|
||||
#include <mpi.h>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include "library.h"
|
||||
#include "lmptype.h"
|
||||
#include "lammps.h"
|
||||
#include "universe.h"
|
||||
#include "input.h"
|
||||
#include "atom_vec.h"
|
||||
#include "atom.h"
|
||||
#include "domain.h"
|
||||
@ -39,6 +37,14 @@
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "info.h"
|
||||
#include "fix_external.h"
|
||||
#include "neighbor.h"
|
||||
#include "neigh_list.h"
|
||||
#include "neigh_request.h"
|
||||
|
||||
#if defined(LAMMPS_EXCEPTIONS)
|
||||
#include "exceptions.h"
|
||||
#endif
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
@ -531,35 +537,19 @@ void *lammps_extract_compute(void *ptr, char *id, int style, int type)
|
||||
|
||||
if (style == 1) {
|
||||
if (!compute->peratom_flag) return NULL;
|
||||
if (type == 1) {
|
||||
if (compute->invoked_peratom != lmp->update->ntimestep)
|
||||
compute->compute_peratom();
|
||||
return (void *) compute->vector_atom;
|
||||
}
|
||||
if (type == 2) {
|
||||
if (compute->invoked_peratom != lmp->update->ntimestep)
|
||||
compute->compute_peratom();
|
||||
return (void *) compute->array_atom;
|
||||
}
|
||||
if (compute->invoked_peratom != lmp->update->ntimestep)
|
||||
compute->compute_peratom();
|
||||
if (type == 1) return (void *) compute->vector_atom;
|
||||
if (type == 2) return (void *) compute->array_atom;
|
||||
}
|
||||
|
||||
if (style == 2) {
|
||||
if (!compute->local_flag) return NULL;
|
||||
if (type == 0) {
|
||||
if (compute->invoked_local != lmp->update->ntimestep)
|
||||
compute->compute_local();
|
||||
return (void *) &compute->size_local_rows;
|
||||
}
|
||||
if (type == 1) {
|
||||
if (compute->invoked_local != lmp->update->ntimestep)
|
||||
compute->compute_local();
|
||||
return (void *) compute->vector_local;
|
||||
}
|
||||
if (type == 2) {
|
||||
if (compute->invoked_local != lmp->update->ntimestep)
|
||||
compute->compute_local();
|
||||
return (void *) compute->array_local;
|
||||
}
|
||||
if (compute->invoked_local != lmp->update->ntimestep)
|
||||
compute->compute_local();
|
||||
if (type == 0) return (void *) &compute->size_local_rows;
|
||||
if (type == 1) return (void *) compute->vector_local;
|
||||
if (type == 2) return (void *) compute->array_local;
|
||||
}
|
||||
}
|
||||
END_CAPTURE
|
||||
@ -631,6 +621,7 @@ void *lammps_extract_fix(void *ptr, char *id, int style, int type,
|
||||
|
||||
if (style == 2) {
|
||||
if (!fix->local_flag) return NULL;
|
||||
if (type == 0) return (void *) &fix->size_local_rows;
|
||||
if (type == 1) return (void *) fix->vector_local;
|
||||
if (type == 2) return (void *) fix->array_local;
|
||||
}
|
||||
@ -808,7 +799,10 @@ void lammps_gather_atoms(void *ptr, char * /*name */,
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
lmp->error->all(FLERR,"Library function lammps_gather_atoms() not compatible with -DLAMMPS_BIGBIG");
|
||||
{
|
||||
lmp->error->all(FLERR,"Library function lammps_gather_atoms() "
|
||||
"is not compatible with -DLAMMPS_BIGBIG");
|
||||
}
|
||||
END_CAPTURE
|
||||
}
|
||||
#else
|
||||
@ -946,7 +940,10 @@ void lammps_gather_atoms_concat(void *ptr, char * /*name */,
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
lmp->error->all(FLERR,"Library function lammps_gather_atoms_concat() not compatible with -DLAMMPS_BIGBIG");
|
||||
{
|
||||
lmp->error->all(FLERR,"Library function lammps_gather_atoms_concat() "
|
||||
"is not compatible with -DLAMMPS_BIGBIG");
|
||||
}
|
||||
END_CAPTURE
|
||||
}
|
||||
#else
|
||||
@ -1103,7 +1100,10 @@ void lammps_gather_atoms_subset(void *ptr, char * /*name */,
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
lmp->error->all(FLERR,"Library function lammps_gather_atoms_subset() not compatible with -DLAMMPS_BIGBIG");
|
||||
{
|
||||
lmp->error->all(FLERR,"Library function lammps_gather_atoms_subset() "
|
||||
"is not compatible with -DLAMMPS_BIGBIG");
|
||||
}
|
||||
END_CAPTURE
|
||||
}
|
||||
#else
|
||||
@ -1249,7 +1249,10 @@ void lammps_scatter_atoms(void *ptr, char * /*name */,
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
lmp->error->all(FLERR,"Library function lammps_scatter_atoms() not compatible with -DLAMMPS_BIGBIG");
|
||||
{
|
||||
lmp->error->all(FLERR,"Library function lammps_scatter_atoms() "
|
||||
"is not compatible with -DLAMMPS_BIGBIG");
|
||||
}
|
||||
END_CAPTURE
|
||||
}
|
||||
#else
|
||||
@ -1375,7 +1378,10 @@ void lammps_scatter_atoms_subset(void *ptr, char * /*name */,
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
lmp->error->all(FLERR,"Library function lammps_scatter_atoms_subset() not compatible with -DLAMMPS_BIGBIG");
|
||||
{
|
||||
lmp->error->all(FLERR,"Library function lammps_scatter_atoms_subset() "
|
||||
"is not compatible with -DLAMMPS_BIGBIG");
|
||||
}
|
||||
END_CAPTURE
|
||||
}
|
||||
#else
|
||||
@ -1763,7 +1769,7 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type,
|
||||
|
||||
if (lmp->atom->natoms != natoms_prev + n) {
|
||||
char str[128];
|
||||
sprintf(str,"Library warning in lammps_create_atoms, "
|
||||
snprintf(str, 128, "Library warning in lammps_create_atoms, "
|
||||
"invalid total atoms " BIGINT_FORMAT " " BIGINT_FORMAT,
|
||||
lmp->atom->natoms,natoms_prev+n);
|
||||
if (lmp->comm->me == 0)
|
||||
@ -1773,6 +1779,40 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type,
|
||||
END_CAPTURE
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
find fix external with given ID and set the callback function
|
||||
and caller pointer
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
void lammps_set_fix_external_callback(void *ptr, char *id, FixExternalFnPtr callback_ptr, void * caller)
|
||||
{
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
FixExternal::FnPtr callback = (FixExternal::FnPtr) callback_ptr;
|
||||
|
||||
BEGIN_CAPTURE
|
||||
{
|
||||
int ifix = lmp->modify->find_fix(id);
|
||||
if (ifix < 0) {
|
||||
char str[128];
|
||||
snprintf(str, 128, "Can not find fix with ID '%s'!", id);
|
||||
lmp->error->all(FLERR,str);
|
||||
}
|
||||
|
||||
Fix *fix = lmp->modify->fix[ifix];
|
||||
|
||||
if (strcmp("external",fix->style) != 0){
|
||||
char str[128];
|
||||
snprintf(str, 128, "Fix '%s' is not of style external!", id);
|
||||
lmp->error->all(FLERR,str);
|
||||
}
|
||||
|
||||
FixExternal * fext = (FixExternal*) fix;
|
||||
fext->set_callback(callback, caller);
|
||||
}
|
||||
END_CAPTURE
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// library API functions for accessing LAMMPS configuration
|
||||
// ----------------------------------------------------------------------
|
||||
@ -1803,6 +1843,31 @@ int lammps_config_package_name(int index, char * buffer, int max_size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int lammps_has_style(void * ptr, char * category, char * name) {
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
Info info(lmp);
|
||||
return info.has_style(category, name);
|
||||
}
|
||||
|
||||
int lammps_style_count(void * ptr, char * category) {
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
Info info(lmp);
|
||||
return info.get_available_styles(category).size();
|
||||
}
|
||||
|
||||
int lammps_style_name(void* ptr, char * category, int index, char * buffer, int max_size) {
|
||||
LAMMPS *lmp = (LAMMPS *) ptr;
|
||||
Info info(lmp);
|
||||
auto styles = info.get_available_styles(category);
|
||||
|
||||
if (index < styles.size()) {
|
||||
strncpy(buffer, styles[index].c_str(), max_size);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int lammps_config_has_gzip_support() {
|
||||
return Info::has_gzip_support();
|
||||
}
|
||||
@ -1860,3 +1925,171 @@ int lammps_get_last_error_message(void *ptr, char * buffer, int buffer_size) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Find neighbor list index of pair style neighbor list
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @param ptr Pointer to LAMMPS instance
|
||||
* @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
|
||||
* @return return neighbor list index if found, otherwise -1
|
||||
******************************************************************************/
|
||||
int lammps_find_pair_neighlist(void* ptr, char * style, int exact, int nsub, int request) {
|
||||
LAMMPS * lmp = (LAMMPS *) ptr;
|
||||
Pair* pair = lmp->force->pair_match(style, exact, nsub);
|
||||
|
||||
if (pair != NULL) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Find neighbor list index of fix neighbor list
|
||||
*
|
||||
* @param ptr Pointer to LAMMPS instance
|
||||
* @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
|
||||
* @return return neighbor list index if found, otherwise -1
|
||||
******************************************************************************/
|
||||
int lammps_find_fix_neighlist(void* ptr, char * id, int request) {
|
||||
LAMMPS * lmp = (LAMMPS *) ptr;
|
||||
Fix* fix = NULL;
|
||||
const int nfix = lmp->modify->nfix;
|
||||
|
||||
// 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 != NULL) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Find neighbor list index of compute neighbor list
|
||||
*
|
||||
* @param ptr Pointer to LAMMPS instance
|
||||
* @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
|
||||
* @return return neighbor list index if found, otherwise -1
|
||||
******************************************************************************/
|
||||
int lammps_find_compute_neighlist(void* ptr, char * id, int request) {
|
||||
LAMMPS * lmp = (LAMMPS *) ptr;
|
||||
Compute* compute = NULL;
|
||||
const int ncompute = lmp->modify->ncompute;
|
||||
|
||||
// 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 == NULL) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Return the number of entries in the neighbor list with given index
|
||||
*
|
||||
* @param ptr Pointer to LAMMPS instance
|
||||
* @param idx neighbor list index
|
||||
* @return return number of entries in neighbor list, -1 if idx is
|
||||
* not a valid index
|
||||
******************************************************************************/
|
||||
int lammps_neighlist_num_elements(void * ptr, int idx) {
|
||||
LAMMPS * lmp = (LAMMPS *) ptr;
|
||||
Neighbor * neighbor = lmp->neighbor;
|
||||
|
||||
if(idx < 0 || idx >= neighbor->nlist) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
NeighList * list = neighbor->lists[idx];
|
||||
return list->inum;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Return atom local index, number of neighbors, and array of neighbor local
|
||||
* atom indices of neighbor list entry
|
||||
*
|
||||
* @param ptr Pointer to LAMMPS instance
|
||||
* @param idx neighbor list index
|
||||
* @param element neighbor list element index
|
||||
* @param[out] iatom atom local index in range [0, nlocal + nghost), -1 if
|
||||
invalid idx or element index
|
||||
* @param[out] numneigh number of neighbors of atom i or 0
|
||||
* @param[out] neighbors pointer to array of neighbor atom local indices or
|
||||
* NULL
|
||||
******************************************************************************/
|
||||
void lammps_neighlist_element_neighbors(void * ptr, int idx, int element, int * iatom, int * numneigh, int ** neighbors) {
|
||||
LAMMPS * lmp = (LAMMPS *) ptr;
|
||||
Neighbor * neighbor = lmp->neighbor;
|
||||
*iatom = -1;
|
||||
*numneigh = 0;
|
||||
*neighbors = NULL;
|
||||
|
||||
if(idx < 0 || idx >= neighbor->nlist) {
|
||||
return;
|
||||
}
|
||||
|
||||
NeighList * list = neighbor->lists[idx];
|
||||
|
||||
if(element < 0 || element >= list->inum) {
|
||||
return;
|
||||
}
|
||||
|
||||
int i = list->ilist[element];
|
||||
*iatom = i;
|
||||
*numneigh = list->numneigh[i];
|
||||
*neighbors = list->firstneigh[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user