From 21c24459c92c88391e387a85ae3780785c126ca4 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Thu, 1 Dec 2011 00:08:08 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@7244 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/fix_dt_reset.cpp | 34 +++++++++++++++++++++++----------- src/fix_dt_reset.h | 3 ++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/fix_dt_reset.cpp b/src/fix_dt_reset.cpp index 758c8b32a5..c35903a69b 100644 --- a/src/fix_dt_reset.cpp +++ b/src/fix_dt_reset.cpp @@ -43,7 +43,7 @@ FixDtReset::FixDtReset(LAMMPS *lmp, int narg, char **arg) : time_depend = 1; scalar_flag = 1; vector_flag = 1; - size_vector = 1; + size_vector = 2; global_freq = 1; extscalar = 0; extvector = 0; @@ -86,7 +86,7 @@ FixDtReset::FixDtReset(LAMMPS *lmp, int narg, char **arg) : // initializations - t_elapsed = 0.0; + t_elapsed = t_laststep = 0.0; laststep = update->ntimestep; } @@ -95,6 +95,7 @@ FixDtReset::FixDtReset(LAMMPS *lmp, int narg, char **arg) : int FixDtReset::setmask() { int mask = 0; + mask |= INITIAL_INTEGRATE; mask |= END_OF_STEP; return mask; } @@ -113,9 +114,11 @@ void FixDtReset::init() for (int i = 0; i < output->ndump; i++) if ((strcmp(output->dump[i]->style,"dcd") == 0 || strcmp(output->dump[i]->style,"xtc") == 0) && comm->me == 0) - error->warning(FLERR,"Dump dcd/xtc timestamp may be wrong with fix dt/reset"); + error->warning(FLERR, + "Dump dcd/xtc timestamp may be wrong with fix dt/reset"); ftm2v = force->ftm2v; + dt = update->dt; } /* ---------------------------------------------------------------------- */ @@ -127,16 +130,21 @@ void FixDtReset::setup(int vflag) /* ---------------------------------------------------------------------- */ +void FixDtReset::initial_integrate(int vflag) +{ + // calculate elapsed time based on previous reset timestep + + t_elapsed = t_laststep + (update->ntimestep-laststep)*dt; +} + +/* ---------------------------------------------------------------------- */ + void FixDtReset::end_of_step() { - double dt,dtv,dtf,dtsq; + double dtv,dtf,dtsq; double vsq,fsq,massinv; double delx,dely,delz,delr; - // accumulate total time based on previous timestep - - t_elapsed += (update->ntimestep - laststep) * update->dt; - // compute vmax and amax of any atom in group double **v = atom->v; @@ -173,12 +181,15 @@ void FixDtReset::end_of_step() if (minbound) dt = MAX(dt,tmin); if (maxbound) dt = MIN(dt,tmax); - // reset update->dt and other classes that depend on it + // if timestep didn't change, just return + // else reset update->dt and other classes that depend on it // rRESPA, pair style, fixes - laststep = update->ntimestep; if (dt == update->dt) return; + t_elapsed = t_laststep += (update->ntimestep-laststep)*update->dt; + laststep = update->ntimestep; + update->dt = dt; if (respaflag) update->integrate->reset_dt(); if (force->pair) force->pair->reset_dt(); @@ -196,5 +207,6 @@ double FixDtReset::compute_scalar() double FixDtReset::compute_vector(int n) { - return t_elapsed; + if (n == 0) return t_elapsed; + return (double) laststep; } diff --git a/src/fix_dt_reset.h b/src/fix_dt_reset.h index 956d35d1b4..3a0146c91d 100644 --- a/src/fix_dt_reset.h +++ b/src/fix_dt_reset.h @@ -31,6 +31,7 @@ class FixDtReset : public Fix { int setmask(); void init(); void setup(int); + void initial_integrate(int); void end_of_step(); double compute_scalar(); double compute_vector(int); @@ -40,7 +41,7 @@ class FixDtReset : public Fix { int minbound,maxbound; double tmin,tmax,xmax; double ftm2v; - double t_elapsed; + double dt,t_elapsed,t_laststep; int respaflag; };