simplify, reformat, and better error messages

This commit is contained in:
Axel Kohlmeyer
2021-07-18 16:42:43 -04:00
parent 57df891572
commit 3c0a2345cc

View File

@ -1429,6 +1429,7 @@ int DumpCustom::parse_fields(int narg, char **arg)
ArgInfo argi(arg[iarg],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE
|ArgInfo::DNAME|ArgInfo::INAME);
argindex[iarg] = argi.get_index1();
auto name = argi.get_name();
switch (argi.get_type()) {
@ -1443,21 +1444,19 @@ int DumpCustom::parse_fields(int narg, char **arg)
pack_choice[iarg] = &DumpCustom::pack_compute;
vtype[iarg] = Dump::DOUBLE;
n = modify->find_compute(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find dump custom compute ID");
n = modify->find_compute(name);
if (n < 0) error->all(FLERR,"Could not find dump custom compute ID: {}",name);
if (modify->compute[n]->peratom_flag == 0)
error->all(FLERR,"Dump custom compute does not compute per-atom info");
error->all(FLERR,"Dump custom compute {} does not compute per-atom info",name);
if (argi.get_dim() == 0 && modify->compute[n]->size_peratom_cols > 0)
error->all(FLERR,
"Dump custom compute does not calculate per-atom vector");
error->all(FLERR,"Dump custom compute {} does not calculate per-atom vector",name);
if (argi.get_dim() > 0 && modify->compute[n]->size_peratom_cols == 0)
error->all(FLERR,
"Dump custom compute does not calculate per-atom array");
error->all(FLERR,"Dump custom compute {} does not calculate per-atom array",name);
if (argi.get_dim() > 0 &&
argi.get_index1() > modify->compute[n]->size_peratom_cols)
error->all(FLERR,"Dump custom compute vector is accessed out-of-range");
error->all(FLERR,"Dump custom compute {} vector is accessed out-of-range",name);
field2index[iarg] = add_compute(argi.get_name());
field2index[iarg] = add_compute(name);
break;
// fix value = f_ID
@ -1467,19 +1466,19 @@ int DumpCustom::parse_fields(int narg, char **arg)
pack_choice[iarg] = &DumpCustom::pack_fix;
vtype[iarg] = Dump::DOUBLE;
n = modify->find_fix(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find dump custom fix ID");
n = modify->find_fix(name);
if (n < 0) error->all(FLERR,"Could not find dump custom fix ID: {}",name);
if (modify->fix[n]->peratom_flag == 0)
error->all(FLERR,"Dump custom fix does not compute per-atom info");
error->all(FLERR,"Dump custom fix {} does not compute per-atom info",name);
if (argi.get_dim() == 0 && modify->fix[n]->size_peratom_cols > 0)
error->all(FLERR,"Dump custom fix does not compute per-atom vector");
error->all(FLERR,"Dump custom fix {} does not compute per-atom vector",name);
if (argi.get_dim() > 0 && modify->fix[n]->size_peratom_cols == 0)
error->all(FLERR,"Dump custom fix does not compute per-atom array");
error->all(FLERR,"Dump custom fix {} does not compute per-atom array",name);
if (argi.get_dim() > 0 &&
argi.get_index1() > modify->fix[n]->size_peratom_cols)
error->all(FLERR,"Dump custom fix vector is accessed out-of-range");
error->all(FLERR,"Dump custom fix {} vector is accessed out-of-range",name);
field2index[iarg] = add_fix(argi.get_name());
field2index[iarg] = add_fix(name);
break;
// variable value = v_name
@ -1488,12 +1487,12 @@ int DumpCustom::parse_fields(int narg, char **arg)
pack_choice[iarg] = &DumpCustom::pack_variable;
vtype[iarg] = Dump::DOUBLE;
n = input->variable->find(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find dump custom variable name");
n = input->variable->find(name);
if (n < 0) error->all(FLERR,"Could not find dump custom variable name {}",name);
if (input->variable->atomstyle(n) == 0)
error->all(FLERR,"Dump custom variable is not atom-style variable");
error->all(FLERR,"Dump custom variable {} is not atom-style variable",name);
field2index[iarg] = add_variable(argi.get_name());
field2index[iarg] = add_variable(name);
break;
// custom per-atom floating point value = d_ID
@ -1503,14 +1502,14 @@ int DumpCustom::parse_fields(int narg, char **arg)
vtype[iarg] = Dump::DOUBLE;
tmp = -1;
n = atom->find_custom(argi.get_name(),tmp);
n = atom->find_custom(name,tmp);
if (n < 0)
error->all(FLERR,"Could not find custom per-atom property ID");
error->all(FLERR,"Could not find custom per-atom property ID: {}", name);
if (tmp != 1)
error->all(FLERR,"Custom per-atom property ID is not floating point");
error->all(FLERR,"Custom per-atom property ID {} is not floating point", name);
field2index[iarg] = add_custom(argi.get_name(),1);
field2index[iarg] = add_custom(name,1);
break;
// custom per-atom integer value = i_ID
@ -1520,14 +1519,14 @@ int DumpCustom::parse_fields(int narg, char **arg)
vtype[iarg] = Dump::INT;
tmp = -1;
n = atom->find_custom(argi.get_name(),tmp);
n = atom->find_custom(name,tmp);
if (n < 0)
error->all(FLERR,"Could not find custom per-atom property ID");
error->all(FLERR,"Could not find custom per-atom property ID: {}", name);
if (tmp != 0)
error->all(FLERR,"Custom per-atom property ID is not integer");
error->all(FLERR,"Custom per-atom property ID {} is not integer", name);
field2index[iarg] = add_custom(argi.get_name(),0);
field2index[iarg] = add_custom(name,0);
break;
default:
@ -1648,7 +1647,7 @@ int DumpCustom::modify_param(int narg, char **arg)
else {
iregion = domain->find_region(arg[1]);
if (iregion == -1)
error->all(FLERR,"Dump_modify region ID does not exist");
error->all(FLERR,"Dump_modify region ID {} does not exist",arg[1]);
delete[] idregion;
idregion = utils::strdup(arg[1]);
}
@ -1679,8 +1678,7 @@ int DumpCustom::modify_param(int narg, char **arg)
// use of &str[1] removes leading '%' from BIGINT_FORMAT string
char *ptr = strchr(format_int_user,'d');
if (ptr == nullptr)
error->all(FLERR,
"Dump_modify int format does not contain d character");
error->all(FLERR,"Dump_modify int format does not contain d character");
char str[8];
sprintf(str,"%s",BIGINT_FORMAT);
*ptr = '\0';
@ -1703,7 +1701,7 @@ int DumpCustom::modify_param(int narg, char **arg)
if (strcmp(arg[0],"element") == 0) {
if (narg < ntypes+1)
error->all(FLERR,"Dump_modify element names do not match atom types");
error->all(FLERR,"Number of dump_modify element names does not match number of atom types");
for (int i = 1; i <= ntypes; i++) delete[] typenames[i];
delete[] typenames;
@ -1850,6 +1848,7 @@ int DumpCustom::modify_param(int narg, char **arg)
ArgInfo argi(arg[1],ArgInfo::COMPUTE|ArgInfo::FIX|ArgInfo::VARIABLE
|ArgInfo::DNAME|ArgInfo::INAME);
argindex[nfield+nthresh] = argi.get_index1();
auto name = argi.get_name();
switch (argi.get_type()) {
@ -1862,23 +1861,20 @@ int DumpCustom::modify_param(int narg, char **arg)
case ArgInfo::COMPUTE:
thresh_array[nthresh] = COMPUTE;
n = modify->find_compute(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find dump modify compute ID");
n = modify->find_compute(name);
if (n < 0) error->all(FLERR,"Could not find dump modify compute ID: {}",name);
if (modify->compute[n]->peratom_flag == 0)
error->all(FLERR,
"Dump modify compute ID does not compute per-atom info");
error->all(FLERR,"Dump modify compute ID {} does not compute per-atom info",name);
if (argi.get_dim() == 0 && modify->compute[n]->size_peratom_cols > 0)
error->all(FLERR,
"Dump modify compute ID does not compute per-atom vector");
error->all(FLERR,"Dump modify compute ID {} does not compute per-atom vector",name);
if (argi.get_index1() > 0 && modify->compute[n]->size_peratom_cols == 0)
error->all(FLERR,
"Dump modify compute ID does not compute per-atom array");
error->all(FLERR,"Dump modify compute ID {} does not compute per-atom array",name);
if (argi.get_index1() > 0 &&
argi.get_index1() > modify->compute[n]->size_peratom_cols)
error->all(FLERR,"Dump modify compute ID vector is not large enough");
error->all(FLERR,"Dump modify compute ID {} vector is not large enough",name);
field2index[nfield+nthresh] = add_compute(argi.get_name());
field2index[nfield+nthresh] = add_compute(name);
break;
// fix value = f_ID
@ -1886,20 +1882,19 @@ int DumpCustom::modify_param(int narg, char **arg)
case ArgInfo::FIX:
thresh_array[nthresh] = FIX;
n = modify->find_fix(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find dump modify fix ID");
n = modify->find_fix(name);
if (n < 0) error->all(FLERR,"Could not find dump modify fix ID: {}",name);
if (modify->fix[n]->peratom_flag == 0)
error->all(FLERR,"Dump modify fix ID does not compute per-atom info");
error->all(FLERR,"Dump modify fix ID {} does not compute per-atom info",name);
if (argi.get_dim() == 0 && modify->fix[n]->size_peratom_cols > 0)
error->all(FLERR,"Dump modify fix ID does not compute per-atom vector");
error->all(FLERR,"Dump modify fix ID {} does not compute per-atom vector",name);
if (argi.get_index1() > 0 && modify->fix[n]->size_peratom_cols == 0)
error->all(FLERR,"Dump modify fix ID does not compute per-atom array");
if (argi.get_index1() > 0 &&
argi.get_index1() > modify->fix[n]->size_peratom_cols)
error->all(FLERR,"Dump modify fix ID vector is not large enough");
error->all(FLERR,"Dump modify fix ID {} does not compute per-atom array",name);
if (argi.get_index1() > 0 && argi.get_index1() > modify->fix[n]->size_peratom_cols)
error->all(FLERR,"Dump modify fix ID {} vector is not large enough",name);
field2index[nfield+nthresh] = add_fix(argi.get_name());
field2index[nfield+nthresh] = add_fix(name);
break;
// variable value = v_ID
@ -1907,12 +1902,12 @@ int DumpCustom::modify_param(int narg, char **arg)
case ArgInfo::VARIABLE:
thresh_array[nthresh] = VARIABLE;
n = input->variable->find(argi.get_name());
if (n < 0) error->all(FLERR,"Could not find dump modify variable name");
n = input->variable->find(name);
if (n < 0) error->all(FLERR,"Could not find dump modify variable name: {}",name);
if (input->variable->atomstyle(n) == 0)
error->all(FLERR,"Dump modify variable is not atom-style variable");
error->all(FLERR,"Dump modify variable {} is not atom-style variable",name);
field2index[nfield+nthresh] = add_variable(argi.get_name());
field2index[nfield+nthresh] = add_variable(name);
break;
// custom per atom floating point value = d_ID
@ -1920,12 +1915,11 @@ int DumpCustom::modify_param(int narg, char **arg)
case ArgInfo::DNAME:
thresh_array[nthresh] = DNAME;
tmp = -1;
n = atom->find_custom(argi.get_name(),tmp);
n = atom->find_custom(name,tmp);
if ((n < 0) || (tmp != 1))
error->all(FLERR,"Could not find dump modify "
"custom atom floating point property ID");
error->all(FLERR,"Could not find dump modify custom atom floating point property ID: {}",name);
field2index[nfield+nthresh] = add_custom(argi.get_name(),1);
field2index[nfield+nthresh] = add_custom(name,1);
break;
// custom per atom integer value = i_ID
@ -1933,16 +1927,15 @@ int DumpCustom::modify_param(int narg, char **arg)
case ArgInfo::INAME:
thresh_array[nthresh] = INAME;
tmp = -1;
n = atom->find_custom(argi.get_name(),tmp);
n = atom->find_custom(name,tmp);
if ((n < 0) || (tmp != 0))
error->all(FLERR,"Could not find dump modify "
"custom atom integer property ID");
error->all(FLERR,"Could not find dump modify custom atom integer property ID: {}",name);
field2index[nfield+nthresh] = add_custom(argi.get_name(),0);
field2index[nfield+nthresh] = add_custom(name,0);
break;
default:
error->all(FLERR,"Invalid dump_modify thresh attribute");
error->all(FLERR,"Invalid dump_modify thresh attribute: {}",name);
break;
}
}