diff --git a/src/compute.cpp b/src/compute.cpp index f3b24f7bbc..eb01566132 100644 --- a/src/compute.cpp +++ b/src/compute.cpp @@ -32,10 +32,16 @@ using namespace LAMMPS_NS; #define DELTA 4 #define BIG MAXTAGINT +// allocate space for static class instance variable and initialize it + +int Compute::instance_total = 0; + /* ---------------------------------------------------------------------- */ Compute::Compute(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) { + instance_me = instance_total++; + if (narg < 3) error->all(FLERR,"Illegal compute command"); // compute ID, group, and style diff --git a/src/compute.h b/src/compute.h index 9344eb92f5..631507bda3 100644 --- a/src/compute.h +++ b/src/compute.h @@ -20,6 +20,8 @@ namespace LAMMPS_NS { class Compute : protected Pointers { public: + static int instance_total; // # of Compute classes ever instantiated + char *id,*style; int igroup,groupbit; @@ -122,6 +124,8 @@ class Compute : protected Pointers { virtual int unsigned data_mask_ext() {return datamask_ext;} protected: + int instance_me; // which Compute class instantiation I am + int extra_dof; // extra DOF for temperature computes int fix_dof; // DOF due to fixes int dynamic; // recount atoms for temperature computes diff --git a/src/fix.cpp b/src/fix.cpp index e904809a1b..2ec28be0a5 100644 --- a/src/fix.cpp +++ b/src/fix.cpp @@ -23,10 +23,16 @@ using namespace LAMMPS_NS; using namespace FixConst; +// allocate space for static class instance variable and initialize it + +int Fix::instance_total = 0; + /* ---------------------------------------------------------------------- */ Fix::Fix(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) { + instance_me = instance_total++; + // fix ID, group, and style // ID must be all alphanumeric chars or underscores diff --git a/src/fix.h b/src/fix.h index 77c1b5322f..04920df238 100644 --- a/src/fix.h +++ b/src/fix.h @@ -20,6 +20,8 @@ namespace LAMMPS_NS { class Fix : protected Pointers { public: + static int instance_total; // # of Fix classes ever instantiated + char *id,*style; int igroup,groupbit; @@ -199,6 +201,8 @@ class Fix : protected Pointers { virtual unsigned int data_mask_ext() {return datamask_ext;} protected: + int instance_me; // which Fix class instantiation I am + int evflag; int vflag_global,vflag_atom; int maxvatom; diff --git a/src/neigh_list.cpp b/src/neigh_list.cpp index 0de4c0cb5f..47eb34bb86 100644 --- a/src/neigh_list.cpp +++ b/src/neigh_list.cpp @@ -224,6 +224,8 @@ void NeighList::print_attributes() NeighRequest *rq = neighbor->requests[index]; printf("Neighbor list/request %d:\n",index); + printf(" %p = requestor ptr (instance %d id %d)\n", + rq->requestor,rq->requestor_instance,rq->id); printf(" %d = build flag\n",buildflag); printf(" %d = grow flag\n",growflag); printf(" %d = stencil flag\n",stencilflag); diff --git a/src/neigh_request.cpp b/src/neigh_request.cpp index 95ddc01517..5f47bf5da4 100644 --- a/src/neigh_request.cpp +++ b/src/neigh_request.cpp @@ -90,7 +90,7 @@ void NeighRequest::archive() /* ---------------------------------------------------------------------- compare this request to other request - identical means all params set by requester are the same + identical means all params set by requestor are the same compare to original values in other if Neighbor may have changed them return 1 if identical, 0 if not ------------------------------------------------------------------------- */ @@ -100,10 +100,15 @@ int NeighRequest::identical(NeighRequest *other) int same = 1; // set same = 0 if old list was never processed - + // use of requestor_instance and instance counter + // prevents an old fix from being unfix/refix in same memory location + // and appearing to be old, when it is really new + // only needed for classes with persistent neigh lists: Fix, Compute, Pair + if (other->unprocessed) same = 0; if (requestor != other->requestor) same = 0; + if (requestor_instance != other->requestor_instance) same = 0; if (id != other->id) same = 0; if (pair != other->pair) same = 0; diff --git a/src/neigh_request.h b/src/neigh_request.h index 41fa951fee..53ca2b797c 100644 --- a/src/neigh_request.h +++ b/src/neigh_request.h @@ -20,11 +20,12 @@ namespace LAMMPS_NS { class NeighRequest : protected Pointers { public: - void *requestor; // class that made request - int id; // ID of request - // used to track multiple requests from one class - int unprocessed; // 1 when first requested - // 0 after processed by Neighbor class + void *requestor; // class that made request + int requestor_instance; // instance of that class (only Fix, Compute, Pair) + int id; // ID of request as stored by requestor + // used to track multiple requests from one class + int unprocessed; // 1 when first requested + // 0 after processed by Neighbor class // which class is requesting the list, one flag is 1, others are 0 @@ -100,7 +101,7 @@ class NeighRequest : protected Pointers { int otherlist; // index of other list to copy or skip from - // original params by requester + // original params by requestor // stored to compare against in identical() in case Neighbor changes them int half_original; diff --git a/src/neighbor.cpp b/src/neighbor.cpp index faf3f01a0f..f9389a47cf 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -908,7 +908,7 @@ void Neighbor::init() /* ---------------------------------------------------------------------- */ -int Neighbor::request(void *requestor) +int Neighbor::request(void *requestor, int instance) { if (nrequest == maxrequest) { maxrequest += RQDELTA; @@ -919,6 +919,7 @@ int Neighbor::request(void *requestor) requests[nrequest] = new NeighRequest(lmp); requests[nrequest]->requestor = requestor; + requests[nrequest]->requestor_instance = instance; nrequest++; return nrequest-1; } diff --git a/src/neighbor.h b/src/neighbor.h index 51add41c1b..8c90569dfd 100644 --- a/src/neighbor.h +++ b/src/neighbor.h @@ -71,7 +71,7 @@ class Neighbor : protected Pointers { Neighbor(class LAMMPS *); virtual ~Neighbor(); virtual void init(); - int request(void *); // another class requests a neighbor list + int request(void *, int instance=0); // another class requests a neigh list void print_lists_of_lists(); // debug print out int decide(); // decide whether to build or not virtual int check_distance(); // check max distance moved since last build diff --git a/src/pair.cpp b/src/pair.cpp index f3986a3b1f..42ad10032b 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -44,10 +44,16 @@ using namespace LAMMPS_NS; enum{NONE,RLINEAR,RSQ,BMP}; +// allocate space for static class instance variable and initialize it + +int Pair::instance_total = 0; + /* ---------------------------------------------------------------------- */ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) { + instance_me = instance_total++; + THIRD = 1.0/3.0; eng_vdwl = eng_coul = 0.0; @@ -70,7 +76,7 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) ewaldflag = pppmflag = msmflag = dispersionflag = tip4pflag = dipoleflag = 0; reinitflag = 1; - // pair_modify settings + // pair_modify settingsx compute_flag = 1; manybody_flag = 0; @@ -246,7 +252,6 @@ void Pair::reinit() if (!reinitflag) error->all(FLERR,"Fix adapt interface to this pair style not supported"); - etail = ptail = 0.0; for (int i = 1; i <= atom->ntypes; i++) @@ -273,7 +278,7 @@ void Pair::reinit() void Pair::init_style() { - neighbor->request(this); + neighbor->request(this,instance_me); } /* ---------------------------------------------------------------------- diff --git a/src/pair.h b/src/pair.h index a29186ff4c..d58b79de9d 100644 --- a/src/pair.h +++ b/src/pair.h @@ -30,6 +30,8 @@ class Pair : protected Pointers { friend class ThrOMP; public: + static int instance_total; // # of Pair classes ever instantiated + double eng_vdwl,eng_coul; // accumulated energies double virial[6]; // accumulated virial double *eatom,**vatom; // accumulated per-atom energy/virial @@ -182,6 +184,8 @@ class Pair : protected Pointers { virtual unsigned int data_mask_ext() {return datamask_ext;} protected: + int instance_me; // which Pair class instantiation I am + enum{GEOMETRIC,ARITHMETIC,SIXTHPOWER}; // mixing options int special_lj[4]; // copied from force->special_lj for Kokkos diff --git a/src/pair_hybrid.cpp b/src/pair_hybrid.cpp index 3c7a51633a..e24f9788ee 100644 --- a/src/pair_hybrid.cpp +++ b/src/pair_hybrid.cpp @@ -431,7 +431,7 @@ void PairHybrid::init_style() for (i = 0; i < neighbor->nrequest; i++) { if (!neighbor->requests[i]->pair) continue; - // istyle = associated sub-style + // istyle = associated sub-style for that request for (istyle = 0; istyle < nstyles; istyle++) if (styles[istyle] == neighbor->requests[i]->requestor) break; @@ -582,7 +582,7 @@ void PairHybrid::modify_requests() if (j < neighbor->nrequest) irq->otherlist = j; else { - int newrequest = neighbor->request(this); + int newrequest = neighbor->request(this,instance_me); neighbor->requests[newrequest]->copy_request(irq); irq->otherlist = newrequest; } @@ -725,7 +725,7 @@ void PairHybrid::modify_params(int narg, char **arg) if (strcmp(arg[1],keywords[m]) == 0 && multiflag == multiple[m]) break; if (m == nstyles) error->all(FLERR,"Unknown pair_modify hybrid sub-style"); - Pair::modify_params(narg-2,&arg[3]); + Pair::modify_params(narg-3,&arg[3]); styles[m]->modify_params(narg-3,&arg[3]); } diff --git a/src/pair_lj_cut.cpp b/src/pair_lj_cut.cpp index 8e4219c53d..8426862e04 100644 --- a/src/pair_lj_cut.cpp +++ b/src/pair_lj_cut.cpp @@ -490,32 +490,32 @@ void PairLJCut::init_style() if (((Respa *) update->integrate)->level_inner >= 0) respa = 1; if (((Respa *) update->integrate)->level_middle >= 0) respa = 2; - if (respa == 0) irequest = neighbor->request(this); + if (respa == 0) irequest = neighbor->request(this,instance_me); else if (respa == 1) { - irequest = neighbor->request(this); + irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this); + irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } else { - irequest = neighbor->request(this); + irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 1; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respainner = 1; - irequest = neighbor->request(this); + irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 2; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respamiddle = 1; - irequest = neighbor->request(this); + irequest = neighbor->request(this,instance_me); neighbor->requests[irequest]->id = 3; neighbor->requests[irequest]->half = 0; neighbor->requests[irequest]->respaouter = 1; } - } else irequest = neighbor->request(this); + } else irequest = neighbor->request(this,instance_me); // set rRESPA cutoffs