diff --git a/src/compute.h b/src/compute.h index 4a678eef65..9b7c161b21 100644 --- a/src/compute.h +++ b/src/compute.h @@ -138,6 +138,17 @@ class Compute : protected Pointers { inline int sbmask(int j) { return j >> SBBITS & 3; } + + // union data struct for packing 32-bit and 64-bit ints into double bufs + // see atom_vec.h for documentation + + union ubuf { + double d; + int64_t i; + ubuf(double arg) : d(arg) {} + ubuf(int64_t arg) : i(arg) {} + ubuf(int arg) : i(arg) {} + }; }; } diff --git a/src/compute_cluster_atom.cpp b/src/compute_cluster_atom.cpp index c217142e33..ba986061bd 100644 --- a/src/compute_cluster_atom.cpp +++ b/src/compute_cluster_atom.cpp @@ -27,6 +27,8 @@ #include "memory.h" #include "error.h" +#include "group.h" + using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ @@ -118,6 +120,13 @@ void ComputeClusterAtom::compute_peratom() numneigh = list->numneigh; firstneigh = list->firstneigh; + // if group is dynamic, insure ghost atom masks are current + + if (group->dynamic[igroup]) { + commflag = 0; + comm->forward_comm_compute(this); + } + // every atom starts in its own cluster, with clusterID = atomID tagint *tag = atom->tag; @@ -136,6 +145,7 @@ void ComputeClusterAtom::compute_peratom() // iterate until no changes in my atoms // then check if any proc made changes + commflag = 1; double **x = atom->x; int change,done,anychange; @@ -191,10 +201,19 @@ int ComputeClusterAtom::pack_comm(int n, int *list, double *buf, int i,j,m; m = 0; - for (i = 0; i < n; i++) { - j = list[i]; - buf[m++] = clusterID[j]; + if (commflag) { + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = clusterID[j]; + } + } else { + int *mask = atom->mask; + for (i = 0; i < n; i++) { + j = list[i]; + buf[m++] = ubuf(mask[j]).d; + } } + return 1; } @@ -206,7 +225,12 @@ void ComputeClusterAtom::unpack_comm(int n, int first, double *buf) m = 0; last = first + n; - for (i = first; i < last; i++) clusterID[i] = buf[m++]; + if (commflag) + for (i = first; i < last; i++) clusterID[i] = buf[m++]; + else { + int *mask = atom->mask; + for (i = first; i < last; i++) mask[i] = (int) ubuf(buf[m++]).i; + } } /* ---------------------------------------------------------------------- diff --git a/src/compute_cluster_atom.h b/src/compute_cluster_atom.h index a88c61b45f..5451f16d0f 100644 --- a/src/compute_cluster_atom.h +++ b/src/compute_cluster_atom.h @@ -36,7 +36,7 @@ class ComputeClusterAtom : public Compute { double memory_usage(); private: - int nmax; + int nmax,commflag; double cutsq; class NeighList *list; double *clusterID; diff --git a/src/fix_group.cpp b/src/fix_group.cpp index 305299830e..49a20bcbb8 100644 --- a/src/fix_group.cpp +++ b/src/fix_group.cpp @@ -187,6 +187,8 @@ void FixGroup::set_group() // set mask for each atom // only in group if in parent group, in region, variable is non-zero + // if compute, fix, etc needs updated masks of ghost atoms, + // it must do forward_comm() to update them double **x = atom->x; int *mask = atom->mask;