propagate changes from library.cpp/library.h to swig and plugin interface

This commit is contained in:
Axel Kohlmeyer
2025-04-25 17:04:32 -04:00
parent 1969c28e0c
commit d406289a7a
4 changed files with 109 additions and 38 deletions

View File

@ -144,6 +144,7 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
ADDSYM(find_pair_neighlist);
ADDSYM(find_fix_neighlist);
ADDSYM(find_compute_neighlist);
ADDSYM(request_single_neighlist);
ADDSYM(neighlist_num_elements);
ADDSYM(neighlist_element_neighbors);

View File

@ -94,6 +94,17 @@ enum _LMP_VAR_CONST {
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 */
};
#ifdef __cplusplus
extern "C" {
#endif
@ -189,14 +200,17 @@ struct _liblammpsplugin {
* caller must match to how LAMMPS library is built */
#if !defined(LAMMPS_BIGBIG)
int (*create_atoms)(void *, int, int *, int *, double *, double *, int *, int);
int (*create_atoms)(void *, int, const int *, const int *, const double *, const double *,
const int *, int);
#else
int (*create_atoms)(void *, int, int64_t *, int *, double *, double *, int64_t *, int);
int (*create_atoms)(void *, int, const int64_t *, const int *, const double *, const double *,
const int64_t *, int);
#endif
int (*find_pair_neighlist)(void *, const char *, int, int, int);
int (*find_fix_neighlist)(void *, const char *, int);
int (*find_compute_neighlist)(void *, const char *, int);
int (*request_single_neighlist)(void *, const char *, int, double);
int (*neighlist_num_elements)(void *, int);
void (*neighlist_element_neighbors)(void *, int, int, int *, int *, int **);

View File

@ -74,7 +74,9 @@ MODULE LIBLAMMPS
LMP_VAR_EQUAL = 0, & ! equal-style variables (and compatible)
LMP_VAR_ATOM = 1, & ! atom-style variables
LMP_VAR_VECTOR = 2, & ! vector variables
LMP_VAR_STRING = 3 ! string variables (everything else)
LMP_VAR_STRING = 3, & ! string variables (everything else)
LMP_NEIGH_HALF = 0, & ! request (default) half neighbor list
LMP_NEIGH_FULL = 1 ! request full neighbor list
! Constants we set once (in the constructor) and never need to check again
INTEGER(c_int), SAVE :: SIZE_TAGINT, SIZE_BIGINT, SIZE_IMAGEINT
@ -198,6 +200,7 @@ MODULE LIBLAMMPS
PROCEDURE :: find_pair_neighlist => lmp_find_pair_neighlist
PROCEDURE :: find_fix_neighlist => lmp_find_fix_neighlist
PROCEDURE :: find_compute_neighlist => lmp_find_compute_neighlist
PROCEDURE :: request_single_neighlist => lmp_request_single_neighlist
PROCEDURE :: neighlist_num_elements => lmp_neighlist_num_elements
PROCEDURE :: neighlist_element_neighbors => lmp_neighlist_element_neighbors
PROCEDURE :: version => lmp_version
@ -778,6 +781,15 @@ MODULE LIBLAMMPS
INTEGER(c_int) :: lammps_find_compute_neighlist
END FUNCTION lammps_find_compute_neighlist
FUNCTION lammps_request_single_neighlist(handle, id, flags, cutoff) BIND(C)
IMPORT :: c_int, c_double, c_ptr
IMPLICIT NONE
TYPE(c_ptr), VALUE :: handle, id
INTEGER(c_int), VALUE :: flags
REAL(c_double), VALUE :: cutoff
INTEGER(c_int) :: lammps_request_single_neighlist
END FUNCTION lammps_request_single_neighlist
FUNCTION lammps_neighlist_num_elements(handle, idx) BIND(C)
IMPORT :: c_ptr, c_int
TYPE(c_ptr), VALUE :: handle
@ -2942,6 +2954,36 @@ CONTAINS
CALL lammps_free(Cid)
END FUNCTION lmp_find_compute_neighlist
! equivalent function to lammps_request_single_neighlist
INTEGER(c_int) FUNCTION lmp_request_single_neighlist(self, id, flags, cutoff) RESULT(idx)
CLASS(lammps), INTENT(IN) :: self
CHARACTER(LEN=*), INTENT(IN) :: id
INTEGER(c_int), INTENT(IN), OPTIONAL :: flags
REAL(c_double), INTENT(IN), OPTIONAL :: cutoff
TYPE(c_ptr) :: Cid
INTEGER(c_int) :: Cflags
REAL(c_double) :: Ccutoff
IF (PRESENT(flags)) THEN
Cflags = flags
ELSE
Cflags = LMP_NEIGH_HALF
END IF
IF (PRESENT(cutoff)) THEN
Ccutoff = cutoff
ELSE
Ccutoff = 1.0_c_double
END IF
Cid = f2c_string(id)
idx = lammps_request_single_neighlist(self%handle, Cid, Cflags, Ccutoff)
IF (idx < 0) THEN
CALL lmp_error(self, LMP_ERROR_WARNING + LMP_ERROR_WORLD, &
'neighbor list build failed [Fortran/request_single_neighlist]')
END IF
CALL lammps_free(Cid)
END FUNCTION lmp_request_single_neighlist
INTEGER(c_int) FUNCTION lmp_neighlist_num_elements(self, idx) RESULT(inum)
CLASS(lammps), INTENT(IN) :: self
INTEGER(c_int), INTENT(IN) :: idx

View File

@ -95,6 +95,17 @@ enum _LMP_VAR_CONST {
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 */
};
/*
extern void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr);
*/
@ -143,31 +154,33 @@ extern int lammps_set_string_variable(void *, const char *, const char *);
extern int lammps_set_internal_variable(void *, const char *, double);
extern int lammps_variable_info(void *handle, int idx, char *buf, int bufsize);
extern double lammps_eval(void *handle, const char *expr);
extern void lammps_clearstep_compute(void *handle);
extern void lammps_addstep_compute(void *handle, void *nstep);
extern void lammps_addstep_compute_all(void *handle, void *nstep);
extern void lammps_gather_atoms(void *, char *, int, int, void *);
extern void lammps_gather_atoms_concat(void *, char *, int, int, void *);
extern void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter_atoms(void *, char *, int, int, void *);
extern void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_gather_atoms(void *, const char *, int, int, void *);
extern void lammps_gather_atoms_concat(void *, const char *, int, int, void *);
extern void lammps_gather_atoms_subset(void *, const char *, int, int, int, int *, void *);
extern void lammps_scatter_atoms(void *, const char *, int, int, void *);
extern void lammps_scatter_atoms_subset(void *, const char *, int, int, int, int *, void *);
extern void lammps_gather_bonds(void *handle, void *data);
extern void lammps_gather_angles(void *handle, void *data);
extern void lammps_gather_dihedrals(void *handle, void *data);
extern void lammps_gather_impropers(void *handle, void *data);
extern void lammps_gather(void *, char *, int, int, void *);
extern void lammps_gather_concat(void *, char *, int, int, void *);
extern void lammps_gather_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter(void *, char *, int, int, void *);
extern void lammps_scatter_subset(void *, char *, int, int, int, int *, void *);
extern int lammps_create_atoms(void *handle, int n, int *id, int *type,
double *x, double *v, int *image, int bexpand);
extern void lammps_gather(void *, const char *, int, int, void *);
extern void lammps_gather_concat(void *, const char *, int, int, void *);
extern void lammps_gather_subset(void *, const char *, int, int, int, int *, void *);
extern void lammps_scatter(void *, const char *, int, int, void *);
extern void lammps_scatter_subset(void *, const char *, int, int, int, int *, void *);
extern 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);
/*
extern int lammps_create_atoms(void *handle, int n, int64_t *id, int *type, */
extern int lammps_find_pair_neighlist(void*, char *, int, int, int);
extern int lammps_find_fix_neighlist(void*, char *, int);
extern int lammps_find_compute_neighlist(void*, char *, int);
extern int lammps_find_pair_neighlist(void *, const char *, int, int, int);
extern int lammps_find_fix_neighlist(void *, const char *, int);
extern int lammps_find_compute_neighlist(void *, const char *, int);
extern int lammps_request_single_neighlist(void *, const char *, int, double);
extern int lammps_neighlist_num_elements(void *, int);
extern void lammps_neighlist_element_neighbors(void *, int, int, int *, int *, int ** );
@ -344,27 +357,28 @@ extern void lammps_clearstep_compute(void *handle);
extern void lammps_addstep_compute(void *handle, void *nstep);
extern void lammps_addstep_compute_all(void *handle, void *nstep);
extern void lammps_gather_atoms(void *, char *, int, int, void *);
extern void lammps_gather_atoms_concat(void *, char *, int, int, void *);
extern void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter_atoms(void *, char *, int, int, void *);
extern void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_gather_atoms(void *, const char *, int, int, void *);
extern void lammps_gather_atoms_concat(void *, const char *, int, int, void *);
extern void lammps_gather_atoms_subset(void *, const char *, int, int, int, int *, void *);
extern void lammps_scatter_atoms(void *, const char *, int, int, void *);
extern void lammps_scatter_atoms_subset(void *, const char *, int, int, int, int *, void *);
extern void lammps_gather_bonds(void *handle, void *data);
extern void lammps_gather_angles(void *handle, void *data);
extern void lammps_gather_dihedrals(void *handle, void *data);
extern void lammps_gather_impropers(void *handle, void *data);
extern void lammps_gather(void *, char *, int, int, void *);
extern void lammps_gather_concat(void *, char *, int, int, void *);
extern void lammps_gather_subset(void *, char *, int, int, int, int *, void *);
extern void lammps_scatter(void *, char *, int, int, void *);
extern void lammps_scatter_subset(void *, char *, int, int, int, int *, void *);
extern int lammps_create_atoms(void *handle, int n, int *id, int *type,
double *x, double *v, int *image, int bexpand);
extern void lammps_gather(void *, const char *, int, int, void *);
extern void lammps_gather_concat(void *, const char *, int, int, void *);
extern void lammps_gather_subset(void *, const char *, int, int, int, int *, void *);
extern void lammps_scatter(void *, const char *, int, int, void *);
extern void lammps_scatter_subset(void *, const char *, int, int, int, int *, void *);
extern 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);
/*
extern int lammps_create_atoms(void *handle, int n, int64_t *id, int *type, */
extern int lammps_find_pair_neighlist(void*, char *, int, int, int);
extern int lammps_find_fix_neighlist(void*, char *, int);
extern int lammps_find_compute_neighlist(void*, char *, int);
extern int lammps_find_pair_neighlist(void*, const char *, int, int, int);
extern int lammps_find_fix_neighlist(void*, const char *, int);
extern int lammps_find_compute_neighlist(void*, const char *, int);
extern int lammps_request_single_neighlist(void *, const char *, int, double);
extern int lammps_neighlist_num_elements(void*, int);
extern void lammps_neighlist_element_neighbors(void *, int, int, int *, int *, int ** );