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

@ -193,16 +193,16 @@ DumpCustom::~DumpCustom()
// could not do in constructor, b/c some derived classes process earg
if (expand) {
for (int i = 0; i < nargnew; i++) delete [] earg[i];
for (int i = 0; i < nargnew; i++) delete[] earg[i];
memory->sfree(earg);
}
delete [] pack_choice;
delete [] vtype;
delete[] pack_choice;
delete[] vtype;
memory->destroy(field2index);
memory->destroy(argindex);
delete [] idregion;
delete[] idregion;
memory->destroy(thresh_array);
memory->destroy(thresh_op);
memory->destroy(thresh_value);
@ -212,27 +212,27 @@ DumpCustom::~DumpCustom()
for (int i = 0; i < nthreshlast; i++) {
if (modify->nfix) modify->delete_fix(thresh_fixID[i]);
delete [] thresh_fixID[i];
delete[] thresh_fixID[i];
}
memory->sfree(thresh_fix);
memory->sfree(thresh_fixID);
memory->destroy(thresh_first);
for (int i = 0; i < ncompute; i++) delete [] id_compute[i];
for (int i = 0; i < ncompute; i++) delete[] id_compute[i];
memory->sfree(id_compute);
delete [] compute;
delete[] compute;
for (int i = 0; i < nfix; i++) delete [] id_fix[i];
for (int i = 0; i < nfix; i++) delete[] id_fix[i];
memory->sfree(id_fix);
delete [] fix;
delete[] fix;
for (int i = 0; i < nvariable; i++) delete [] id_variable[i];
for (int i = 0; i < nvariable; i++) delete[] id_variable[i];
memory->sfree(id_variable);
delete [] variable;
delete[] variable;
for (int i = 0; i < nvariable; i++) memory->destroy(vbuf[i]);
delete [] vbuf;
delete[] vbuf;
for (int i = 0; i < ncustom; i++) delete [] id_custom[i];
for (int i = 0; i < ncustom; i++) delete[] id_custom[i];
memory->sfree(id_custom);
memory->sfree(flag_custom);
@ -240,20 +240,20 @@ DumpCustom::~DumpCustom()
memory->destroy(dchoose);
memory->destroy(clist);
for (int i = 1; i <= ntypes; i++) delete [] typenames[i];
delete [] typenames;
for (int i = 1; i <= ntypes; i++) delete[] typenames[i];
delete[] typenames;
if (vformat) {
for (int i = 0; i < nfield; i++) delete [] vformat[i];
delete [] vformat;
for (int i = 0; i < nfield; i++) delete[] vformat[i];
delete[] vformat;
}
if (format_column_user) {
for (int i = 0; i < nfield; i++) delete [] format_column_user[i];
delete [] format_column_user;
for (int i = 0; i < nfield; i++) delete[] format_column_user[i];
delete[] format_column_user;
}
delete [] columns;
delete[] columns;
}
/* ---------------------------------------------------------------------- */
@ -262,7 +262,7 @@ void DumpCustom::init_style()
{
// format = copy of default or user-specified line format
delete [] format;
delete[] format;
if (format_line_user) format = utils::strdup(format_line_user);
else format = utils::strdup(format_default);
@ -277,7 +277,7 @@ void DumpCustom::init_style()
int i=0;
for (auto word : words) {
delete [] vformat[i];
delete[] vformat[i];
if (format_column_user[i])
vformat[i] = utils::strdup(std::string(format_column_user[i]) + " ");
@ -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:
@ -1554,7 +1553,7 @@ int DumpCustom::add_compute(const char *id)
id_compute = (char **)
memory->srealloc(id_compute,(ncompute+1)*sizeof(char *),"dump:id_compute");
delete [] compute;
delete[] compute;
compute = new Compute*[ncompute+1];
id_compute[ncompute] = utils::strdup(id);
@ -1577,7 +1576,7 @@ int DumpCustom::add_fix(const char *id)
id_fix = (char **)
memory->srealloc(id_fix,(nfix+1)*sizeof(char *),"dump:id_fix");
delete [] fix;
delete[] fix;
fix = new Fix*[nfix+1];
id_fix[nfix] = utils::strdup(id);
@ -1601,9 +1600,9 @@ int DumpCustom::add_variable(const char *id)
id_variable = (char **)
memory->srealloc(id_variable,(nvariable+1)*sizeof(char *),
"dump:id_variable");
delete [] variable;
delete[] variable;
variable = new int[nvariable+1];
delete [] vbuf;
delete[] vbuf;
vbuf = new double*[nvariable+1];
for (int i = 0; i <= nvariable; i++) vbuf[i] = nullptr;
@ -1648,8 +1647,8 @@ 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");
delete [] idregion;
error->all(FLERR,"Dump_modify region ID {} does not exist",arg[1]);
delete[] idregion;
idregion = utils::strdup(arg[1]);
}
return 2;
@ -1661,7 +1660,7 @@ int DumpCustom::modify_param(int narg, char **arg)
if (strcmp(arg[1],"none") == 0) {
// just clear format_column_user allocated by this dump child class
for (int i = 0; i < nfield; i++) {
delete [] format_column_user[i];
delete[] format_column_user[i];
format_column_user[i] = nullptr;
}
return 2;
@ -1670,17 +1669,16 @@ int DumpCustom::modify_param(int narg, char **arg)
if (narg < 3) error->all(FLERR,"Illegal dump_modify command");
if (strcmp(arg[1],"int") == 0) {
delete [] format_int_user;
delete[] format_int_user;
format_int_user = utils::strdup(arg[2]);
delete [] format_bigint_user;
delete[] format_bigint_user;
int n = strlen(format_int_user) + 8;
format_bigint_user = new char[n];
// replace "d" in format_int_user with bigint format specifier
// 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';
@ -1688,14 +1686,14 @@ int DumpCustom::modify_param(int narg, char **arg)
*ptr = 'd';
} else if (strcmp(arg[1],"float") == 0) {
delete [] format_float_user;
delete[] format_float_user;
format_float_user = utils::strdup(arg[2]);
} else {
int i = utils::inumeric(FLERR,arg[1],false,lmp) - 1;
if (i < 0 || i >= nfield)
error->all(FLERR,"Illegal dump_modify command");
if (format_column_user[i]) delete [] format_column_user[i];
if (format_column_user[i]) delete[] format_column_user[i];
format_column_user[i] = utils::strdup(arg[2]);
}
return 3;
@ -1703,10 +1701,10 @@ 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;
for (int i = 1; i <= ntypes; i++) delete[] typenames[i];
delete[] typenames;
typenames = new char*[ntypes+1];
for (int itype = 1; itype <= ntypes; itype++) {
typenames[itype] = utils::strdup(arg[itype]);
@ -1739,7 +1737,7 @@ int DumpCustom::modify_param(int narg, char **arg)
thresh_last = nullptr;
for (int i = 0; i < nthreshlast; i++) {
modify->delete_fix(thresh_fixID[i]);
delete [] thresh_fixID[i];
delete[] thresh_fixID[i];
}
thresh_fix = nullptr;
thresh_fixID = nullptr;
@ -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;
}
}