Commit ded8b22c authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@4795 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 1d3b3778
Loading
Loading
Loading
Loading
+108 −78
Original line number Diff line number Diff line
@@ -15,10 +15,11 @@
   Contributing authors: Naveen Michaud-Agrawal (Johns Hopkins U)
                         open-source XDR routines from
			   Frans van Hoesel (http://md.chem.rug.nl/hoesel)
			   are also included in this file
                         Axel Kohlmeyer (UPenn)
			   are included in this file
                         Axel Kohlmeyer (Temple U)
                           port to platforms without XDR support
                           added support for unwrapped trajectories
			   support for groups
------------------------------------------------------------------------- */

#include "math.h"
@@ -31,6 +32,7 @@
#include "atom.h"
#include "update.h"
#include "group.h"
#include "output.h"
#include "error.h"
#include "memory.h"

@@ -52,11 +54,12 @@ int xdr3dfcoord(XDR *, float *, int *, float *);
DumpXTC::DumpXTC(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg)
{
  if (narg != 5) error->all("Illegal dump xtc command");
  if (igroup != group->find("all")) error->all("Dump xtc must use group all");
  if (binary || compressed || multifile || multiproc)
    error->all("Invalid dump xtc filename");

  size_one = 4;
  size_one = 3;
  sort_flag = 1;
  sortcol = 0;
  format_default = NULL;
  flush_flag = 0;
  unwrap_flag = 0;
@@ -64,10 +67,10 @@ DumpXTC::DumpXTC(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg)

  // allocate global array for atom coords

  natoms = static_cast<int> (atom->natoms);
  if (igroup == 0) natoms = static_cast<int> (atom->natoms);
  else natoms = static_cast<int> (group->count(igroup));
  if (natoms <= 0) error->all("Invalid natoms for dump xtc");
  if (atom->tag_consecutive() == 0)
    error->all("Atom IDs must be consecutive for dump xtc");

  coords = (float *) memory->smalloc(3*natoms*sizeof(float),"dump:coords");

  // sfactor = conversion of coords to XTC units
@@ -77,6 +80,7 @@ DumpXTC::DumpXTC(LAMMPS *lmp, int narg, char **arg) : Dump(lmp, narg, arg)
  if (strcmp(update->unit_style,"lj") == 0) sfactor = 1.0;

  openfile();
  nevery_save = 0;
  ntotal = 0;
}

@@ -94,45 +98,26 @@ DumpXTC::~DumpXTC()

/* ---------------------------------------------------------------------- */

void DumpXTC::init()
void DumpXTC::init_style()
{
  if (sort_flag == 0 || sortcol != 0)
    error->all("Dump xtc requires sorting by atom ID");

  // check that flush_flag is not set since dump::write() will use it

  if (flush_flag) error->all("Cannot set dump_modify flush for dump xtc");
}

/* ---------------------------------------------------------------------- */
  // check that dump frequency has not changed and is not a variable

int DumpXTC::modify_param(int narg, char **arg)
{
  if (strcmp(arg[0],"unwrap") == 0) {
    if (narg < 2) error->all("Illegal dump_modify command");
    if (strcmp(arg[1],"yes") == 0) unwrap_flag = 1;
    else if (strcmp(arg[1],"no") == 0) unwrap_flag = 0;
    else error->all("Illegal dump_modify command");
    return 2;
  } else if (strcmp(arg[0],"precision") == 0) {
    if (narg < 2) error->all("Illegal dump_modify command");
    precision = atof(arg[1]);
    if ((fabs(precision-10.0) > EPS) && (fabs(precision-100.0) > EPS) && 
	(fabs(precision-1000.0) > EPS) && (fabs(precision-10000.0) > EPS) && 
	(fabs(precision-100000.0) > EPS) && 
	(fabs(precision-1000000.0) > EPS)) 
      error->all("Illegal dump_modify command");
    return 2;
  }
  return 0;
}

/* ----------------------------------------------------------------------
   return # of bytes of allocated memory in buf and global coords array
------------------------------------------------------------------------- */
  int idump;
  for (idump = 0; idump < output->ndump; idump++)
    if (strcmp(id,output->dump[idump]->id) == 0) break;
  if (output->every_dump[idump] == 0)
    error->all("Cannot use variable every setting for dump dcd");

double DumpXTC::memory_usage()
{
  double bytes = maxbuf * sizeof(double);
  bytes += 3*natoms * sizeof(float);
  return bytes;
  if (nevery_save == 0) nevery_save = output->every_dump[idump];
  else if (nevery_save != output->every_dump[idump])
    error->all("Cannot change dump_modify every for dump dcd");
}

/* ---------------------------------------------------------------------- */
@@ -151,13 +136,11 @@ void DumpXTC::openfile()

void DumpXTC::write_header(int n)
{
  // all procs realloc types & coords if necessary
  // all procs realloc coords if total count grew

  if (n != natoms) {
    memory->sfree(coords);
    if (atom->tag_consecutive() == 0)
      error->all("Atom IDs must be consecutive for dump xtc");
    natoms = n;
    memory->sfree(coords);
    coords = (float *) memory->smalloc(3*natoms*sizeof(float),"dump:coords");
  }

@@ -201,21 +184,32 @@ void DumpXTC::write_header(int n)

int DumpXTC::count()
{
  return atom->nlocal;
  if (igroup == 0) return atom->nlocal;

  int *mask = atom->mask;
  int nlocal = atom->nlocal;

  int m = 0;
  for (int i = 0; i < nlocal; i++)
    if (mask[i] & groupbit) m++;
  return m;
}

/* ---------------------------------------------------------------------- */

int DumpXTC::pack()
void DumpXTC::pack(int *ids)
{
  int m,n;

  int *tag = atom->tag;
  double **x = atom->x;
  int *image = atom->image;
  int *mask = atom->mask;
  int nlocal = atom->nlocal;

  // assume group all, so no need to perform mask check

  int m = 0;
  m = n = 0;
  if (unwrap_flag == 1) {
    double xprd = domain->xprd;
    double yprd = domain->yprd;
@@ -224,7 +218,8 @@ int DumpXTC::pack()
    double xz = domain->xz;
    double yz = domain->yz;

    for (int i = 0; i < nlocal; i++) {
    for (int i = 0; i < nlocal; i++)
      if (mask[i] & groupbit) {
	int ix = (image[i] & 1023) - 512;
	int iy = (image[i] >> 10 & 1023) - 512;
	int iz = (image[i] >> 20) - 512;
@@ -240,39 +235,40 @@ int DumpXTC::pack()
	  buf[m++] = sfactor * (x[i][1] + iy * yprd);
	  buf[m++] = sfactor * (x[i][2] + iz * zprd);
	}
	ids[n++] = tag[i];
      }

  } else {
    for (int i = 0; i < nlocal; i++) {
    for (int i = 0; i < nlocal; i++)
      if (mask[i] & groupbit) {
	buf[m++] = tag[i];
	buf[m++] = sfactor*x[i][0];
	buf[m++] = sfactor*x[i][1];
	buf[m++] = sfactor*x[i][2];
	ids[n++] = tag[i];
      }
  }

  return m;
}

/* ---------------------------------------------------------------------- */

void DumpXTC::write_data(int n, double *mybuf)
{
  float *xyz;
  int j,tag;
  int j;

  // copy buf atom coords into global array

  int m = 0;
  int k = 3*ntotal;
  for (int i = 0; i < n; i++) {
    tag = static_cast<int> (mybuf[m]) - 1;
    j = 3*tag;
    coords[j++] = mybuf[m+1];
    coords[j++] = mybuf[m+2];
    coords[j] = mybuf[m+3];
    m += size_one;
    coords[k++] = mybuf[m++];
    coords[k++] = mybuf[m++];
    coords[k++] = mybuf[m++];
    ntotal++;
  }

  // if last chunk of atoms in this snapshot, write global arrays to file

  ntotal += n;
  if (ntotal == natoms) {
    write_frame();
    ntotal = 0;
@@ -281,6 +277,40 @@ void DumpXTC::write_data(int n, double *mybuf)

/* ---------------------------------------------------------------------- */

int DumpXTC::modify_param(int narg, char **arg)
{
  if (strcmp(arg[0],"unwrap") == 0) {
    if (narg < 2) error->all("Illegal dump_modify command");
    if (strcmp(arg[1],"yes") == 0) unwrap_flag = 1;
    else if (strcmp(arg[1],"no") == 0) unwrap_flag = 0;
    else error->all("Illegal dump_modify command");
    return 2;
  } else if (strcmp(arg[0],"precision") == 0) {
    if (narg < 2) error->all("Illegal dump_modify command");
    precision = atof(arg[1]);
    if ((fabs(precision-10.0) > EPS) && (fabs(precision-100.0) > EPS) && 
	(fabs(precision-1000.0) > EPS) && (fabs(precision-10000.0) > EPS) && 
	(fabs(precision-100000.0) > EPS) && 
	(fabs(precision-1000000.0) > EPS)) 
      error->all("Illegal dump_modify command");
    return 2;
  }
  return 0;
}

/* ----------------------------------------------------------------------
   return # of bytes of allocated memory in buf and global coords array
------------------------------------------------------------------------- */

double DumpXTC::memory_usage()
{
  double bytes = Dump::memory_usage();
  bytes += 3*natoms * sizeof(float);
  return bytes;
}

/* ---------------------------------------------------------------------- */

void DumpXTC::write_frame()
{
  xdr3dfcoord(&xd,coords,&natoms,&precision);
+4 −3
Original line number Diff line number Diff line
@@ -35,23 +35,24 @@ class DumpXTC : public Dump {
 public:
  DumpXTC(class LAMMPS *, int, char**);
  ~DumpXTC();
  void init();
  double memory_usage();
	
 private:
  int natoms,ntotal;
  int nevery_save;
  int unwrap_flag;            // 1 if atom coords are unwrapped, 0 if no
  float precision;            // user-adjustable precision setting
  float *coords;
  double sfactor;
  XDR xd;

  void init_style();
  int modify_param(int, char **);
  void openfile();
  void write_header(int);
  int count();
  int pack();
  void pack(int *);
  void write_data(int, double *);
  double memory_usage();

  void write_frame();
};
+5 −0
Original line number Diff line number Diff line
@@ -60,6 +60,11 @@ extern "C" {

typedef int bool_t;

#if defined(__MINGW32_VERSION)
typedef char * caddr_t;
typedef unsigned int u_int;
#endif

/* 
 * Aninteger type that is 32 bits wide. Check if int,
 * long or short is 32 bits and die if none of them is :-)
+311 −72
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "stdio.h"
#include "dump.h"
#include "atom.h"
#include "irregular.h"
#include "update.h"
#include "domain.h"
#include "group.h"
@@ -26,6 +27,17 @@

using namespace LAMMPS_NS;

// allocate space for static class variable

Dump *Dump::dumpptr;

#define BIG 1.0e20
#define IBIG 2147483647
#define EPSILON 1.0e-6

#define MIN(A,B) ((A) < (B)) ? (A) : (B)
#define MAX(A,B) ((A) > (B)) ? (A) : (B)

/* ---------------------------------------------------------------------- */

Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
@@ -56,8 +68,10 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
  sort_flag = 0;
  append_flag = 0;

  maxbuf = 0;
  buf = NULL;
  maxbuf = maxsort = maxproc = 0;
  buf = bufsort = NULL;
  idsort = index = proclist = NULL;
  irregular = NULL;

  // parse filename for special syntax
  // if contains '%', write one file per proc and replace % with proc-ID
@@ -108,6 +122,11 @@ Dump::~Dump()
  delete [] format_user;

  memory->sfree(buf);
  memory->sfree(bufsort);
  memory->sfree(idsort);
  memory->sfree(index);
  memory->sfree(proclist);
  delete irregular;

  // XTC style sets fp to NULL since it closes file in its destructor

@@ -124,6 +143,36 @@ Dump::~Dump()

/* ---------------------------------------------------------------------- */

void Dump::init()
{
  init_style();

  if (!sort_flag) {
    memory->sfree(buf);
    memory->sfree(bufsort);
    memory->sfree(idsort);
    memory->sfree(index);
    memory->sfree(proclist);
    delete irregular;

    maxbuf = maxsort = maxproc = 0;
    buf = bufsort = NULL;
    idsort = index = proclist = NULL;
    irregular = NULL;
  }

  if (sort_flag && sortcol == 0 && atom->tag_enable == 0)
      error->all("Cannot use dump sort on atom IDs with no atom IDs defined");

  if (sort_flag && sortcol > size_one)
    error->all("Dump sort column is invalid");

  if (sort_flag && nprocs > 1 && irregular == NULL)
    irregular = new Irregular(lmp);
}

/* ---------------------------------------------------------------------- */

void Dump::write()
{
  // if file per timestep, open new file
@@ -152,11 +201,12 @@ void Dump::write()
  }

  // nme = # of dump lines this proc will contribute to dump

  nme = count();

  // ntotal = total # of dump lines
  // nmax = max # of dump lines on any proc

  int nme = count();

  int ntotal,nmax;
  if (multiproc) nmax = nme;
  else {
@@ -169,25 +219,31 @@ void Dump::write()
  if (multiproc) write_header(nme);
  else write_header(ntotal);

  // grow communication buffer if necessary
  // pack my data into buf
  // if sorting on IDs also request ID list from pack()
  // sort buf as needed

  if (nmax*size_one > maxbuf) {
    maxbuf = nmax*size_one;
  if (nmax > maxbuf) {
    maxbuf = nmax;
    memory->sfree(buf);
    buf = (double *) memory->smalloc(maxbuf*sizeof(double),"dump:buf");
    buf = (double *) 
      memory->smalloc(maxbuf*size_one*sizeof(double),"dump:buf");
    if (sort_flag && sortcol == 0) {
      memory->sfree(ids);
      ids = (int *) memory->smalloc(maxbuf*sizeof(int),"dump:ids");
    }
  }

  // pack my data into buf
  // me_size = # of quantities in buf

  int me_size = pack();
  if (sort_flag && sortcol == 0) pack(ids);
  else pack(NULL);
  if (sort_flag) sort();

  // multiproc = 1 = each proc writes own data to own file 
  // multiproc = 0 = all procs write to one file thru proc 0
  //   proc 0 pings each proc, receives it's data, writes to file
  //   all other procs wait for ping, send their data to proc 0

  if (multiproc) write_data(me_size/size_one,buf);
  if (multiproc) write_data(nme,buf);
  else {
    int tmp,nlines;
    MPI_Status status;
@@ -201,7 +257,7 @@ void Dump::write()
	  MPI_Wait(&request,&status);
	  MPI_Get_count(&status,MPI_DOUBLE,&nlines);
	  nlines /= size_one;
	} else nlines = me_size/size_one;
	} else nlines = nme;

	write_data(nlines,buf);
      }
@@ -209,7 +265,7 @@ void Dump::write()
      
    } else {
      MPI_Recv(&tmp,0,MPI_INT,0,0,world,&status);
      MPI_Rsend(buf,me_size,MPI_DOUBLE,0,0,world);
      MPI_Rsend(buf,nme*size_one,MPI_DOUBLE,0,0,world);
    }
  }

@@ -226,6 +282,229 @@ void Dump::write()
  }
}

/* ----------------------------------------------------------------------
   generic opening of a dump file
   ASCII or binary or gzipped
   some derived classes override this function
------------------------------------------------------------------------- */

void Dump::openfile()
{
  // single file, already opened, so just return

  if (singlefile_opened) return;
  if (multifile == 0) singlefile_opened = 1;

  // if one file per timestep, replace '*' with current timestep

  char *filecurrent;
  if (multifile == 0) filecurrent = filename;
  else {
    filecurrent = new char[strlen(filename) + 16];
    char *ptr = strchr(filename,'*');
    *ptr = '\0';
    sprintf(filecurrent,"%s%d%s",filename,update->ntimestep,ptr+1);
    *ptr = '*';
  }

  // open one file on proc 0 or file on every proc

  if (me == 0 || multiproc) {
    if (compressed) {
#ifdef LAMMPS_GZIP
      char gzip[128];
      sprintf(gzip,"gzip -6 > %s",filecurrent);
      fp = popen(gzip,"w");
#else
      error->one("Cannot open gzipped file");
#endif
    } else if (binary) {
      fp = fopen(filecurrent,"wb");
    } else if (append_flag) {
      fp = fopen(filecurrent,"a");
    } else {
      fp = fopen(filecurrent,"w");
    }

    if (fp == NULL) error->one("Cannot open dump file");
  } else fp = NULL;

  // delete string with timestep replaced

  if (multifile) delete [] filecurrent;
}

/* ----------------------------------------------------------------------
   parallel sort of buf across all procs
   changes nme, reorders datums in buf, grows buf if necessary
------------------------------------------------------------------------- */

void Dump::sort()
{
  int i,iproc;
  double value;

  // if single proc, swap ptrs to buf,ids <-> bufsort,idsort

  if (nprocs == 1) {
    if (nme > maxsort) {
      maxsort = nme;
      memory->sfree(bufsort);
      bufsort = (double *)
	memory->smalloc(maxsort*size_one*sizeof(double),"dump:bufsort");
      memory->sfree(index);
      index = (int *) memory->smalloc(maxsort*sizeof(int),"dump:index");
      if (sortcol == 0) {
	memory->sfree(idsort);
	idsort = (int *) memory->smalloc(maxsort*sizeof(int),"dump:idsort");
      }
    }

    double *dptr = buf;
    buf = bufsort;
    bufsort = dptr;

    if (sortcol == 0) {
      int *iptr = ids;
      ids = idsort;
      idsort = iptr;
    }

  // if multiple procs, exchange datums between procs via irregular
    
  } else {

    // grow proclist if necessary

    if (nme > maxproc) {
      maxproc = nme;
      memory->sfree(proclist);
      proclist = (int *) memory->smalloc(maxproc*sizeof(int),"dump:proclist");
    }
    
    // proclist[i] = which proc Ith datum will be sent to

    if (sortcol == 0) {
      int min = IBIG;
      int max = 0;
      for (i = 0; i < nme; i++) {
	min = MIN(min,ids[i]);
	max = MAX(max,ids[i]);
      }
      int minall,maxall;
      MPI_Allreduce(&min,&minall,1,MPI_INT,MPI_MIN,world);
      MPI_Allreduce(&max,&maxall,1,MPI_INT,MPI_MAX,world);
      double range = maxall - minall + 0.1;
      for (i = 0; i < nme; i++) {
	iproc = static_cast<int> ((ids[i]-minall)/range * nprocs);
	proclist[i] = iproc;
      }

    } else {
      double min = BIG;
      double max = -BIG;
      for (i = 0; i < nme; i++) {
	value = buf[i*size_one + sortcolm1];
	min = MIN(min,value);
	max = MAX(max,value);
      }
      double minall,maxall;
      MPI_Allreduce(&min,&minall,1,MPI_DOUBLE,MPI_MIN,world);
      MPI_Allreduce(&max,&maxall,1,MPI_DOUBLE,MPI_MAX,world);
      double range = maxall-minall + EPSILON*(maxall-minall);
      if (range == 0.0) range = EPSILON;
      for (i = 0; i < nme; i++) {
	value = buf[i*size_one + sortcolm1];
	iproc = static_cast<int> ((value-minall)/range * nprocs);
	proclist[i] = iproc;
      }
    }

    // create comm plan, grow recv bufs if necessary,
    // exchange datums, destroy plan
    // if sorting on atom IDs, exchange IDs also

    nme = irregular->create_data(nme,proclist);

    if (nme > maxsort) {
      maxsort = nme;
      memory->sfree(bufsort);
      bufsort = (double *) 
	memory->smalloc(maxsort*size_one*sizeof(double),"dump:bufsort");
      memory->sfree(index);
      index = (int *) memory->smalloc(maxsort*sizeof(int),"dump:index");
      if (sortcol == 0) {
	memory->sfree(idsort);
	idsort = (int *) memory->smalloc(maxsort*sizeof(int),"dump:idsort");
      }
    }
    
    irregular->exchange_data((char *) buf,size_one*sizeof(double),
			     (char *) bufsort);
    if (sortcol == 0) 
      irregular->exchange_data((char *) ids,sizeof(int),(char *) idsort);
    irregular->destroy_data();
  }

  // quicksort indices using IDs or buf column as comparator

  dumpptr = this;
  for (i = 0; i < nme; i++) index[i] = i;
  if (sortcol == 0) qsort(index,nme,sizeof(int),idcompare);
  else qsort(index,nme,sizeof(int),bufcompare);

  // copy data from bufsort to buf using index

  if (nme > maxbuf) {
    maxbuf = nme;
    memory->sfree(buf);
    buf = (double *) 
      memory->smalloc(maxbuf*size_one*sizeof(double),"dump:buf");
  }
    
  int nbytes = size_one*sizeof(double);
  for (i = 0; i < nme; i++)
    memcpy(&buf[i*size_one],&bufsort[index[i]*size_one],nbytes);
}

/* ----------------------------------------------------------------------
   compare two atom IDs in sort data structure
   called via qsort_r in sort() method
   is a static method so access sort data structure via ptr
------------------------------------------------------------------------- */

int Dump::idcompare(const void *pi, const void *pj)
{
  int *idsort = dumpptr->idsort;

  int i = *((int *) pi);
  int j = *((int *) pj);

  if (idsort[i] < idsort[j]) return -1;
  if (idsort[i] > idsort[j]) return 1;
  return 0;
}

/* ----------------------------------------------------------------------
   compare two buffer quantities in sort data structure with size_one stride
   called via qsort_r in sort() method
   is a static method so access sort data structure via ptr
------------------------------------------------------------------------- */

int Dump::bufcompare(const void *pi, const void *pj)
{
  double *bufsort = dumpptr->bufsort;
  int size_one = dumpptr->size_one;
  int sortcolm1 = dumpptr->sortcolm1;

  int i = *((int *) pi)*size_one + sortcolm1;
  int j = *((int *) pj)*size_one + sortcolm1;

  if (bufsort[i] < bufsort[j]) return -1;
  if (bufsort[i] > bufsort[j]) return 1;
  return 0;
}

/* ----------------------------------------------------------------------
   process params common to all dumps here
   if unknown param, call modify_param specific to the dump
@@ -285,9 +564,13 @@ void Dump::modify_params(int narg, char **arg)
      iarg += 2;
    } else if (strcmp(arg[iarg],"sort") == 0) {
      if (iarg+2 > narg) error->all("Illegal dump_modify command");
      if (strcmp(arg[iarg+1],"yes") == 0) sort_flag = 1;
      else if (strcmp(arg[iarg+1],"no") == 0) sort_flag = 0;
      else error->all("Illegal dump_modify command");
      if (strcmp(arg[iarg+1],"off") == 0) sort_flag = 0;
      else {
	sort_flag = 1;
	sortcol = atoi(arg[iarg+1]);
	if (sortcol < 0) error->all("Illegal dump_modify command");
	sortcolm1 = sortcol - 1;
      }
      iarg += 2;
    } else {
      int n = modify_param(narg-iarg,&arg[iarg]);
@@ -298,63 +581,19 @@ void Dump::modify_params(int narg, char **arg)
}

/* ----------------------------------------------------------------------
   return # of bytes of allocated memory in buf
   return # of bytes of allocated memory
------------------------------------------------------------------------- */

double Dump::memory_usage()
{
  double bytes = maxbuf * sizeof(double);
  return bytes;
}

/* ----------------------------------------------------------------------
   generic opening of a dump file
   ASCII or binary or gzipped
   some derived classes override this function
------------------------------------------------------------------------- */

void Dump::openfile()
{
  // single file, already opened, so just return

  if (singlefile_opened) return;
  if (multifile == 0) singlefile_opened = 1;

  // if one file per timestep, replace '*' with current timestep

  char *filecurrent;
  if (multifile == 0) filecurrent = filename;
  else {
    filecurrent = new char[strlen(filename) + 16];
    char *ptr = strchr(filename,'*');
    *ptr = '\0';
    sprintf(filecurrent,"%s%d%s",filename,update->ntimestep,ptr+1);
    *ptr = '*';
  }

  // open one file on proc 0 or file on every proc

  if (me == 0 || multiproc) {
    if (compressed) {
#ifdef LAMMPS_GZIP
      char gzip[128];
      sprintf(gzip,"gzip -6 > %s",filecurrent);
      fp = popen(gzip,"w");
#else
      error->one("Cannot open gzipped file");
#endif
    } else if (binary) {
      fp = fopen(filecurrent,"wb");
    } else if (append_flag) {
      fp = fopen(filecurrent,"a");
    } else {
      fp = fopen(filecurrent,"w");
  double bytes = maxbuf*size_one * sizeof(double);
  if (sort_flag) {
    if (sortcol == 0) bytes += maxbuf * sizeof(int);    // ids
    bytes += maxsort*size_one * sizeof(double);         // bufsort
    bytes += maxsort * sizeof(int);                     // index
    if (sortcol == 0) bytes += maxsort * sizeof(int);   // idsort
    bytes += maxproc * sizeof(int);                     // proclist
    if (irregular) bytes += irregular->memory_usage();
  }

    if (fp == NULL) error->one("Cannot open dump file");
  } else fp = NULL;

  // delete string with timestep replaced

  if (multifile) delete [] filecurrent;
  return bytes;
}
+36 −15
Original line number Diff line number Diff line
@@ -24,6 +24,22 @@ class Dump : protected Pointers {
  char *id;                  // user-defined name of Dump
  char *style;               // style of Dump
  int igroup,groupbit;       // group that Dump is performed on

  int first_flag;            // 0 if no initial dump, 1 if yes initial dump
  int clearstep;             // 1 if dump invokes computes, 0 if not

  // static variable across all Dump objects

  static Dump *dumpptr;         // holds a ptr to Dump currently being used

  Dump(class LAMMPS *, int, char **);
  virtual ~Dump();
  void init();
  void write();
  void modify_params(int, char **);
  virtual double memory_usage();

 protected:
  int me,nprocs;             // proc info

  char *filename;            // user-specified file
@@ -33,41 +49,46 @@ class Dump : protected Pointers {
  int multiproc;             // 0 = proc 0 writes for all, 1 = one file/proc

  int header_flag;           // 0 = item, 2 = xyz
  int first_flag;            // 0 if no initial dump, 1 if yes initial dump
  int flush_flag;            // 0 if no flush, 1 if flush every dump
  int sort_flag;             // 1 if write in sorted order, 0 if not
  int sort_flag;             // 1 if sorted output
  int append_flag;           // 1 if open file in append mode, 0 if not
  int singlefile_opened;     // 1 = one big file, already opened, else 0
  int clearstep;             // 1 if dump invokes computes, 0 if not
  int sortcol;               // 0 to sort on ID, 1-N on columns
  int sortcolm1;             // sortcol - 1

  char *format_default;      // default format string
  char *format_user;         // format string set by user
  char *format;              // format string for the file write
  double *buf;               // memory for atom quantities
  int maxbuf;                // size of buf
  FILE *fp;                  // file to write dump to
  int size_one;              // # of quantities for one atom
  int nme;                   // # of atoms in this dump from me

  Dump(class LAMMPS *, int, char **);
  virtual ~Dump();
  virtual void init() {}
  void write();
  void modify_params(int, char **);
  virtual double memory_usage();

 protected:
  double boxxlo,boxxhi;      // local copies of domain values
  double boxylo,boxyhi;      // lo/hi are bounding box for triclinic
  double boxzlo,boxzhi;
  double boxxy,boxxz,boxyz;

  int maxbuf;                // size of buf and ids
  int maxsort;               // size of bufsort, idsort, index
  int maxproc;               // size of proclist
  double *buf;               // memory for atom quantities
  int *ids;                  // list of atom IDs, if sorting on IDs
  double *bufsort;
  int *idsort,*index,*proclist;

  class Irregular *irregular;

  virtual void init_style() = 0;
  virtual void openfile();
  virtual int modify_param(int, char **) {return 0;}

  virtual void write_header(int) = 0;
  virtual int count() = 0;
  virtual int pack() = 0;
  virtual void pack(int *) = 0;
  virtual void write_data(int, double *) = 0;

  void sort();
  static int idcompare(const void *, const void *);
  static int bufcompare(const void *, const void *);
};

}
Loading