fix logic issue in compute reduce
This commit is contained in:
@ -133,8 +133,6 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
// parse values
|
// parse values
|
||||||
|
|
||||||
input_mode = UNDECIDED;
|
|
||||||
|
|
||||||
values.clear();
|
values.clear();
|
||||||
nvalues = 0;
|
nvalues = 0;
|
||||||
for (int iarg = 0; iarg < nargnew; ++iarg) {
|
for (int iarg = 0; iarg < nargnew; ++iarg) {
|
||||||
@ -144,41 +142,32 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
val.val.c = nullptr;
|
val.val.c = nullptr;
|
||||||
|
|
||||||
if (strcmp(arg[iarg], "x") == 0) {
|
if (strcmp(arg[iarg], "x") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::X;
|
val.which = ArgInfo::X;
|
||||||
val.argindex = 0;
|
val.argindex = 0;
|
||||||
} else if (strcmp(arg[iarg], "y") == 0) {
|
} else if (strcmp(arg[iarg], "y") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::X;
|
val.which = ArgInfo::X;
|
||||||
val.argindex = 1;
|
val.argindex = 1;
|
||||||
} else if (strcmp(arg[iarg], "z") == 0) {
|
} else if (strcmp(arg[iarg], "z") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::X;
|
val.which = ArgInfo::X;
|
||||||
val.argindex = 2;
|
val.argindex = 2;
|
||||||
|
|
||||||
} else if (strcmp(arg[iarg], "vx") == 0) {
|
} else if (strcmp(arg[iarg], "vx") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::V;
|
val.which = ArgInfo::V;
|
||||||
val.argindex = 0;
|
val.argindex = 0;
|
||||||
} else if (strcmp(arg[iarg], "vy") == 0) {
|
} else if (strcmp(arg[iarg], "vy") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::V;
|
val.which = ArgInfo::V;
|
||||||
val.argindex = 1;
|
val.argindex = 1;
|
||||||
} else if (strcmp(arg[iarg], "vz") == 0) {
|
} else if (strcmp(arg[iarg], "vz") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::V;
|
val.which = ArgInfo::V;
|
||||||
val.argindex = 2;
|
val.argindex = 2;
|
||||||
|
|
||||||
} else if (strcmp(arg[iarg], "fx") == 0) {
|
} else if (strcmp(arg[iarg], "fx") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::F;
|
val.which = ArgInfo::F;
|
||||||
val.argindex = 0;
|
val.argindex = 0;
|
||||||
} else if (strcmp(arg[iarg], "fy") == 0) {
|
} else if (strcmp(arg[iarg], "fy") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::F;
|
val.which = ArgInfo::F;
|
||||||
val.argindex = 1;
|
val.argindex = 1;
|
||||||
} else if (strcmp(arg[iarg], "fz") == 0) {
|
} else if (strcmp(arg[iarg], "fz") == 0) {
|
||||||
input_mode = PERATOM;
|
|
||||||
val.which = ArgInfo::F;
|
val.which = ArgInfo::F;
|
||||||
val.argindex = 2;
|
val.argindex = 2;
|
||||||
|
|
||||||
@ -203,6 +192,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
nvalues = values.size();
|
nvalues = values.size();
|
||||||
replace = new int[nvalues];
|
replace = new int[nvalues];
|
||||||
for (int i = 0; i < nvalues; ++i) replace[i] = -1;
|
for (int i = 0; i < nvalues; ++i) replace[i] = -1;
|
||||||
|
input_mode = PERATOM;
|
||||||
std::string mycmd = "compute ";
|
std::string mycmd = "compute ";
|
||||||
mycmd += style;
|
mycmd += style;
|
||||||
|
|
||||||
@ -225,11 +215,7 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
} else if (strcmp(arg[iarg], "inputs") == 0) {
|
} else if (strcmp(arg[iarg], "inputs") == 0) {
|
||||||
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, mycmd + " inputs", error);
|
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, mycmd + " inputs", error);
|
||||||
if (strcmp(arg[iarg+1], "peratom") == 0) input_mode = PERATOM;
|
if (strcmp(arg[iarg+1], "peratom") == 0) input_mode = PERATOM;
|
||||||
else if (strcmp(arg[iarg+1], "local") == 0) {
|
else if (strcmp(arg[iarg+1], "local") == 0) input_mode = LOCAL;
|
||||||
if (input_mode == PERATOM)
|
|
||||||
error->all(FLERR,"Compute {} inputs must be all peratom or all local");
|
|
||||||
input_mode = LOCAL;
|
|
||||||
}
|
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else
|
} else
|
||||||
error->all(FLERR, "Unknown compute {} keyword: {}", style, arg[iarg]);
|
error->all(FLERR, "Unknown compute {} keyword: {}", style, arg[iarg]);
|
||||||
@ -255,7 +241,10 @@ ComputeReduce::ComputeReduce(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
// setup and error check
|
// setup and error check
|
||||||
|
|
||||||
for (auto &val : values) {
|
for (auto &val : values) {
|
||||||
if (val.which == ArgInfo::COMPUTE) {
|
if (val.which == ArgInfo::X || val.which == ArgInfo::V || val.which == ArgInfo::F) {
|
||||||
|
if (input_mode == LOCAL) error->all(FLERR,"Compute {} inputs must be all local");
|
||||||
|
|
||||||
|
} else if (val.which == ArgInfo::COMPUTE) {
|
||||||
val.val.c = modify->get_compute_by_id(val.id);
|
val.val.c = modify->get_compute_by_id(val.id);
|
||||||
if (!val.val.c)
|
if (!val.val.c)
|
||||||
error->all(FLERR, "Compute ID {} for compute {} does not exist", val.id, style);
|
error->all(FLERR, "Compute ID {} for compute {} does not exist", val.id, style);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ namespace LAMMPS_NS {
|
|||||||
class ComputeReduce : public Compute {
|
class ComputeReduce : public Compute {
|
||||||
public:
|
public:
|
||||||
enum { SUM, SUMSQ, SUMABS, MINN, MAXX, AVE, AVESQ, AVEABS, MINABS, MAXABS };
|
enum { SUM, SUMSQ, SUMABS, MINN, MAXX, AVE, AVESQ, AVEABS, MINABS, MAXABS };
|
||||||
enum { UNDECIDED, PERATOM, LOCAL };
|
enum { PERATOM, LOCAL };
|
||||||
|
|
||||||
ComputeReduce(class LAMMPS *, int, char **);
|
ComputeReduce(class LAMMPS *, int, char **);
|
||||||
~ComputeReduce() override;
|
~ComputeReduce() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user