git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@15418 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2016-08-01 21:30:11 +00:00
parent e6c5898e53
commit 98aee05152
6 changed files with 134 additions and 135 deletions

View File

@ -82,7 +82,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
arghold = arg; arghold = arg;
arg = earg; arg = earg;
// parse remaining values until one isn't recognized // parse values until one isn't recognized
which = new int[nargnew]; which = new int[nargnew];
argindex = new int[nargnew]; argindex = new int[nargnew];

View File

@ -57,15 +57,25 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
global_freq = nfreq; global_freq = nfreq;
no_change_box = 1; no_change_box = 1;
// expand args if any have wildcard character "*"
int expand = 0;
char **earg,**arghold;
int nargnew = input->expand_args(narg-7,&arg[7],1,earg);
if (earg != &arg[7]) expand = 1;
arghold = arg;
arg = earg;
// parse values until one isn't recognized // parse values until one isn't recognized
int iarg = 7; which = new int[nargnew];
which = new int[narg-iarg]; argindex = new int[nargnew];
argindex = new int[narg-iarg]; ids = new char*[nargnew];
ids = new char*[narg-iarg]; value2index = new int[nargnew];
value2index = new int[narg-iarg];
nvalues = 0; nvalues = 0;
int iarg = 7;
while (iarg < narg) { while (iarg < narg) {
ids[nvalues] = NULL; ids[nvalues] = NULL;
@ -152,7 +162,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
char *title2 = NULL; char *title2 = NULL;
char *title3 = NULL; char *title3 = NULL;
while (iarg < narg) { while (iarg < nargnew) {
if (strcmp(arg[iarg],"norm") == 0) { if (strcmp(arg[iarg],"norm") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command"); if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
if (strcmp(arg[iarg+1],"all") == 0) { if (strcmp(arg[iarg+1],"all") == 0) {
@ -349,7 +359,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
else if (ncoord == 3) else if (ncoord == 3)
fprintf(fp,"# Chunk OrigID Coord1 Coord2 Coord3 Ncount"); fprintf(fp,"# Chunk OrigID Coord1 Coord2 Coord3 Ncount");
} }
for (int i = 0; i < nvalues; i++) fprintf(fp," %s",arg[7+i]); for (int i = 0; i < nvalues; i++) fprintf(fp," %s",earg[i]);
fprintf(fp,"\n"); fprintf(fp,"\n");
} }
if (ferror(fp)) if (ferror(fp))
@ -362,6 +372,15 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
delete [] title2; delete [] title2;
delete [] title3; delete [] title3;
// if wildcard expansion occurred, free earg memory from expand_args()
// wait to do this until after file comment lines are printed
if (expand) {
for (int i = 0; i < nvalues; i++) delete [] earg[i];
memory->sfree(earg);
arg = arghold;
}
// this fix produces a global array // this fix produces a global array
// size_array_rows is variable and set by allocate() // size_array_rows is variable and set by allocate()

View File

@ -56,16 +56,26 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
global_freq = nfreq; global_freq = nfreq;
// expand args if any have wildcard character "*"
int expand = 0;
char **earg,**arghold;
int nargnew = input->expand_args(narg-6,&arg[6],0,earg);
if (earg != &arg[6]) expand = 1;
arghold = arg;
arg = earg;
// parse values until one isn't recognized // parse values until one isn't recognized
which = new int[narg-6]; which = new int[nargnew];
argindex = new int[narg-6]; argindex = new int[nargnew];
ids = new char*[narg-6]; ids = new char*[nargnew];
value2index = new int[narg-6]; value2index = new int[nargnew];
nvalues = 0; nvalues = 0;
int iarg = 6; int iarg = 0;
while (iarg < narg) { while (iarg < nargnew) {
if (strncmp(arg[iarg],"c_",2) == 0 || if (strncmp(arg[iarg],"c_",2) == 0 ||
strncmp(arg[iarg],"f_",2) == 0 || strncmp(arg[iarg],"f_",2) == 0 ||
strncmp(arg[iarg],"v_",2) == 0) { strncmp(arg[iarg],"v_",2) == 0) {
@ -107,7 +117,7 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
char *title2 = NULL; char *title2 = NULL;
char *title3 = NULL; char *title3 = NULL;
while (iarg < narg) { while (iarg < nargnew) {
if (strcmp(arg[iarg],"type") == 0) { if (strcmp(arg[iarg],"type") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command"); if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/correlate command");
if (strcmp(arg[iarg+1],"auto") == 0) type = AUTO; if (strcmp(arg[iarg+1],"auto") == 0) type = AUTO;
@ -245,27 +255,27 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
fprintf(fp,"# Index TimeDelta Ncount"); fprintf(fp,"# Index TimeDelta Ncount");
if (type == AUTO) if (type == AUTO)
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
fprintf(fp," %s*%s",arg[6+i],arg[6+i]); fprintf(fp," %s*%s",earg[i],earg[i]);
else if (type == UPPER) else if (type == UPPER)
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
for (int j = i+1; j < nvalues; j++) for (int j = i+1; j < nvalues; j++)
fprintf(fp," %s*%s",arg[6+i],arg[6+j]); fprintf(fp," %s*%s",earg[i],earg[j]);
else if (type == LOWER) else if (type == LOWER)
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
for (int j = 0; j < i-1; j++) for (int j = 0; j < i-1; j++)
fprintf(fp," %s*%s",arg[6+i],arg[6+j]); fprintf(fp," %s*%s",earg[i],earg[j]);
else if (type == AUTOUPPER) else if (type == AUTOUPPER)
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
for (int j = i; j < nvalues; j++) for (int j = i; j < nvalues; j++)
fprintf(fp," %s*%s",arg[6+i],arg[6+j]); fprintf(fp," %s*%s",earg[i],earg[j]);
else if (type == AUTOLOWER) else if (type == AUTOLOWER)
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
fprintf(fp," %s*%s",arg[6+i],arg[6+j]); fprintf(fp," %s*%s",earg[i],earg[j]);
else if (type == FULL) else if (type == FULL)
for (int i = 0; i < nvalues; i++) for (int i = 0; i < nvalues; i++)
for (int j = 0; j < nvalues; j++) for (int j = 0; j < nvalues; j++)
fprintf(fp," %s*%s",arg[6+i],arg[6+j]); fprintf(fp," %s*%s",earg[i],earg[j]);
fprintf(fp,"\n"); fprintf(fp,"\n");
} }
if (ferror(fp)) if (ferror(fp))
@ -278,6 +288,15 @@ FixAveCorrelate::FixAveCorrelate(LAMMPS * lmp, int narg, char **arg):
delete [] title2; delete [] title2;
delete [] title3; delete [] title3;
// if wildcard expansion occurred, free earg memory from expand_args()
// wait to do this until after file comment lines are printed
if (expand) {
for (int i = 0; i < nvalues; i++) delete [] earg[i];
memory->sfree(earg);
arg = arghold;
}
// allocate and initialize memory for averaging // allocate and initialize memory for averaging
// set count and corr to zero since they accumulate // set count and corr to zero since they accumulate
// also set save versions to zero in case accessed via compute_array() // also set save versions to zero in case accessed via compute_array()

View File

@ -92,146 +92,108 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
} else break; } else break;
} }
options(narg,arg); if (nvalues == 0) error->all(FLERR,"No values in fix ave/histo command");
// parse values until one isn't recognized options(iarg,narg,arg);
// if mode = VECTOR and value is a global array:
// expand it as if columns listed one by one // expand args if any have wildcard character "*"
// adjust nvalues accordingly via maxvalues // this can reset nvalues
int expand = 0;
char **earg,**arghold;
nvalues = input->expand_args(nvalues,&arg[9],mode,earg);
if (earg != &arg[9]) expand = 1;
arghold = arg;
arg = earg;
// parse values
which = argindex = value2index = NULL; which = argindex = value2index = NULL;
ids = NULL; ids = NULL;
int maxvalues = nvalues; allocate_values(nvalues);
allocate_values(maxvalues);
nvalues = 0;
iarg = 9; for (int i = 0; i < nvalues; i++) {
while (iarg < narg) { if (strcmp(arg[i],"x") == 0) {
if (strcmp(arg[iarg],"x") == 0) { which[i] = X;
which[nvalues] = X; argindex[i] = 0;
argindex[nvalues] = 0; ids[i] = NULL;
ids[nvalues] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"y") == 0) { } else if (strcmp(arg[i],"y") == 0) {
which[nvalues] = X; which[i] = X;
argindex[nvalues] = 1; argindex[i] = 1;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"z") == 0) { } else if (strcmp(arg[i],"z") == 0) {
which[nvalues] = X; which[i] = X;
argindex[nvalues] = 2; argindex[i] = 2;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"vx") == 0) { } else if (strcmp(arg[i],"vx") == 0) {
which[nvalues] = V; which[i] = V;
argindex[nvalues] = 0; argindex[i] = 0;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"vy") == 0) { } else if (strcmp(arg[i],"vy") == 0) {
which[nvalues] = V; which[i] = V;
argindex[nvalues] = 1; argindex[i] = 1;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"vz") == 0) { } else if (strcmp(arg[i],"vz") == 0) {
which[nvalues] = V; which[i] = V;
argindex[nvalues] = 2; argindex[i] = 2;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"fx") == 0) { } else if (strcmp(arg[i],"fx") == 0) {
which[nvalues] = F; which[i] = F;
argindex[nvalues] = 0; argindex[i] = 0;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"fy") == 0) { } else if (strcmp(arg[i],"fy") == 0) {
which[nvalues] = F; which[i] = F;
argindex[nvalues] = 1; argindex[i] = 1;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if (strcmp(arg[iarg],"fz") == 0) { } else if (strcmp(arg[i],"fz") == 0) {
which[nvalues] = F; which[i] = F;
argindex[nvalues] = 2; argindex[i] = 2;
ids[nvalues] = NULL; ids[i] = NULL;
nvalues++;
iarg++; iarg++;
} else if ((strncmp(arg[iarg],"c_",2) == 0) || } else if ((strncmp(arg[i],"c_",2) == 0) ||
(strncmp(arg[iarg],"f_",2) == 0) || (strncmp(arg[i],"f_",2) == 0) ||
(strncmp(arg[iarg],"v_",2) == 0)) { (strncmp(arg[i],"v_",2) == 0)) {
if (arg[iarg][0] == 'c') which[nvalues] = COMPUTE; if (arg[i][0] == 'c') which[i] = COMPUTE;
else if (arg[iarg][0] == 'f') which[nvalues] = FIX; else if (arg[i][0] == 'f') which[i] = FIX;
else if (arg[iarg][0] == 'v') which[nvalues] = VARIABLE; else if (arg[i][0] == 'v') which[i] = VARIABLE;
int n = strlen(arg[iarg]); int n = strlen(arg[i]);
char *suffix = new char[n]; char *suffix = new char[n];
strcpy(suffix,&arg[iarg][2]); strcpy(suffix,&arg[i][2]);
char *ptr = strchr(suffix,'['); char *ptr = strchr(suffix,'[');
if (ptr) { if (ptr) {
if (suffix[strlen(suffix)-1] != ']') if (suffix[strlen(suffix)-1] != ']')
error->all(FLERR,"Illegal fix ave/histo command"); error->all(FLERR,"Illegal fix ave/histo command");
argindex[nvalues] = atoi(ptr+1); argindex[i] = atoi(ptr+1);
*ptr = '\0'; *ptr = '\0';
} else argindex[nvalues] = 0; } else argindex[i] = 0;
n = strlen(suffix) + 1; n = strlen(suffix) + 1;
ids[nvalues] = new char[n]; ids[i] = new char[n];
strcpy(ids[nvalues],suffix); strcpy(ids[i],suffix);
delete [] suffix; delete [] suffix;
}
}
if (mode == VECTOR && which[nvalues] == COMPUTE && // if wildcard expansion occurred, free earg memory from expand_args()
argindex[nvalues] == 0) {
int icompute = modify->find_compute(ids[nvalues]);
if (icompute < 0)
error->all(FLERR,"Compute ID for fix ave/histo does not exist");
if (modify->compute[icompute]->array_flag) {
int ncols = modify->compute[icompute]->size_array_cols;
maxvalues += ncols-1;
allocate_values(maxvalues);
argindex[nvalues] = 1;
for (int icol = 1; icol < ncols; icol++) {
which[nvalues+icol] = which[nvalues];
argindex[nvalues+icol] = icol+1;
n = strlen(ids[nvalues]) + 1;
ids[nvalues+icol] = new char[n];
strcpy(ids[nvalues+icol],ids[nvalues]);
}
nvalues += ncols-1;
}
} else if (mode == VECTOR && which[nvalues] == FIX && if (expand) {
argindex[nvalues] == 0) { for (int i = 0; i < nvalues; i++) delete [] earg[i];
int ifix = modify->find_fix(ids[nvalues]); memory->sfree(earg);
if (ifix < 0) arg = arghold;
error->all(FLERR,"Fix ID for fix ave/histo does not exist");
if (modify->fix[ifix]->array_flag) {
int ncols = modify->fix[ifix]->size_array_cols;
maxvalues += ncols-1;
allocate_values(maxvalues);
argindex[nvalues] = 1;
for (int icol = 1; icol < ncols; icol++) {
which[nvalues+icol] = which[nvalues];
argindex[nvalues+icol] = icol+1;
n = strlen(ids[nvalues]) + 1;
ids[nvalues+icol] = new char[n];
strcpy(ids[nvalues+icol],ids[nvalues]);
}
nvalues += ncols-1;
}
}
nvalues++;
iarg++;
} else break;
} }
// setup and error check // setup and error check
@ -955,7 +917,7 @@ void FixAveHisto::bin_atoms(double *values, int stride)
parse optional args parse optional args
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void FixAveHisto::options(int narg, char **arg) void FixAveHisto::options(int iarg, int narg, char **arg)
{ {
// option defaults // option defaults
@ -971,7 +933,6 @@ void FixAveHisto::options(int narg, char **arg)
// optional args // optional args
int iarg = 9 + nvalues;
while (iarg < narg) { while (iarg < narg) {
if (strcmp(arg[iarg],"file") == 0) { if (strcmp(arg[iarg],"file") == 0) {
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command"); if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/histo command");

View File

@ -65,7 +65,7 @@ class FixAveHisto : public Fix {
void bin_one(double); void bin_one(double);
void bin_vector(int, double *, int); void bin_vector(int, double *, int);
void bin_atoms(double *, int); void bin_atoms(double *, int);
void options(int, char **); void options(int, int, char **);
void allocate_values(int); void allocate_values(int);
bigint nextvalid(); bigint nextvalid();
}; };

View File

@ -288,7 +288,7 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
delete [] title3; delete [] title3;
// if wildcard expansion occurred, free earg memory from expand_args() // if wildcard expansion occurred, free earg memory from expand_args()
// wait to do this after file comment lines are printed // wait to do this until after file comment lines are printed
if (expand) { if (expand) {
for (int i = 0; i < nvalues; i++) delete [] earg[i]; for (int i = 0; i < nvalues; i++) delete [] earg[i];