From 46f98ec4dc85d04d0f5e65cb2155e6b3e3a24fcb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 3 Apr 2021 10:23:16 -0400 Subject: [PATCH] make compatible with const data pointers as arguments --- src/library.cpp | 18 +++++++++++------- src/library.h | 14 +++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 7dbe5f9467..ac059f53ae 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -3822,8 +3822,8 @@ X(1),Y(1),Z(1),X(2),Y(2),Z(2),...,X(N),Y(N),Z(N). * \return number of atoms created on success; -1 on failure (no box, no atom IDs, etc.) */ -int lammps_create_atoms(void *handle, int n, tagint *id, int *type, - double *x, double *v, imageint *image, +int lammps_create_atoms(void *handle, int n, const tagint *id, const int *type, + const double *x, const double *v, const imageint *image, int bexpand) { LAMMPS *lmp = (LAMMPS *) handle; @@ -3859,13 +3859,17 @@ int lammps_create_atoms(void *handle, int n, tagint *id, int *type, int nlocal_prev = nlocal; double xdata[3]; + imageint idata, *img; for (int i = 0; i < n; i++) { xdata[0] = x[3*i]; xdata[1] = x[3*i+1]; xdata[2] = x[3*i+2]; - imageint * img = image ? image + i : nullptr; - tagint tag = id ? id[i] : 0; + if (image) { + idata = image[i]; + img = &idata; + } else img = nullptr; + const tagint tag = id ? id[i] : 0; // create atom only on MPI rank that would own it @@ -3943,7 +3947,7 @@ int lammps_create_atoms(void *handle, int n, tagint *id, int *type, * 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 reqid) { +int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int nsub, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; Pair *pair = lmp->force->pair_match(style, exact, nsub); @@ -3973,7 +3977,7 @@ int lammps_find_pair_neighlist(void *handle, char *style, int exact, int nsub, i * 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 reqid) { +int lammps_find_fix_neighlist(void *handle, const char *id, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; const int ifix = lmp->modify->find_fix(id); if (ifix < 0) return -1; @@ -4003,7 +4007,7 @@ int lammps_find_fix_neighlist(void *handle, char *id, int reqid) { * 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 reqid) { +int lammps_find_compute_neighlist(void* handle, const char *id, int reqid) { LAMMPS *lmp = (LAMMPS *) handle; const int icompute = lmp->modify->find_compute(id); if (icompute < 0) return -1; diff --git a/src/library.h b/src/library.h index 11cd72388a..3500e1b65e 100644 --- a/src/library.h +++ b/src/library.h @@ -160,20 +160,20 @@ void lammps_scatter(void *handle, char *name, int type, int count, void *data); void lammps_scatter_subset(void *handle, char *name, int type, int count, int ndata, int *ids, void *data); #if !defined(LAMMPS_BIGBIG) -int lammps_create_atoms(void *handle, int n, int *id, int *type, - double *x, double *v, int *image, int bexpand); +int lammps_create_atoms(void *handle, int n, const int *id, const int *type, + const double *x, const double *v, const int *image, int bexpand); #else -int lammps_create_atoms(void *handle, int n, int64_t *id, int *type, - double *x, double *v, int64_t* image, int bexpand); +int lammps_create_atoms(void *handle, int n, const int64_t *id, const int *type, + const double *x, const double *v, const int64_t* image, int bexpand); #endif /* ---------------------------------------------------------------------- * Library functions for accessing neighbor lists * ---------------------------------------------------------------------- */ -int lammps_find_pair_neighlist(void *handle, char *style, int exact, int nsub, int request); -int lammps_find_fix_neighlist(void *handle, char *id, int request); -int lammps_find_compute_neighlist(void *handle, char *id, 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_compute_neighlist(void *handle, const char *id, int request); 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);