From 0ff3ee02270e6c3c4b730256431ad22ae8c9624b Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 4 Feb 2022 10:42:22 -0500 Subject: [PATCH] Add and use lammps_flush_buffers() in Python interface --- python/lammps/core.py | 11 +++++++++++ python/lammps/pylammps.py | 2 ++ 2 files changed, 13 insertions(+) diff --git a/python/lammps/core.py b/python/lammps/core.py index 62b0f5d8b6..d934ee1baa 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -164,6 +164,7 @@ class lammps(object): self.lib.lammps_open.restype = c_void_p self.lib.lammps_open_no_mpi.restype = c_void_p self.lib.lammps_close.argtypes = [c_void_p] + self.lib.lammps_flush_buffers.argtypes = [c_void_p] self.lib.lammps_free.argtypes = [c_void_p] self.lib.lammps_file.argtypes = [c_void_p, c_char_p] @@ -1118,6 +1119,16 @@ class lammps(object): # ------------------------------------------------------------------------- + def flush_buffers(self): + """Flush output buffers + + This is a wrapper around the :cpp:func:`lammps_flush_buffers` + function of the C-library interface. + """ + self.lib.lammps_flush_buffers(self.lmp) + + # ------------------------------------------------------------------------- + def set_variable(self,name,value): """Set a new value for a LAMMPS string style variable diff --git a/python/lammps/pylammps.py b/python/lammps/pylammps.py index 2ad34a7a88..cdb6620c27 100644 --- a/python/lammps/pylammps.py +++ b/python/lammps/pylammps.py @@ -857,10 +857,12 @@ class PyLammps(object): """ def handler(*args, **kwargs): cmd_args = [name] + [str(x) for x in args] + self.lmp.flush_buffers() with OutputCapture() as capture: cmd = ' '.join(cmd_args) self.command(cmd) + self.lmp.flush_buffers() output = capture.output comm = self.lmp.get_mpi_comm()