1 /* -*- c++ -*- ---------------------------------------------------------- 2 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator 3 https://www.lammps.org/ Sandia National Laboratories 4 Steve Plimpton, sjplimp@sandia.gov 5 6 Copyright (2003) Sandia Corporation. Under the terms of Contract 7 DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains 8 certain rights in this software. This software is distributed under 9 the GNU General Public License. 10 11 See the README file in the top-level LAMMPS directory. 12 ------------------------------------------------------------------------- */ 13 14 #ifndef LIBLAMMPSPLUGIN_H 15 #define LIBLAMMPSPLUGIN_H 16 /* 17 Variant of the C style library interface to LAMMPS 18 that uses a shared library and dynamically opens it, 19 so this can be used as a prototype code to integrate 20 a LAMMPS plugin to some other software. 21 */ 22 23 /* 24 * Follow the behavior of regular LAMMPS compilation and assume 25 * -DLAMMPS_SMALLBIG when no define is set. 26 */ 27 #if !defined(LAMMPS_BIGBIG) && !defined(LAMMPS_SMALLBIG) && !defined(LAMMPS_SMALLSMALL) 28 #define LAMMPS_SMALLBIG 29 #endif 30 31 #include <mpi.h> 32 #if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG) 33 #include <inttypes.h> /* for int64_t */ 34 #endif 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #if defined(LAMMPS_BIGBIG) 41 typedef void (*FixExternalFnPtr)(void *, int64_t, int, int64_t *, double **, double **); 42 #elif defined(LAMMPS_SMALLSMALL) 43 typedef void (*FixExternalFnPtr)(void *, int, int, int *, double **, double **); 44 #else 45 typedef void (*FixExternalFnPtr)(void *, int64_t, int, int *, double **, double **); 46 #endif 47 48 struct _liblammpsplugin { 49 int abiversion; 50 int has_exceptions; 51 void *handle; 52 void *(*open)(int, char **, MPI_Comm, void **); 53 void *(*open_no_mpi)(int, char **, void **); 54 void *(*open_fortran)(int, char **, void **, int); 55 void (*close)(void *); 56 57 void (*mpi_init)(); 58 void (*mpi_finalize)(); 59 void (*kokkos_finalize)(); 60 void (*python_finalize)(); 61 62 void (*file)(void *, char *); 63 char *(*command)(void *, const char *); 64 void (*commands_list)(void *, int, const char **); 65 void (*commands_string)(void *, const char *); 66 67 double (*get_natoms)(void *); 68 double (*get_thermo)(void *, char *); 69 70 void (*extract_box)(void *, double *, double *, 71 double *, double *, double *, int *, int *); 72 void (*reset_box)(void *, double *, double *, double, double, double); 73 74 void (*memory_usage)(void *, double *); 75 int (*get_mpi_comm)(void *); 76 77 int (*extract_setting)(void *, const char *); 78 int *(*extract_global_datatype)(void *, const char *); 79 void *(*extract_global)(void *, const char *); 80 81 void *(*extract_atom_datatype)(void *, const char *); 82 void *(*extract_atom)(void *, const char *); 83 84 void *(*extract_compute)(void *, const char *, int, int); 85 void *(*extract_fix)(void *, const char *, int, int, int, int); 86 void *(*extract_variable)(void *, const char *, char *); 87 int (*set_variable)(void *, char *, char *); 88 89 void (*gather_atoms)(void *, char *, int, int, void *); 90 void (*gather_atoms_concat)(void *, char *, int, int, void *); 91 void (*gather_atoms_subset)(void *, char *, int, int, int, int *, void *); 92 void (*scatter_atoms)(void *, char *, int, int, void *); 93 void (*scatter_atoms_subset)(void *, char *, int, int, int, int *, void *); 94 95 void (*gather_bonds)(void *, void *); 96 97 // lammps_create_atoms() takes tagint and imageint as args 98 // ifdef insures they are compatible with rest of LAMMPS 99 // caller must match to how LAMMPS library is built 100 101 #ifndef LAMMPS_BIGBIG 102 void (*create_atoms)(void *, int, int *, int *, double *, 103 double *, int *, int); 104 #else 105 void (*create_atoms)(void *, int, int64_t *, int *, double *, 106 double *, int64_t *, int); 107 #endif 108 109 int (*find_pair_neighlist)(void *, const char *, int, int, int); 110 int (*find_fix_neighlist)(void *, const char *, int); 111 int (*find_compute_neighlist)(void *, char *, int); 112 int (*neighlist_num_elements)(void *, int); 113 void (*neighlist_element_neighbors)(void *, int, int, int *, int *, int **); 114 115 int (*version)(void *); 116 void (*get_os_info)(char *, int); 117 118 int (*config_has_mpi_support)(); 119 int (*config_has_gzip_support)(); 120 int (*config_has_png_support)(); 121 int (*config_has_jpeg_support)(); 122 int (*config_has_ffmpeg_support)(); 123 int (*config_has_exceptions)(); 124 125 int (*config_has_package)(const char *); 126 int (*config_package_count)(); 127 int (*config_package_name)(int, char *, int); 128 129 int (*config_accelerator)(const char *, const char *, const char *); 130 int (*has_gpu_device)(); 131 void (*get_gpu_device_info)(char *, int); 132 133 int (*has_style)(void *, const char *, const char *); 134 int (*style_count)(void *, const char *); 135 int (*style_name)(void *, const char *, int, char *, int); 136 137 int (*has_id)(void *, const char *, const char *); 138 int (*id_count)(void *, const char *); 139 int (*id_name)(void *, const char *, int, char *, int); 140 141 int (*plugin_count)(); 142 int (*plugin_name)(int, char *, char *, int); 143 144 void (*set_fix_external_callback)(void *, const char *, FixExternalFnPtr, void*); 145 void (*fix_external_get_force)(void *, const char *); 146 void (*fix_external_set_energy_global)(void *, const char *, double); 147 void (*fix_external_set_energy_peratom)(void *, const char *, double *); 148 void (*fix_external_set_virial_global)(void *, const char *, double *); 149 void (*fix_external_set_virial_peratom)(void *, const char *, double **); 150 void (*fix_external_set_vector_length)(void *, const char *, int); 151 void (*fix_external_set_vector)(void *, const char *, int, double); 152 153 void (*free)(void *); 154 155 void (*is_running)(void *); 156 void (*force_timeout)(void *); 157 158 int (*has_error)(void *); 159 int (*get_last_error_message)(void *, char *, int); 160 }; 161 162 typedef struct _liblammpsplugin liblammpsplugin_t; 163 164 liblammpsplugin_t *liblammpsplugin_load(const char *); 165 int liblammpsplugin_release(liblammpsplugin_t *); 166 167 #undef LAMMPS 168 #ifdef __cplusplus 169 } 170 #endif 171 172 #endif 173