update prototypes and struct entries for liblammpsplugin. port to windows.
This commit is contained in:
@ -18,10 +18,29 @@
|
|||||||
a LAMMPS plugin to some other software.
|
a LAMMPS plugin to some other software.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "library.h"
|
|
||||||
#include "liblammpsplugin.h"
|
#include "liblammpsplugin.h"
|
||||||
#include <stdlib.h>
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32_WINNT)
|
||||||
|
#undef _WIN32_WINNT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// target Windows version is windows 7 and later
|
||||||
|
#define _WIN32_WINNT _WIN32_WINNT_WIN7
|
||||||
|
#define PSAPI_VERSION 2
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
||||||
{
|
{
|
||||||
@ -29,14 +48,26 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
void *handle;
|
void *handle;
|
||||||
|
|
||||||
if (lib == NULL) return NULL;
|
if (lib == NULL) return NULL;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
handle = (void *) LoadLibrary(lib);
|
||||||
|
#else
|
||||||
handle = dlopen(lib,RTLD_NOW|RTLD_GLOBAL);
|
handle = dlopen(lib,RTLD_NOW|RTLD_GLOBAL);
|
||||||
|
#endif
|
||||||
if (handle == NULL) return NULL;
|
if (handle == NULL) return NULL;
|
||||||
|
|
||||||
lmp = (liblammpsplugin_t *) malloc(sizeof(liblammpsplugin_t));
|
lmp = (liblammpsplugin_t *) malloc(sizeof(liblammpsplugin_t));
|
||||||
lmp->handle = handle;
|
lmp->handle = handle;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define ADDSYM(symbol) lmp->symbol = (void *) GetProcAddress((HINSTANCE) handle, "lammps_" #symbol)
|
||||||
|
#else
|
||||||
#define ADDSYM(symbol) lmp->symbol = dlsym(handle,"lammps_" #symbol)
|
#define ADDSYM(symbol) lmp->symbol = dlsym(handle,"lammps_" #symbol)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(LAMMPS_LIB_MPI)
|
||||||
ADDSYM(open);
|
ADDSYM(open);
|
||||||
|
#endif
|
||||||
ADDSYM(open_no_mpi);
|
ADDSYM(open_no_mpi);
|
||||||
ADDSYM(open_fortran);
|
ADDSYM(open_fortran);
|
||||||
ADDSYM(close);
|
ADDSYM(close);
|
||||||
@ -46,6 +77,8 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
ADDSYM(kokkos_finalize);
|
ADDSYM(kokkos_finalize);
|
||||||
ADDSYM(python_finalize);
|
ADDSYM(python_finalize);
|
||||||
|
|
||||||
|
ADDSYM(error);
|
||||||
|
|
||||||
ADDSYM(file);
|
ADDSYM(file);
|
||||||
ADDSYM(command);
|
ADDSYM(command);
|
||||||
ADDSYM(commands_list);
|
ADDSYM(commands_list);
|
||||||
@ -70,6 +103,7 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
ADDSYM(extract_compute);
|
ADDSYM(extract_compute);
|
||||||
ADDSYM(extract_fix);
|
ADDSYM(extract_fix);
|
||||||
ADDSYM(extract_variable);
|
ADDSYM(extract_variable);
|
||||||
|
ADDSYM(extract_variable_datatype);
|
||||||
ADDSYM(set_variable);
|
ADDSYM(set_variable);
|
||||||
|
|
||||||
ADDSYM(gather_atoms);
|
ADDSYM(gather_atoms);
|
||||||
@ -77,8 +111,15 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
ADDSYM(gather_atoms_subset);
|
ADDSYM(gather_atoms_subset);
|
||||||
ADDSYM(scatter_atoms);
|
ADDSYM(scatter_atoms);
|
||||||
ADDSYM(scatter_atoms_subset);
|
ADDSYM(scatter_atoms_subset);
|
||||||
|
|
||||||
ADDSYM(gather_bonds);
|
ADDSYM(gather_bonds);
|
||||||
|
|
||||||
|
ADDSYM(gather);
|
||||||
|
ADDSYM(gather_concat);
|
||||||
|
ADDSYM(gather_subset);
|
||||||
|
ADDSYM(scatter);
|
||||||
|
ADDSYM(scatter_subset);
|
||||||
|
|
||||||
ADDSYM(create_atoms);
|
ADDSYM(create_atoms);
|
||||||
|
|
||||||
ADDSYM(find_pair_neighlist);
|
ADDSYM(find_pair_neighlist);
|
||||||
@ -116,6 +157,9 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
ADDSYM(plugin_count);
|
ADDSYM(plugin_count);
|
||||||
ADDSYM(plugin_name);
|
ADDSYM(plugin_name);
|
||||||
|
|
||||||
|
ADDSYM(encode_image_flags);
|
||||||
|
ADDSYM(decode_image_flags);
|
||||||
|
|
||||||
ADDSYM(set_fix_external_callback);
|
ADDSYM(set_fix_external_callback);
|
||||||
ADDSYM(fix_external_get_force);
|
ADDSYM(fix_external_get_force);
|
||||||
ADDSYM(fix_external_set_energy_global);
|
ADDSYM(fix_external_set_energy_global);
|
||||||
@ -125,6 +169,8 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
ADDSYM(fix_external_set_vector_length);
|
ADDSYM(fix_external_set_vector_length);
|
||||||
ADDSYM(fix_external_set_vector);
|
ADDSYM(fix_external_set_vector);
|
||||||
|
|
||||||
|
ADDSYM(flush_buffers);
|
||||||
|
|
||||||
ADDSYM(free);
|
ADDSYM(free);
|
||||||
|
|
||||||
ADDSYM(is_running);
|
ADDSYM(is_running);
|
||||||
@ -139,6 +185,8 @@ liblammpsplugin_t *liblammpsplugin_load(const char *lib)
|
|||||||
lmp->has_error = NULL;
|
lmp->has_error = NULL;
|
||||||
lmp->get_last_error_message = NULL;
|
lmp->get_last_error_message = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ADDSYM(python_api_version);
|
||||||
return lmp;
|
return lmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +195,11 @@ int liblammpsplugin_release(liblammpsplugin_t *lmp)
|
|||||||
if (lmp == NULL) return 1;
|
if (lmp == NULL) return 1;
|
||||||
if (lmp->handle == NULL) return 2;
|
if (lmp->handle == NULL) return 2;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
FreeLibrary((HINSTANCE) handle);
|
||||||
|
#else
|
||||||
dlclose(lmp->handle);
|
dlclose(lmp->handle);
|
||||||
|
#endif
|
||||||
free((void *)lmp);
|
free((void *)lmp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,11 +28,71 @@
|
|||||||
#define LAMMPS_SMALLBIG
|
#define LAMMPS_SMALLBIG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LAMMPS_LIB_MPI)
|
||||||
#include <mpi.h>
|
#include <mpi.h>
|
||||||
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
|
|
||||||
#include <inttypes.h> /* for int64_t */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
|
||||||
|
#include <stdint.h> /* for int64_t */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* The following 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 */
|
||||||
|
|
||||||
|
/* Data type constants for extracting data from atoms, computes and fixes */
|
||||||
|
|
||||||
|
enum _LMP_DATATYPE_CONST {
|
||||||
|
LAMMPS_INT = 0, /*!< 32-bit integer (array) */
|
||||||
|
LAMMPS_INT_2D = 1, /*!< two-dimensional 32-bit integer array */
|
||||||
|
LAMMPS_DOUBLE = 2, /*!< 64-bit double (array) */
|
||||||
|
LAMMPS_DOUBLE_2D = 3, /*!< two-dimensional 64-bit double array */
|
||||||
|
LAMMPS_INT64 = 4, /*!< 64-bit integer (array) */
|
||||||
|
LAMMPS_INT64_2D = 5, /*!< two-dimensional 64-bit integer array */
|
||||||
|
LAMMPS_STRING = 6 /*!< C-String */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Style constants for extracting data from computes and fixes. */
|
||||||
|
|
||||||
|
enum _LMP_STYLE_CONST {
|
||||||
|
LMP_STYLE_GLOBAL = 0, /*!< return global data */
|
||||||
|
LMP_STYLE_ATOM = 1, /*!< return per-atom data */
|
||||||
|
LMP_STYLE_LOCAL = 2 /*!< return local data */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Type and size constants for extracting data from computes and fixes. */
|
||||||
|
|
||||||
|
enum _LMP_TYPE_CONST {
|
||||||
|
LMP_TYPE_SCALAR = 0, /*!< return scalar */
|
||||||
|
LMP_TYPE_VECTOR = 1, /*!< return vector */
|
||||||
|
LMP_TYPE_ARRAY = 2, /*!< return array */
|
||||||
|
LMP_SIZE_VECTOR = 3, /*!< return length of vector */
|
||||||
|
LMP_SIZE_ROWS = 4, /*!< return number of rows */
|
||||||
|
LMP_SIZE_COLS = 5 /*!< return number of columns */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Error codes to select the suitable function in the Error class */
|
||||||
|
|
||||||
|
enum _LMP_ERROR_CONST {
|
||||||
|
LMP_ERROR_WARNING = 0, /*!< call Error::warning() */
|
||||||
|
LMP_ERROR_ONE = 1, /*!< called from one MPI rank */
|
||||||
|
LMP_ERROR_ALL = 2, /*!< called from all MPI ranks */
|
||||||
|
LMP_ERROR_WORLD = 4, /*!< error on Comm::world */
|
||||||
|
LMP_ERROR_UNIVERSE = 8 /*!< error on Comm::universe */
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Variable style constants for extracting data from variables.
|
||||||
|
*
|
||||||
|
* Must be kept in sync with the equivalent constants in python/lammps/constants.py,
|
||||||
|
* fortran/lammps.f90, and tools/swig/lammps.i */
|
||||||
|
|
||||||
|
enum _LMP_VAR_CONST {
|
||||||
|
LMP_VAR_EQUAL = 0, /*!< compatible with equal-style variables */
|
||||||
|
LMP_VAR_ATOM = 1, /*!< compatible with atom-style variables */
|
||||||
|
LMP_VAR_VECTOR = 2, /*!< compatible with vector-style variables */
|
||||||
|
LMP_VAR_STRING = 3 /*!< return value will be a string (catch-all) */
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -49,7 +109,9 @@ struct _liblammpsplugin {
|
|||||||
int abiversion;
|
int abiversion;
|
||||||
int has_exceptions;
|
int has_exceptions;
|
||||||
void *handle;
|
void *handle;
|
||||||
|
#if defined(LAMMPS_LIB_MPI)
|
||||||
void *(*open)(int, char **, MPI_Comm, void **);
|
void *(*open)(int, char **, MPI_Comm, void **);
|
||||||
|
#endif
|
||||||
void *(*open_no_mpi)(int, char **, void **);
|
void *(*open_no_mpi)(int, char **, void **);
|
||||||
void *(*open_fortran)(int, char **, void **, int);
|
void *(*open_fortran)(int, char **, void **, int);
|
||||||
void (*close)(void *);
|
void (*close)(void *);
|
||||||
@ -59,13 +121,15 @@ struct _liblammpsplugin {
|
|||||||
void (*kokkos_finalize)();
|
void (*kokkos_finalize)();
|
||||||
void (*python_finalize)();
|
void (*python_finalize)();
|
||||||
|
|
||||||
|
void (*error)(void *, int, const char *);
|
||||||
|
|
||||||
void (*file)(void *, char *);
|
void (*file)(void *, char *);
|
||||||
char *(*command)(void *, const char *);
|
char *(*command)(void *, const char *);
|
||||||
void (*commands_list)(void *, int, const char **);
|
void (*commands_list)(void *, int, const char **);
|
||||||
void (*commands_string)(void *, const char *);
|
void (*commands_string)(void *, const char *);
|
||||||
|
|
||||||
double (*get_natoms)(void *);
|
double (*get_natoms)(void *);
|
||||||
double (*get_thermo)(void *, char *);
|
double (*get_thermo)(void *, const char *);
|
||||||
|
|
||||||
void (*extract_box)(void *, double *, double *,
|
void (*extract_box)(void *, double *, double *,
|
||||||
double *, double *, double *, int *, int *);
|
double *, double *, double *, int *, int *);
|
||||||
@ -78,12 +142,13 @@ struct _liblammpsplugin {
|
|||||||
int *(*extract_global_datatype)(void *, const char *);
|
int *(*extract_global_datatype)(void *, const char *);
|
||||||
void *(*extract_global)(void *, const char *);
|
void *(*extract_global)(void *, const char *);
|
||||||
|
|
||||||
void *(*extract_atom_datatype)(void *, const char *);
|
int *(*extract_atom_datatype)(void *, const char *);
|
||||||
void *(*extract_atom)(void *, const char *);
|
void *(*extract_atom)(void *, const char *);
|
||||||
|
|
||||||
void *(*extract_compute)(void *, const char *, int, int);
|
void *(*extract_compute)(void *, const char *, int, int);
|
||||||
void *(*extract_fix)(void *, const char *, int, int, int, int);
|
void *(*extract_fix)(void *, const char *, int, int, int, int);
|
||||||
void *(*extract_variable)(void *, const char *, char *);
|
void *(*extract_variable)(void *, const char *, char *);
|
||||||
|
int (*extract_variable_datatype)(void *, const char *);
|
||||||
int (*set_variable)(void *, char *, char *);
|
int (*set_variable)(void *, char *, char *);
|
||||||
|
|
||||||
void (*gather_atoms)(void *, char *, int, int, void *);
|
void (*gather_atoms)(void *, char *, int, int, void *);
|
||||||
@ -94,21 +159,25 @@ struct _liblammpsplugin {
|
|||||||
|
|
||||||
void (*gather_bonds)(void *, void *);
|
void (*gather_bonds)(void *, void *);
|
||||||
|
|
||||||
|
void (*gather)(void *, char *, int, int, void *);
|
||||||
|
void (*gather_concat)(void *, char *, int, int, void *);
|
||||||
|
void (*gather_subset)(void *, char *, int, int, int, int *,void *);
|
||||||
|
void (*scatter)(void *, char *, int, int, void *);
|
||||||
|
void (*scatter_subset)(void *, char *, int, int, int, int *, void *);
|
||||||
|
|
||||||
// lammps_create_atoms() takes tagint and imageint as args
|
// lammps_create_atoms() takes tagint and imageint as args
|
||||||
// ifdef insures they are compatible with rest of LAMMPS
|
// ifdef insures they are compatible with rest of LAMMPS
|
||||||
// caller must match to how LAMMPS library is built
|
// caller must match to how LAMMPS library is built
|
||||||
|
|
||||||
#ifndef LAMMPS_BIGBIG
|
#ifndef LAMMPS_BIGBIG
|
||||||
void (*create_atoms)(void *, int, int *, int *, double *,
|
void (*create_atoms)(void *, int, int *, int *, double *, double *, int *, int);
|
||||||
double *, int *, int);
|
|
||||||
#else
|
#else
|
||||||
void (*create_atoms)(void *, int, int64_t *, int *, double *,
|
void (*create_atoms)(void *, int, int64_t *, int *, double *, double *, int64_t *, int);
|
||||||
double *, int64_t *, int);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int (*find_pair_neighlist)(void *, const char *, int, int, int);
|
int (*find_pair_neighlist)(void *, const char *, int, int, int);
|
||||||
int (*find_fix_neighlist)(void *, const char *, int);
|
int (*find_fix_neighlist)(void *, const char *, int);
|
||||||
int (*find_compute_neighlist)(void *, char *, int);
|
int (*find_compute_neighlist)(void *, const char *, int);
|
||||||
int (*neighlist_num_elements)(void *, int);
|
int (*neighlist_num_elements)(void *, int);
|
||||||
void (*neighlist_element_neighbors)(void *, int, int, int *, int *, int **);
|
void (*neighlist_element_neighbors)(void *, int, int, int *, int *, int **);
|
||||||
|
|
||||||
@ -141,8 +210,16 @@ struct _liblammpsplugin {
|
|||||||
int (*plugin_count)();
|
int (*plugin_count)();
|
||||||
int (*plugin_name)(int, char *, char *, int);
|
int (*plugin_name)(int, char *, char *, int);
|
||||||
|
|
||||||
|
#if !defined(LAMMPS_BIGBIG)
|
||||||
|
int (*encode_image_flags)(int, int, int);
|
||||||
|
void (*decode_image_flags)(int, int *);
|
||||||
|
#else
|
||||||
|
int64_t (*encode_image_flags)(int, int, int);
|
||||||
|
void (*decode_image_flags)(int64_t, int *);
|
||||||
|
#endif
|
||||||
|
|
||||||
void (*set_fix_external_callback)(void *, const char *, FixExternalFnPtr, void *);
|
void (*set_fix_external_callback)(void *, const char *, FixExternalFnPtr, void *);
|
||||||
void (*fix_external_get_force)(void *, const char *);
|
double **(*fix_external_get_force)(void *, const char *);
|
||||||
void (*fix_external_set_energy_global)(void *, const char *, double);
|
void (*fix_external_set_energy_global)(void *, const char *, double);
|
||||||
void (*fix_external_set_energy_peratom)(void *, const char *, double *);
|
void (*fix_external_set_energy_peratom)(void *, const char *, double *);
|
||||||
void (*fix_external_set_virial_global)(void *, const char *, double *);
|
void (*fix_external_set_virial_global)(void *, const char *, double *);
|
||||||
@ -150,6 +227,8 @@ struct _liblammpsplugin {
|
|||||||
void (*fix_external_set_vector_length)(void *, const char *, int);
|
void (*fix_external_set_vector_length)(void *, const char *, int);
|
||||||
void (*fix_external_set_vector)(void *, const char *, int, double);
|
void (*fix_external_set_vector)(void *, const char *, int, double);
|
||||||
|
|
||||||
|
void (*flush_buffers)(void *);
|
||||||
|
|
||||||
void (*free)(void *);
|
void (*free)(void *);
|
||||||
|
|
||||||
void (*is_running)(void *);
|
void (*is_running)(void *);
|
||||||
@ -157,6 +236,8 @@ struct _liblammpsplugin {
|
|||||||
|
|
||||||
int (*has_error)(void *);
|
int (*has_error)(void *);
|
||||||
int (*get_last_error_message)(void *, char *, int);
|
int (*get_last_error_message)(void *, char *, int);
|
||||||
|
|
||||||
|
int (*python_api_version)();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _liblammpsplugin liblammpsplugin_t;
|
typedef struct _liblammpsplugin liblammpsplugin_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user