diff --git a/src/atom_vec_body.cpp b/src/atom_vec_body.cpp index af955bad4c..a3f73519be 100644 --- a/src/atom_vec_body.cpp +++ b/src/atom_vec_body.cpp @@ -219,8 +219,9 @@ void AtomVecBody::copy(int i, int j, int delflag) } // if atom I has bonus data, reset I's bonus.ilocal to loc J + // do NOT do this if self-copy (I=J) since I's bonus data is already deleted - if (body[i] >= 0) bonus[body[i]].ilocal = j; + if (body[i] >= 0 && i != j) bonus[body[i]].ilocal = j; body[j] = body[i]; if (atom->nextra_grow) @@ -230,13 +231,13 @@ void AtomVecBody::copy(int i, int j, int delflag) /* ---------------------------------------------------------------------- copy bonus data from I to J, effectively deleting the J entry - insure index pointers between per-atom and bonus data are updated + also reset body that points to I to now point to J ------------------------------------------------------------------------- */ void AtomVecBody::copy_bonus(int i, int j) { + body[bonus[i].ilocal] = j; memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); - body[bonus[j].ilocal] = j; } /* ---------------------------------------------------------------------- @@ -1407,3 +1408,52 @@ bigint AtomVecBody::memory_usage() return bytes; } + +/* ---------------------------------------------------------------------- + debug method for sanity checking of own/bonus data pointers +------------------------------------------------------------------------- */ + +/* +void AtomVecBody::check(int flag) +{ + for (int i = 0; i < atom->nlocal; i++) { + if (atom->body[i] >= 0 && atom->body[i] >= nlocal_bonus) { + printf("Proc %d, step %ld, flag %d\n",comm->me,update->ntimestep,flag); + error->one(FLERR,"BAD AAA"); + } + } + for (int i = atom->nlocal; i < atom->nlocal+atom->nghost; i++) { + if (atom->body[i] >= 0 && + (atom->body[i] < nlocal_bonus || + atom->body[i] >= nlocal_bonus+nghost_bonus)) { + printf("Proc %d, step %ld, flag %d\n",comm->me,update->ntimestep,flag); + error->one(FLERR,"BAD BBB"); + } + } + for (int i = 0; i < nlocal_bonus; i++) { + if (bonus[i].ilocal < 0 || bonus[i].ilocal >= atom->nlocal) { + printf("Proc %d, step %ld, flag %d\n",comm->me,update->ntimestep,flag); + error->one(FLERR,"BAD CCC"); + } + } + for (int i = 0; i < nlocal_bonus; i++) { + if (atom->body[bonus[i].ilocal] != i) { + printf("Proc %d, step %ld, flag %d\n",comm->me,update->ntimestep,flag); + error->one(FLERR,"BAD DDD"); + } + } + for (int i = nlocal_bonus; i < nlocal_bonus+nghost_bonus; i++) { + if (bonus[i].ilocal < atom->nlocal || + bonus[i].ilocal >= atom->nlocal+atom->nghost) { + printf("Proc %d, step %ld, flag %d\n",comm->me,update->ntimestep,flag); + error->one(FLERR,"BAD EEE"); + } + } + for (int i = nlocal_bonus; i < nlocal_bonus+nghost_bonus; i++) { + if (atom->body[bonus[i].ilocal] != i) { + printf("Proc %d, step %ld, flag %d\n",comm->me,update->ntimestep,flag); + error->one(FLERR,"BAD FFF"); + } + } +} +*/ diff --git a/src/atom_vec_body.h b/src/atom_vec_body.h index 5f6207375c..da4bc6d6af 100644 --- a/src/atom_vec_body.h +++ b/src/atom_vec_body.h @@ -25,6 +25,12 @@ AtomStyle(body,AtomVecBody) namespace LAMMPS_NS { class AtomVecBody : public AtomVec { + friend class Comm; + + + + + public: class Body *bptr; @@ -96,6 +102,7 @@ class AtomVecBody : public AtomVec { void grow_bonus(); void copy_bonus(int, int); + //void check(int); }; } diff --git a/src/atom_vec_ellipsoid.cpp b/src/atom_vec_ellipsoid.cpp index c30cbaa0b9..36c7a1ffbe 100755 --- a/src/atom_vec_ellipsoid.cpp +++ b/src/atom_vec_ellipsoid.cpp @@ -153,8 +153,9 @@ void AtomVecEllipsoid::copy(int i, int j, int delflag) } // if atom I has bonus data, reset I's bonus.ilocal to loc J + // do NOT do this if self-copy (I=J) since I's bonus data is already deleted - if (ellipsoid[i] >= 0) bonus[ellipsoid[i]].ilocal = j; + if (ellipsoid[i] >= 0 && i != j) bonus[ellipsoid[i]].ilocal = j; ellipsoid[j] = ellipsoid[i]; if (atom->nextra_grow) @@ -164,13 +165,13 @@ void AtomVecEllipsoid::copy(int i, int j, int delflag) /* ---------------------------------------------------------------------- copy bonus data from I to J, effectively deleting the J entry - insure index pointers between per-atom and bonus data are updated + also reset ellipsoid that points to I to now point to J ------------------------------------------------------------------------- */ void AtomVecEllipsoid::copy_bonus(int i, int j) { + ellipsoid[bonus[i].ilocal] = j; memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); - ellipsoid[bonus[j].ilocal] = j; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec_line.cpp b/src/atom_vec_line.cpp index 000f38b4af..e0aba2ead9 100644 --- a/src/atom_vec_line.cpp +++ b/src/atom_vec_line.cpp @@ -163,8 +163,9 @@ void AtomVecLine::copy(int i, int j, int delflag) } // if atom I has bonus data, reset I's bonus.ilocal to loc J + // do NOT do this if self-copy (I=J) since I's bonus data is already deleted - if (line[i] >= 0) bonus[line[i]].ilocal = j; + if (line[i] >= 0 && i != j) bonus[line[i]].ilocal = j; line[j] = line[i]; if (atom->nextra_grow) @@ -174,13 +175,13 @@ void AtomVecLine::copy(int i, int j, int delflag) /* ---------------------------------------------------------------------- copy bonus data from I to J, effectively deleting the J entry - insure index pointers between per-atom and bonus data are updated + also reset ine that points to I to now point to J ------------------------------------------------------------------------- */ void AtomVecLine::copy_bonus(int i, int j) { + line[bonus[i].ilocal] = j; memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); - line[bonus[j].ilocal] = j; } /* ---------------------------------------------------------------------- diff --git a/src/atom_vec_tri.cpp b/src/atom_vec_tri.cpp index fc405d2fd5..6d88a06ce3 100644 --- a/src/atom_vec_tri.cpp +++ b/src/atom_vec_tri.cpp @@ -165,8 +165,9 @@ void AtomVecTri::copy(int i, int j, int delflag) } // if atom I has bonus data, reset I's bonus.ilocal to loc J + // do NOT do this if self-copy (I=J) since I's bonus data is already deleted - if (tri[i] >= 0) bonus[tri[i]].ilocal = j; + if (tri[i] >= 0 && i != j) bonus[tri[i]].ilocal = j; tri[j] = tri[i]; if (atom->nextra_grow) @@ -176,13 +177,13 @@ void AtomVecTri::copy(int i, int j, int delflag) /* ---------------------------------------------------------------------- copy bonus data from I to J, effectively deleting the J entry - insure index pointers between per-atom and bonus data are updated + also reset tri that points to I to now point to J ------------------------------------------------------------------------- */ void AtomVecTri::copy_bonus(int i, int j) { + tri[bonus[i].ilocal] = j; memcpy(&bonus[j],&bonus[i],sizeof(Bonus)); - tri[bonus[j].ilocal] = j; } /* ----------------------------------------------------------------------