modernize, more selective argument checking, better error messages
This commit is contained in:
@ -82,7 +82,7 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
bstyle[nvalues++] = VARIABLE;
|
bstyle[nvalues++] = VARIABLE;
|
||||||
vstr[nvar] = utils::strdup(&arg[iarg][2]);
|
vstr[nvar] = utils::strdup(&arg[iarg][2]);
|
||||||
nvar++;
|
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]);
|
int n = std::stoi(&arg[iarg][1]);
|
||||||
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]);
|
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute bond/local command", arg[iarg]);
|
||||||
bstyle[nvalues] = BN;
|
bstyle[nvalues] = BN;
|
||||||
@ -98,13 +98,13 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
while (iarg < narg) {
|
while (iarg < narg) {
|
||||||
if (strcmp(arg[iarg],"set") == 0) {
|
if (strcmp(arg[iarg],"set") == 0) {
|
||||||
setflag = 1;
|
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) {
|
if (strcmp(arg[iarg+1],"dist") == 0) {
|
||||||
delete [] dstr;
|
delete [] dstr;
|
||||||
dstr = utils::strdup(arg[iarg+2]);
|
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;
|
iarg += 3;
|
||||||
} else error->all(FLERR,"Illegal compute bond/local command");
|
} else error->all(FLERR,"Unknown compute bond/local keyword: {}", arg[iarg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// error check
|
// error check
|
||||||
@ -115,9 +115,9 @@ ComputeBondLocal::ComputeBondLocal(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
for (int i = 0; i < nvar; i++) {
|
for (int i = 0; i < nvar; i++) {
|
||||||
vvar[i] = input->variable->find(vstr[i]);
|
vvar[i] = input->variable->find(vstr[i]);
|
||||||
if (vvar[i] < 0)
|
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]))
|
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) {
|
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");
|
error->all(FLERR,"Variable for compute bond/local is invalid style");
|
||||||
}
|
}
|
||||||
} else if (setflag)
|
} 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()
|
// set singleflag if need to call bond->single()
|
||||||
|
|||||||
@ -66,15 +66,13 @@ ComputePairLocal::ComputePairLocal(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
pstyle[nvalues++] = DY;
|
pstyle[nvalues++] = DY;
|
||||||
else if (strcmp(arg[iarg], "dz") == 0)
|
else if (strcmp(arg[iarg], "dz") == 0)
|
||||||
pstyle[nvalues++] = DZ;
|
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]);
|
int n = std::stoi(&arg[iarg][1]);
|
||||||
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute pair/local command", arg[iarg]);
|
if (n <= 0) error->all(FLERR, "Invalid keyword {} in compute pair/local command", arg[iarg]);
|
||||||
pstyle[nvalues] = PN;
|
pstyle[nvalues] = PN;
|
||||||
pindex[nvalues++] = n - 1;
|
pindex[nvalues++] = n - 1;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
iarg++;
|
iarg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,22 +82,22 @@ ComputePairLocal::ComputePairLocal(LAMMPS *lmp, int narg, char **arg) :
|
|||||||
|
|
||||||
while (iarg < narg) {
|
while (iarg < narg) {
|
||||||
if (strcmp(arg[iarg], "cutoff") == 0) {
|
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)
|
if (strcmp(arg[iarg + 1], "type") == 0)
|
||||||
cutstyle = TYPE;
|
cutstyle = TYPE;
|
||||||
else if (strcmp(arg[iarg + 1], "radius") == 0)
|
else if (strcmp(arg[iarg + 1], "radius") == 0)
|
||||||
cutstyle = RADIUS;
|
cutstyle = RADIUS;
|
||||||
else
|
else
|
||||||
error->all(FLERR, "Illegal compute pair/local command");
|
error->all(FLERR, "Unknown compute pair/local cutoff keyword: {}", arg[iarg + 1]);
|
||||||
iarg += 2;
|
iarg += 2;
|
||||||
} else
|
} else
|
||||||
error->all(FLERR, "Illegal compute pair/local command");
|
error->all(FLERR, "Unknown compute pair/local keyword: {}", arg[iarg]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// error check
|
// error check
|
||||||
|
|
||||||
if (cutstyle == RADIUS && !atom->radius_flag)
|
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()
|
// set singleflag if need to call pair->single()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user