clarify doc for fix ave/histo command

This commit is contained in:
Steve Plimpton
2023-08-21 10:54:42 -06:00
parent c6233547a5
commit ab2b83f654
4 changed files with 86 additions and 129 deletions

View File

@ -35,13 +35,15 @@ static constexpr double BIG = 1.0e20;
ComputeReduceRegion::ComputeReduceRegion(LAMMPS *lmp, int narg, char **arg) :
ComputeReduce(lmp, narg, arg)
{
if (input_mode == LOCAL)
error->all(FLERR,"Compute reduce/region cannot use local data as input");
}
/* ----------------------------------------------------------------------
calculate reduced value for one input M and return it
if flag = -1:
sum/min/max/ave all values in vector
for per-atom quantities, limit to atoms in group and region
limit to atoms in group and region
if mode = MIN or MAX, also set index to which vector value wins
if flag >= 0: simply return vector[flag]
------------------------------------------------------------------------- */
@ -59,6 +61,7 @@ double ComputeReduceRegion::compute_one(int m, int flag)
// initialization in case it has not yet been run, e.g. when
// the compute was invoked right after it has been created
if ((val.which == ArgInfo::COMPUTE) || (val.which == ArgInfo::FIX)) {
if (val.val.c == nullptr) init();
}
@ -99,52 +102,29 @@ double ComputeReduceRegion::compute_one(int m, int flag)
// invoke compute if not previously invoked
} else if (val.which == ArgInfo::COMPUTE) {
if (input_mode == PERATOM) {
if (!(val.val.c->invoked_flag & Compute::INVOKED_PERATOM)) {
val.val.c->compute_peratom();
val.val.c->invoked_flag |= Compute::INVOKED_PERATOM;
}
if (aidx == 0) {
double *compute_vector = val.val.c->vector_atom;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, compute_vector[i], i);
} else
one = compute_vector[flag];
} else {
double **compute_array = val.val.c->array_atom;
int aidxm1 = aidx - 1;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, compute_array[i][aidxm1], i);
} else
one = compute_array[flag][aidxm1];
}
if (!(val.val.c->invoked_flag & Compute::INVOKED_PERATOM)) {
val.val.c->compute_peratom();
val.val.c->invoked_flag |= Compute::INVOKED_PERATOM;
}
} else if (input_mode == LOCAL) {
if (!(val.val.c->invoked_flag & Compute::INVOKED_LOCAL)) {
val.val.c->compute_local();
val.val.c->invoked_flag |= Compute::INVOKED_LOCAL;
}
if (aidx == 0) {
double *compute_vector = val.val.c->vector_local;
if (flag < 0)
for (int i = 0; i < val.val.c->size_local_rows; i++) combine(one, compute_vector[i], i);
else
one = compute_vector[flag];
} else {
double **compute_array = val.val.c->array_local;
int aidxm1 = aidx - 1;
if (flag < 0)
for (int i = 0; i < val.val.c->size_local_rows; i++)
if (aidx == 0) {
double *compute_vector = val.val.c->vector_atom;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, compute_vector[i], i);
} else
one = compute_vector[flag];
} else {
double **compute_array = val.val.c->array_atom;
int aidxm1 = aidx - 1;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, compute_array[i][aidxm1], i);
else
one = compute_array[flag][aidxm1];
}
} else
one = compute_array[flag][aidxm1];
}
// check if fix frequency is a match
@ -153,45 +133,26 @@ double ComputeReduceRegion::compute_one(int m, int flag)
if (update->ntimestep % val.val.f->peratom_freq)
error->all(FLERR, "Fix {} used in compute {} not computed at compatible time", val.id, style);
if (input_mode == PERATOM) {
if (aidx == 0) {
double *fix_vector = val.val.f->vector_atom;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, fix_vector[i], i);
} else
one = fix_vector[flag];
} else {
double **fix_array = val.val.f->array_atom;
int aidxm1 = aidx - 1;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, fix_array[i][aidxm1], i);
} else
one = fix_array[flag][aidxm1];
}
} else if (input_mode == LOCAL) {
if (aidx == 0) {
double *fix_vector = val.val.f->vector_local;
if (flag < 0)
for (int i = 0; i < val.val.f->size_local_rows; i++) combine(one, fix_vector[i], i);
else
one = fix_vector[flag];
} else {
double **fix_array = val.val.f->array_local;
int aidxm1 = aidx - 1;
if (flag < 0)
for (int i = 0; i < val.val.f->size_local_rows; i++)
if (aidx == 0) {
double *fix_vector = val.val.f->vector_atom;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, fix_vector[i], i);
} else
one = fix_vector[flag];
} else {
double **fix_array = val.val.f->array_atom;
int aidxm1 = aidx - 1;
if (flag < 0) {
for (int i = 0; i < nlocal; i++)
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
combine(one, fix_array[i][aidxm1], i);
else
one = fix_array[flag][aidxm1];
}
} else
one = fix_array[flag][aidxm1];
}
// evaluate atom-style variable
// evaluate atom-style variable
} else if (val.which == ArgInfo::VARIABLE) {
if (atom->nmax > maxatom) {
@ -220,25 +181,11 @@ bigint ComputeReduceRegion::count(int m)
if (val.which == ArgInfo::X || val.which == ArgInfo::V || val.which == ArgInfo::F)
return group->count(igroup, region);
else if (val.which == ArgInfo::COMPUTE) {
if (input_mode == PERATOM) {
return group->count(igroup, region);
} else if (input_mode == LOCAL) {
bigint ncount = val.val.c->size_local_rows;
bigint ncountall;
MPI_Allreduce(&ncount, &ncountall, 1, MPI_DOUBLE, MPI_SUM, world);
return ncountall;
}
} else if (val.which == ArgInfo::FIX) {
if (input_mode == PERATOM) {
return group->count(igroup, region);
} else if (input_mode == LOCAL) {
bigint ncount = val.val.f->size_local_rows;
bigint ncountall;
MPI_Allreduce(&ncount, &ncountall, 1, MPI_DOUBLE, MPI_SUM, world);
return ncountall;
}
} else if (val.which == ArgInfo::VARIABLE)
else if (val.which == ArgInfo::COMPUTE)
return group->count(igroup, region);
else if (val.which == ArgInfo::FIX)
return group->count(igroup, region);
else if (val.which == ArgInfo::VARIABLE)
return group->count(igroup, region);
bigint dummy = 0;