diff --git a/doc/src/fix_spring_chunk.rst b/doc/src/fix_spring_chunk.rst index d839d9158c..db90cb505c 100644 --- a/doc/src/fix_spring_chunk.rst +++ b/doc/src/fix_spring_chunk.rst @@ -50,7 +50,16 @@ atom. **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 locations of the initial per-chunk center of mass +coordinates 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. Since this fix depends +on an instance of :doc:`compute chunk/atom ` +it will check when reading the restart if the chunk still exists and +will define the same number of chunks. The restart data is only applied +when the number of chunks matches. Otherwise the center of mass +coordinates are recomputed. The :doc:`fix_modify ` *energy* option is supported by this fix to add the energy stored in all the springs to the system's potential diff --git a/doc/src/fix_spring_rg.rst b/doc/src/fix_spring_rg.rst index 962e780f7f..2329bb6e4a 100644 --- a/doc/src/fix_spring_rg.rst +++ b/doc/src/fix_spring_rg.rst @@ -59,9 +59,20 @@ the time the fix is specified, and that value is used as the target. **Restart, fix_modify, output, run start/stop, minimize info:** -No information about this fix is written to :doc:`binary restart files `. None of the :doc:`fix_modify ` options -are relevant to this fix. No global or per-atom quantities are stored -by this fix for access by various :doc:`output commands `. +This fix writes the currently used reference RG (:math:`R_{G0}`) 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. + +None of the :doc:`fix_modify ` options +are relevant to this fix. + +This fix computes a global scalar which can be accessed by various +:doc:`output commands `. The scalar is the reference +radius of gyration :math:`R_{G0}` used by the fix. energy change due to +this fix. The scalar value calculated by this fix is "intensive". + No parameter of this fix can be used with the *start/stop* keywords of the :doc:`run ` command. This fix is not invoked during :doc:`energy minimization `. diff --git a/doc/src/fix_temp_rescale.rst b/doc/src/fix_temp_rescale.rst index d23006c52b..7e6f212d04 100644 --- a/doc/src/fix_temp_rescale.rst +++ b/doc/src/fix_temp_rescale.rst @@ -126,7 +126,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 ` @@ -136,7 +140,8 @@ this fix and by the compute should be the same. The :doc:`fix_modify ` *energy* option is supported by this fix to add the energy change implied by a velocity rescaling to the -system's potential energy as part of :doc:`thermodynamic output `. +system's potential energy as part of :doc:`thermodynamic output +`. This fix computes a global scalar which can be accessed by various :doc:`output commands `. The scalar is the cumulative diff --git a/src/fix_spring_chunk.cpp b/src/fix_spring_chunk.cpp index e14936a976..f9f36e11e9 100644 --- a/src/fix_spring_chunk.cpp +++ b/src/fix_spring_chunk.cpp @@ -15,6 +15,7 @@ #include #include #include "atom.h" +#include "comm.h" #include "update.h" #include "force.h" #include "respa.h" @@ -37,6 +38,7 @@ FixSpringChunk::FixSpringChunk(LAMMPS *lmp, int narg, char **arg) : { if (narg != 6) error->all(FLERR,"Illegal fix spring/chunk command"); + restart_global = 1; scalar_flag = 1; global_freq = 1; extscalar = 1; @@ -241,6 +243,58 @@ void FixSpringChunk::min_post_force(int vflag) post_force(vflag); } +/* ---------------------------------------------------------------------- + writ number of chunks and position of original COM into restart +------------------------------------------------------------------------- */ + +void FixSpringChunk::write_restart(FILE *fp) +{ + double n = nchunk; + + if (comm->me == 0) { + int size = (3*n+1) * sizeof(double); + fwrite(&size,sizeof(int),1,fp); + fwrite(&n,sizeof(double),1,fp); + fwrite(&com0[0][0],3*sizeof(double),nchunk,fp); + } +} + +/* ---------------------------------------------------------------------- + use state info from restart file to restart the Fix +------------------------------------------------------------------------- */ + +void FixSpringChunk::restart(char *buf) +{ + double *list = (double *) buf; + int n = list[0]; + + memory->destroy(com0); + memory->destroy(fcom); + + int icompute = modify->find_compute(idchunk); + if (icompute < 0) + error->all(FLERR,"Chunk/atom compute does not exist for fix spring/chunk"); + cchunk = (ComputeChunkAtom *) modify->compute[icompute]; + if (strcmp(cchunk->style,"chunk/atom") != 0) + error->all(FLERR,"Fix spring/chunk does not use chunk/atom compute"); + nchunk = cchunk->setup_chunks(); + cchunk->compute_ichunk(); + memory->create(com0,nchunk,3,"spring/chunk:com0"); + memory->create(fcom,nchunk,3,"spring/chunk:fcom"); + printf("restart chunks:%d computed chunks: %d\n",n,nchunk); + + if (n != nchunk) { + if (comm->me == 0) + error->warning(FLERR,"Number of chunks has changed. Cannot use restart"); + memory->destroy(com0); + memory->destroy(fcom); + nchunk = 1; + } else { + cchunk->lock(this,update->ntimestep,-1); + memcpy(&com0[0][0],list+1,3*n*sizeof(double)); + } +} + /* ---------------------------------------------------------------------- energy of stretched spring ------------------------------------------------------------------------- */ diff --git a/src/fix_spring_chunk.h b/src/fix_spring_chunk.h index 9ba6d3a2f8..2955d4b67d 100644 --- a/src/fix_spring_chunk.h +++ b/src/fix_spring_chunk.h @@ -35,6 +35,8 @@ class FixSpringChunk : public Fix { void post_force(int); void post_force_respa(int, int, int); void min_post_force(int); + void write_restart(FILE *); + void restart(char *); double compute_scalar(); private: diff --git a/src/fix_spring_rg.cpp b/src/fix_spring_rg.cpp index f1e68bffa4..1c65023169 100644 --- a/src/fix_spring_rg.cpp +++ b/src/fix_spring_rg.cpp @@ -19,6 +19,7 @@ #include "fix_spring_rg.h" #include #include "atom.h" +#include "comm.h" #include "update.h" #include "group.h" #include "respa.h" @@ -41,6 +42,9 @@ FixSpringRG::FixSpringRG(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[4],"NULL") == 0) rg0_flag = 1; else rg0 = force->numeric(FLERR,arg[4]); + restart_global = 1; + scalar_flag = 1; + restart_global = 1; dynamic_group_allow = 1; respa_level_support = 1; ilevel_respa = 0; @@ -144,3 +148,43 @@ void FixSpringRG::post_force_respa(int vflag, int ilevel, int /*iloop*/) { if (ilevel == ilevel_respa) post_force(vflag); } + +/* ---------------------------------------------------------------------- + pack entire state of Fix into one write +------------------------------------------------------------------------- */ + +void FixSpringRG::write_restart(FILE *fp) +{ + int n = 0; + double list[1]; + list[n++] = rg0; + + 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 FixSpringRG::restart(char *buf) +{ + int n = 0; + double *list = (double *) buf; + + rg0 = list[n++]; + rg0_flag = 0; +} + + +/* ---------------------------------------------------------------------- + return reference radius of gyration +------------------------------------------------------------------------- */ + +double FixSpringRG::compute_scalar() +{ + return rg0; +} diff --git a/src/fix_spring_rg.h b/src/fix_spring_rg.h index 17337be6fd..a46df0fa75 100644 --- a/src/fix_spring_rg.h +++ b/src/fix_spring_rg.h @@ -32,6 +32,9 @@ class FixSpringRG : public Fix { void setup(int); void post_force(int); void post_force_respa(int, int, int); + void write_restart(FILE *); + void restart(char *); + double compute_scalar(); private: int ilevel_respa,rg0_flag; diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index 575a81c40b..083f590c9a 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -44,6 +44,7 @@ FixTempRescale::FixTempRescale(LAMMPS *lmp, int narg, char **arg) : nevery = force->inumeric(FLERR,arg[3]); if (nevery <= 0) error->all(FLERR,"Illegal fix temp/rescale command"); + restart_global = 1; scalar_flag = 1; global_freq = nevery; extscalar = 1; @@ -238,6 +239,35 @@ double FixTempRescale::compute_scalar() return energy; } +/* ---------------------------------------------------------------------- + pack entire state of Fix into one write +------------------------------------------------------------------------- */ + +void FixTempRescale::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 FixTempRescale::restart(char *buf) +{ + int n = 0; + double *list = (double *) buf; + + energy = list[n++]; +} + /* ---------------------------------------------------------------------- extract thermostat properties ------------------------------------------------------------------------- */ diff --git a/src/fix_temp_rescale.h b/src/fix_temp_rescale.h index 20f4686f30..b90ca905cb 100644 --- a/src/fix_temp_rescale.h +++ b/src/fix_temp_rescale.h @@ -34,6 +34,8 @@ class FixTempRescale : 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 &); protected: