diff --git a/src/GRANULAR/fix_wall_gran.cpp b/src/GRANULAR/fix_wall_gran.cpp index 6557a7ebf1..4793557c4c 100644 --- a/src/GRANULAR/fix_wall_gran.cpp +++ b/src/GRANULAR/fix_wall_gran.cpp @@ -49,13 +49,8 @@ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : if (!atom->sphere_flag) error->all(FLERR,"Fix wall/gran requires atom style sphere"); - // set time_depend so that history will be preserved correctly - // across multiple runs via laststep setting in granular pair styles - // same as fix shear/history - restart_peratom = 1; create_attribute = 1; - time_depend = 1; // wall/particle coefficients @@ -184,7 +179,6 @@ FixWallGran::FixWallGran(LAMMPS *lmp, int narg, char **arg) : shear[i][0] = shear[i][1] = shear[i][2] = 0.0; time_origin = update->ntimestep; - laststep = -1; } /* ---------------------------------------------------------------------- */ @@ -289,8 +283,8 @@ void FixWallGran::post_force(int vflag) int *mask = atom->mask; int nlocal = atom->nlocal; - if (update->ntimestep > laststep) shearupdate = 1; - else shearupdate = 0; + int shearupdate = 1; + if (update->setupflag) shearupdate = 0; for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { @@ -348,8 +342,6 @@ void FixWallGran::post_force(int vflag) } } } - - laststep = update->ntimestep; } /* ---------------------------------------------------------------------- */ diff --git a/src/GRANULAR/fix_wall_gran.h b/src/GRANULAR/fix_wall_gran.h index 4f29675057..1d101ab3ca 100644 --- a/src/GRANULAR/fix_wall_gran.h +++ b/src/GRANULAR/fix_wall_gran.h @@ -55,7 +55,6 @@ class FixWallGran : public Fix { int nlevels_respa; int time_origin; - bigint laststep; int *touch; double **shear; int shearupdate; diff --git a/src/GRANULAR/pair_gran_hertz_history.cpp b/src/GRANULAR/pair_gran_hertz_history.cpp index 19d302a1fb..52c17d1be9 100644 --- a/src/GRANULAR/pair_gran_hertz_history.cpp +++ b/src/GRANULAR/pair_gran_hertz_history.cpp @@ -53,8 +53,9 @@ void PairGranHertzHistory::compute(int eflag, int vflag) if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; - int shearupdate = 0; - if (update->ntimestep > laststep) shearupdate = 1; + computeflag = 1; + int shearupdate = 1; + if (update->setupflag) shearupdate = 0; double **x = atom->x; double **v = atom->v; @@ -243,8 +244,6 @@ void PairGranHertzHistory::compute(int eflag, int vflag) } } } - - laststep = update->ntimestep; } /* ---------------------------------------------------------------------- diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index 268b196644..ea4888d92c 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -51,7 +51,7 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp) single_extra = 4; svector = new double[4]; - laststep = -1; + computeflag = 0; neighprev = 0; } @@ -94,8 +94,9 @@ void PairGranHookeHistory::compute(int eflag, int vflag) if (eflag || vflag) ev_setup(eflag,vflag); else evflag = vflag_fdotr = 0; - int shearupdate = 0; - if (update->ntimestep > laststep) shearupdate = 1; + computeflag = 1; + int shearupdate = 1; + if (update->setupflag) shearupdate = 0; double **x = atom->x; double **v = atom->v; @@ -283,8 +284,6 @@ void PairGranHookeHistory::compute(int eflag, int vflag) } } } - - laststep = update->ntimestep; } /* ---------------------------------------------------------------------- @@ -393,7 +392,8 @@ void PairGranHookeHistory::init_style() // if first init, create Fix needed for storing shear history if (history && force->newton_pair == 1) - error->all(FLERR,"Pair granular with shear history requires newton pair off"); + error->all(FLERR, + "Pair granular with shear history requires newton pair off"); if (history && fix_history == NULL) { char **fixarg = new char*[3]; diff --git a/src/GRANULAR/pair_gran_hooke_history.h b/src/GRANULAR/pair_gran_hooke_history.h index ec111a957d..b799627317 100644 --- a/src/GRANULAR/pair_gran_hooke_history.h +++ b/src/GRANULAR/pair_gran_hooke_history.h @@ -26,6 +26,8 @@ namespace LAMMPS_NS { class PairGranHookeHistory : public Pair { public: + int computeflag; + PairGranHookeHistory(class LAMMPS *); virtual ~PairGranHookeHistory(); virtual void compute(int, int); @@ -48,15 +50,12 @@ class PairGranHookeHistory : public Pair { int freeze_group_bit; int history; - bigint laststep; - class FixShearHistory *fix_history; - char *suffix; - + int neighprev; double *onerad_dynamic,*onerad_frozen; double *maxrad_dynamic,*maxrad_frozen; - int neighprev; + class FixShearHistory *fix_history; void allocate(); }; diff --git a/src/fix.h b/src/fix.h index 2de97dc9b0..4602b3c5b5 100644 --- a/src/fix.h +++ b/src/fix.h @@ -117,6 +117,7 @@ class Fix : protected Pointers { virtual void post_force_respa(int, int, int) {} virtual void final_integrate_respa(int, int) {} + virtual void min_setup_pre_exchange() {} virtual void min_setup_pre_force(int) {} virtual void min_pre_exchange() {} virtual void min_pre_force(int) {} diff --git a/src/fix_shear_history.cpp b/src/fix_shear_history.cpp index b63d7a0369..7d409e6c59 100644 --- a/src/fix_shear_history.cpp +++ b/src/fix_shear_history.cpp @@ -18,7 +18,7 @@ #include "neighbor.h" #include "neigh_list.h" #include "force.h" -#include "pair.h" +#include "pair_gran_hooke_history.h" #include "update.h" #include "modify.h" #include "memory.h" @@ -34,12 +34,8 @@ using namespace FixConst; FixShearHistory::FixShearHistory(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) { - // set time_depend so that history will be preserved correctly - // across multiple runs via laststep setting in granular pair styles - restart_peratom = 1; create_attribute = 1; - time_depend = 1; // perform initial allocation of atom-based arrays // register with atom class @@ -79,6 +75,7 @@ int FixShearHistory::setmask() { int mask = 0; mask |= PRE_EXCHANGE; + mask |= MIN_PRE_EXCHANGE; return mask; } @@ -91,16 +88,30 @@ void FixShearHistory::init() "Pair style granular with history requires atoms have IDs"); } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + called by setup of run or minimize + called by write_restart as input script command + only invoke pre_exchange() if neigh list stores more current history info + than npartner/partner arrays in this fix + that will only be case if pair->compute() has been invoked since + upate of npartner/npartner + this logic avoids 2 problems: + run 100; write_restart; run 100 + setup_pre_exchange is called twice (by write_restart and 2nd run setup) + w/out a neighbor list being created in between + read_restart; run 100 + setup_pre_exchange called by run setup whacks restart shear history info +------------------------------------------------------------------------- */ void FixShearHistory::setup_pre_exchange() { - pre_exchange(); + if (pair->computeflag) pre_exchange(); + pair->computeflag = 0; } /* ---------------------------------------------------------------------- copy shear partner info from neighbor lists to atom arrays - so can be exchanged with atoms + so can be migrated or stored with atoms ------------------------------------------------------------------------- */ void FixShearHistory::pre_exchange() @@ -111,23 +122,14 @@ void FixShearHistory::pre_exchange() double *shear,*allshear,**firstshear; // zero npartner for all current atoms - // do not do this if inum = 0, since will wipe out npartner counts - // inum is 0 when pre_exchange() is called from integrate->setup() - // before first run when no neighbor lists yet exist - // partner info may have just been read from restart file - // and won't be used until granular neighbor lists are built - // if nothing read from restart file, constructor sets npartner = 0 - NeighList *list = pair->list; int nlocal = atom->nlocal; - - if (list->inum) - for (i = 0; i < nlocal; i++) - npartner[i] = 0; + for (i = 0; i < nlocal; i++) npartner[i] = 0; // copy shear info from neighbor list atoms to atom arrays int *tag = atom->tag; + NeighList *list = pair->list; inum = list->inum; ilist = list->ilist; numneigh = list->numneigh; @@ -180,6 +182,21 @@ void FixShearHistory::pre_exchange() error->all(FLERR,"Too many touching neighbors - boost MAXTOUCH"); } +/* ---------------------------------------------------------------------- */ + +void FixShearHistory::min_setup_pre_exchange() +{ + if (pair->computeflag) pre_exchange(); + pair->computeflag = 0; +} + +/* ---------------------------------------------------------------------- */ + +void FixShearHistory::min_pre_exchange() +{ + pre_exchange(); +} + /* ---------------------------------------------------------------------- memory usage of local atom-based arrays ------------------------------------------------------------------------- */ diff --git a/src/fix_shear_history.h b/src/fix_shear_history.h index 58e7bcfb2d..29b917eaf4 100644 --- a/src/fix_shear_history.h +++ b/src/fix_shear_history.h @@ -36,6 +36,8 @@ class FixShearHistory : public Fix { void init(); void setup_pre_exchange(); virtual void pre_exchange(); + void min_setup_pre_exchange(); + void min_pre_exchange(); double memory_usage(); void grow_arrays(int); @@ -53,7 +55,7 @@ class FixShearHistory : public Fix { int **partner; // tags for the partners double ***shearpartner; // 3 shear values with the partner - class Pair *pair; + class PairGranHookeHistory *pair; }; } diff --git a/src/min.cpp b/src/min.cpp index e5c2cb46af..629a895449 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -189,6 +189,8 @@ void Min::setup() { if (comm->me == 0 && screen) fprintf(screen,"Setting up minimization ...\n"); + update->setupflag = 1; + // setup extra global dof due to fixes // cannot be done in init() b/c update init() is before modify init() @@ -222,6 +224,7 @@ void Min::setup() // build neighbor lists atom->setup(); + modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); @@ -279,6 +282,7 @@ void Min::setup() modify->setup(vflag); output->setup(); + update->setupflag = 0; // stats for Finish to print @@ -299,11 +303,14 @@ void Min::setup() void Min::setup_minimal(int flag) { + update->setupflag = 1; + // setup domain, communication and neighboring // acquire ghosts // build neighbor lists if (flag) { + modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); @@ -351,6 +358,7 @@ void Min::setup_minimal(int flag) requestor[m]->min_xf_get(m); modify->setup(vflag); + update->setupflag = 0; // stats for Finish to print diff --git a/src/modify.cpp b/src/modify.cpp index 1dc6a04dd7..2b7c4637d4 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -235,8 +235,12 @@ void Modify::setup(int vflag) void Modify::setup_pre_exchange() { - for (int i = 0; i < n_pre_exchange; i++) - fix[list_pre_exchange[i]]->setup_pre_exchange(); + if (update->whichflag == 1) + for (int i = 0; i < n_pre_exchange; i++) + fix[list_pre_exchange[i]]->setup_pre_exchange(); + else if (update->whichflag == 2) + for (int i = 0; i < n_min_pre_exchange; i++) + fix[list_min_pre_exchange[i]]->min_setup_pre_exchange(); } /* ---------------------------------------------------------------------- diff --git a/src/modify.h b/src/modify.h index 9172f577d9..4bf7c731f2 100644 --- a/src/modify.h +++ b/src/modify.h @@ -64,7 +64,6 @@ class Modify : protected Pointers { void post_force_respa(int, int, int); void final_integrate_respa(int, int); - void setup_min_pre_force(int); void min_pre_exchange(); void min_pre_force(int); void min_post_force(int); diff --git a/src/respa.cpp b/src/respa.cpp index 94321af98b..fec5b10e89 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -418,6 +418,7 @@ void Respa::setup_minimal(int flag) // build neighbor lists if (flag) { + modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); diff --git a/src/verlet.cpp b/src/verlet.cpp index 095dccbd6a..20bc2d6112 100644 --- a/src/verlet.cpp +++ b/src/verlet.cpp @@ -158,6 +158,7 @@ void Verlet::setup_minimal(int flag) // build neighbor lists if (flag) { + modify->setup_pre_exchange(); if (triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box(); diff --git a/src/write_restart.cpp b/src/write_restart.cpp index 7605b65b21..8305413f89 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -95,12 +95,11 @@ void WriteRestart::command(int narg, char **arg) lmp->init(); // move atoms to new processors before writing file - // do pre_exchange so FixShearHistory will store - // current neigh info with atoms + // do setup_pre_exchange to force update of per-atom info if needed // enforce PBC in case atoms are outside box // call borders() to rebuild atom map since exchange() destroys map - if (modify->n_pre_exchange) modify->pre_exchange(); + modify->setup_pre_exchange(); if (domain->triclinic) domain->x2lamda(atom->nlocal); domain->pbc(); domain->reset_box();