diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index f83d593c96..cbc03a5b7e 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -49,6 +49,7 @@ FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) : // CSLD thermostat should be applied every step + restart_global = 1; nevery = 1; scalar_flag = 1; global_freq = nevery; @@ -297,6 +298,48 @@ double FixTempCSLD::compute_scalar() return energy; } + +/* ---------------------------------------------------------------------- + pack entire state of Fix into one write +------------------------------------------------------------------------- */ + +void FixTempCSLD::write_restart(FILE *fp) +{ + int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy + double *list; + if (comm->me == 0) list = new double[nsize]; + list[0] = energy; + list[1] = comm->nprocs; + double state[103]; + random->get_state(state); + MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world); + + if (comm->me == 0) { + int size = nsize * sizeof(double); + fwrite(&size,sizeof(int),1,fp); + fwrite(list,sizeof(double),nsize,fp); + } + if (comm->me == 0) delete[] list; +} + +/* ---------------------------------------------------------------------- + use state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixTempCSLD::restart(char *buf) +{ + int n = 0; + double *list = (double *) buf; + + energy = list[n++]; + int nprocs = (int) list[n++]; + if (nprocs != comm->nprocs) { + if (comm->me == 0) + error->warning(FLERR,"Different number of procs. Cannot restore RNG state."); + } else random->set_state(list+n+comm->me*103); +} + + /* ---------------------------------------------------------------------- extract thermostat properties ------------------------------------------------------------------------- */ diff --git a/src/fix_temp_csld.h b/src/fix_temp_csld.h index 2fde8537ee..8937ad43db 100644 --- a/src/fix_temp_csld.h +++ b/src/fix_temp_csld.h @@ -34,6 +34,8 @@ class FixTempCSLD : public Fix { int modify_param(int, char **); void reset_target(double); virtual double compute_scalar(); + void write_restart(FILE *); + void restart(char *buf); virtual void *extract(const char *, int &); private: diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index cca204a4b2..9ad8caff3d 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -331,6 +331,46 @@ double FixTempCSVR::compute_scalar() return energy; } +/* ---------------------------------------------------------------------- + pack entire state of Fix into one write +------------------------------------------------------------------------- */ + +void FixTempCSVR::write_restart(FILE *fp) +{ + int nsize = (98+2+3)*comm->nprocs+2; // pRNG state per proc + nprocs + energy + double *list; + if (comm->me == 0) list = new double[nsize]; + list[0] = energy; + list[1] = comm->nprocs; + double state[103]; + random->get_state(state); + MPI_Gather(state,103,MPI_DOUBLE,list+2,103*comm->nprocs,MPI_DOUBLE,0,world); + + if (comm->me == 0) { + int size = nsize * sizeof(double); + fwrite(&size,sizeof(int),1,fp); + fwrite(list,sizeof(double),nsize,fp); + } + if (comm->me == 0) delete[] list; +} + +/* ---------------------------------------------------------------------- + use state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixTempCSVR::restart(char *buf) +{ + int n = 0; + double *list = (double *) buf; + + energy = list[0]; + int nprocs = (int) list[1]; + if (nprocs != comm->nprocs) { + if (comm->me == 0) + error->warning(FLERR,"Different number of procs. Cannot restore RNG state."); + } else random->set_state(list+n+comm->me*103); +} + /* ---------------------------------------------------------------------- extract thermostat properties ------------------------------------------------------------------------- */ diff --git a/src/fix_temp_csvr.h b/src/fix_temp_csvr.h index a97a0e1fed..44d6630525 100644 --- a/src/fix_temp_csvr.h +++ b/src/fix_temp_csvr.h @@ -34,6 +34,8 @@ class FixTempCSVR : public Fix { int modify_param(int, char **); void reset_target(double); virtual double compute_scalar(); + void write_restart(FILE *); + void restart(char *buf); virtual void *extract(const char *, int &); private: