diff --git a/python/lammps/core.py b/python/lammps/core.py index 30df44f050..045d893448 100644 --- a/python/lammps/core.py +++ b/python/lammps/core.py @@ -339,6 +339,10 @@ class lammps(object): self.lib.lammps_extract_variable_datatype.argtypes = [c_void_p, c_char_p] self.lib.lammps_extract_variable_datatype.restype = c_int + self.lib.lammps_compute_clearstep.argtype = [c_void_p] + self.lib.lammps_compute_addstep.argtype = [c_void_p, self.c_bigint] + self.lib.lammps_compute_addstep_all.argtype = [c_void_p, self.c_bigint] + self.lib.lammps_fix_external_get_force.argtypes = [c_void_p, c_char_p] self.lib.lammps_fix_external_get_force.restype = POINTER(POINTER(c_double)) @@ -1453,6 +1457,24 @@ class lammps(object): # ------------------------------------------------------------------------- + def compute_clearstep(self, nextstep): + with ExceptionCheck(self): + return self.lib.lammps_compute_clearstep(self.lmp) + + # ------------------------------------------------------------------------- + + def compute_addstep(self, nextstep): + with ExceptionCheck(self): + return self.lib.lammps_compute_addstep(self.lmp, nextstep) + + # ------------------------------------------------------------------------- + + def compute_addstep_all(self, nextstep): + with ExceptionCheck(self): + return self.lib.lammps_compute_addstep_all(self.lmp, nextstep) + + # ------------------------------------------------------------------------- + def flush_buffers(self): """Flush output buffers diff --git a/src/library.cpp b/src/library.cpp index 9876d363e5..89c6e92bbd 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -2904,6 +2904,87 @@ int lammps_variable_info(void *handle, int idx, char *buffer, int buf_size) { return 0; } +/* ---------------------------------------------------------------------- */ + +/** Clear whether a compute has been invoked. + * +\verbatim embed:rst + +.. versionadded:: TBD + + This function clears the invoked flag of all computes. + Called everywhere that computes are used, before computes are invoked. + The invoked flag is used to avoid re-invoking same compute multiple times + and to flag computes that store invocation times as having been invoked + +\endverbatim + + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + */ +void lammps_compute_clearstep(void * handle) { + auto lmp = (LAMMPS *) handle; + + BEGIN_CAPTURE + { + lmp->modify->clearstep_compute(); + } + END_CAPTURE +} + +/* ---------------------------------------------------------------------- */ + +/** Add next timestep to all computes + * +\verbatim embed:rst + +.. versionadded:: TBD + + loop over all computes + schedule next invocation for those that store invocation times + called when not sure what computes will be needed on newstep + do not loop only over n_timeflag, since may not be set yet + +\endverbatim + + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param newstep next timestep the compute will be invoked + */ +void lammps_compute_addstep_all(void * handle, bigint newstep) { + auto lmp = (LAMMPS *) handle; + + BEGIN_CAPTURE + { + lmp->modify->addstep_compute_all(newstep); + } + END_CAPTURE +} +/* ---------------------------------------------------------------------- */ + +/** Add next timestep to compute if it has been invoked in the current timestep + * +\verbatim embed:rst + +.. versionadded:: TBD + + loop over computes that store invocation times + if its invoked flag set on this timestep, schedule next invocation + called everywhere that computes are used, after computes are invoked + +\endverbatim + + * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param newstep next timestep the compute will be invoked + */ +void lammps_compute_addstep(void * handle, bigint newstep) { + auto lmp = (LAMMPS *) handle; + + BEGIN_CAPTURE + { + lmp->modify->addstep_compute(newstep); + } + END_CAPTURE +} + // ---------------------------------------------------------------------- // Library functions for scatter/gather operations of data // ---------------------------------------------------------------------- diff --git a/src/library.h b/src/library.h index 36e67470ae..b1213b67c8 100644 --- a/src/library.h +++ b/src/library.h @@ -190,6 +190,15 @@ int lammps_set_string_variable(void *handle, const char *name, const char *str); int lammps_set_internal_variable(void *handle, const char *name, double value); int lammps_variable_info(void *handle, int idx, char *buf, int bufsize); +void lammps_compute_clearstep(void * handle); +#if defined(LAMMPS_SMALLSMALL) +void lammps_compute_addstep_all(void * handle, int nextstep); +void lammps_compute_addstep(void * handle, int nextstep); +#else +void lammps_compute_addstep_all(void * handle, int64_t nextstep); +void lammps_compute_addstep(void * handle, int64_t nextstep); +#endif + /* ---------------------------------------------------------------------- * Library functions for scatter/gather operations of data * ---------------------------------------------------------------------- */