From 62a501ebda59547bb3483fb2511df6266190e4e0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 9 Aug 2020 01:27:14 -0400 Subject: [PATCH] store cumulative energy change in restart file --- doc/src/fix_temp_berendsen.rst | 6 +++++- src/fix_temp_berendsen.cpp | 29 +++++++++++++++++++++++++++++ src/fix_temp_berendsen.h | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/src/fix_temp_berendsen.rst b/doc/src/fix_temp_berendsen.rst index 2774075827..e837a21847 100644 --- a/doc/src/fix_temp_berendsen.rst +++ b/doc/src/fix_temp_berendsen.rst @@ -119,7 +119,11 @@ thermal degrees of freedom, and the bias is added back in. **Restart, fix_modify, output, run start/stop, minimize info:** -No information about this fix is written to :doc:`binary restart files `. +This fix writes the cumulative global energy change to +:doc:`binary restart files `. See the +:doc:`read_restart ` command for info on how to +re-specify a fix in an input script that reads a restart file, +so that the fix continues in an uninterrupted fashion. The :doc:`fix_modify ` *temp* option is supported by this fix. You can use it to assign a temperature :doc:`compute ` diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index 9b385bf96c..f2b7940584 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -43,6 +43,7 @@ FixTempBerendsen::FixTempBerendsen(LAMMPS *lmp, int narg, char **arg) : // Berendsen thermostat should be applied every step + restart_global = 1; dynamic_group_allow = 1; nevery = 1; scalar_flag = 1; @@ -241,6 +242,34 @@ double FixTempBerendsen::compute_scalar() return energy; } +/* ---------------------------------------------------------------------- + pack entire state of Fix into one write +------------------------------------------------------------------------- */ + +void FixTempBerendsen::write_restart(FILE *fp) +{ + int n = 0; + double list[1]; + list[n++] = energy; + + if (comm->me == 0) { + int size = n * sizeof(double); + fwrite(&size,sizeof(int),1,fp); + fwrite(list,sizeof(double),n,fp); + } +} + +/* ---------------------------------------------------------------------- + use state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixTempBerendsen::restart(char *buf) +{ + int n = 0; + double *list = (double *) buf; + + energy = list[n++]; +} /* ---------------------------------------------------------------------- extract thermostat properties ------------------------------------------------------------------------- */ diff --git a/src/fix_temp_berendsen.h b/src/fix_temp_berendsen.h index ffc0ca5def..5657b0fd97 100644 --- a/src/fix_temp_berendsen.h +++ b/src/fix_temp_berendsen.h @@ -34,6 +34,8 @@ class FixTempBerendsen : public Fix { int modify_param(int, char **); void reset_target(double); double compute_scalar(); + void write_restart(FILE *); + void restart(char *buf); virtual void *extract(const char *, int &); private: