Loading...
Searching...
No Matches
library.h
Go to the documentation of this file.
1/* -*- c -*- ------------------------------------------------------------
2 LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3 https://www.lammps.org/, Sandia National Laboratories
4 LAMMPS development team: developers@lammps.org
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 LAMMPS_LIBRARY_H
15#define LAMMPS_LIBRARY_H
16
17/* C style library interface to LAMMPS which allows to create and
18 * control instances of the LAMMPS C++ class and exchange data with it.
19 * The C bindings are the basis for the Python and Fortran modules.
20 *
21 * If needed, new LAMMPS-specific functions can be added to expose
22 * additional LAMMPS functionality to this library interface. */
23
24/* We 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) && \
28 !defined(LAMMPS_SMALLSMALL)
29#define LAMMPS_SMALLBIG
30#endif
31
32/* To allow including the library interface without MPI */
33
34#if defined(LAMMPS_LIB_MPI)
35#include <mpi.h>
36#endif
37
38#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
39#include <stdint.h> /* for int64_t */
40#endif
41
48
59
66
72
79
88
95
103
110
117
118/* Ifdefs to allow this file to be included in C and C++ programs */
119
120#ifdef __cplusplus
121extern "C" {
122#endif
123
124/* ----------------------------------------------------------------------
125 * Library functions to create/destroy an instance of LAMMPS
126 * ---------------------------------------------------------------------- */
127
128#if defined(LAMMPS_LIB_MPI)
129void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr);
130#endif
131void *lammps_open_no_mpi(int argc, char **argv, void **ptr);
132void *lammps_open_fortran(int argc, char **argv, int f_comm);
133void lammps_close(void *handle);
134
139
140void lammps_error(void *handle, int error_type, const char *error_text);
141
142/* ----------------------------------------------------------------------
143 * Library functions to process commands
144 * ---------------------------------------------------------------------- */
145
146void lammps_file(void *handle, const char *file);
147
148char *lammps_command(void *handle, const char *cmd);
149void lammps_commands_list(void *handle, int ncmd, const char **cmds);
150void lammps_commands_string(void *handle, const char *str);
151
152/* -----------------------------------------------------------------------
153 * Library functions to extract info from LAMMPS or set data in LAMMPS
154 * ----------------------------------------------------------------------- */
155
156double lammps_get_natoms(void *handle);
157double lammps_get_thermo(void *handle, const char *keyword);
158void *lammps_last_thermo(void *handle, const char *what, int index);
159
160void lammps_extract_box(void *handle, double *boxlo, double *boxhi, double *xy,
161 double *yz, double *xz, int *pflags, int *boxflag);
162void lammps_reset_box(void *handle, double *boxlo, double *boxhi, double xy,
163 double yz, double xz);
164
165void lammps_memory_usage(void *handle, double *meminfo);
166int lammps_get_mpi_comm(void *handle);
167
168int lammps_extract_setting(void *handle, const char *keyword);
169int lammps_extract_global_datatype(void *handle, const char *name);
170void *lammps_extract_global(void *handle, const char *name);
171
172int lammps_map_atom(void *handle, const void *id);
173
174/* ----------------------------------------------------------------------
175 * Library functions to read or modify per-atom data in LAMMPS
176 * ---------------------------------------------------------------------- */
177
178int lammps_extract_atom_datatype(void *handle, const char *name);
179void *lammps_extract_atom(void *handle, const char *name);
180
181/* ----------------------------------------------------------------------
182 * Library functions to access data from computes, fixes, variables in LAMMPS
183 * ---------------------------------------------------------------------- */
184
185void *lammps_extract_compute(void *handle, const char *id, int style, int type);
186void *lammps_extract_fix(void *handle, const char *id, int style, int type,
187 int nrow, int ncol);
188void *lammps_extract_variable(void *handle, const char *name,
189 const char *group);
190int lammps_extract_variable_datatype(void *handle, const char *name);
191int lammps_set_variable(void *handle, const char *name, const char *str);
192int lammps_set_string_variable(void *handle, const char *name, const char *str);
193int lammps_set_internal_variable(void *handle, const char *name, double value);
194int lammps_variable_info(void *handle, int idx, char *buf, int bufsize);
195
196/* ----------------------------------------------------------------------
197 * Library functions for scatter/gather operations of data
198 * ---------------------------------------------------------------------- */
199
200void lammps_gather_atoms(void *handle, const char *name, int type, int count,
201 void *data);
202void lammps_gather_atoms_concat(void *handle, const char *name, int type,
203 int count, void *data);
204void lammps_gather_atoms_subset(void *handle, const char *name, int type,
205 int count, int ndata, int *ids, void *data);
206void lammps_scatter_atoms(void *handle, const char *name, int type, int count,
207 void *data);
208void lammps_scatter_atoms_subset(void *handle, const char *name, int type,
209 int count, int ndata, int *ids, void *data);
210
211void lammps_gather_bonds(void *handle, void *data);
212void lammps_gather_angles(void *handle, void *data);
213void lammps_gather_dihedrals(void *handle, void *data);
214void lammps_gather_impropers(void *handle, void *data);
215
216void lammps_gather(void *handle, const char *name, int type, int count,
217 void *data);
218void lammps_gather_concat(void *handle, const char *name, int type, int count,
219 void *data);
220void lammps_gather_subset(void *handle, const char *name, int type, int count,
221 int ndata, int *ids, void *data);
222void lammps_scatter(void *handle, const char *name, int type, int count,
223 void *data);
224void lammps_scatter_subset(void *handle, const char *name, int type, int count,
225 int ndata, int *ids, void *data);
226
227#if !defined(LAMMPS_BIGBIG)
228int lammps_create_atoms(void *handle, int n, const int *id, const int *type,
229 const double *x, const double *v, const int *image,
230 int bexpand);
231#else
232int lammps_create_atoms(void *handle, int n, const int64_t *id, const int *type,
233 const double *x, const double *v, const int64_t *image,
234 int bexpand);
235#endif
236
237/* ----------------------------------------------------------------------
238 * Library functions for accessing neighbor lists
239 * ---------------------------------------------------------------------- */
240
241int lammps_find_pair_neighlist(void *handle, const char *style, int exact,
242 int nsub, int request);
243int lammps_find_fix_neighlist(void *handle, const char *id, int request);
244int lammps_find_compute_neighlist(void *handle, const char *id, int request);
245int lammps_neighlist_num_elements(void *handle, int idx);
246void lammps_neighlist_element_neighbors(void *handle, int idx, int element,
247 int *iatom, int *numneigh,
248 int **neighbors);
249
250/* ----------------------------------------------------------------------
251 * Library functions for retrieving configuration information
252 * ---------------------------------------------------------------------- */
253
254int lammps_version(void *handle);
255void lammps_get_os_info(char *buffer, int buf_size);
256
263
266int lammps_config_package_name(int, char *, int);
267
268int lammps_config_accelerator(const char *, const char *, const char *);
270void lammps_get_gpu_device_info(char *buffer, int buf_size);
271
272int lammps_has_style(void *, const char *, const char *);
273int lammps_style_count(void *, const char *);
274int lammps_style_name(void *, const char *, int, char *, int);
275
276int lammps_has_id(void *, const char *, const char *);
277int lammps_id_count(void *, const char *);
278int lammps_id_name(void *, const char *, int, char *, int);
279
281int lammps_plugin_name(int, char *, char *, int);
282
283/* ----------------------------------------------------------------------
284 * Utility functions
285 * ---------------------------------------------------------------------- */
286
287#if !defined(LAMMPS_BIGBIG)
288int lammps_encode_image_flags(int ix, int iy, int iz);
289void lammps_decode_image_flags(int image, int *flags);
290#else
291int64_t lammps_encode_image_flags(int ix, int iy, int iz);
292void lammps_decode_image_flags(int64_t image, int *flags);
293#endif
294
295#if defined(LAMMPS_BIGBIG)
296typedef void (*FixExternalFnPtr)(void *, int64_t, int, int64_t *, double **,
297 double **);
298#elif defined(LAMMPS_SMALLBIG)
299typedef void (*FixExternalFnPtr)(void *, int64_t, int, int *, double **,
300 double **);
301#else
302typedef void (*FixExternalFnPtr)(void *, int, int, int *, double **, double **);
303#endif
304
305void lammps_set_fix_external_callback(void *handle, const char *id,
306 FixExternalFnPtr funcptr, void *ptr);
307double **lammps_fix_external_get_force(void *handle, const char *id);
308void lammps_fix_external_set_energy_global(void *handle, const char *id,
309 double eng);
310void lammps_fix_external_set_energy_peratom(void *handle, const char *id,
311 double *eng);
312void lammps_fix_external_set_virial_global(void *handle, const char *id,
313 double *virial);
314void lammps_fix_external_set_virial_peratom(void *handle, const char *id,
315 double **virial);
316void lammps_fix_external_set_vector_length(void *handle, const char *id,
317 int len);
318void lammps_fix_external_set_vector(void *handle, const char *id, int idx,
319 double val);
320
321void lammps_flush_buffers(void *ptr);
322
323void lammps_free(void *ptr);
324
325int lammps_is_running(void *handle);
326void lammps_force_timeout(void *handle);
327
328int lammps_has_error(void *handle);
329int lammps_get_last_error_message(void *handle, char *buffer, int buf_size);
330
332
333#ifdef __cplusplus
334}
335#endif
336
337#endif /* LAMMPS_LIBRARY_H */
338
339/* Local Variables:
340 * fill-column: 72
341 * End: */
void * lammps_open_fortran(int argc, char **argv, int f_comm)
int lammps_find_compute_neighlist(void *handle, const char *id, int request)
_LMP_VAR_CONST
Variable style constants for extracting data from variables.
Definition library.h:111
@ LMP_VAR_VECTOR
Definition library.h:114
@ LMP_VAR_ATOM
Definition library.h:113
@ LMP_VAR_STRING
Definition library.h:115
@ LMP_VAR_EQUAL
Definition library.h:112
_LMP_ERROR_CONST
Error codes to select the suitable function in the Error class.
Definition library.h:96
@ LMP_ERROR_WARNING
Definition library.h:97
@ LMP_ERROR_UNIVERSE
Definition library.h:101
@ LMP_ERROR_ALL
Definition library.h:99
@ LMP_ERROR_WORLD
Definition library.h:100
@ LMP_ERROR_ONE
Definition library.h:98
void lammps_neighlist_element_neighbors(void *handle, int idx, int element, int *iatom, int *numneigh, int **neighbors)
int lammps_config_has_gzip_support()
void lammps_scatter(void *handle, const char *name, int type, int count, void *data)
void lammps_mpi_finalize()
int lammps_get_last_error_message(void *handle, char *buffer, int buf_size)
int lammps_config_package_count()
int lammps_set_internal_variable(void *handle, const char *name, double value)
void * lammps_open_no_mpi(int argc, char **argv, void **ptr)
int lammps_get_mpi_comm(void *handle)
void lammps_kokkos_finalize()
void lammps_force_timeout(void *handle)
void lammps_set_fix_external_callback(void *handle, const char *id, FixExternalFnPtr funcptr, void *ptr)
void * lammps_extract_compute(void *handle, const char *id, int style, int type)
_LMP_TYPE_CONST
Type and size constants for extracting data from computes and fixes.
Definition library.h:80
@ LMP_SIZE_COLS
Definition library.h:86
@ LMP_TYPE_SCALAR
Definition library.h:81
@ LMP_SIZE_ROWS
Definition library.h:85
@ LMP_TYPE_ARRAY
Definition library.h:83
@ LMP_SIZE_VECTOR
Definition library.h:84
@ LMP_TYPE_VECTOR
Definition library.h:82
void lammps_gather_bonds(void *handle, void *data)
void(* FixExternalFnPtr)(void *, int64_t, int, int *, double **, double **)
Definition library.h:299
void * lammps_last_thermo(void *handle, const char *what, int index)
double ** lammps_fix_external_get_force(void *handle, const char *id)
int lammps_map_atom(void *handle, const void *id)
int lammps_version(void *handle)
void lammps_scatter_atoms_subset(void *handle, const char *name, int type, int count, int ndata, int *ids, void *data)
int lammps_id_name(void *, const char *, int, char *, int)
char * lammps_command(void *handle, const char *cmd)
int lammps_config_accelerator(const char *, const char *, const char *)
int lammps_find_fix_neighlist(void *handle, const char *id, int request)
void lammps_extract_box(void *handle, double *boxlo, double *boxhi, double *xy, double *yz, double *xz, int *pflags, int *boxflag)
int lammps_set_string_variable(void *handle, const char *name, const char *str)
int lammps_extract_variable_datatype(void *handle, const char *name)
void lammps_python_finalize()
void lammps_gather_atoms_concat(void *handle, const char *name, int type, int count, void *data)
double lammps_get_thermo(void *handle, const char *keyword)
void lammps_fix_external_set_vector(void *handle, const char *id, int idx, double val)
void lammps_fix_external_set_vector_length(void *handle, const char *id, int len)
void lammps_fix_external_set_energy_global(void *handle, const char *id, double eng)
int lammps_has_error(void *handle)
void lammps_gather_angles(void *handle, void *data)
int lammps_has_style(void *, const char *, const char *)
void lammps_close(void *handle)
void lammps_file(void *handle, const char *file)
int lammps_extract_global_datatype(void *handle, const char *name)
int lammps_variable_info(void *handle, int idx, char *buf, int bufsize)
void lammps_commands_string(void *handle, const char *str)
void lammps_get_gpu_device_info(char *buffer, int buf_size)
int lammps_find_pair_neighlist(void *handle, const char *style, int exact, int nsub, int request)
int lammps_plugin_name(int, char *, char *, int)
_LMP_DATATYPE_CONST
Data type constants for extracting data from atoms, computes and fixes.
Definition library.h:49
@ LAMMPS_NONE
Definition library.h:50
@ LAMMPS_INT64
Definition library.h:55
@ LAMMPS_DOUBLE_2D
Definition library.h:54
@ LAMMPS_DOUBLE
Definition library.h:53
@ LAMMPS_INT
Definition library.h:51
@ LAMMPS_INT64_2D
Definition library.h:56
@ LAMMPS_INT_2D
Definition library.h:52
@ LAMMPS_STRING
Definition library.h:57
void lammps_scatter_atoms(void *handle, const char *name, int type, int count, void *data)
void lammps_gather_dihedrals(void *handle, void *data)
void * lammps_extract_variable(void *handle, const char *name, const char *group)
int lammps_is_running(void *handle)
int lammps_config_has_png_support()
void * lammps_extract_atom(void *handle, const char *name)
void lammps_free(void *ptr)
void * lammps_extract_fix(void *handle, const char *id, int style, int type, int nrow, int ncol)
double lammps_get_natoms(void *handle)
int lammps_id_count(void *, const char *)
void lammps_fix_external_set_energy_peratom(void *handle, const char *id, double *eng)
void lammps_gather_subset(void *handle, const char *name, int type, int count, int ndata, int *ids, void *data)
void lammps_memory_usage(void *handle, double *meminfo)
int lammps_set_variable(void *handle, const char *name, const char *str)
int lammps_neighlist_num_elements(void *handle, int idx)
void lammps_commands_list(void *handle, int ncmd, const char **cmds)
int lammps_style_name(void *, const char *, int, char *, int)
void lammps_gather_impropers(void *handle, void *data)
int lammps_config_has_jpeg_support()
int lammps_python_api_version()
int lammps_config_package_name(int, char *, int)
int lammps_config_has_ffmpeg_support()
int lammps_has_gpu_device()
int lammps_encode_image_flags(int ix, int iy, int iz)
int lammps_has_id(void *, const char *, const char *)
void lammps_gather_atoms(void *handle, const char *name, int type, int count, void *data)
void lammps_error(void *handle, int error_type, const char *error_text)
int lammps_plugin_count()
void lammps_reset_box(void *handle, double *boxlo, double *boxhi, double xy, double yz, double xz)
int lammps_config_has_mpi_support()
void lammps_gather_atoms_subset(void *handle, const char *name, int type, int count, int ndata, int *ids, void *data)
int lammps_config_has_package(const char *)
void lammps_gather_concat(void *handle, const char *name, int type, int count, void *data)
int lammps_config_has_exceptions()
void * lammps_extract_global(void *handle, const char *name)
void lammps_scatter_subset(void *handle, const char *name, int type, int count, int ndata, int *ids, void *data)
void lammps_get_os_info(char *buffer, int buf_size)
void lammps_decode_image_flags(int image, int *flags)
void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double **virial)
void lammps_gather(void *handle, const char *name, int type, int count, void *data)
int lammps_extract_setting(void *handle, const char *keyword)
int lammps_extract_atom_datatype(void *handle, const char *name)
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)
int lammps_style_count(void *, const char *)
void lammps_flush_buffers(void *ptr)
void lammps_fix_external_set_virial_global(void *handle, const char *id, double *virial)
_LMP_STYLE_CONST
Style constants for extracting data from computes and fixes.
Definition library.h:67
@ LMP_STYLE_GLOBAL
Definition library.h:68
@ LMP_STYLE_LOCAL
Definition library.h:70
@ LMP_STYLE_ATOM
Definition library.h:69
void lammps_mpi_init()