diff --git a/doc/src/Library_utility.rst b/doc/src/Library_utility.rst index 32fac6bcc8..da64e3b8f0 100644 --- a/doc/src/Library_utility.rst +++ b/doc/src/Library_utility.rst @@ -13,6 +13,7 @@ functions. They do not directly call the LAMMPS library. - :cpp:func:`lammps_fix_external_set_virial_peratom` - :cpp:func:`lammps_fix_external_set_vector_length` - :cpp:func:`lammps_fix_external_set_vector` +- :cpp:func:`lammps_flush_buffers` - :cpp:func:`lammps_free` - :cpp:func:`lammps_is_running` - :cpp:func:`lammps_force_timeout` @@ -72,6 +73,11 @@ where such memory buffers were allocated that require the use of ----------------------- +.. doxygenfunction:: lammps_flush_buffers + :project: progguide + +----------------------- + .. doxygenfunction:: lammps_free :project: progguide diff --git a/src/library.cpp b/src/library.cpp index a27da0d478..7f80e6066c 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -5439,6 +5439,25 @@ void lammps_fix_external_set_vector(void *handle, const char *id, int idx, doubl /* ---------------------------------------------------------------------- */ +/** Flush output buffers + +\verbatim embed:rst +This function can be used to force output to be written to screen and logfiles +to simplify capturing output from LAMMPS library calls. +\endverbatim + * + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + */ +void lammps_flush_buffers(void *handle) { + LAMMPS *lmp = (LAMMPS *) handle; + if (lmp->screen) fflush(lmp->screen); + if (lmp->logfile) fflush(lmp->logfile); + if (lmp->universe->uscreen) fflush(lmp->universe->uscreen); + if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile); +} + +/* ---------------------------------------------------------------------- */ + /** Free memory buffer allocated by LAMMPS. * \verbatim embed:rst diff --git a/src/library.h b/src/library.h index 1605267818..94fd7f7380 100644 --- a/src/library.h +++ b/src/library.h @@ -246,6 +246,8 @@ void lammps_fix_external_set_virial_peratom(void *handle, const char *id, double void lammps_fix_external_set_vector_length(void *handle, const char *id, int len); void lammps_fix_external_set_vector(void *handle, const char *id, int idx, double val); +void lammps_flush_buffers(void *ptr); + void lammps_free(void *ptr); int lammps_is_running(void *handle);