refactor compute reduce and compute reduce/region
This commit is contained in:
@ -55,62 +55,58 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
// only include atoms in group
|
||||
|
||||
index = -1;
|
||||
auto &val = values[m];
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
int aidx = val.argindex;
|
||||
double **x = atom->x;
|
||||
int *mask = atom->mask;
|
||||
int nlocal = atom->nlocal;
|
||||
|
||||
int n = value2index[m];
|
||||
|
||||
// initialization in case it has not yet been run,
|
||||
// e.g. when invoked
|
||||
if (n == ArgInfo::UNKNOWN) {
|
||||
init();
|
||||
n = value2index[m];
|
||||
}
|
||||
|
||||
int j = argindex[m];
|
||||
|
||||
double one = 0.0;
|
||||
if (mode == MINN) one = BIG;
|
||||
if (mode == MAXX) one = -BIG;
|
||||
|
||||
if (which[m] == ArgInfo::X) {
|
||||
if (val.which == ArgInfo::X) {
|
||||
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, x[i][j], i);
|
||||
combine(one, x[i][aidx], i);
|
||||
} else
|
||||
one = x[flag][j];
|
||||
} else if (which[m] == ArgInfo::V) {
|
||||
one = x[flag][aidx];
|
||||
} else if (val.which == ArgInfo::V) {
|
||||
double **v = atom->v;
|
||||
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, v[i][j], i);
|
||||
combine(one, v[i][aidx], i);
|
||||
} else
|
||||
one = v[flag][j];
|
||||
} else if (which[m] == ArgInfo::F) {
|
||||
one = v[flag][aidx];
|
||||
} else if (val.which == ArgInfo::F) {
|
||||
double **f = atom->f;
|
||||
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, f[i][j], i);
|
||||
combine(one, f[i][aidx], i);
|
||||
} else
|
||||
one = f[flag][j];
|
||||
one = f[flag][aidx];
|
||||
|
||||
// invoke compute if not previously invoked
|
||||
|
||||
} else if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
|
||||
if (flavor[m] == PERATOM) {
|
||||
if (!(compute->invoked_flag & Compute::INVOKED_PERATOM)) {
|
||||
compute->compute_peratom();
|
||||
compute->invoked_flag |= Compute::INVOKED_PERATOM;
|
||||
} else if (val.which == ArgInfo::COMPUTE) {
|
||||
if (val.flavor == PERATOM) {
|
||||
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;
|
||||
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]))
|
||||
@ -118,48 +114,48 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
} else
|
||||
one = compute_vector[flag];
|
||||
} else {
|
||||
double **compute_array = compute->array_atom;
|
||||
int jm1 = j - 1;
|
||||
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][jm1], i);
|
||||
combine(one, compute_array[i][aidxm1], i);
|
||||
} else
|
||||
one = compute_array[flag][jm1];
|
||||
one = compute_array[flag][aidxm1];
|
||||
}
|
||||
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
if (!(compute->invoked_flag & Compute::INVOKED_LOCAL)) {
|
||||
compute->compute_local();
|
||||
compute->invoked_flag |= Compute::INVOKED_LOCAL;
|
||||
} else if (val.flavor == LOCAL) {
|
||||
if (!(val.val.c->invoked_flag & Compute::INVOKED_LOCAL)) {
|
||||
val.val.c->compute_local();
|
||||
val.val.c->invoked_flag |= Compute::INVOKED_LOCAL;
|
||||
}
|
||||
|
||||
if (j == 0) {
|
||||
double *compute_vector = compute->vector_local;
|
||||
if (aidx == 0) {
|
||||
double *compute_vector = val.val.c->vector_local;
|
||||
if (flag < 0)
|
||||
for (int i = 0; i < compute->size_local_rows; i++) combine(one, compute_vector[i], i);
|
||||
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 = compute->array_local;
|
||||
int jm1 = j - 1;
|
||||
double **compute_array = val.val.c->array_local;
|
||||
int aidxm1 = aidx - 1;
|
||||
if (flag < 0)
|
||||
for (int i = 0; i < compute->size_local_rows; i++) combine(one, compute_array[i][jm1], i);
|
||||
for (int i = 0; i < val.val.c->size_local_rows; i++)
|
||||
combine(one, compute_array[i][aidxm1], i);
|
||||
else
|
||||
one = compute_array[flag][jm1];
|
||||
one = compute_array[flag][aidxm1];
|
||||
}
|
||||
}
|
||||
|
||||
// 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");
|
||||
Fix *fix = modify->fix[n];
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
if (update->ntimestep % val.val.f->peratom_freq)
|
||||
error->all(FLERR, "Fix {} used in compute {} not computed at compatible time", val.id, style);
|
||||
|
||||
if (flavor[m] == PERATOM) {
|
||||
if (j == 0) {
|
||||
double *fix_vector = fix->vector_atom;
|
||||
if (val.flavor == 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]))
|
||||
@ -167,43 +163,44 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
} else
|
||||
one = fix_vector[flag];
|
||||
} else {
|
||||
double **fix_array = fix->array_atom;
|
||||
int jm1 = j - 1;
|
||||
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][jm1], i);
|
||||
combine(one, fix_array[i][aidxm1], i);
|
||||
} else
|
||||
one = fix_array[flag][jm1];
|
||||
one = fix_array[flag][aidxm1];
|
||||
}
|
||||
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
if (j == 0) {
|
||||
double *fix_vector = fix->vector_local;
|
||||
} else if (val.flavor == LOCAL) {
|
||||
if (aidx == 0) {
|
||||
double *fix_vector = val.val.f->vector_local;
|
||||
if (flag < 0)
|
||||
for (int i = 0; i < fix->size_local_rows; i++) combine(one, fix_vector[i], i);
|
||||
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 = fix->array_local;
|
||||
int jm1 = j - 1;
|
||||
double **fix_array = val.val.f->array_local;
|
||||
int aidxm1 = aidx - 1;
|
||||
if (flag < 0)
|
||||
for (int i = 0; i < fix->size_local_rows; i++) combine(one, fix_array[i][jm1], i);
|
||||
for (int i = 0; i < val.val.f->size_local_rows; i++)
|
||||
combine(one, fix_array[i][aidxm1], i);
|
||||
else
|
||||
one = fix_array[flag][jm1];
|
||||
one = fix_array[flag][aidxm1];
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate atom-style variable
|
||||
|
||||
} else if (which[m] == ArgInfo::VARIABLE) {
|
||||
} else if (val.which == ArgInfo::VARIABLE) {
|
||||
if (atom->nmax > maxatom) {
|
||||
maxatom = atom->nmax;
|
||||
memory->destroy(varatom);
|
||||
memory->create(varatom, maxatom, "reduce/region:varatom");
|
||||
}
|
||||
|
||||
input->variable->compute_atom(n, igroup, varatom, 1, 0);
|
||||
input->variable->compute_atom(val.val.v, igroup, varatom, 1, 0);
|
||||
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]))
|
||||
@ -219,31 +216,29 @@ double ComputeReduceRegion::compute_one(int m, int flag)
|
||||
|
||||
bigint ComputeReduceRegion::count(int m)
|
||||
{
|
||||
int n = value2index[m];
|
||||
auto &val = values[m];
|
||||
|
||||
if (which[m] == ArgInfo::X || which[m] == ArgInfo::V || which[m] == ArgInfo::F)
|
||||
if (val.which == ArgInfo::X || val.which == ArgInfo::V || val.which == ArgInfo::F)
|
||||
return group->count(igroup, region);
|
||||
else if (which[m] == ArgInfo::COMPUTE) {
|
||||
Compute *compute = modify->compute[n];
|
||||
if (flavor[m] == PERATOM) {
|
||||
else if (val.which == ArgInfo::COMPUTE) {
|
||||
if (val.flavor == PERATOM) {
|
||||
return group->count(igroup, region);
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
bigint ncount = compute->size_local_rows;
|
||||
} else if (val.flavor == 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 (which[m] == ArgInfo::FIX) {
|
||||
Fix *fix = modify->fix[n];
|
||||
if (flavor[m] == PERATOM) {
|
||||
} else if (val.which == ArgInfo::FIX) {
|
||||
if (val.flavor == PERATOM) {
|
||||
return group->count(igroup, region);
|
||||
} else if (flavor[m] == LOCAL) {
|
||||
bigint ncount = fix->size_local_rows;
|
||||
} else if (val.flavor == 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 (which[m] == ArgInfo::VARIABLE)
|
||||
} else if (val.which == ArgInfo::VARIABLE)
|
||||
return group->count(igroup, region);
|
||||
|
||||
bigint dummy = 0;
|
||||
|
||||
Reference in New Issue
Block a user