diff --git a/src/atom.cpp b/src/atom.cpp index e6998ebfb1..838d67deec 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -52,6 +52,10 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) extra_bond_per_atom = 0; firstgroupname = NULL; + sortfreq = 0; + maxbin = maxnext = 0; + binhead = NULL; + next = permute = NULL; // initialize atom arrays // customize by adding new array @@ -110,13 +114,6 @@ Atom::Atom(LAMMPS *lmp) : Pointers(lmp) nextra_store = 0; extra = NULL; - // sorting - - sortflag = 0; - maxbin = maxnext = 0; - binhead = NULL; - next = permute = NULL; - // default mapping values and hash table primes tag_enable = 1; @@ -146,7 +143,11 @@ Atom::~Atom() { delete [] atom_style; delete avec; + delete [] firstgroupname; + memory->sfree(binhead); + memory->sfree(next); + memory->sfree(permute); // delete atom arrays // customize by adding new array @@ -211,12 +212,6 @@ Atom::~Atom() delete [] dipole; delete [] dipole_setflag; - // delete sorting arrays - - memory->sfree(binhead); - memory->sfree(next); - memory->sfree(permute); - // delete extra arrays memory->sfree(extra_grow); @@ -315,7 +310,7 @@ void Atom::setup() // setup for sorting // binsize = user setting or 1/2 of neighbor cutoff - if (sortflag) { + if (sortfreq > 0) { double binsize; if (userbinsize > 0.0) binsize = userbinsize; else binsize = 0.5 * neighbor->cutneighmax; @@ -341,6 +336,8 @@ int Atom::style_match(const char *style) /* ---------------------------------------------------------------------- modify parameters of the atom style + some options can only be invoked before simulation box is defined + first and sort options cannot be used together ------------------------------------------------------------------------- */ void Atom::modify_params(int narg, char **arg) @@ -354,6 +351,8 @@ void Atom::modify_params(int narg, char **arg) if (strcmp(arg[iarg+1],"array") == 0) map_style = 1; else if (strcmp(arg[iarg+1],"hash") == 0) map_style = 2; else error->all("Illegal atom_modify command"); + if (domain->box_exist) + error->all("Atom_modify map command after simulation box is defined"); iarg += 2; } else if (strcmp(arg[iarg],"first") == 0) { if (iarg+2 > narg) error->all("Illegal atom_modify command"); @@ -363,6 +362,7 @@ void Atom::modify_params(int narg, char **arg) firstgroupname = new char[n]; strcpy(firstgroupname,arg[iarg+1]); } + sortfreq = 0; iarg += 2; } else if (strcmp(arg[iarg],"sort") == 0) { if (iarg+3 > narg) error->all("Illegal atom_modify command"); @@ -370,8 +370,9 @@ void Atom::modify_params(int narg, char **arg) userbinsize = atof(arg[iarg+2]); if (sortfreq < 0 || userbinsize < 0.0) error->all("Illegal atom_modify command"); - if (sortfreq == 0) sortflag = 0; - else sortflag = 1; + if (sortfreq >= 0 && firstgroupname) + error->all("Atom_modify sort and first options " + "cannot be used together"); iarg += 3; } else error->all("Illegal atom_modify command"); } @@ -1370,7 +1371,7 @@ void Atom::sort() permute = (int *) memory->smalloc(maxnext*sizeof(int),"atom:permute"); } - // insure one extra location at end of atom arrays + // insure there is one extra atom location at end of arrays for swaps if (nlocal == nmax) avec->grow(0); diff --git a/src/atom.h b/src/atom.h index 7d993b269a..0ee3608e13 100644 --- a/src/atom.h +++ b/src/atom.h @@ -102,7 +102,7 @@ class Atom : protected Pointers { // spatial sorting of atoms - int sortflag; // 0 = off, 1 = on + int sortfreq; // sort atoms every this many steps, 0 = off int nextsort; // next timestep to sort on // functions @@ -203,7 +203,6 @@ class Atom : protected Pointers { int *permute; // permutation vector double userbinsize; // sorting bin size double bininv; - int sortfreq; int memlength; // allocated size of memstr char *memstr; // string of array names already counted diff --git a/src/compute_pressure.cpp b/src/compute_pressure.cpp index e8c2221df2..94391ce527 100644 --- a/src/compute_pressure.cpp +++ b/src/compute_pressure.cpp @@ -172,7 +172,7 @@ double ComputePressure::compute_scalar() double t; if (keflag) { - if (temperature->invoked_scalar == update->ntimestep) + if (temperature->invoked_scalar != update->ntimestep) t = temperature->compute_scalar(); else t = temperature->scalar; } @@ -209,7 +209,7 @@ void ComputePressure::compute_vector() if (update->vflag_global != invoked_vector) error->all("Virial was not tallied on needed timestep"); - // invoke temperature it it hasn't been already + // invoke temperature if it hasn't been already double *ke_tensor; if (keflag) { diff --git a/src/input.cpp b/src/input.cpp index ac6da866a5..7201b69578 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -691,8 +691,6 @@ void Input::angle_style() void Input::atom_modify() { - if (domain->box_exist) - error->all("Atom_modify command after simulation box is defined"); atom->modify_params(narg,arg); } diff --git a/src/modify.cpp b/src/modify.cpp index 2500e33511..c0e9dc2e57 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -192,12 +192,20 @@ void Modify::init() list_init_compute(); // init each compute + // set invoked_scalar,vector,etc to -1 to force new run to re-compute them // add initial timestep to all computes that store invocation times // since any of them may be invoked by initial thermo // do not clear out invocation times stored within a compute, // b/c some may be holdovers from previous run, like for ave fixes - for (i = 0; i < ncompute; i++) compute[i]->init(); + for (i = 0; i < ncompute; i++) { + compute[i]->init(); + compute[i]->invoked_scalar = -1; + compute[i]->invoked_vector = -1; + compute[i]->invoked_array = -1; + compute[i]->invoked_peratom = -1; + compute[i]->invoked_local = -1; + } addstep_compute_all(update->ntimestep); // warn if any particle is time integrated more than once diff --git a/src/update.cpp b/src/update.cpp index c6a26b9d14..68bdd98771 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -222,7 +222,8 @@ void Update::create_minimize(int narg, char **arg) do not allow any timestep-dependent fixes to be defined do not allow any dynamic regions to be defined reset eflag/vflag global so nothing will think eng/virial are current - reset invoked flags of computes, so nothing will think they are current + reset invoked flags of computes, + so nothing will think they are current between runs clear timestep list of computes that store future invocation times ------------------------------------------------------------------------- */ @@ -249,6 +250,7 @@ void Update::reset_timestep(int narg, char **arg) for (int i = 0; i < modify->ncompute; i++) { modify->compute[i]->invoked_scalar = -1; modify->compute[i]->invoked_vector = -1; + modify->compute[i]->invoked_array = -1; modify->compute[i]->invoked_peratom = -1; modify->compute[i]->invoked_local = -1; } diff --git a/src/verlet.cpp b/src/verlet.cpp index c8ab8995be..0f6d358d65 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -92,7 +92,7 @@ void Verlet::setup() comm->setup(); if (neighbor->style) neighbor->setup_bins(); comm->exchange(); - if (atom->sortflag) atom->sort(); + if (atom->sortfreq > 0) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); neighbor->build(); @@ -178,7 +178,7 @@ void Verlet::setup_minimal(int flag) void Verlet::run(int n) { - int nflag,ntimestep; + int nflag,ntimestep,sortflag; int n_post_integrate = modify->n_post_integrate; int n_pre_exchange = modify->n_pre_exchange; @@ -186,7 +186,9 @@ void Verlet::run(int n) int n_pre_force = modify->n_pre_force; int n_post_force = modify->n_post_force; int n_end_of_step = modify->n_end_of_step; - int sortflag = atom->sortflag; + + if (atom->sortfreq > 0) sortflag = 1; + else sortflag = 0; for (int i = 0; i < n; i++) { @@ -217,7 +219,7 @@ void Verlet::run(int n) } timer->stamp(); comm->exchange(); - if (sortflag && ntimestep > atom->nextsort) atom->sort(); + if (sortflag && ntimestep >= atom->nextsort) atom->sort(); comm->borders(); if (triclinic) domain->lamda2x(atom->nlocal+atom->nghost); timer->stamp(TIME_COMM);