From eb8a7d8d9750e070b08f6947a1e4b580ceea9bed Mon Sep 17 00:00:00 2001 From: sjplimp Date: Mon, 5 Jan 2015 16:50:37 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@12862 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/fix_vector.cpp | 33 ++++++++++++++++++++------------- src/fix_vector.h | 3 +++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/fix_vector.cpp b/src/fix_vector.cpp index 1f4ba69025..8cdf58564c 100644 --- a/src/fix_vector.cpp +++ b/src/fix_vector.cpp @@ -147,12 +147,13 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) : } global_freq = nevery; + time_depend = 1; // ncount = current size of vector or array vector = NULL; array = NULL; - ncount = 0; + ncount = ncountmax = 0; if (nvalues == 1) size_vector = 0; else size_array_rows = 0; @@ -161,9 +162,13 @@ FixVector::FixVector(LAMMPS *lmp, int narg, char **arg) : // since don't know a priori which are invoked by this fix // once in end_of_step() can set timestep for ones actually invoked - bigint nextstep = (update->ntimestep/nevery)*nevery; + nextstep = (update->ntimestep/nevery)*nevery; if (nextstep < update->ntimestep) nextstep += nevery; modify->addstep_compute_all(nextstep); + + // initialstep = first step the vector/array will store values for + + initialstep = nextstep; } /* ---------------------------------------------------------------------- */ @@ -216,16 +221,15 @@ void FixVector::init() } } - // reallocate vector or array for size at end of run - // nsize = # of entries this run will add + // reallocate vector or array for accumulated size at end of run + // use endstep to allow for subsequent runs with "pre no" + // nsize = # of entries from initialstep to finalstep - bigint nfirst = update->firststep/nevery * nevery; - if (nfirst < update->firststep) nfirst += nevery; - bigint nlast = update->laststep/nevery * nevery; - if (nlast > update->laststep) nlast -= nevery; - int nsize = (nlast-nfirst)/nevery + 1; - if (nvalues == 1) memory->grow(vector,ncount+nsize,"vector:vector"); - else memory->grow(array,ncount+nsize,nvalues,"vector:array"); + bigint finalstep = update->endstep/nevery * nevery; + if (finalstep > update->endstep) finalstep -= nevery; + ncountmax = (finalstep-initialstep)/nevery + 1; + if (nvalues == 1) memory->grow(vector,ncountmax,"vector:vector"); + else memory->grow(array,ncountmax,nvalues,"vector:array"); } /* ---------------------------------------------------------------------- @@ -243,7 +247,9 @@ void FixVector::end_of_step() { // skip if not step which requires doing something - if (update->ntimestep % nevery) return; + if (update->ntimestep != nextstep) return; + if (ncount == ncountmax) + error->all(FLERR,"Overflow of allocated fix vector storage"); // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add @@ -292,7 +298,8 @@ void FixVector::end_of_step() // trigger computes on next needed step - modify->addstep_compute(update->ntimestep + nevery); + nextstep += nevery; + modify->addstep_compute(nextstep); // update size of vector or array diff --git a/src/fix_vector.h b/src/fix_vector.h index fc8e03d43e..48179e03aa 100644 --- a/src/fix_vector.h +++ b/src/fix_vector.h @@ -40,7 +40,10 @@ class FixVector : public Fix { int *which,*argindex,*value2index; char **ids; + bigint nextstep,initialstep; + int ncount; // # of values currently in growing vector or array + int ncountmax; // max # of values vector/array can hold double *vector; double **array; };