modernize, more selective argument checking, better error messages

This commit is contained in:
Axel Kohlmeyer
2024-07-30 14:21:56 -04:00
parent 75b09ed143
commit b6834f33c0
2 changed files with 12 additions and 14 deletions

View File

@ -82,7 +82,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
bstyle[nvalues++] = VARIABLE;
vstr[nvar] = utils::strdup(&arg[iarg][2]);
nvar++;
} else if (arg[iarg][0] == 'b') {
} else if (utils::strmatch(arg[iarg], "^b\\d+$")) { // b1, b2, b3, ... bN
int n = std::stoi(&arg[iarg][1]);
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]);
bstyle[nvalues] = BN;
@ -98,13 +98,13 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
while (iarg < narg) {
if (strcmp(arg[iarg],"set") == 0) {
setflag = 1;
if (iarg+3 > narg) error->all(FLERR,"Illegal compute bond/local command");
if (iarg+3 > narg) utils::missing_cmd_args(FLERR,"compute bond/local set", error);
if (strcmp(arg[iarg+1],"dist") == 0) {
delete [] dstr;
dstr = utils::strdup(arg[iarg+2]);
} else error->all(FLERR,"Illegal compute bond/local command");
} else error->all(FLERR,"Unknown compute bond/local set keyword: {}", arg[iarg+2]);
iarg += 3;
} else error->all(FLERR,"Illegal compute bond/local command");
} else error->all(FLERR,"Unknown compute bond/local keyword: {}", arg[iarg]);
}
// error check
@ -115,9 +115,9 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
for (int i = 0; i < nvar; i++) {
vvar[i] = input->variable->find(vstr[i]);
if (vvar[i] < 0)
error->all(FLERR,"Variable name for copute bond/local does not exist");
error->all(FLERR,"Variable name {} for copute bond/local does not exist", vstr[i]);
if (!input->variable->equalstyle(vvar[i]))
error->all(FLERR,"Variable for compute bond/local is invalid style");
error->all(FLERR,"Variable {} for compute bond/local is invalid style", vstr[i]);
}
if (dstr) {
@ -128,7 +128,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
error->all(FLERR,"Variable for compute bond/local is invalid style");
}
} else if (setflag)
error->all(FLERR,"Compute bond/local set with no variable");
error->all(FLERR,"Compute bond/local set used with without a variable");
// set singleflag if need to call bond->single()

View File

@ -66,15 +66,13 @@ ComputePairLocal::ComputePairLocal(LAMMPS *lmp, int narg, char **arg) :
pstyle[nvalues++] = DY;
else if (strcmp(arg[iarg], "dz") == 0)
pstyle[nvalues++] = DZ;
else if (arg[iarg][0] == 'p') {
else if (utils::strmatch(arg[iarg], "^p\\d+$")) { // p1, p2, p3, ... pN
int n = std::stoi(&arg[iarg][1]);
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute pair/local command", arg[iarg]);
pstyle[nvalues] = PN;
pindex[nvalues++] = n - 1;
} else
break;
iarg++;
}
@ -84,22 +82,22 @@ ComputePairLocal::ComputePairLocal(LAMMPS *lmp, int narg, char **arg) :
while (iarg < narg) {
if (strcmp(arg[iarg], "cutoff") == 0) {
if (iarg + 2 > narg) error->all(FLERR, "Illegal compute pair/local command");
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "compute pair/local cutoff", error);
if (strcmp(arg[iarg + 1], "type") == 0)
cutstyle = TYPE;
else if (strcmp(arg[iarg + 1], "radius") == 0)
cutstyle = RADIUS;
else
error->all(FLERR, "Illegal compute pair/local command");
error->all(FLERR, "Unknown compute pair/local cutoff keyword: {}", arg[iarg + 1]);
iarg += 2;
} else
error->all(FLERR, "Illegal compute pair/local command");
error->all(FLERR, "Unknown compute pair/local keyword: {}", arg[iarg]);
}
// error check
if (cutstyle == RADIUS && !atom->radius_flag)
error->all(FLERR, "Compute pair/local requires atom attribute radius");
error->all(FLERR, "This compute pair/local requires atom attribute radius");
// set singleflag if need to call pair->single()