git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@4192 f3b2605a-c512-4ea7-a41b-209d697bcdaa
This commit is contained in:
@ -95,11 +95,14 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
options(narg,arg);
|
options(narg,arg);
|
||||||
|
|
||||||
// parse values until one isn't recognized
|
// parse values until one isn't recognized
|
||||||
|
// if mode = VECTOR and value is a global array:
|
||||||
|
// expand it as if columns listed one by one
|
||||||
|
// adjust nvalues accordingly via maxvalues
|
||||||
|
|
||||||
which = new int[narg-9];
|
which = argindex = value2index = NULL;
|
||||||
argindex = new int[narg-9];
|
ids = NULL;
|
||||||
ids = new char*[narg-9];
|
int maxvalues = nvalues;
|
||||||
value2index = new int[narg-9];
|
allocate_values(maxvalues);
|
||||||
nvalues = 0;
|
nvalues = 0;
|
||||||
|
|
||||||
iarg = 9;
|
iarg = 9;
|
||||||
@ -158,12 +161,52 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
n = strlen(suffix) + 1;
|
n = strlen(suffix) + 1;
|
||||||
ids[nvalues] = new char[n];
|
ids[nvalues] = new char[n];
|
||||||
strcpy(ids[nvalues],suffix);
|
strcpy(ids[nvalues],suffix);
|
||||||
nvalues++;
|
|
||||||
delete [] suffix;
|
delete [] suffix;
|
||||||
|
|
||||||
} else break;
|
if (mode == VECTOR && which[nvalues] == COMPUTE &&
|
||||||
|
argindex[nvalues] == 0) {
|
||||||
|
int icompute = modify->find_compute(ids[nvalues]);
|
||||||
|
if (icompute < 0)
|
||||||
|
error->all("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;
|
||||||
|
}
|
||||||
|
|
||||||
iarg++;
|
} else if (mode == VECTOR && which[nvalues] == FIX &&
|
||||||
|
argindex[nvalues] == 0) {
|
||||||
|
int ifix = modify->find_fix(ids[nvalues]);
|
||||||
|
if (ifix < 0)
|
||||||
|
error->all("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
|
||||||
@ -430,11 +473,11 @@ FixAveHisto::FixAveHisto(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
FixAveHisto::~FixAveHisto()
|
FixAveHisto::~FixAveHisto()
|
||||||
{
|
{
|
||||||
delete [] which;
|
memory->sfree(which);
|
||||||
delete [] argindex;
|
memory->sfree(argindex);
|
||||||
|
memory->sfree(value2index);
|
||||||
for (int i = 0; i < nvalues; i++) delete [] ids[i];
|
for (int i = 0; i < nvalues; i++) delete [] ids[i];
|
||||||
delete [] ids;
|
memory->sfree(ids);
|
||||||
delete [] value2index;
|
|
||||||
|
|
||||||
if (fp && me == 0) fclose(fp);
|
if (fp && me == 0) fclose(fp);
|
||||||
|
|
||||||
@ -901,3 +944,17 @@ void FixAveHisto::options(int narg, char **arg)
|
|||||||
} else error->all("Illegal fix ave/histo command");
|
} else error->all("Illegal fix ave/histo command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
reallocate vectors for each input value, of length N
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void FixAveHisto::allocate_values(int n)
|
||||||
|
{
|
||||||
|
which = (int *) memory->srealloc(which,n*sizeof(int),"ave/time:which");
|
||||||
|
argindex = (int *) memory->srealloc(argindex,n*sizeof(int),
|
||||||
|
"ave/time:argindex");
|
||||||
|
value2index = (int *) memory->srealloc(value2index,n*sizeof(int),
|
||||||
|
"ave/time:value2index");
|
||||||
|
ids = (char **) memory->srealloc(ids,n*sizeof(char *),"ave/time:ids");
|
||||||
|
}
|
||||||
|
|||||||
@ -64,6 +64,7 @@ class FixAveHisto : public Fix {
|
|||||||
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, char **);
|
||||||
|
void allocate_values(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,11 +71,14 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
options(narg,arg);
|
options(narg,arg);
|
||||||
|
|
||||||
// parse values until one isn't recognized
|
// parse values until one isn't recognized
|
||||||
|
// if mode = VECTOR and value is a global array:
|
||||||
|
// expand it as if columns listed one by one
|
||||||
|
// adjust nvalues accordingly via maxvalues
|
||||||
|
|
||||||
which = new int[nvalues];
|
which = argindex = value2index = offcol = NULL;
|
||||||
argindex = new int[nvalues];
|
ids = NULL;
|
||||||
ids = new char*[nvalues];
|
int maxvalues = nvalues;
|
||||||
value2index = new int[nvalues];
|
allocate_values(maxvalues);
|
||||||
nvalues = 0;
|
nvalues = 0;
|
||||||
|
|
||||||
iarg = 6;
|
iarg = 6;
|
||||||
@ -102,12 +105,60 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
n = strlen(suffix) + 1;
|
n = strlen(suffix) + 1;
|
||||||
ids[nvalues] = new char[n];
|
ids[nvalues] = new char[n];
|
||||||
strcpy(ids[nvalues],suffix);
|
strcpy(ids[nvalues],suffix);
|
||||||
nvalues++;
|
|
||||||
delete [] suffix;
|
delete [] suffix;
|
||||||
|
|
||||||
} else break;
|
if (mode == VECTOR && which[nvalues] == COMPUTE &&
|
||||||
|
argindex[nvalues] == 0) {
|
||||||
|
int icompute = modify->find_compute(ids[nvalues]);
|
||||||
|
if (icompute < 0)
|
||||||
|
error->all("Compute ID for fix ave/time 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;
|
||||||
|
}
|
||||||
|
|
||||||
iarg++;
|
} else if (mode == VECTOR && which[nvalues] == FIX &&
|
||||||
|
argindex[nvalues] == 0) {
|
||||||
|
int ifix = modify->find_fix(ids[nvalues]);
|
||||||
|
if (ifix < 0)
|
||||||
|
error->all("Fix ID for fix ave/time 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else nvalues++;
|
||||||
|
iarg++;
|
||||||
|
} else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set off columns now that nvalues is finalized
|
||||||
|
|
||||||
|
for (int i = 0; i < nvalues; i++) offcol[i] = 0;
|
||||||
|
for (int i = 0; i < noff; i++) {
|
||||||
|
if (offlist[i] < 1 || offlist[i] > nvalues)
|
||||||
|
error->all("Invalid fix ave/time off column");
|
||||||
|
offcol[offlist[i]-1] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup and error check
|
// setup and error check
|
||||||
@ -203,6 +254,8 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
} else column = NULL;
|
} else column = NULL;
|
||||||
|
|
||||||
// print file comment lines
|
// print file comment lines
|
||||||
|
// for mode = VECTOR, cannot use arg to print
|
||||||
|
// since array args may have been expanded to multiple vectors
|
||||||
|
|
||||||
if (fp && me == 0) {
|
if (fp && me == 0) {
|
||||||
if (title1) fprintf(fp,"%s\n",title1);
|
if (title1) fprintf(fp,"%s\n",title1);
|
||||||
@ -216,7 +269,12 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
if (title3 && mode == VECTOR) fprintf(fp,"%s\n",title3);
|
if (title3 && mode == VECTOR) fprintf(fp,"%s\n",title3);
|
||||||
else if (mode == VECTOR) {
|
else if (mode == VECTOR) {
|
||||||
fprintf(fp,"# Row");
|
fprintf(fp,"# Row");
|
||||||
for (int i = 0; i < nvalues; i++) fprintf(fp," %s",arg[6+i]);
|
for (int i = 0; i < nvalues; i++) {
|
||||||
|
if (which[i] == COMPUTE) fprintf(fp," c_%s",ids[i]);
|
||||||
|
else if (which[i] == FIX) fprintf(fp," f_%s",ids[i]);
|
||||||
|
else if (which[i] == VARIABLE) fprintf(fp," v_%s",ids[i]);
|
||||||
|
if (argindex[i]) fprintf(fp,"[%d]",argindex[i]);
|
||||||
|
}
|
||||||
fprintf(fp,"\n");
|
fprintf(fp,"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,13 +434,13 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
FixAveTime::~FixAveTime()
|
FixAveTime::~FixAveTime()
|
||||||
{
|
{
|
||||||
delete [] offcol;
|
memory->sfree(which);
|
||||||
|
memory->sfree(argindex);
|
||||||
delete [] which;
|
memory->sfree(value2index);
|
||||||
delete [] argindex;
|
memory->sfree(offcol);
|
||||||
for (int i = 0; i < nvalues; i++) delete [] ids[i];
|
for (int i = 0; i < nvalues; i++) delete [] ids[i];
|
||||||
delete [] ids;
|
memory->sfree(ids);
|
||||||
delete [] value2index;
|
|
||||||
delete [] extlist;
|
delete [] extlist;
|
||||||
|
|
||||||
if (fp && me == 0) fclose(fp);
|
if (fp && me == 0) fclose(fp);
|
||||||
@ -763,8 +821,8 @@ void FixAveTime::options(int narg, char **arg)
|
|||||||
ave = ONE;
|
ave = ONE;
|
||||||
startstep = 0;
|
startstep = 0;
|
||||||
mode = SCALAR;
|
mode = SCALAR;
|
||||||
offcol = new int[nvalues];
|
noff = 0;
|
||||||
for (int i = 0; i < nvalues; i++) offcol[i] = 0;
|
offlist = NULL;
|
||||||
title1 = NULL;
|
title1 = NULL;
|
||||||
title2 = NULL;
|
title2 = NULL;
|
||||||
title3 = NULL;
|
title3 = NULL;
|
||||||
@ -809,10 +867,9 @@ void FixAveTime::options(int narg, char **arg)
|
|||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else if (strcmp(arg[iarg],"off") == 0) {
|
} else if (strcmp(arg[iarg],"off") == 0) {
|
||||||
if (iarg+2 > narg) error->all("Illegal fix ave/time command");
|
if (iarg+2 > narg) error->all("Illegal fix ave/time command");
|
||||||
int ncolumn = atoi(arg[iarg+1]);
|
offlist = (int *)
|
||||||
if (ncolumn <= 0 || ncolumn > nvalues)
|
memory->srealloc(offlist,(noff+1)*sizeof(int),"ave/time:offlist");
|
||||||
error->all("Invalid fix ave/time off column");
|
offlist[noff++] = atoi(arg[iarg+1]);
|
||||||
offcol[ncolumn-1] = 1;
|
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else if (strcmp(arg[iarg],"title1") == 0) {
|
} else if (strcmp(arg[iarg],"title1") == 0) {
|
||||||
if (iarg+2 > narg) error->all("Illegal fix ave/spatial command");
|
if (iarg+2 > narg) error->all("Illegal fix ave/spatial command");
|
||||||
@ -838,3 +895,18 @@ void FixAveTime::options(int narg, char **arg)
|
|||||||
} else error->all("Illegal fix ave/time command");
|
} else error->all("Illegal fix ave/time command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
reallocate vectors for each input value, of length N
|
||||||
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void FixAveTime::allocate_values(int n)
|
||||||
|
{
|
||||||
|
which = (int *) memory->srealloc(which,n*sizeof(int),"ave/time:which");
|
||||||
|
argindex = (int *) memory->srealloc(argindex,n*sizeof(int),
|
||||||
|
"ave/time:argindex");
|
||||||
|
value2index = (int *) memory->srealloc(value2index,n*sizeof(int),
|
||||||
|
"ave/time:value2index");
|
||||||
|
offcol = (int *) memory->srealloc(offcol,n*sizeof(int),"ave/time:offcol");
|
||||||
|
ids = (char **) memory->srealloc(ids,n*sizeof(char *),"ave/time:ids");
|
||||||
|
}
|
||||||
|
|||||||
@ -40,13 +40,14 @@ class FixAveTime : public Fix {
|
|||||||
private:
|
private:
|
||||||
int me,nvalues;
|
int me,nvalues;
|
||||||
int nrepeat,nfreq,nvalid,irepeat;
|
int nrepeat,nfreq,nvalid,irepeat;
|
||||||
int *which,*argindex,*value2index;
|
int *which,*argindex,*value2index,*offcol;
|
||||||
char **ids;
|
char **ids;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int nrows;
|
int nrows;
|
||||||
|
|
||||||
int ave,nwindow,nsum,startstep,mode;
|
int ave,nwindow,nsum,startstep,mode;
|
||||||
int *offcol;
|
int noff;
|
||||||
|
int *offlist;
|
||||||
char *title1,*title2,*title3;
|
char *title1,*title2,*title3;
|
||||||
|
|
||||||
int norm,iwindow,window_limit;
|
int norm,iwindow,window_limit;
|
||||||
@ -61,6 +62,7 @@ class FixAveTime : public Fix {
|
|||||||
void invoke_scalar(int);
|
void invoke_scalar(int);
|
||||||
void invoke_vector(int);
|
void invoke_vector(int);
|
||||||
void options(int, char **);
|
void options(int, char **);
|
||||||
|
void allocate_values(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user