diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index e9976b9032..cea70dd3af 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -305,6 +305,8 @@ of the contents of the :f:mod:`LIBLAMMPS` Fortran interface to LAMMPS. :ftype extract_setting: function :f extract_global: :f:func:`extract_global` :ftype extract_global: function + :f map_atom: :f:func:`map_atom` + :ftype map_atom: function :f extract_atom: :f:func:`extract_atom` :ftype extract_atom: function :f extract_compute: :f:func:`extract_compute` diff --git a/examples/COUPLE/plugin/liblammpsplugin.c b/examples/COUPLE/plugin/liblammpsplugin.c index 011c320254..81dcf2cd50 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.c +++ b/examples/COUPLE/plugin/liblammpsplugin.c @@ -101,6 +101,7 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib) ADDSYM(extract_setting); ADDSYM(extract_global_datatype); ADDSYM(extract_global); + ADDSYM(map_atom); ADDSYM(extract_atom_datatype); ADDSYM(extract_atom); diff --git a/examples/COUPLE/plugin/liblammpsplugin.h b/examples/COUPLE/plugin/liblammpsplugin.h index 1d647e8e93..ea00277083 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.h +++ b/examples/COUPLE/plugin/liblammpsplugin.h @@ -146,6 +146,7 @@ struct _liblammpsplugin { int (*extract_setting)(void *, const char *); int *(*extract_global_datatype)(void *, const char *); void *(*extract_global)(void *, const char *); + void *(*map_atom)(void *, const void *); int *(*extract_atom_datatype)(void *, const char *); void *(*extract_atom)(void *, const char *); diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index c297bad2ef..5130b96676 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -113,6 +113,9 @@ MODULE LIBLAMMPS PROCEDURE :: get_mpi_comm => lmp_get_mpi_comm PROCEDURE :: extract_setting => lmp_extract_setting PROCEDURE :: extract_global => lmp_extract_global + PROCEDURE, PRIVATE :: lmp_map_atom_int + PROCEDURE, PRIVATE :: lmp_map_atom_big + GENERIC :: map_atom => lmp_map_atom_int, lmp_map_atom_big PROCEDURE :: extract_atom => lmp_extract_atom PROCEDURE :: extract_compute => lmp_extract_compute PROCEDURE :: extract_fix => lmp_extract_fix @@ -508,6 +511,13 @@ MODULE LIBLAMMPS TYPE(c_ptr) :: lammps_extract_global END FUNCTION lammps_extract_global + FUNCTION lammps_map_atom(handle, tag) BIND(C) + IMPORT :: c_ptr, c_int + IMPLICIT NONE + TYPE(c_ptr), INTENT(IN), VALUE :: handle, tag + INTEGER(c_int) :: lammps_map_atom + END FUNCTION lammps_map_atom + FUNCTION lammps_extract_atom_datatype(handle, name) BIND(C) IMPORT :: c_ptr, c_int IMPLICIT NONE @@ -1323,6 +1333,38 @@ CONTAINS END SELECT END FUNCTION + ! equivalent function to lammps_map_atom (for 32-bit integer tags) + INTEGER FUNCTION lmp_map_atom_int(self, id) + CLASS(lammps), INTENT(IN) :: self + INTEGER(c_int), INTENT(IN), TARGET :: id + INTEGER(c_int64_t), TARGET :: id64 + TYPE(c_ptr) :: Cptr + + IF (SIZE_TAGINT == 8) THEN + id64 = id + Cptr = C_LOC(id64) + ELSE + Cptr = C_LOC(id) + END IF + lmp_map_atom_int = lammps_map_atom(self%handle, Cptr) + 1 + END FUNCTION lmp_map_atom_int + + ! equivalent function to lammps_map_atom (for 64-bit integer tags) + INTEGER FUNCTION lmp_map_atom_big(self, id) + CLASS(lammps), INTENT(IN) :: self + INTEGER(c_int64_t), INTENT(IN), TARGET :: id + INTEGER(c_int), TARGET :: id32 + TYPE(c_ptr) :: Cptr + + IF (SIZE_TAGINT == 8) THEN + Cptr = C_LOC(id) + ELSE + id32 = id + Cptr = C_LOC(id32) + END IF + lmp_map_atom_big = lammps_map_atom(self%handle, Cptr) + 1 + END FUNCTION lmp_map_atom_big + ! equivalent function to lammps_extract_atom ! the assignment is actually overloaded so as to bind the pointers to ! lammps data based on the information available from LAMMPS diff --git a/tools/swig/lammps.i b/tools/swig/lammps.i index b0670b40a4..d350966c2a 100644 --- a/tools/swig/lammps.i +++ b/tools/swig/lammps.i @@ -125,6 +125,7 @@ extern int lammps_get_mpi_comm(void *handle); extern int lammps_extract_setting(void *handle, const char *keyword); extern int lammps_extract_global_datatype(void *handle, const char *name); extern void *lammps_extract_global(void *handle, const char *name); +extern int lammps_map_atom(void *handle, const void *id); extern int lammps_extract_atom_datatype(void *handle, const char *name); extern void *lammps_extract_atom(void *handle, const char *name); @@ -310,6 +311,7 @@ extern int lammps_get_mpi_comm(void *handle); extern int lammps_extract_setting(void *handle, const char *keyword); extern int lammps_extract_global_datatype(void *handle, const char *name); extern void *lammps_extract_global(void *handle, const char *name); +extern int lammps_map_atom(void *handle, const void *id); extern int lammps_extract_atom_datatype(void *handle, const char *name); extern void *lammps_extract_atom(void *handle, const char *name);