convert fix ave/atom and fix ave/chunk
This commit is contained in:
@ -31,149 +31,135 @@ using namespace FixConst;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
nvalues(0), which(nullptr), argindex(nullptr), value2index(nullptr),
|
||||
ids(nullptr), array(nullptr)
|
||||
FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), array(nullptr)
|
||||
{
|
||||
if (narg < 7) error->all(FLERR,"Illegal fix ave/atom command");
|
||||
if (narg < 7) utils::missing_cmd_args(FLERR, "fix ave/atom", error);
|
||||
|
||||
nevery = utils::inumeric(FLERR,arg[3],false,lmp);
|
||||
nrepeat = utils::inumeric(FLERR,arg[4],false,lmp);
|
||||
peratom_freq = utils::inumeric(FLERR,arg[5],false,lmp);
|
||||
nevery = utils::inumeric(FLERR, arg[3], false, lmp);
|
||||
nrepeat = utils::inumeric(FLERR, arg[4], false, lmp);
|
||||
peratom_freq = utils::inumeric(FLERR, arg[5], false, lmp);
|
||||
time_depend = 1;
|
||||
|
||||
nvalues = narg - 6;
|
||||
|
||||
// expand args if any have wildcard character "*"
|
||||
// this can reset nvalues
|
||||
|
||||
int expand = 0;
|
||||
char **earg;
|
||||
nvalues = utils::expand_args(FLERR,nvalues,&arg[6],1,earg,lmp);
|
||||
int nvalues = utils::expand_args(FLERR, narg - 6, &arg[6], 1, earg, lmp);
|
||||
|
||||
if (earg != &arg[6]) expand = 1;
|
||||
arg = earg;
|
||||
|
||||
// parse values
|
||||
|
||||
which = new int[nvalues];
|
||||
argindex = new int[nvalues];
|
||||
ids = new char*[nvalues];
|
||||
value2index = new int[nvalues];
|
||||
|
||||
values.clear();
|
||||
for (int i = 0; i < nvalues; i++) {
|
||||
ids[i] = nullptr;
|
||||
|
||||
if (strcmp(arg[i],"x") == 0) {
|
||||
which[i] = ArgInfo::X;
|
||||
argindex[i] = 0;
|
||||
} else if (strcmp(arg[i],"y") == 0) {
|
||||
which[i] = ArgInfo::X;
|
||||
argindex[i] = 1;
|
||||
} else if (strcmp(arg[i],"z") == 0) {
|
||||
which[i] = ArgInfo::X;
|
||||
argindex[i] = 2;
|
||||
value_t val;
|
||||
val.id = "";
|
||||
val.val.c = nullptr;
|
||||
|
||||
} else if (strcmp(arg[i],"vx") == 0) {
|
||||
which[i] = ArgInfo::V;
|
||||
argindex[i] = 0;
|
||||
} else if (strcmp(arg[i],"vy") == 0) {
|
||||
which[i] = ArgInfo::V;
|
||||
argindex[i] = 1;
|
||||
} else if (strcmp(arg[i],"vz") == 0) {
|
||||
which[i] = ArgInfo::V;
|
||||
argindex[i] = 2;
|
||||
if (strcmp(arg[i], "x") == 0) {
|
||||
val.which = ArgInfo::X;
|
||||
val.argindex = 0;
|
||||
} else if (strcmp(arg[i], "y") == 0) {
|
||||
val.which = ArgInfo::X;
|
||||
val.argindex = 1;
|
||||
} else if (strcmp(arg[i], "z") == 0) {
|
||||
val.which = ArgInfo::X;
|
||||
val.argindex = 2;
|
||||
|
||||
} else if (strcmp(arg[i],"fx") == 0) {
|
||||
which[i] = ArgInfo::F;
|
||||
argindex[i] = 0;
|
||||
} else if (strcmp(arg[i],"fy") == 0) {
|
||||
which[i] = ArgInfo::F;
|
||||
argindex[i] = 1;
|
||||
} else if (strcmp(arg[i],"fz") == 0) {
|
||||
which[i] = ArgInfo::F;
|
||||
argindex[i] = 2;
|
||||
} else if (strcmp(arg[i], "vx") == 0) {
|
||||
val.which = ArgInfo::V;
|
||||
val.argindex = 0;
|
||||
} else if (strcmp(arg[i], "vy") == 0) {
|
||||
val.which = ArgInfo::V;
|
||||
val.argindex = 1;
|
||||
} else if (strcmp(arg[i], "vz") == 0) {
|
||||
val.which = ArgInfo::V;
|
||||
val.argindex = 2;
|
||||
|
||||
} else if (strcmp(arg[i], "fx") == 0) {
|
||||
val.which = ArgInfo::F;
|
||||
val.argindex = 0;
|
||||
} else if (strcmp(arg[i], "fy") == 0) {
|
||||
val.which = ArgInfo::F;
|
||||
val.argindex = 1;
|
||||
} else if (strcmp(arg[i], "fz") == 0) {
|
||||
val.which = ArgInfo::F;
|
||||
val.argindex = 2;
|
||||
|
||||
} else {
|
||||
ArgInfo argi(arg[i]);
|
||||
|
||||
which[i] = argi.get_type();
|
||||
argindex[i] = argi.get_index1();
|
||||
ids[i] = argi.copy_name();
|
||||
val.which = argi.get_type();
|
||||
val.argindex = argi.get_index1();
|
||||
val.id = argi.get_name();
|
||||
|
||||
if ((which[i] == ArgInfo::UNKNOWN) || (which[i] == ArgInfo::NONE)
|
||||
|| (argi.get_dim() > 1))
|
||||
error->all(FLERR,"Illegal fix ave/atom command");
|
||||
if ((val.which == ArgInfo::UNKNOWN) || (val.which == ArgInfo::NONE) || (argi.get_dim() > 1))
|
||||
error->all(FLERR, "Invalid fix ave/atom argument: {}", arg[i]);
|
||||
}
|
||||
values.push_back(val);
|
||||
}
|
||||
|
||||
// if wildcard expansion occurred, free earg memory from exapnd_args()
|
||||
|
||||
if (expand) {
|
||||
for (int i = 0; i < nvalues; i++) delete [] earg[i];
|
||||
for (int i = 0; i < nvalues; i++) delete[] earg[i];
|
||||
memory->sfree(earg);
|
||||
}
|
||||
|
||||
// setup and error check
|
||||
// for fix inputs, check that fix frequency is acceptable
|
||||
|
||||
if (nevery <= 0 || nrepeat <= 0 || peratom_freq <= 0)
|
||||
error->all(FLERR,"Illegal fix ave/atom command");
|
||||
if (nevery <= 0) error->all(FLERR,"Illegal fix ave/atom nevery value: {}", nevery);
|
||||
if (nrepeat <= 0) error->all(FLERR,"Illegal fix ave/atom nrepeat value: {}", nrepeat);
|
||||
if (peratom_freq <= 0) error->all(FLERR,"Illegal fix ave/atom nfreq value: {}", peratom_freq);
|
||||
if (peratom_freq % nevery || nrepeat*nevery > peratom_freq)
|
||||
error->all(FLERR,"Illegal fix ave/atom command");
|
||||
error->all(FLERR,"Inconsistent fix ave/atom nevery/nrepeat/nfreq values");
|
||||
|
||||
for (int i = 0; i < nvalues; i++) {
|
||||
if (which[i] == ArgInfo::COMPUTE) {
|
||||
int icompute = modify->find_compute(ids[i]);
|
||||
if (icompute < 0)
|
||||
error->all(FLERR,"Compute ID for fix ave/atom does not exist");
|
||||
if (modify->compute[icompute]->peratom_flag == 0)
|
||||
error->all(FLERR,
|
||||
"Fix ave/atom compute does not calculate per-atom values");
|
||||
if (argindex[i] == 0 &&
|
||||
modify->compute[icompute]->size_peratom_cols != 0)
|
||||
error->all(FLERR,"Fix ave/atom compute does not "
|
||||
"calculate a per-atom vector");
|
||||
if (argindex[i] && modify->compute[icompute]->size_peratom_cols == 0)
|
||||
error->all(FLERR,"Fix ave/atom compute does not "
|
||||
"calculate a per-atom array");
|
||||
if (argindex[i] &&
|
||||
argindex[i] > modify->compute[icompute]->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom compute array is accessed out-of-range");
|
||||
for (auto &val : values) {
|
||||
|
||||
} else if (which[i] == ArgInfo::FIX) {
|
||||
int ifix = modify->find_fix(ids[i]);
|
||||
if (ifix < 0)
|
||||
error->all(FLERR,"Fix ID for fix ave/atom does not exist");
|
||||
if (modify->fix[ifix]->peratom_flag == 0)
|
||||
error->all(FLERR,"Fix ave/atom fix does not calculate per-atom values");
|
||||
if (argindex[i] == 0 && modify->fix[ifix]->size_peratom_cols != 0)
|
||||
error->all(FLERR,
|
||||
"Fix ave/atom fix does not calculate a per-atom vector");
|
||||
if (argindex[i] && modify->fix[ifix]->size_peratom_cols == 0)
|
||||
error->all(FLERR,
|
||||
"Fix ave/atom fix does not calculate a per-atom array");
|
||||
if (argindex[i] && argindex[i] > modify->fix[ifix]->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom fix array is accessed out-of-range");
|
||||
if (nevery % modify->fix[ifix]->peratom_freq)
|
||||
error->all(FLERR,
|
||||
"Fix for fix ave/atom not computed at compatible time");
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
val.val.c = modify->get_compute_by_id(val.id);
|
||||
if (!val.val.c) error->all(FLERR,"Compute ID {} for fix ave/atom does not exist", val.id);
|
||||
if (val.val.c->peratom_flag == 0)
|
||||
error->all(FLERR, "Fix ave/atom compute {} does not calculate per-atom values", val.id);
|
||||
if (val.argindex == 0 && val.val.c->size_peratom_cols != 0)
|
||||
error->all(FLERR,"Fix ave/atom compute {} does not calculate a per-atom vector", val.id);
|
||||
if (val.argindex && val.val.c->size_peratom_cols == 0)
|
||||
error->all(FLERR,"Fix ave/atom compute {} does not calculate a per-atom array", val.id);
|
||||
if (val.argindex && val.argindex > val.val.c->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom compute {} array is accessed out-of-range", val.id);
|
||||
|
||||
} else if (which[i] == ArgInfo::VARIABLE) {
|
||||
int ivariable = input->variable->find(ids[i]);
|
||||
if (ivariable < 0)
|
||||
error->all(FLERR,"Variable name for fix ave/atom does not exist");
|
||||
if (input->variable->atomstyle(ivariable) == 0)
|
||||
error->all(FLERR,"Fix ave/atom variable is not atom-style variable");
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
val.val.f = modify->get_fix_by_id(val.id);
|
||||
if (!val.val.f) error->all(FLERR, "Fix ID {} for fix ave/atom does not exist", val.id);
|
||||
if (val.val.f->peratom_flag == 0)
|
||||
error->all(FLERR, "Fix ave/atom fix {} does not calculate per-atom values", val.id);
|
||||
if (val.argindex == 0 && val.val.f->size_peratom_cols != 0)
|
||||
error->all(FLERR, "Fix ave/atom fix {} does not calculate a per-atom vector", val.id);
|
||||
if (val.argindex && val.val.f->size_peratom_cols == 0)
|
||||
error->all(FLERR, "Fix ave/atom fix {} does not calculate a per-atom array", val.id);
|
||||
if (val.argindex && val.argindex > val.val.f->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/atom fix {} array is accessed out-of-range", val.id);
|
||||
if (nevery % val.val.f->peratom_freq)
|
||||
error->all(FLERR, "Fix {} for fix ave/atom not computed at compatible time", val.id);
|
||||
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
val.val.v = input->variable->find(val.id.c_str());
|
||||
if (val.val.v < 0)
|
||||
error->all(FLERR,"Variable name {} for fix ave/atom does not exist", val.id);
|
||||
if (input->variable->atomstyle(val.val.v) == 0)
|
||||
error->all(FLERR,"Fix ave/atom variable {} is not atom-style variable", val.id);
|
||||
}
|
||||
}
|
||||
|
||||
// this fix produces either a per-atom vector or array
|
||||
|
||||
peratom_flag = 1;
|
||||
if (nvalues == 1) size_peratom_cols = 0;
|
||||
else size_peratom_cols = nvalues;
|
||||
if (values.size() == 1) size_peratom_cols = 0;
|
||||
else size_peratom_cols = values.size();
|
||||
|
||||
// perform initial allocation of atom-based array
|
||||
// register with Atom class
|
||||
@ -186,7 +172,7 @@ FixAveAtom::FixAveAtom(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
int nlocal = atom->nlocal;
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
for (int m = 0; m < nvalues; m++)
|
||||
for (std::size_t m = 0; m < values.size(); m++)
|
||||
array[i][m] = 0.0;
|
||||
|
||||
// nvalid = next step on which end_of_step does something
|
||||
@ -207,13 +193,6 @@ FixAveAtom::~FixAveAtom()
|
||||
// unregister callback to this fix from Atom class
|
||||
|
||||
atom->delete_callback(id,Atom::GROW);
|
||||
|
||||
delete [] which;
|
||||
delete [] argindex;
|
||||
for (int m = 0; m < nvalues; m++) delete [] ids[m];
|
||||
delete [] ids;
|
||||
delete [] value2index;
|
||||
|
||||
memory->destroy(array);
|
||||
}
|
||||
|
||||
@ -232,26 +211,20 @@ void FixAveAtom::init()
|
||||
{
|
||||
// set indices and check validity of all computes,fixes,variables
|
||||
|
||||
for (int m = 0; m < nvalues; m++) {
|
||||
if (which[m] == ArgInfo::COMPUTE) {
|
||||
int icompute = modify->find_compute(ids[m]);
|
||||
if (icompute < 0)
|
||||
error->all(FLERR,"Compute ID for fix ave/atom does not exist");
|
||||
value2index[m] = icompute;
|
||||
for (auto &val : values) {
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
val.val.c = modify->get_compute_by_id(val.id);
|
||||
if (!val.val.c) error->all(FLERR, "Compute ID {} for fix ave/atom does not exist", val.id);
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
int ifix = modify->find_fix(ids[m]);
|
||||
if (ifix < 0)
|
||||
error->all(FLERR,"Fix ID for fix ave/atom does not exist");
|
||||
value2index[m] = ifix;
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
val.val.f = modify->get_fix_by_id(val.id);
|
||||
if (!val.val.f) error->all(FLERR, "Fix ID {} for fix ave/atom does not exist", val.id);
|
||||
|
||||
} else if (which[m] == ArgInfo::VARIABLE) {
|
||||
int ivariable = input->variable->find(ids[m]);
|
||||
if (ivariable < 0)
|
||||
error->all(FLERR,"Variable name for fix ave/atom does not exist");
|
||||
value2index[m] = ivariable;
|
||||
|
||||
} else value2index[m] = -1;
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
val.val.v = input->variable->find(val.id.c_str());
|
||||
if (val.val.v < 0)
|
||||
error->all(FLERR,"Variable name {} for fix ave/atom does not exist", val.id);
|
||||
}
|
||||
}
|
||||
|
||||
// need to reset nvalid if nvalid < ntimestep b/c minimize was performed
|
||||
@ -276,8 +249,6 @@ void FixAveAtom::setup(int /*vflag*/)
|
||||
|
||||
void FixAveAtom::end_of_step()
|
||||
{
|
||||
int i,j,m,n;
|
||||
|
||||
// skip if not step which requires doing something
|
||||
|
||||
bigint ntimestep = update->ntimestep;
|
||||
@ -289,8 +260,8 @@ void FixAveAtom::end_of_step()
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
if (irepeat == 0)
|
||||
for (i = 0; i < nlocal; i++)
|
||||
for (m = 0; m < nvalues; m++)
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
for (std::size_t m = 0; m < values.size(); m++)
|
||||
array[i][m] = 0.0;
|
||||
|
||||
// accumulate results of attributes,computes,fixes,variables to local copy
|
||||
@ -300,55 +271,54 @@ void FixAveAtom::end_of_step()
|
||||
|
||||
int *mask = atom->mask;
|
||||
|
||||
for (m = 0; m < nvalues; m++) {
|
||||
n = value2index[m];
|
||||
j = argindex[m];
|
||||
int i, j, m = 0;
|
||||
for (auto &val : values) {
|
||||
j = val.argindex;
|
||||
|
||||
if (which[m] == ArgInfo::X) {
|
||||
if (val.which == ArgInfo::X) {
|
||||
double **x = atom->x;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += x[i][j];
|
||||
|
||||
} else if (which[m] == ArgInfo::V) {
|
||||
} else if (val.which == ArgInfo::V) {
|
||||
double **v = atom->v;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += v[i][j];
|
||||
|
||||
} else if (which[m] == ArgInfo::F) {
|
||||
} else if (val.which == ArgInfo::F) {
|
||||
double **f = atom->f;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += f[i][j];
|
||||
|
||||
// invoke compute if not previously invoked
|
||||
|
||||
} else if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
|
||||
compute->compute_peratom();
|
||||
compute->invoked_flag |= Compute::INVOKED_PERATOM;
|
||||
} else if (val.which == ArgInfo::COMPUTE) {
|
||||
if (!(val.val.c->invoked_flag & Compute::INVOKED_PERATOM)) {
|
||||
val.val.c->compute_peratom();
|
||||
val.val.c->invoked_flag |= Compute::INVOKED_PERATOM;
|
||||
}
|
||||
|
||||
if (j == 0) {
|
||||
double *compute_vector = compute->vector_atom;
|
||||
double *compute_vector = val.val.c->vector_atom;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += compute_vector[i];
|
||||
} else {
|
||||
int jm1 = j - 1;
|
||||
double **compute_array = compute->array_atom;
|
||||
double **compute_array = val.val.c->array_atom;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += compute_array[i][jm1];
|
||||
}
|
||||
|
||||
// access fix fields, guaranteed to be ready
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
if (j == 0) {
|
||||
double *fix_vector = modify->fix[n]->vector_atom;
|
||||
double *fix_vector = val.val.f->vector_atom;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += fix_vector[i];
|
||||
} else {
|
||||
int jm1 = j - 1;
|
||||
double **fix_array = modify->fix[n]->array_atom;
|
||||
double **fix_array = val.val.f->array_atom;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit) array[i][m] += fix_array[i][jm1];
|
||||
}
|
||||
@ -356,10 +326,11 @@ void FixAveAtom::end_of_step()
|
||||
// evaluate atom-style variable
|
||||
// final argument = 1 sums result to array
|
||||
|
||||
} else if (which[m] == ArgInfo::VARIABLE) {
|
||||
if (array) input->variable->compute_atom(n,igroup,&array[0][m],nvalues,1);
|
||||
else input->variable->compute_atom(n,igroup,nullptr,nvalues,1);
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
if (array) input->variable->compute_atom(val.val.v,igroup,&array[0][m],values.size(),1);
|
||||
else input->variable->compute_atom(val.val.v,igroup,nullptr,values.size(),1);
|
||||
}
|
||||
++m;
|
||||
}
|
||||
|
||||
// done if irepeat < nrepeat
|
||||
@ -382,7 +353,7 @@ void FixAveAtom::end_of_step()
|
||||
|
||||
double repeat = nrepeat;
|
||||
for (i = 0; i < nlocal; i++)
|
||||
for (m = 0; m < nvalues; m++)
|
||||
for (m = 0; m < (int)values.size(); m++)
|
||||
array[i][m] /= repeat;
|
||||
}
|
||||
|
||||
@ -393,7 +364,7 @@ void FixAveAtom::end_of_step()
|
||||
double FixAveAtom::memory_usage()
|
||||
{
|
||||
double bytes;
|
||||
bytes = (double)atom->nmax*nvalues * sizeof(double);
|
||||
bytes = (double)atom->nmax*values.size() * sizeof(double);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@ -403,7 +374,7 @@ double FixAveAtom::memory_usage()
|
||||
|
||||
void FixAveAtom::grow_arrays(int nmax)
|
||||
{
|
||||
memory->grow(array,nmax,nvalues,"fix_ave/atom:array");
|
||||
memory->grow(array,nmax,values.size(),"fix_ave/atom:array");
|
||||
array_atom = array;
|
||||
if (array) vector_atom = array[0];
|
||||
else vector_atom = nullptr;
|
||||
@ -415,7 +386,7 @@ void FixAveAtom::grow_arrays(int nmax)
|
||||
|
||||
void FixAveAtom::copy_arrays(int i, int j, int /*delflag*/)
|
||||
{
|
||||
for (int m = 0; m < nvalues; m++)
|
||||
for (int m = 0; m < values.size(); m++)
|
||||
array[j][m] = array[i][m];
|
||||
}
|
||||
|
||||
@ -425,8 +396,8 @@ void FixAveAtom::copy_arrays(int i, int j, int /*delflag*/)
|
||||
|
||||
int FixAveAtom::pack_exchange(int i, double *buf)
|
||||
{
|
||||
for (int m = 0; m < nvalues; m++) buf[m] = array[i][m];
|
||||
return nvalues;
|
||||
for (int m = 0; m < values.size(); m++) buf[m] = array[i][m];
|
||||
return values.size();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -435,8 +406,8 @@ int FixAveAtom::pack_exchange(int i, double *buf)
|
||||
|
||||
int FixAveAtom::unpack_exchange(int nlocal, double *buf)
|
||||
{
|
||||
for (int m = 0; m < nvalues; m++) array[nlocal][m] = buf[m];
|
||||
return nvalues;
|
||||
for (int m = 0; m < values.size(); m++) array[nlocal][m] = buf[m];
|
||||
return values.size();
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
||||
@ -40,11 +40,20 @@ class FixAveAtom : public Fix {
|
||||
int unpack_exchange(int, double *) override;
|
||||
|
||||
private:
|
||||
int nvalues;
|
||||
struct value_t {
|
||||
int which; // type of data: COMPUTE, FIX, VARIABLE
|
||||
int argindex; // 1-based index if data is vector, else 0
|
||||
std::string id; // compute/fix/variable ID
|
||||
union {
|
||||
class Compute *c;
|
||||
class Fix *f;
|
||||
int v;
|
||||
} val;
|
||||
};
|
||||
std::vector<value_t> values;
|
||||
|
||||
int nrepeat, irepeat;
|
||||
bigint nvalid, nvalid_last;
|
||||
int *which, *argindex, *value2index;
|
||||
char **ids;
|
||||
double **array;
|
||||
|
||||
bigint nextvalid();
|
||||
|
||||
@ -33,29 +33,24 @@
|
||||
using namespace LAMMPS_NS;
|
||||
using namespace FixConst;
|
||||
|
||||
enum{SCALAR,VECTOR};
|
||||
enum{SAMPLE,ALL};
|
||||
enum{NOSCALE,ATOM};
|
||||
enum{ONE,RUNNING,WINDOW};
|
||||
|
||||
enum { SCALAR, VECTOR };
|
||||
enum { SAMPLE, ALL };
|
||||
enum { NOSCALE, ATOM };
|
||||
enum { ONE, RUNNING, WINDOW };
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
||||
Fix(lmp, narg, arg),
|
||||
nvalues(0), nrepeat(0),
|
||||
which(nullptr), argindex(nullptr), value2index(nullptr), ids(nullptr),
|
||||
fp(nullptr), idchunk(nullptr), varatom(nullptr),
|
||||
count_one(nullptr), count_many(nullptr), count_sum(nullptr),
|
||||
values_one(nullptr), values_many(nullptr), values_sum(nullptr),
|
||||
count_total(nullptr), count_list(nullptr),
|
||||
Fix(lmp, narg, arg), nvalues(0), nrepeat(0), fp(nullptr), idchunk(nullptr), varatom(nullptr),
|
||||
count_one(nullptr), count_many(nullptr), count_sum(nullptr), values_one(nullptr),
|
||||
values_many(nullptr), values_sum(nullptr), count_total(nullptr), count_list(nullptr),
|
||||
values_total(nullptr), values_list(nullptr)
|
||||
{
|
||||
if (narg < 7) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (narg < 7) utils::missing_cmd_args(FLERR, "fix ave/chunk", error);
|
||||
|
||||
nevery = utils::inumeric(FLERR,arg[3],false,lmp);
|
||||
nrepeat = utils::inumeric(FLERR,arg[4],false,lmp);
|
||||
nfreq = utils::inumeric(FLERR,arg[5],false,lmp);
|
||||
nevery = utils::inumeric(FLERR, arg[3], false, lmp);
|
||||
nrepeat = utils::inumeric(FLERR, arg[4], false, lmp);
|
||||
nfreq = utils::inumeric(FLERR, arg[5], false, lmp);
|
||||
|
||||
idchunk = utils::strdup(arg[6]);
|
||||
|
||||
@ -63,82 +58,81 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
||||
no_change_box = 1;
|
||||
time_depend = 1;
|
||||
|
||||
char * group = arg[1];
|
||||
char *group = arg[1];
|
||||
|
||||
// expand args if any have wildcard character "*"
|
||||
|
||||
int expand = 0;
|
||||
char **earg;
|
||||
int nargnew = utils::expand_args(FLERR,narg-7,&arg[7],1,earg,lmp);
|
||||
int nargnew = utils::expand_args(FLERR, narg - 7, &arg[7], 1, earg, lmp);
|
||||
|
||||
if (earg != &arg[7]) expand = 1;
|
||||
arg = earg;
|
||||
|
||||
// parse values until one isn't recognized
|
||||
|
||||
which = new int[nargnew];
|
||||
argindex = new int[nargnew];
|
||||
ids = new char*[nargnew];
|
||||
value2index = new int[nargnew];
|
||||
densityflag = 0;
|
||||
|
||||
int iarg = 0;
|
||||
values.clear();
|
||||
while (iarg < nargnew) {
|
||||
|
||||
ids[nvalues] = nullptr;
|
||||
value_t val;
|
||||
val.id = "";
|
||||
val.val.c = nullptr;
|
||||
|
||||
if (strcmp(arg[iarg],"vx") == 0) {
|
||||
which[nvalues] = ArgInfo::V;
|
||||
argindex[nvalues++] = 0;
|
||||
val.which = ArgInfo::V;
|
||||
val.which = 0;
|
||||
} else if (strcmp(arg[iarg],"vy") == 0) {
|
||||
which[nvalues] = ArgInfo::V;
|
||||
argindex[nvalues++] = 1;
|
||||
val.which = ArgInfo::V;
|
||||
val.which = 1;
|
||||
} else if (strcmp(arg[iarg],"vz") == 0) {
|
||||
which[nvalues] = ArgInfo::V;
|
||||
argindex[nvalues++] = 2;
|
||||
val.which = ArgInfo::V;
|
||||
val.which = 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"fx") == 0) {
|
||||
which[nvalues] = ArgInfo::F;
|
||||
argindex[nvalues++] = 0;
|
||||
val.which = ArgInfo::F;
|
||||
val.which = 0;
|
||||
} else if (strcmp(arg[iarg],"fy") == 0) {
|
||||
which[nvalues] = ArgInfo::F;
|
||||
argindex[nvalues++] = 1;
|
||||
val.which = ArgInfo::F;
|
||||
val.which = 1;
|
||||
} else if (strcmp(arg[iarg],"fz") == 0) {
|
||||
which[nvalues] = ArgInfo::F;
|
||||
argindex[nvalues++] = 2;
|
||||
val.which = ArgInfo::F;
|
||||
val.which = 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"mass") == 0) {
|
||||
which[nvalues] = ArgInfo::MASS;
|
||||
argindex[nvalues++] = 0;
|
||||
val.which = ArgInfo::MASS;
|
||||
val.which = 0;
|
||||
} else if (strcmp(arg[iarg],"density/number") == 0) {
|
||||
densityflag = 1;
|
||||
which[nvalues] = ArgInfo::DENSITY_NUMBER;
|
||||
argindex[nvalues++] = 0;
|
||||
val.which = ArgInfo::DENSITY_NUMBER;
|
||||
val.which = 0;
|
||||
} else if (strcmp(arg[iarg],"density/mass") == 0) {
|
||||
densityflag = 1;
|
||||
which[nvalues] = ArgInfo::DENSITY_MASS;
|
||||
argindex[nvalues++] = 0;
|
||||
val.which = ArgInfo::DENSITY_MASS;
|
||||
val.which = 0;
|
||||
} else if (strcmp(arg[iarg],"temp") == 0) {
|
||||
which[nvalues] = ArgInfo::TEMPERATURE;
|
||||
argindex[nvalues++] = 0;
|
||||
val.which = ArgInfo::TEMPERATURE;
|
||||
val.which = 0;
|
||||
|
||||
} else {
|
||||
ArgInfo argi(arg[iarg]);
|
||||
|
||||
if (argi.get_type() == ArgInfo::NONE) break;
|
||||
if ((argi.get_type() == ArgInfo::UNKNOWN) || (argi.get_dim() > 1))
|
||||
error->all(FLERR,"Invalid fix ave/chunk command");
|
||||
error->all(FLERR,"Unknown fix ave/chunk data value: {}", arg[iarg]);
|
||||
|
||||
which[nvalues] = argi.get_type();
|
||||
argindex[nvalues] = argi.get_index1();
|
||||
ids[nvalues] = argi.copy_name();
|
||||
|
||||
nvalues++;
|
||||
val.which = argi.get_type();
|
||||
val.argindex = argi.get_index1();
|
||||
val.id = argi.get_name();
|
||||
}
|
||||
values.push_back(val);
|
||||
iarg++;
|
||||
}
|
||||
|
||||
if (nvalues == 0) error->all(FLERR,"No values in fix ave/chunk command");
|
||||
nvalues = values.size();
|
||||
if (nvalues == 0) error->all(FLERR, "No values in fix ave/chunk command");
|
||||
|
||||
// optional args
|
||||
|
||||
@ -159,7 +153,7 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
while (iarg < nargnew) {
|
||||
if (strcmp(arg[iarg],"norm") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk norm", error);
|
||||
if (strcmp(arg[iarg+1],"all") == 0) {
|
||||
normflag = ALL;
|
||||
scaleflag = ATOM;
|
||||
@ -169,45 +163,42 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
||||
} else if (strcmp(arg[iarg+1],"none") == 0) {
|
||||
normflag = SAMPLE;
|
||||
scaleflag = NOSCALE;
|
||||
} else error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
} else error->all(FLERR,"Unknown fix ave/chunk norm mode: {}", arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"ave") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk ave", error);
|
||||
if (strcmp(arg[iarg+1],"one") == 0) ave = ONE;
|
||||
else if (strcmp(arg[iarg+1],"running") == 0) ave = RUNNING;
|
||||
else if (strcmp(arg[iarg+1],"window") == 0) ave = WINDOW;
|
||||
else error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
else error->all(FLERR,"Unknown fix ave/chunk ave mode: {}", arg[iarg+1]);
|
||||
if (ave == WINDOW) {
|
||||
if (iarg+3 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+3 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk ave window", error);
|
||||
nwindow = utils::inumeric(FLERR,arg[iarg+2],false,lmp);
|
||||
if (nwindow <= 0) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (nwindow <= 0) error->all(FLERR,"Illegal fix ave/chunk number of windows: {}", nwindow);
|
||||
}
|
||||
iarg += 2;
|
||||
if (ave == WINDOW) iarg++;
|
||||
|
||||
} else if (strcmp(arg[iarg],"bias") == 0) {
|
||||
if (iarg+2 > narg)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk bias", error);
|
||||
biasflag = 1;
|
||||
id_bias = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"adof") == 0) {
|
||||
if (iarg+2 > narg)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk adof", error);
|
||||
adof = utils::numeric(FLERR,arg[iarg+1],false,lmp);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"cdof") == 0) {
|
||||
if (iarg+2 > narg)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk cdof", error);
|
||||
cdof = utils::numeric(FLERR,arg[iarg+1],false,lmp);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"file") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk file", error);
|
||||
if (comm->me == 0) {
|
||||
fp = fopen(arg[iarg+1],"w");
|
||||
if (fp == nullptr)
|
||||
error->one(FLERR,"Cannot open fix ave/chunk file {}: {}",
|
||||
error->one(FLERR, "Cannot open fix ave/chunk file {}: {}",
|
||||
arg[iarg+1], utils::getsyserror());
|
||||
}
|
||||
iarg += 2;
|
||||
@ -215,81 +206,81 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
||||
overwrite = 1;
|
||||
iarg += 1;
|
||||
} else if (strcmp(arg[iarg],"format") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk format", error);
|
||||
delete[] format_user;
|
||||
format_user = utils::strdup(arg[iarg+1]);
|
||||
format = format_user;
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title1") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk title1", error);
|
||||
delete[] title1;
|
||||
title1 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title2") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk title2", error);
|
||||
delete[] title2;
|
||||
title2 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg],"title3") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (iarg+2 > narg) utils::missing_cmd_args(FLERR, "fix ave/chunk title3", error);
|
||||
delete[] title3;
|
||||
title3 = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
} else error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
} else error->all(FLERR,"Unknown fix ave/chunk keyword: {}", arg[iarg]);
|
||||
}
|
||||
|
||||
// setup and error check
|
||||
|
||||
if (nevery <= 0 || nrepeat <= 0 || nfreq <= 0)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
if (nevery <= 0) error->all(FLERR,"Illegal fix ave/chunk nevery value: {}", nevery);
|
||||
if (nrepeat <= 0) error->all(FLERR,"Illegal fix ave/chunk nrepeat value: {}", nrepeat);
|
||||
if (nfreq <= 0) error->all(FLERR,"Illegal fix ave/chunk nfreq value: {}", nfreq);
|
||||
if (nfreq % nevery || nrepeat*nevery > nfreq)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
error->all(FLERR,"Inconsistent fix ave/chunk nevery/nrepeat/nfreq values");
|
||||
if (ave != RUNNING && overwrite)
|
||||
error->all(FLERR,"Illegal fix ave/chunk command");
|
||||
error->all(FLERR,"Fix ave/chunk overwrite keyword requires ave running setting");
|
||||
|
||||
if (biasflag) {
|
||||
int i = modify->find_compute(id_bias);
|
||||
if (i < 0)
|
||||
error->all(FLERR,"Could not find compute ID for temperature bias");
|
||||
tbias = modify->compute[i];
|
||||
tbias = modify->get_compute_by_id(id_bias);
|
||||
if (!tbias) error->all(FLERR,"Could not find compute ID {} for temperature bias", id_bias);
|
||||
if (tbias->tempflag == 0)
|
||||
error->all(FLERR,"Bias compute does not calculate temperature");
|
||||
error->all(FLERR,"Bias compute {} does not calculate temperature", id_bias);
|
||||
if (tbias->tempbias == 0)
|
||||
error->all(FLERR,"Bias compute does not calculate a velocity bias");
|
||||
error->all(FLERR,"Bias compute {} does not calculate a velocity bias", id_bias);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nvalues; i++) {
|
||||
if (which[i] == ArgInfo::COMPUTE) {
|
||||
auto icompute = modify->get_compute_by_id(ids[i]);
|
||||
if (!icompute)
|
||||
error->all(FLERR,"Compute ID {} for fix ave/chunk does not exist",ids[i]);
|
||||
if (icompute->peratom_flag == 0)
|
||||
error->all(FLERR,"Fix ave/chunk compute {} does not calculate per-atom values",ids[i]);
|
||||
if (argindex[i] == 0 && (icompute->size_peratom_cols != 0))
|
||||
error->all(FLERR,"Fix ave/chunk compute {} does not calculate a per-atom vector",ids[i]);
|
||||
if (argindex[i] && (icompute->size_peratom_cols == 0))
|
||||
error->all(FLERR,"Fix ave/chunk compute {} does not calculate a per-atom array",ids[i]);
|
||||
if (argindex[i] && (argindex[i] > icompute->size_peratom_cols))
|
||||
error->all(FLERR,"Fix ave/chunk compute {} vector is accessed out-of-range",ids[i]);
|
||||
for (auto &val : values) {
|
||||
|
||||
} else if (which[i] == ArgInfo::FIX) {
|
||||
auto ifix = modify->get_fix_by_id(ids[i]);
|
||||
if (!ifix)
|
||||
error->all(FLERR, "Fix ID {} for fix ave/chunk does not exist",ids[i]);
|
||||
if (ifix->peratom_flag == 0)
|
||||
error->all(FLERR, "Fix ave/chunk fix {} does not calculate per-atom values",ids[i]);
|
||||
if (argindex[i] == 0 && (ifix->size_peratom_cols != 0))
|
||||
error->all(FLERR, "Fix ave/chunk fix {} does not calculate a per-atom vector",ids[i]);
|
||||
if (argindex[i] && (ifix->size_peratom_cols == 0))
|
||||
error->all(FLERR, "Fix ave/chunk fix {} does not calculate a per-atom array",ids[i]);
|
||||
if (argindex[i] && argindex[i] > ifix->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/chunk fix {} vector is accessed out-of-range",ids[i]);
|
||||
} else if (which[i] == ArgInfo::VARIABLE) {
|
||||
int ivariable = input->variable->find(ids[i]);
|
||||
if (ivariable < 0)
|
||||
error->all(FLERR,"Variable name {} for fix ave/chunk does not exist",ids[i]);
|
||||
if (input->variable->atomstyle(ivariable) == 0)
|
||||
error->all(FLERR,"Fix ave/chunk variable {} is not atom-style variable",ids[i]);
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
val.val.c = modify->get_compute_by_id(val.id);
|
||||
if (!val.val.c)
|
||||
error->all(FLERR,"Compute ID {} for fix ave/chunk does not exist",val.id);
|
||||
if (val.val.c->peratom_flag == 0)
|
||||
error->all(FLERR,"Fix ave/chunk compute {} does not calculate per-atom values",val.id);
|
||||
if (val.argindex == 0 && (val.val.c->size_peratom_cols != 0))
|
||||
error->all(FLERR,"Fix ave/chunk compute {} does not calculate a per-atom vector",val.id);
|
||||
if (val.argindex && (val.val.c->size_peratom_cols == 0))
|
||||
error->all(FLERR,"Fix ave/chunk compute {} does not calculate a per-atom array",val.id);
|
||||
if (val.argindex && (val.argindex > val.val.c->size_peratom_cols))
|
||||
error->all(FLERR,"Fix ave/chunk compute {} vector is accessed out-of-range",val.id);
|
||||
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
val.val.f = modify->get_fix_by_id(val.id);
|
||||
if (!val.val.f)
|
||||
error->all(FLERR, "Fix ID {} for fix ave/chunk does not exist",val.id);
|
||||
if (val.val.f->peratom_flag == 0)
|
||||
error->all(FLERR, "Fix ave/chunk fix {} does not calculate per-atom values",val.id);
|
||||
if (val.argindex == 0 && (val.val.f->size_peratom_cols != 0))
|
||||
error->all(FLERR, "Fix ave/chunk fix {} does not calculate a per-atom vector",val.id);
|
||||
if (val.argindex && (val.val.f->size_peratom_cols == 0))
|
||||
error->all(FLERR, "Fix ave/chunk fix {} does not calculate a per-atom array",val.id);
|
||||
if (val.argindex && val.argindex > val.val.f->size_peratom_cols)
|
||||
error->all(FLERR,"Fix ave/chunk fix {} vector is accessed out-of-range",val.id);
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
val.val.v = input->variable->find(val.id.c_str());
|
||||
if (val.val.v < 0)
|
||||
error->all(FLERR,"Variable name {} for fix ave/chunk does not exist",val.id);
|
||||
if (input->variable->atomstyle(val.val.v) == 0)
|
||||
error->all(FLERR,"Fix ave/chunk variable {} is not atom-style variable",val.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -396,12 +387,6 @@ FixAveChunk::FixAveChunk(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
FixAveChunk::~FixAveChunk()
|
||||
{
|
||||
delete[] which;
|
||||
delete[] argindex;
|
||||
for (int i = 0; i < nvalues; i++) delete[] ids[i];
|
||||
delete[] ids;
|
||||
delete[] value2index;
|
||||
|
||||
if (fp && comm->me == 0) fclose(fp);
|
||||
|
||||
memory->destroy(varatom);
|
||||
@ -427,10 +412,6 @@ FixAveChunk::~FixAveChunk()
|
||||
}
|
||||
|
||||
delete[] idchunk;
|
||||
which = nullptr;
|
||||
argindex = nullptr;
|
||||
ids = nullptr;
|
||||
value2index = nullptr;
|
||||
fp = nullptr;
|
||||
varatom = nullptr;
|
||||
count_one = nullptr;
|
||||
@ -463,42 +444,34 @@ void FixAveChunk::init()
|
||||
// set indices and check validity of all computes,fixes,variables
|
||||
// check that fix frequency is acceptable
|
||||
|
||||
int icompute = modify->find_compute(idchunk);
|
||||
if (icompute < 0)
|
||||
error->all(FLERR,"Chunk/atom compute does not exist for fix ave/chunk");
|
||||
cchunk = dynamic_cast<ComputeChunkAtom *>(modify->compute[icompute]);
|
||||
cchunk = dynamic_cast<ComputeChunkAtom *>(modify->get_compute_by_id(idchunk));
|
||||
if (!cchunk)
|
||||
error->all(FLERR,"Chunk/atom compute {} does not exist or is "
|
||||
"incorrect style for fix ave/chunk",idchunk);
|
||||
|
||||
if (biasflag) {
|
||||
int i = modify->find_compute(id_bias);
|
||||
if (i < 0)
|
||||
error->all(FLERR,"Could not find compute ID for temperature bias");
|
||||
tbias = modify->compute[i];
|
||||
tbias = modify->get_compute_by_id(id_bias);
|
||||
if (!tbias)
|
||||
error->all(FLERR,"Could not find compute ID {} for temperature bias", id_bias);
|
||||
}
|
||||
|
||||
for (int m = 0; m < nvalues; m++) {
|
||||
if (which[m] == ArgInfo::COMPUTE) {
|
||||
icompute = modify->find_compute(ids[m]);
|
||||
if (icompute < 0)
|
||||
error->all(FLERR,"Compute ID for fix ave/chunk does not exist");
|
||||
value2index[m] = icompute;
|
||||
for (auto &val : values) {
|
||||
if (val.which == ArgInfo::COMPUTE) {
|
||||
val.val.c = modify->get_compute_by_id(val.id);
|
||||
if (!val.val.c) error->all(FLERR,"Compute ID {} for fix ave/chunk does not exist", val.id);
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
int ifix = modify->find_fix(ids[m]);
|
||||
if (ifix < 0)
|
||||
error->all(FLERR,"Fix ID for fix ave/chunk does not exist");
|
||||
value2index[m] = ifix;
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
val.val.f = modify->get_fix_by_id(val.id);
|
||||
if (!val.val.f) error->all(FLERR,"Fix ID {} for fix ave/chunk does not exist", val.id);
|
||||
|
||||
if (nevery % modify->fix[ifix]->peratom_freq)
|
||||
error->all(FLERR,
|
||||
"Fix for fix ave/chunk not computed at compatible time");
|
||||
if (nevery % val.val.f->peratom_freq)
|
||||
error->all(FLERR, "Fix {} for fix ave/chunk not computed at compatible time", val.id);
|
||||
|
||||
} else if (which[m] == ArgInfo::VARIABLE) {
|
||||
int ivariable = input->variable->find(ids[m]);
|
||||
if (ivariable < 0)
|
||||
error->all(FLERR,"Variable name for fix ave/chunk does not exist");
|
||||
value2index[m] = ivariable;
|
||||
|
||||
} else value2index[m] = -1;
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
val.val.v = input->variable->find(val.id.c_str());
|
||||
if (val.val.v < 0)
|
||||
error->all(FLERR,"Variable name {} for fix ave/chunk does not exist", val.id);
|
||||
}
|
||||
}
|
||||
|
||||
// need to reset nvalid if nvalid < ntimestep b/c minimize was performed
|
||||
@ -527,7 +500,7 @@ void FixAveChunk::setup(int /*vflag*/)
|
||||
|
||||
void FixAveChunk::end_of_step()
|
||||
{
|
||||
int i,j,m,n,index;
|
||||
int i,j,m,index;
|
||||
|
||||
// skip if not step which requires doing something
|
||||
|
||||
@ -609,15 +582,15 @@ void FixAveChunk::end_of_step()
|
||||
|
||||
modify->clearstep_compute();
|
||||
|
||||
for (m = 0; m < nvalues; m++) {
|
||||
n = value2index[m];
|
||||
j = argindex[m];
|
||||
m = 0;
|
||||
for (auto &val : values) {
|
||||
j = val.argindex;
|
||||
|
||||
// V,F adds velocities,forces to values
|
||||
|
||||
if (which[m] == ArgInfo::V || which[m] == ArgInfo::F) {
|
||||
if (val.which == ArgInfo::V || val.which == ArgInfo::F) {
|
||||
double **attribute;
|
||||
if (which[m] == ArgInfo::V) attribute = atom->v;
|
||||
if (val.which == ArgInfo::V) attribute = atom->v;
|
||||
else attribute = atom->f;
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
@ -628,7 +601,7 @@ void FixAveChunk::end_of_step()
|
||||
|
||||
// DENSITY_NUMBER adds 1 to values
|
||||
|
||||
} else if (which[m] == ArgInfo::DENSITY_NUMBER) {
|
||||
} else if (val.which == ArgInfo::DENSITY_NUMBER) {
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && ichunk[i] > 0) {
|
||||
@ -638,8 +611,7 @@ void FixAveChunk::end_of_step()
|
||||
|
||||
// DENSITY_MASS or MASS adds mass to values
|
||||
|
||||
} else if ((which[m] == ArgInfo::DENSITY_MASS)
|
||||
|| (which[m] == ArgInfo::MASS)) {
|
||||
} else if ((val.which == ArgInfo::DENSITY_MASS) || (val.which == ArgInfo::MASS)) {
|
||||
int *type = atom->type;
|
||||
double *mass = atom->mass;
|
||||
double *rmass = atom->rmass;
|
||||
@ -661,7 +633,7 @@ void FixAveChunk::end_of_step()
|
||||
// TEMPERATURE adds KE to values
|
||||
// subtract and restore velocity bias if requested
|
||||
|
||||
} else if (which[m] == ArgInfo::TEMPERATURE) {
|
||||
} else if (val.which == ArgInfo::TEMPERATURE) {
|
||||
|
||||
if (biasflag) {
|
||||
if (tbias->invoked_scalar != ntimestep) tbias->compute_scalar();
|
||||
@ -695,14 +667,13 @@ void FixAveChunk::end_of_step()
|
||||
// COMPUTE adds its scalar or vector component to values
|
||||
// invoke compute if not previously invoked
|
||||
|
||||
} else if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
|
||||
compute->compute_peratom();
|
||||
compute->invoked_flag |= Compute::INVOKED_PERATOM;
|
||||
} else if (val.which == ArgInfo::COMPUTE) {
|
||||
if (!(val.val.c->invoked_flag & Compute::INVOKED_PERATOM)) {
|
||||
val.val.c->compute_peratom();
|
||||
val.val.c->invoked_flag |= Compute::INVOKED_PERATOM;
|
||||
}
|
||||
double *vector = compute->vector_atom;
|
||||
double **array = compute->array_atom;
|
||||
double *vector = val.val.c->vector_atom;
|
||||
double **array = val.val.c->array_atom;
|
||||
int jm1 = j - 1;
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
@ -715,9 +686,9 @@ void FixAveChunk::end_of_step()
|
||||
// FIX adds its scalar or vector component to values
|
||||
// access fix fields, guaranteed to be ready
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
double *vector = modify->fix[n]->vector_atom;
|
||||
double **array = modify->fix[n]->array_atom;
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
double *vector = val.val.f->vector_atom;
|
||||
double **array = val.val.f->array_atom;
|
||||
int jm1 = j - 1;
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
@ -730,14 +701,14 @@ void FixAveChunk::end_of_step()
|
||||
// VARIABLE adds its per-atom quantities to values
|
||||
// evaluate atom-style variable
|
||||
|
||||
} else if (which[m] == ArgInfo::VARIABLE) {
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
if (atom->nmax > maxvar) {
|
||||
maxvar = atom->nmax;
|
||||
memory->destroy(varatom);
|
||||
memory->create(varatom,maxvar,"ave/chunk:varatom");
|
||||
}
|
||||
|
||||
input->variable->compute_atom(n,igroup,varatom,1,0);
|
||||
input->variable->compute_atom(val.val.v,igroup,varatom,1,0);
|
||||
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && ichunk[i] > 0) {
|
||||
@ -745,6 +716,7 @@ void FixAveChunk::end_of_step()
|
||||
values_one[index][m] += varatom[i];
|
||||
}
|
||||
}
|
||||
++m;
|
||||
}
|
||||
|
||||
// process the current sample
|
||||
@ -784,14 +756,14 @@ void FixAveChunk::end_of_step()
|
||||
for (m = 0; m < nchunk; m++) {
|
||||
if (count_many[m] > 0.0)
|
||||
for (j = 0; j < nvalues; j++) {
|
||||
if (which[j] == ArgInfo::TEMPERATURE) {
|
||||
if (values[j].which == ArgInfo::TEMPERATURE) {
|
||||
values_many[m][j] += mvv2e*values_one[m][j] /
|
||||
((cdof + adof*count_many[m]) * boltz);
|
||||
} else if (which[j] == ArgInfo::DENSITY_NUMBER) {
|
||||
} else if (values[j].which == ArgInfo::DENSITY_NUMBER) {
|
||||
if (volflag == SCALAR) values_one[m][j] /= chunk_volume_scalar;
|
||||
else values_one[m][j] /= chunk_volume_vec[m];
|
||||
values_many[m][j] += values_one[m][j];
|
||||
} else if (which[j] == ArgInfo::DENSITY_MASS) {
|
||||
} else if (values[j].which == ArgInfo::DENSITY_MASS) {
|
||||
if (volflag == SCALAR) values_one[m][j] /= chunk_volume_scalar;
|
||||
else values_one[m][j] /= chunk_volume_vec[m];
|
||||
values_many[m][j] += mv2d*values_one[m][j];
|
||||
@ -854,13 +826,13 @@ void FixAveChunk::end_of_step()
|
||||
for (m = 0; m < nchunk; m++) {
|
||||
if (count_sum[m] > 0.0)
|
||||
for (j = 0; j < nvalues; j++) {
|
||||
if (which[j] == ArgInfo::TEMPERATURE) {
|
||||
if (values[j].which == ArgInfo::TEMPERATURE) {
|
||||
values_sum[m][j] *= mvv2e/((repeat*cdof + adof*count_sum[m])*boltz);
|
||||
} else if (which[j] == ArgInfo::DENSITY_NUMBER) {
|
||||
} else if (values[j].which == ArgInfo::DENSITY_NUMBER) {
|
||||
if (volflag == SCALAR) values_sum[m][j] /= chunk_volume_scalar;
|
||||
else values_sum[m][j] /= chunk_volume_vec[m];
|
||||
values_sum[m][j] /= repeat;
|
||||
} else if (which[j] == ArgInfo::DENSITY_MASS) {
|
||||
} else if (values[j].which == ArgInfo::DENSITY_MASS) {
|
||||
if (volflag == SCALAR) values_sum[m][j] /= chunk_volume_scalar;
|
||||
else values_sum[m][j] /= chunk_volume_vec[m];
|
||||
values_sum[m][j] *= mv2d/repeat;
|
||||
@ -1045,8 +1017,7 @@ void FixAveChunk::allocate()
|
||||
|
||||
if (ave == WINDOW) {
|
||||
memory->create(count_list,nwindow,nchunk,"ave/chunk:count_list");
|
||||
memory->create(values_list,nwindow,nchunk,nvalues,
|
||||
"ave/chunk:values_list");
|
||||
memory->create(values_list,nwindow,nchunk,nvalues,"ave/chunk:values_list");
|
||||
}
|
||||
|
||||
// reinitialize regrown count/values total since they accumulate
|
||||
|
||||
@ -36,15 +36,24 @@ class FixAveChunk : public Fix {
|
||||
double memory_usage() override;
|
||||
|
||||
private:
|
||||
int nvalues;
|
||||
int nrepeat, nfreq, irepeat;
|
||||
struct value_t {
|
||||
int which; // type of data: COMPUTE, FIX, VARIABLE
|
||||
int argindex; // 1-based index if data is vector, else 0
|
||||
std::string id; // compute/fix/variable ID
|
||||
union {
|
||||
class Compute *c;
|
||||
class Fix *f;
|
||||
int v;
|
||||
} val;
|
||||
};
|
||||
std::vector<value_t> values;
|
||||
|
||||
int nvalues, nrepeat, nfreq, irepeat;
|
||||
int normflag, scaleflag, overwrite, biasflag, colextra;
|
||||
bigint nvalid, nvalid_last;
|
||||
double adof, cdof;
|
||||
char *format, *format_user;
|
||||
char *tstring, *sstring, *id_bias;
|
||||
int *which, *argindex, *value2index;
|
||||
char **ids;
|
||||
class Compute *tbias; // ptr to additional bias compute
|
||||
FILE *fp;
|
||||
|
||||
|
||||
@ -92,14 +92,12 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
value_t val;
|
||||
val.keyword = arg[i];
|
||||
val.which = argi.get_type();
|
||||
key2col[arg[i]] = i;
|
||||
|
||||
if ((argi.get_type() == ArgInfo::NONE)
|
||||
|| (argi.get_type() == ArgInfo::UNKNOWN)
|
||||
|| (argi.get_dim() > 1))
|
||||
if ((val.which == ArgInfo::NONE) || (val.which == ArgInfo::UNKNOWN) || (argi.get_dim() > 1))
|
||||
error->all(FLERR,"Invalid fix ave/time argument: {}", arg[i]);
|
||||
|
||||
val.which = argi.get_type();
|
||||
val.argindex = argi.get_index1();
|
||||
val.varlen = 0;
|
||||
val.offcol = 0;
|
||||
@ -123,12 +121,9 @@ FixAveTime::FixAveTime(LAMMPS *lmp, int narg, char **arg) :
|
||||
// for fix inputs, check that fix frequency is acceptable
|
||||
// set variable_length if any compute is variable length
|
||||
|
||||
if (nevery <= 0)
|
||||
error->all(FLERR,"Illegal fix ave/time nevery value: {}", nevery);
|
||||
if (nrepeat <= 0)
|
||||
error->all(FLERR,"Illegal fix ave/time nrepeat value: {}", nrepeat);
|
||||
if (nfreq <= 0)
|
||||
error->all(FLERR,"Illegal fix ave/time nfreq value: {}", nfreq);
|
||||
if (nevery <= 0) error->all(FLERR,"Illegal fix ave/time nevery value: {}", nevery);
|
||||
if (nrepeat <= 0) error->all(FLERR,"Illegal fix ave/time nrepeat value: {}", nrepeat);
|
||||
if (nfreq <= 0) error->all(FLERR,"Illegal fix ave/time nfreq value: {}", nfreq);
|
||||
if (nfreq % nevery || nrepeat*nevery > nfreq)
|
||||
error->all(FLERR,"Inconsistent fix ave/time nevery/nrepeat/nfreq values");
|
||||
if (ave != RUNNING && overwrite)
|
||||
|
||||
Reference in New Issue
Block a user