diff --git a/src/dump.cpp b/src/dump.cpp index ac69c43d10..8849282bb9 100644 --- a/src/dump.cpp +++ b/src/dump.cpp @@ -81,7 +81,8 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) buffer_allow = 0; buffer_flag = 0; padflag = 0; - + pbcflag = 0; + maxbuf = maxids = maxsort = maxproc = 0; buf = bufsort = NULL; ids = idsort = NULL; @@ -91,6 +92,10 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) maxsbuf = 0; sbuf = NULL; + maxpbc = 0; + xpbc = vpbc = NULL; + imagepbc = NULL; + // parse filename for special syntax // if contains '%', write one file per proc and replace % with proc-ID // if contains '*', write one file per timestep and replace * with timestep @@ -163,7 +168,13 @@ Dump::~Dump() delete irregular; memory->destroy(sbuf); - + + if (pbcflag) { + memory->destroy(xpbc); + memory->destroy(vpbc); + memory->destroy(imagepbc); + } + if (multiproc) MPI_Comm_free(&clustercomm); // XTC style sets fp to NULL since it closes file in its destructor @@ -262,6 +273,10 @@ void Dump::init() } } } + + // preallocation for PBC copies if requested + + if (pbcflag && atom->nlocal > maxpbc) pbc_allocate(); } /* ---------------------------------------------------------------------- */ @@ -352,6 +367,28 @@ void Dump::write() memory->create(ids,maxids,"dump:ids"); } + // apply PBC on copy of x,v,image if requested + + if (pbcflag) { + int nlocal = atom->nlocal; + if (nlocal > maxpbc) pbc_allocate(); + if (nlocal) { + memcpy(&xpbc[0][0],&atom->x[0][0],3*nlocal*sizeof(double)); + memcpy(&vpbc[0][0],&atom->v[0][0],3*nlocal*sizeof(double)); + memcpy(imagepbc,atom->image,nlocal*sizeof(imageint)); + } + double **dtmp = atom->x; + atom->x = xpbc; + xpbc = dtmp; + dtmp = atom->v; + atom->v = vpbc; + vpbc = dtmp; + imageint *itmp = atom->image; + atom->image = imagepbc; + imagepbc = itmp; + domain->pbc(); + } + // pack my data into buf // if sorting on IDs also request ID list from pack() // sort buf as needed @@ -430,6 +467,20 @@ void Dump::write() } } + // restore original x,v,image unaltered by PBC + + if (pbcflag) { + double **dtmp = atom->x; + atom->x = xpbc; + xpbc = dtmp; + dtmp = atom->v; + atom->v = vpbc; + vpbc = dtmp; + imageint *itmp = atom->image; + atom->image = imagepbc; + imagepbc = itmp; + } + // if file per timestep, close file if I am filewriter if (multifile) { @@ -887,6 +938,13 @@ void Dump::modify_params(int narg, char **arg) if (padflag < 0) error->all(FLERR,"Illegal dump_modify command"); iarg += 2; + } else if (strcmp(arg[iarg],"pbc") == 0) { + if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command"); + if (strcmp(arg[iarg+1],"yes") == 0) pbcflag = 1; + else if (strcmp(arg[iarg+1],"no") == 0) pbcflag = 0; + else error->all(FLERR,"Illegal dump_modify command"); + iarg += 2; + } else if (strcmp(arg[iarg],"sort") == 0) { if (iarg+2 > narg) error->all(FLERR,"Illegal dump_modify command"); if (strcmp(arg[iarg+1],"off") == 0) sort_flag = 0; @@ -919,6 +977,21 @@ void Dump::modify_params(int narg, char **arg) return # of bytes of allocated memory ------------------------------------------------------------------------- */ +void Dump::pbc_allocate() +{ + memory->destroy(xpbc); + memory->destroy(vpbc); + memory->destroy(imagepbc); + maxpbc = atom->nmax; + memory->create(xpbc,maxpbc,3,"dump:xbpc"); + memory->create(vpbc,maxpbc,3,"dump:vbpc"); + memory->create(imagepbc,maxpbc,"dump:imagebpc"); +} + +/* ---------------------------------------------------------------------- + return # of bytes of allocated memory +------------------------------------------------------------------------- */ + bigint Dump::memory_usage() { bigint bytes = memory->usage(buf,size_one*maxbuf); @@ -931,5 +1004,9 @@ bigint Dump::memory_usage() bytes += memory->usage(proclist,maxproc); if (irregular) bytes += irregular->memory_usage(); } + if (pbcflag) { + bytes += 6*maxpbc * sizeof(double); + bytes += maxpbc * sizeof(imageint); + } return bytes; } diff --git a/src/dump.h b/src/dump.h index dbcf8547fe..e92d048b9d 100644 --- a/src/dump.h +++ b/src/dump.h @@ -71,6 +71,7 @@ class Dump : protected Pointers { int buffer_allow; // 1 if style allows for buffer_flag, 0 if not int buffer_flag; // 1 if buffer output as one big string, 0 if not int padflag; // timestep padding in filename + int pbcflag; // 1 if remap dumped atoms via PBC, 0 if not int singlefile_opened; // 1 = one big file, already opened, else 0 int sortcol; // 0 to sort on ID, 1-N on columns int sortcolm1; // sortcol - 1 @@ -116,6 +117,10 @@ class Dump : protected Pointers { tagint *idsort; int *index,*proclist; + double **xpbc,**vpbc; + int *imagepbc; + int maxpbc; + class Irregular *irregular; virtual void init_style() = 0; @@ -126,7 +131,8 @@ class Dump : protected Pointers { virtual void pack(tagint *) = 0; virtual int convert_string(int, double *) {return 0;} virtual void write_data(int, double *) = 0; - + void pbc_allocate(); + void sort(); static int idcompare(const void *, const void *); static int bufcompare(const void *, const void *);