Commit 6888a80d authored by sjplimp's avatar sjplimp
Browse files

git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15740 f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent 59215db1
Loading
Loading
Loading
Loading
+147 −25
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "modify.h"
#include "compute.h"
#include "fix.h"
#include "fix_store.h"
#include "memory.h"
#include "error.h"

@@ -82,10 +83,17 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
  buffer_flag = 1;
  iregion = -1;
  idregion = NULL;

  nthresh = 0;
  thresh_array = NULL;
  thresh_op = NULL;
  thresh_value = NULL;
  thresh_last = NULL;

  nthreshlast = 0;
  thresh_fix = NULL;
  thresh_fixID = NULL;
  thresh_first = NULL;

  // computes, fixes, variables which the dump accesses

@@ -193,6 +201,17 @@ DumpCustom::~DumpCustom()
  memory->destroy(thresh_array);
  memory->destroy(thresh_op);
  memory->destroy(thresh_value);
  memory->destroy(thresh_last);

  // check nfix in case all fixes have already been deleted

  for (int i = 0; i < nthreshlast; i++) {
    if (modify->nfix) modify->delete_fix(thresh_fixID[i]);
    delete [] thresh_fixID[i];
  }
  memory->sfree(thresh_fix);
  memory->sfree(thresh_fixID);
  memory->destroy(thresh_first);

  for (int i = 0; i < ncompute; i++) delete [] id_compute[i];
  memory->sfree(id_compute);
@@ -498,9 +517,10 @@ int DumpCustom::count()
  // un-choose if any threshold criterion isn't met

  if (nthresh) {
    double *ptr;
    double *ptr,*ptrhold;
    double *values;
    double value;
    int nstride;
    int nstride,lastflag;
    int nlocal = atom->nlocal;

    for (int ithresh = 0; ithresh < nthresh; ithresh++) {
@@ -926,34 +946,93 @@ int DumpCustom::count()
      }

      // unselect atoms that don't meet threshold criterion
      // compare to single value or values stored in threshfix
      // copy ptr attribute into thresh_fix if this is first comparison

      if (thresh_last[ithresh] < 0) {
	lastflag = 0;
	value = thresh_value[ithresh];
      } else {
	lastflag = 1;
	int ilast = thresh_last[ithresh];
	values = thresh_fix[ilast]->vstore;
	ptrhold = ptr;
	if (thresh_first[ilast]) {
	  thresh_first[ilast] = 0;
	  for (i = 0; i < nlocal; i++, ptr += nstride) values[i] = *ptr;
	  ptr = ptrhold;
	}
      }

      if (thresh_op[ithresh] == LT) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr >= values[i]) choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr >= value) choose[i] = 0;
	}
      } else if (thresh_op[ithresh] == LE) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr > values[i]) choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr > value) choose[i] = 0;
	}
      } else if (thresh_op[ithresh] == GT) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr <= values[i]) choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr <= value) choose[i] = 0;
	}
      } else if (thresh_op[ithresh] == GE) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr < values[i]) choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr < value) choose[i] = 0;
	}
      } else if (thresh_op[ithresh] == EQ) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr != values[i]) choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr != value) choose[i] = 0;
	}
      } else if (thresh_op[ithresh] == NEQ) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr == values[i]) choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && *ptr == value) choose[i] = 0;
	}
      } else if (thresh_op[ithresh] == XOR) {
	if (lastflag) {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && (*ptr == 0.0 && values[i] == 0.0) || 
		(*ptr != 0.0 && values[i] != 0.0))
	      choose[i] = 0;
	} else {
	  for (i = 0; i < nlocal; i++, ptr += nstride)
	    if (choose[i] && (*ptr == 0.0 && value == 0.0) || 
		(*ptr != 0.0 && value != 0.0))
	      choose[i] = 0;
	}
      }

      // update values stored in threshfix

      if (lastflag) {
	ptr = ptrhold;
	for (i = 0; i < nlocal; i++, ptr += nstride) values[i] = *ptr;
      }
    }
  }

  // compress choose flags into clist
@@ -1594,8 +1673,16 @@ int DumpCustom::modify_param(int narg, char **arg)
        thresh_array = NULL;
        thresh_op = NULL;
        thresh_value = NULL;
        thresh_last = NULL;
	for (int i = 0; i < nthreshlast; i++) {
	  modify->delete_fix(thresh_fixID[i]);
	  delete [] thresh_fixID[i];
	}
      nthresh = 0;
	thresh_fix = NULL;
	thresh_fixID = NULL;
        thresh_first = NULL;
      }
      nthresh = nthreshlast = 0;
      return 2;
    }

@@ -1606,6 +1693,7 @@ int DumpCustom::modify_param(int narg, char **arg)
    memory->grow(thresh_array,nthresh+1,"dump:thresh_array");
    memory->grow(thresh_op,(nthresh+1),"dump:thresh_op");
    memory->grow(thresh_value,(nthresh+1),"dump:thresh_value");
    memory->grow(thresh_last,(nthresh+1),"dump:thresh_last");
    
    // set attribute type of threshold
    // customize by adding to if statement
@@ -1830,7 +1918,7 @@ int DumpCustom::modify_param(int narg, char **arg)
      field2index[nfield+nthresh] = add_custom(suffix,0);
      delete [] suffix;

    } else error->all(FLERR,"Invalid dump_modify threshhold operator");
    } else error->all(FLERR,"Invalid dump_modify threshold operator");

    // set operation type of threshold

@@ -1843,9 +1931,43 @@ int DumpCustom::modify_param(int narg, char **arg)
    else if (strcmp(arg[2],"|^") == 0) thresh_op[nthresh] = XOR;
    else error->all(FLERR,"Invalid dump_modify threshold operator");

    // set threshold value
    // set threshold value as number or special LAST keyword
    // create FixStore to hold LAST values, should work with restart
    // id = dump-ID + nthreshlast + DUMP_STORE, fix group = dump group

    if (strcmp(arg[3],"LAST") != 0) {
      thresh_value[nthresh] = force->numeric(FLERR,arg[3]);
      thresh_last[nthresh] = -1;
    } else {
      thresh_fix = (FixStore **) 
	memory->srealloc(thresh_fix,(nthreshlast+1)*sizeof(FixStore *),
			 "dump:thresh_fix");
      thresh_fixID = (char **)
	memory->srealloc(thresh_fixID,(nthreshlast+1)*sizeof(char *),
			 "dump:thresh_fixID");
      memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first");

      int n = strlen(id) + strlen("_DUMP_STORE") + 8;
      thresh_fixID[nthreshlast] = new char[n];
      strcpy(thresh_fixID[nthreshlast],id);
      sprintf(&thresh_fixID[nthreshlast][strlen(id)],"%d",nthreshlast);
      strcat(thresh_fixID[nthreshlast],"_DUMP_STORE");

      char **newarg = new char*[6];
      newarg[0] = thresh_fixID[nthreshlast];
      newarg[1] = group->names[igroup];
      newarg[2] = (char *) "STORE";
      newarg[3] = (char *) "peratom";
      newarg[4] = (char *) "1";
      newarg[5] = (char *) "1";
      modify->add_fix(6,newarg);
      thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1];
      delete [] newarg;

      thresh_last[nthreshlast] = nthreshlast;
      thresh_first[nthreshlast] = 1;
      nthreshlast++;
    }

    nthresh++;
    return 4;
+18 −8
Original line number Diff line number Diff line
@@ -33,10 +33,20 @@ class DumpCustom : public Dump {
  int nevery;                // dump frequency for output
  int iregion;               // -1 if no region, else which region
  char *idregion;            // region ID
  int nthresh;               // # of defined threshholds
  int *thresh_array;         // array to threshhhold on for each nthresh
  int *thresh_op;            // threshhold operation for each nthresh
  double *thresh_value;      // threshhold value for each nthresh

  int nthresh;               // # of defined thresholds
  int nthreshlast;           // # of defined thresholds with value = LAST

  int *thresh_array;         // array to threshold on for each nthresh
  int *thresh_op;            // threshold operation for each nthresh
  double *thresh_value;      // threshold value for each nthresh
  int *thresh_last;          // for threshold value = LAST,
                             // index into thresh_fix
                             // -1 if not LAST, value is numeric

  class FixStore **thresh_fix;  // stores values for each threshold LAST
  char **thresh_fixID;          // IDs of thresh_fixes
  int *thresh_first;            // 1 the first time a FixStore values accessed

  int expand;                // flag for whether field args were expanded
  char **earg;               // field names with wildcard expansion
@@ -50,7 +60,7 @@ class DumpCustom : public Dump {
  int nchoose;               // # of selected atoms
  int maxlocal;              // size of atom selection and variable arrays
  int *choose;               // local indices of selected atoms
  double *dchoose;           // value for each atom to threshhold against
  double *dchoose;           // value for each atom to threshold against
  int *clist;                // compressed list of indices of selected atoms

  int nfield;                // # of keywords listed by user
@@ -233,9 +243,9 @@ E: Compute used in dump between runs is not current
The compute was not invoked on the current timestep, therefore it
cannot be used in a dump between runs.

E: Threshhold for an atom property that isn't allocated
E: Threshold for an atom property that isn't allocated

A dump threshhold has been requested on a quantity that is
A dump threshold has been requested on a quantity that is
not defined by the atom style used in this simulation.

E: Dumping an atom property that isn't allocated
@@ -362,7 +372,7 @@ E: Could not find dump modify custom atom integer property ID

Self-explanatory.

E: Invalid dump_modify threshhold operator
E: Invalid dump_modify threshold operator

Operator keyword used for threshold specification in not recognized.

+3 −0
Original line number Diff line number Diff line
@@ -154,6 +154,9 @@ void FixStore::reset_global(int nrow_caller, int ncol_caller)
  if (vecflag) memory->create(vstore,nrow,"fix/store:vstore");
  else memory->create(astore,nrow,ncol,"fix/store:astore");
  memory->create(rbuf,nrow*ncol+2,"fix/store:rbuf");


  printf("AAA HOW GET HERE\n");
}

/* ----------------------------------------------------------------------
+81 −13
Original line number Diff line number Diff line
@@ -68,10 +68,12 @@ Modify::Modify(LAMMPS *lmp) : Pointers(lmp)
  list_timeflag = NULL;

  nfix_restart_global = 0;
  id_restart_global = style_restart_global = state_restart_global = NULL;
  id_restart_global = style_restart_global = NULL;
  state_restart_global = NULL;
  used_restart_global = NULL;
  nfix_restart_peratom = 0;
  id_restart_peratom = style_restart_peratom = NULL;
  index_restart_peratom = NULL;
  index_restart_peratom = used_restart_peratom = NULL;

  ncompute = maxcompute = 0;
  compute = NULL;
@@ -140,7 +142,7 @@ Modify::~Modify()
  delete [] end_of_step_every;
  delete [] list_timeflag;

  restart_deallocate();
  restart_deallocate(0);

  delete compute_map;
  delete fix_map;
@@ -156,7 +158,7 @@ void Modify::init()

  // delete storage of restart info since it is not valid after 1st run

  restart_deallocate();
  restart_deallocate(1);

  // create lists of fixes to call at each stage of run

@@ -819,11 +821,16 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
    if (strcmp(id_restart_global[i],fix[ifix]->id) == 0 &&
        strcmp(style_restart_global[i],fix[ifix]->style) == 0) {
      fix[ifix]->restart(state_restart_global[i]);
      used_restart_global[i] = 1;
      if (comm->me == 0) {
        const char *str = (const char *) ("Resetting global state of Fix %s "
                                          "Style %s from restart file info\n");
        if (screen) fprintf(screen,str,fix[ifix]->id,fix[ifix]->style);
        if (logfile) fprintf(logfile,str,fix[ifix]->id,fix[ifix]->style);
	if (screen) 
          fprintf(screen,"Resetting global fix info from restart file:\n");
	if (logfile) 
          fprintf(logfile,"Resetting global fix info from restart file:\n");
        if (screen) fprintf(screen,"  fix style: %s, fix ID: %s\n",
                            fix[ifix]->style,fix[ifix]->id);
        if (logfile) fprintf(logfile,"  fix style: %s, fix ID: %s\n",
                             fix[ifix]->style,fix[ifix]->id);
      }
    }

@@ -833,14 +840,19 @@ void Modify::add_fix(int narg, char **arg, int trysuffix)
  for (int i = 0; i < nfix_restart_peratom; i++)
    if (strcmp(id_restart_peratom[i],fix[ifix]->id) == 0 &&
        strcmp(style_restart_peratom[i],fix[ifix]->style) == 0) {
      used_restart_peratom[i] = 1;
      for (int j = 0; j < atom->nlocal; j++)
        fix[ifix]->unpack_restart(j,index_restart_peratom[i]);
      fix[ifix]->restart_reset = 1;
      if (comm->me == 0) {
        char *str = (char *) ("Resetting per-atom state of Fix %s Style %s "
                     "from restart file info\n");
        if (screen) fprintf(screen,str,fix[ifix]->id,fix[ifix]->style);
        if (logfile) fprintf(logfile,str,fix[ifix]->id,fix[ifix]->style);
	if (screen) 
          fprintf(screen,"Resetting peratom fix info from restart file:\n");
	if (logfile) 
          fprintf(logfile,"Resetting peratom fix info from restart file:\n");
        if (screen) fprintf(screen,"  fix style: %s, fix ID: %s\n",
                            fix[ifix]->style,fix[ifix]->id);
        if (logfile) fprintf(logfile,"  fix style: %s, fix ID: %s\n",
                             fix[ifix]->style,fix[ifix]->id);
      }
    }

@@ -1158,6 +1170,7 @@ int Modify::read_restart(FILE *fp)
    id_restart_global = new char*[nfix_restart_global];
    style_restart_global = new char*[nfix_restart_global];
    state_restart_global = new char*[nfix_restart_global];
    used_restart_global = new int[nfix_restart_global];
  }

  // read each entry and Bcast to all procs
@@ -1182,6 +1195,8 @@ int Modify::read_restart(FILE *fp)
    state_restart_global[i] = new char[n];
    if (me == 0) fread(state_restart_global[i],sizeof(char),n,fp);
    MPI_Bcast(state_restart_global[i],n,MPI_CHAR,0,world);

    used_restart_global[i] = 0;
  }

  // nfix_restart_peratom = # of restart entries with peratom info
@@ -1197,6 +1212,7 @@ int Modify::read_restart(FILE *fp)
    id_restart_peratom = new char*[nfix_restart_peratom];
    style_restart_peratom = new char*[nfix_restart_peratom];
    index_restart_peratom = new int[nfix_restart_peratom];
    used_restart_peratom = new int[nfix_restart_peratom];
  }

  // read each entry and Bcast to all procs
@@ -1221,6 +1237,7 @@ int Modify::read_restart(FILE *fp)
    maxsize += n;

    index_restart_peratom[i] = i;
    used_restart_peratom[i] = 0;
  }

  return maxsize;
@@ -1228,11 +1245,36 @@ int Modify::read_restart(FILE *fp)

/* ----------------------------------------------------------------------
   delete all lists of restart file Fix info
   if flag set, print list of restart file info not assigned to new fixes
------------------------------------------------------------------------- */

void Modify::restart_deallocate()
void Modify::restart_deallocate(int flag)
{
  if (nfix_restart_global) {
    if (flag && comm->me == 0) {
      int i;
      for (i = 0; i < nfix_restart_global; i++)
	if (used_restart_global[i] == 0) break;
      if (i == nfix_restart_global) {
	if (screen) 
          fprintf(screen,"All restart file global fix info "
                  "was re-assigned\n");
	if (logfile) 
          fprintf(logfile,"All restart file global fix info "
                  "was re-assigned\n");
      } else {
	if (screen) fprintf(screen,"Unused restart file global fix info:\n");
	if (logfile) fprintf(logfile,"Unused restart file global fix info:\n");
	for (i = 0; i < nfix_restart_global; i++) {
	  if (used_restart_global[i]) continue;
	  if (screen) fprintf(screen,"  fix style: %s, fix ID: %s\n",
			      style_restart_global[i],id_restart_global[i]);
	  if (logfile) fprintf(logfile,"  fix style: %s, fix ID: %s\n",
			       style_restart_global[i],id_restart_global[i]);
	}
      }
    }

    for (int i = 0; i < nfix_restart_global; i++) {
      delete [] id_restart_global[i];
      delete [] style_restart_global[i];
@@ -1241,9 +1283,34 @@ void Modify::restart_deallocate()
    delete [] id_restart_global;
    delete [] style_restart_global;
    delete [] state_restart_global;
    delete [] used_restart_global;
  }

  if (nfix_restart_peratom) {
    if (flag && comm->me == 0) {
      int i;
      for (i = 0; i < nfix_restart_peratom; i++)
	if (used_restart_peratom[i] == 0) break;
      if (i == nfix_restart_peratom) {
	if (screen) 
          fprintf(screen,"All restart file peratom fix info "
                  "was re-assigned\n");
	if (logfile) 
          fprintf(logfile,"All restart file peratom fix info "
                  "was re-assigned\n");
      } else {
	if (screen) fprintf(screen,"Unused restart file peratom fix info:\n");
	if (logfile) fprintf(logfile,"Unused restart file peratom fix info:\n");
	for (i = 0; i < nfix_restart_peratom; i++) {
	  if (used_restart_peratom[i]) continue;
	  if (screen) fprintf(screen,"  fix style: %s, fix ID: %s\n",
			      style_restart_peratom[i],id_restart_peratom[i]);
	  if (logfile) fprintf(logfile,"  fix style: %s, fix ID: %s\n",
			       style_restart_peratom[i],id_restart_peratom[i]);
	}
      }
    }

    for (int i = 0; i < nfix_restart_peratom; i++) {
      delete [] id_restart_peratom[i];
      delete [] style_restart_peratom[i];
@@ -1251,6 +1318,7 @@ void Modify::restart_deallocate()
    delete [] id_restart_peratom;
    delete [] style_restart_peratom;
    delete [] index_restart_peratom;
    delete [] used_restart_peratom;
  }

  nfix_restart_global = nfix_restart_peratom = 0;
+3 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ class Modify : protected Pointers {

  void write_restart(FILE *);
  int read_restart(FILE *);
  void restart_deallocate();
  void restart_deallocate(int);

  bigint memory_usage();

@@ -135,10 +135,12 @@ class Modify : protected Pointers {
  char **id_restart_global;           // stored fix global info
  char **style_restart_global;        // from read-in restart file
  char **state_restart_global;
  int *used_restart_global;

  char **id_restart_peratom;          // stored fix peratom info
  char **style_restart_peratom;       // from read-in restart file
  int *index_restart_peratom;
  int *used_restart_peratom;

  int index_permanent;        // fix/compute index returned to library call

Loading