From 3ec5b8356436d05880a6582d74a993bc412c7bbe Mon Sep 17 00:00:00 2001 From: sjplimp Date: Fri, 2 Nov 2007 20:57:15 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@1121 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/fix_ave_time.cpp | 7 +++++++ src/modify.cpp | 47 +++++++++++++++++++++++++++++++++++--------- src/modify.h | 4 ++++ src/verlet.cpp | 1 - 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index b9c30341be..bdf4b708e3 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -199,6 +199,13 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) : if (nvalid < update->ntimestep) error->all("Fix ave/time cannot be started on this timestep"); + + // must set timestep for all computes that store invocation times + // since don't know a priori which are invoked by this fix + // once in end_of_step() can just set timestep for ones actually invoked + + for (int i = 0; i < modify->ncompute; i++) + if (modify->compute[i]->timeflag) modify->compute[i]->add_step(nvalid); } /* ---------------------------------------------------------------------- */ diff --git a/src/modify.cpp b/src/modify.cpp index e188685f2a..eaf82d90a1 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -72,6 +72,8 @@ Modify::Modify(LAMMPS *lmp) : Pointers(lmp) end_of_step_every = NULL; + list_timeflag = NULL; + nfix_restart_global = 0; id_restart_global = style_restart_global = state_restart_global = NULL; nfix_restart_peratom = 0; @@ -108,6 +110,8 @@ Modify::~Modify() delete [] end_of_step_every; + delete [] list_timeflag; + restart_deallocate(); // delete all computes @@ -153,8 +157,12 @@ void Modify::init() list_init(MIN_POST_FORCE,n_min_post_force,list_min_post_force); list_init(MIN_ENERGY,n_min_energy,list_min_energy); + // create list of computes that store invocation times + + list_init_compute(); + // init each compute - // notify relevant computes they may be called on this timestep + // for computes that store invocation times, add initial step to their list for (i = 0; i < ncompute; i++) { compute[i]->init(); @@ -573,25 +581,28 @@ int Modify::find_compute(char *id) } /* ---------------------------------------------------------------------- - clear the invoked flag of computes that stores their next invocation - called by classes that are invoking computes + loop over computes that store invocation times + clear their invoked flag + called by classes that invoke computes ------------------------------------------------------------------------- */ void Modify::clearstep_compute() { - for (int icompute = 0; icompute < ncompute; icompute++) - if (compute[icompute]->timeflag) compute[icompute]->invoked = 0; + for (int icompute = 0; icompute < n_timeflag; icompute++) + compute[list_timeflag[icompute]]->invoked = 0; } /* ---------------------------------------------------------------------- - schedule the next invocation of computes that were invoked - called by classes that invoked computes to schedule the next invocation + loop over computes that store invocation times + if it was invoked, schedule the next invocation + called by classes that invoke computes ------------------------------------------------------------------------- */ void Modify::addstep_compute(int ntimestep) { - for (int icompute = 0; icompute < ncompute; icompute++) - if (compute[icompute]->invoked) compute[icompute]->add_step(ntimestep); + for (int icompute = 0; icompute < n_timeflag; icompute++) + if (compute[list_timeflag[icompute]]->invoked) + compute[list_timeflag[icompute]]->add_step(ntimestep); } /* ---------------------------------------------------------------------- @@ -823,6 +834,24 @@ void Modify::list_init_thermo_energy(int mask, int &n, int *&list) if (fmask[i] & mask && fix[i]->thermo_energy) list[n++] = i; } +/* ---------------------------------------------------------------------- + create list of compute indices for computes which store invocation times +------------------------------------------------------------------------- */ + +void Modify::list_init_compute() +{ + delete [] list_timeflag; + + n_timeflag = 0; + for (int i = 0; i < ncompute; i++) + if (compute[i]->timeflag) n_timeflag++; + list_timeflag = new int[n_timeflag]; + + n_timeflag = 0; + for (int i = 0; i < ncompute; i++) + if (compute[i]->timeflag) list_timeflag[n_timeflag++] = i; +} + /* ---------------------------------------------------------------------- return # of bytes of allocated memory from all fixes ------------------------------------------------------------------------- */ diff --git a/src/modify.h b/src/modify.h index 66fbe47786..d228552c7b 100644 --- a/src/modify.h +++ b/src/modify.h @@ -86,6 +86,9 @@ class Modify : protected Pointers { int *end_of_step_every; + int n_timeflag; // list of computes that store time invocation + int *list_timeflag; + int nfix_restart_global; char **id_restart_global; char **style_restart_global; @@ -98,6 +101,7 @@ class Modify : protected Pointers { void list_init(int, int &, int *&); void list_init_end_of_step(int, int &, int *&); void list_init_thermo_energy(int, int &, int *&); + void list_init_compute(); }; } diff --git a/src/verlet.cpp b/src/verlet.cpp index c31109a243..664340659d 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -184,7 +184,6 @@ void Verlet::iterate(int n) // force computations ev_set(ntimestep); - ///printf("AAA %d %d %d\n",ntimestep,eflag,vflag); force_clear(vflag); timer->stamp();