diff --git a/src/atom_vec_sphere.cpp b/src/atom_vec_sphere.cpp index 7c6691ebf6..32aeb5139e 100644 --- a/src/atom_vec_sphere.cpp +++ b/src/atom_vec_sphere.cpp @@ -1048,12 +1048,11 @@ void AtomVecSphere::pack_data(double **buf) else buf[i][3] = rmass[i] / (4.0*MY_PI/3.0 * radius[i]*radius[i]*radius[i]); buf[i][4] = x[i][0]; - buf[i][5] = x[i][0]; - buf[i][6] = x[i][1]; - buf[i][7] = x[i][2]; - buf[i][8] = (image[i] & IMGMASK) - IMGMAX; - buf[i][9] = (image[i] >> IMGBITS & IMGMASK) - IMGMAX; - buf[i][10] = (image[i] >> IMG2BITS) - IMGMAX; + buf[i][5] = x[i][1]; + buf[i][6] = x[i][2]; + buf[i][7] = (image[i] & IMGMASK) - IMGMAX; + buf[i][8] = (image[i] >> IMGBITS & IMGMASK) - IMGMAX; + buf[i][9] = (image[i] >> IMG2BITS) - IMGMAX; } } diff --git a/src/comm.cpp b/src/comm.cpp index 648711d239..b15fc5a285 100644 --- a/src/comm.cpp +++ b/src/comm.cpp @@ -1509,9 +1509,10 @@ void Comm::forward_comm_array(int n, double **array) communicate inbuf around full ring of processors with messtag nbytes = size of inbuf = n datums * nper bytes callback() is invoked to allow caller to process/update each proc's inbuf - note that callback() is invoked on final iteration for original inbuf + if self=1 (default), then callback() is invoked on final iteration + using original inbuf, which may have been updated for non-NULL outbuf, final updated inbuf is copied to it - outbuf = inbuf is OK + outbuf = inbuf is OK ------------------------------------------------------------------------- */ void Comm::ring(int n, int nper, void *inbuf, int messtag, diff --git a/src/delete_atoms.cpp b/src/delete_atoms.cpp index dc70d8557c..d2fa42192b 100644 --- a/src/delete_atoms.cpp +++ b/src/delete_atoms.cpp @@ -28,8 +28,14 @@ #include "memory.h" #include "error.h" +#include + using namespace LAMMPS_NS; +// allocate space for static class variable + +DeleteAtoms *DeleteAtoms::cptr; + /* ---------------------------------------------------------------------- */ DeleteAtoms::DeleteAtoms(LAMMPS *lmp) : Pointers(lmp) {} @@ -138,6 +144,7 @@ void DeleteAtoms::delete_group(int narg, char **arg) /* ---------------------------------------------------------------------- delete all atoms in region + if mol_flag is set, also delete atoms in molecules with any deletions ------------------------------------------------------------------------- */ void DeleteAtoms::delete_region(int narg, char **arg) @@ -158,6 +165,54 @@ void DeleteAtoms::delete_region(int narg, char **arg) for (int i = 0; i < nlocal; i++) if (domain->regions[iregion]->match(x[i][0],x[i][1],x[i][2])) dlist[i] = 1; + + if (mol_flag == 0) return; + + // delete entire molecules if any atom in molecule was deleted + // store list of molecule IDs I delete atoms from in list + // pass list from proc to proc via ring communication + + hash = new std::map(); + + int *molecule = atom->molecule; + for (int i = 0; i < nlocal; i++) + if (dlist[i] && hash->find(molecule[i]) == hash->end()) + (*hash)[molecule[i]] = 1; + + int n = hash->size(); + int *list; + memory->create(list,n,"delete_atoms:list"); + + n = 0; + std::map::iterator pos; + for (pos = hash->begin(); pos != hash->end(); ++pos) list[n++] = pos->first; + + cptr = this; + comm->ring(n,sizeof(int),list,1,molring,NULL); + + delete hash; + memory->destroy(list); +} + +/* ---------------------------------------------------------------------- + callback from comm->ring() + cbuf = list of N molecule IDs, put them in hash + loop over my atoms, if matches moleculed ID in hash, delete that atom +------------------------------------------------------------------------- */ + +void DeleteAtoms::molring(int n, char *cbuf) +{ + int *list = (int *) cbuf; + int *dlist = cptr->dlist; + std::map *hash = cptr->hash; + int nlocal = cptr->atom->nlocal; + int *molecule = cptr->atom->molecule; + + hash->clear(); + for (int i = 0; i < n; i++) (*hash)[list[i]] = 1; + + for (int i = 0; i < nlocal; i++) + if (hash->find(molecule[i]) != hash->end()) dlist[i] = 1; } /* ---------------------------------------------------------------------- @@ -346,6 +401,7 @@ void DeleteAtoms::delete_porosity(int narg, char **arg) void DeleteAtoms::options(int narg, char **arg) { compress_flag = 1; + mol_flag = 0; int iarg = 0; while (iarg < narg) { @@ -355,6 +411,12 @@ void DeleteAtoms::options(int narg, char **arg) else if (strcmp(arg[iarg+1],"no") == 0) compress_flag = 0; else error->all(FLERR,"Illegal delete_bonds command"); iarg += 2; + } else if (strcmp(arg[iarg],"mol") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal delete_bonds command"); + if (strcmp(arg[iarg+1],"yes") == 0) mol_flag = 1; + else if (strcmp(arg[iarg+1],"no") == 0) mol_flag = 0; + else error->all(FLERR,"Illegal delete_bonds command"); + iarg += 2; } else error->all(FLERR,"Illegal delete_bonds command"); } } diff --git a/src/delete_atoms.h b/src/delete_atoms.h index a1d8104e88..f091bbbabc 100644 --- a/src/delete_atoms.h +++ b/src/delete_atoms.h @@ -21,6 +21,7 @@ CommandStyle(delete_atoms,DeleteAtoms) #define LMP_DELETE_ATOMS_H #include "pointers.h" +#include namespace LAMMPS_NS { @@ -31,7 +32,8 @@ class DeleteAtoms : protected Pointers { private: int *dlist; - int compress_flag; + int compress_flag,mol_flag; + std::map *hash; void delete_group(int, char **); void delete_region(int, char **); @@ -42,6 +44,12 @@ class DeleteAtoms : protected Pointers { inline int sbmask(int j) { return j >> SBBITS & 3; } + + // static variable for ring communication callback to access class data + // callback functions for ring communication + + static DeleteAtoms *cptr; + static void molring(int, char *); }; }