refactor group access, enable and apply clang-format
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
// clang-format off
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
@ -29,12 +28,14 @@
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
#define BIG 1.0e20
|
||||
static constexpr double BIG = 1.0e20;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
ComputeReduceRegion::ComputeReduceRegion(LAMMPS *lmp, int narg, char **arg) :
|
||||
ComputeReduce(lmp, narg, arg) {}
|
||||
ComputeReduce(lmp, narg, arg)
|
||||
{
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
calculate reduced value for one input M and return it
|
||||
@ -47,9 +48,6 @@ ComputeReduceRegion::ComputeReduceRegion(LAMMPS *lmp, int narg, char **arg) :
|
||||
|
||||
double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
{
|
||||
int i;
|
||||
|
||||
Region *region = domain->regions[iregion];
|
||||
region->prematch();
|
||||
|
||||
// invoke the appropriate attribute,compute,fix,variable
|
||||
@ -78,26 +76,29 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
|
||||
if (which[m] == ArgInfo::X) {
|
||||
if (flag < 0) {
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2]))
|
||||
combine(one,x[i][j],i);
|
||||
} else one = x[flag][j];
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
|
||||
combine(one, x[i][j], i);
|
||||
} else
|
||||
one = x[flag][j];
|
||||
} else if (which[m] == ArgInfo::V) {
|
||||
double **v = atom->v;
|
||||
if (flag < 0) {
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2]))
|
||||
combine(one,v[i][j],i);
|
||||
} else one = v[flag][j];
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
|
||||
combine(one, v[i][j], i);
|
||||
} else
|
||||
one = v[flag][j];
|
||||
} else if (which[m] == ArgInfo::F) {
|
||||
double **f = atom->f;
|
||||
if (flag < 0) {
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2]))
|
||||
combine(one,f[i][j],i);
|
||||
} else one = f[flag][j];
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
|
||||
combine(one, f[i][j], i);
|
||||
} else
|
||||
one = f[flag][j];
|
||||
|
||||
// invoke compute if not previously invoked
|
||||
// invoke compute if not previously invoked
|
||||
|
||||
} else if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
@ -111,18 +112,20 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
if (j == 0) {
|
||||
double *compute_vector = compute->vector_atom;
|
||||
if (flag < 0) {
|
||||
for (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];
|
||||
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 = compute->array_atom;
|
||||
int jm1 = j - 1;
|
||||
if (flag < 0) {
|
||||
for (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][jm1],i);
|
||||
} else one = compute_array[flag][jm1];
|
||||
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][jm1], i);
|
||||
} else
|
||||
one = compute_array[flag][jm1];
|
||||
}
|
||||
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
@ -134,76 +137,79 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
if (j == 0) {
|
||||
double *compute_vector = compute->vector_local;
|
||||
if (flag < 0)
|
||||
for (i = 0; i < compute->size_local_rows; i++)
|
||||
combine(one,compute_vector[i],i);
|
||||
else one = compute_vector[flag];
|
||||
for (int i = 0; i < compute->size_local_rows; i++) combine(one, compute_vector[i], i);
|
||||
else
|
||||
one = compute_vector[flag];
|
||||
} else {
|
||||
double **compute_array = compute->array_local;
|
||||
int jm1 = j - 1;
|
||||
if (flag < 0)
|
||||
for (i = 0; i < compute->size_local_rows; i++)
|
||||
combine(one,compute_array[i][jm1],i);
|
||||
else one = compute_array[flag][jm1];
|
||||
for (int i = 0; i < compute->size_local_rows; i++) combine(one, compute_array[i][jm1], i);
|
||||
else
|
||||
one = compute_array[flag][jm1];
|
||||
}
|
||||
}
|
||||
|
||||
// check if fix frequency is a match
|
||||
// check if fix frequency is a match
|
||||
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
if (update->ntimestep % modify->fix[n]->peratom_freq)
|
||||
error->all(FLERR,"Fix used in compute reduce not computed at compatible time");
|
||||
error->all(FLERR, "Fix used in compute reduce not computed at compatible time");
|
||||
Fix *fix = modify->fix[n];
|
||||
|
||||
if (flavor[m] == PERATOM) {
|
||||
if (j == 0) {
|
||||
double *fix_vector = fix->vector_atom;
|
||||
if (flag < 0) {
|
||||
for (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];
|
||||
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 = fix->array_atom;
|
||||
int jm1 = j - 1;
|
||||
if (flag < 0) {
|
||||
for (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][jm1],i);
|
||||
} else one = fix_array[flag][jm1];
|
||||
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][jm1], i);
|
||||
} else
|
||||
one = fix_array[flag][jm1];
|
||||
}
|
||||
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
if (j == 0) {
|
||||
double *fix_vector = fix->vector_local;
|
||||
if (flag < 0)
|
||||
for (i = 0; i < fix->size_local_rows; i++)
|
||||
combine(one,fix_vector[i],i);
|
||||
else one = fix_vector[flag];
|
||||
for (int i = 0; i < fix->size_local_rows; i++) combine(one, fix_vector[i], i);
|
||||
else
|
||||
one = fix_vector[flag];
|
||||
} else {
|
||||
double **fix_array = fix->array_local;
|
||||
int jm1 = j - 1;
|
||||
if (flag < 0)
|
||||
for (i = 0; i < fix->size_local_rows; i++)
|
||||
combine(one,fix_array[i][jm1],i);
|
||||
else one = fix_array[flag][jm1];
|
||||
for (int i = 0; i < fix->size_local_rows; i++) combine(one, fix_array[i][jm1], i);
|
||||
else
|
||||
one = fix_array[flag][jm1];
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate atom-style variable
|
||||
// evaluate atom-style variable
|
||||
|
||||
} else if (which[m] == ArgInfo::VARIABLE) {
|
||||
if (atom->nmax > maxatom) {
|
||||
maxatom = atom->nmax;
|
||||
memory->destroy(varatom);
|
||||
memory->create(varatom,maxatom,"reduce/region:varatom");
|
||||
memory->create(varatom, maxatom, "reduce/region:varatom");
|
||||
}
|
||||
|
||||
input->variable->compute_atom(n,igroup,varatom,1,0);
|
||||
input->variable->compute_atom(n, igroup, varatom, 1, 0);
|
||||
if (flag < 0) {
|
||||
for (i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2]))
|
||||
combine(one,varatom[i],i);
|
||||
} else one = varatom[flag];
|
||||
for (int i = 0; i < nlocal; i++)
|
||||
if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2]))
|
||||
combine(one, varatom[i], i);
|
||||
} else
|
||||
one = varatom[flag];
|
||||
}
|
||||
|
||||
return one;
|
||||
@ -216,29 +222,29 @@ bigint ComputeReduceRegion::count(int m)
|
||||
int n = value2index[m];
|
||||
|
||||
if (which[m] == ArgInfo::X || which[m] == ArgInfo::V || which[m] == ArgInfo::F)
|
||||
return group->count(igroup,iregion);
|
||||
return group->count(igroup, region);
|
||||
else if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
if (flavor[m] == PERATOM) {
|
||||
return group->count(igroup,iregion);
|
||||
return group->count(igroup, region);
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
bigint ncount = compute->size_local_rows;
|
||||
bigint ncountall;
|
||||
MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
MPI_Allreduce(&ncount, &ncountall, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
return ncountall;
|
||||
}
|
||||
} else if (which[m] == ArgInfo::FIX) {
|
||||
Fix *fix = modify->fix[n];
|
||||
if (flavor[m] == PERATOM) {
|
||||
return group->count(igroup,iregion);
|
||||
return group->count(igroup, region);
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
bigint ncount = fix->size_local_rows;
|
||||
bigint ncountall;
|
||||
MPI_Allreduce(&ncount,&ncountall,1,MPI_DOUBLE,MPI_SUM,world);
|
||||
MPI_Allreduce(&ncount, &ncountall, 1, MPI_DOUBLE, MPI_SUM, world);
|
||||
return ncountall;
|
||||
}
|
||||
} else if (which[m] == ArgInfo::VARIABLE)
|
||||
return group->count(igroup,iregion);
|
||||
return group->count(igroup, region);
|
||||
|
||||
bigint dummy = 0;
|
||||
return dummy;
|
||||
|
||||
Reference in New Issue
Block a user