add option to print_var_error() function to delegate errors to error->one() instead of error->all()

this change is applied to cases that may happen on individual ranks only, e.g. out-of-range access, division by zero, invalid argument.
This commit is contained in:
Axel Kohlmeyer
2019-01-09 17:03:32 -05:00
parent 6fbd0c08cc
commit 6f8c544a7d
2 changed files with 31 additions and 23 deletions

View File

@ -1352,7 +1352,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index1 > compute->size_vector &&
compute->size_vector_variable == 0)
print_var_error(FLERR,"Variable formula compute vector "
"is accessed out-of-range",ivar);
"is accessed out-of-range",ivar,0);
if (update->whichflag == 0) {
if (compute->invoked_vector != update->ntimestep)
print_var_error(FLERR,"Compute used in variable between runs "
@ -1381,10 +1381,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index1 > compute->size_array_rows &&
compute->size_array_rows_variable == 0)
print_var_error(FLERR,"Variable formula compute array "
"is accessed out-of-range",ivar);
"is accessed out-of-range",ivar,0);
if (index2 > compute->size_array_cols)
print_var_error(FLERR,"Variable formula compute array "
"is accessed out-of-range",ivar);
"is accessed out-of-range",ivar,0);
if (update->whichflag == 0) {
if (compute->invoked_array != update->ntimestep)
print_var_error(FLERR,"Compute used in variable between runs "
@ -1494,7 +1494,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index2 > compute->size_peratom_cols)
print_var_error(FLERR,"Variable formula compute "
"array is accessed out-of-range",ivar);
"array is accessed out-of-range",ivar,0);
if (update->whichflag == 0) {
if (compute->invoked_peratom != update->ntimestep)
print_var_error(FLERR,"Compute used in variable "
@ -1555,7 +1555,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
"vector-style variable formula",ivar);
if (index1 > compute->size_peratom_cols)
print_var_error(FLERR,"Variable formula compute array "
"is accessed out-of-range",ivar);
"is accessed out-of-range",ivar,0);
if (update->whichflag == 0) {
if (compute->invoked_peratom != update->ntimestep)
print_var_error(FLERR,"Compute used in variable "
@ -1649,7 +1649,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index1 > fix->size_vector &&
fix->size_vector_variable == 0)
print_var_error(FLERR,"Variable formula fix vector is "
"accessed out-of-range",ivar);
"accessed out-of-range",ivar,0);
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
print_var_error(FLERR,"Fix in variable not computed "
"at a compatible time",ivar);
@ -1671,10 +1671,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index1 > fix->size_array_rows &&
fix->size_array_rows_variable == 0)
print_var_error(FLERR,"Variable formula fix array is "
"accessed out-of-range",ivar);
"accessed out-of-range",ivar,0);
if (index2 > fix->size_array_cols)
print_var_error(FLERR,"Variable formula fix array is "
"accessed out-of-range",ivar);
"accessed out-of-range",ivar,0);
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
print_var_error(FLERR,"Fix in variable not computed at a "
"compatible time",ivar);
@ -1775,7 +1775,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
if (index2 > fix->size_peratom_cols)
print_var_error(FLERR,"Variable formula fix array is "
"accessed out-of-range",ivar);
"accessed out-of-range",ivar,0);
if (update->whichflag > 0 &&
update->ntimestep % fix->peratom_freq)
print_var_error(FLERR,"Fix in variable not computed "
@ -1822,7 +1822,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
"equal-style variable formula",ivar);
if (index1 > fix->size_peratom_cols)
print_var_error(FLERR,"Variable formula fix array "
"is accessed out-of-range",ivar);
"is accessed out-of-range",ivar,0);
if (update->whichflag > 0 &&
update->ntimestep % fix->peratom_freq)
print_var_error(FLERR,"Fix in variable not computed at "
@ -2202,18 +2202,18 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
argstack[nargstack++] = value1 * value2;
else if (opprevious == DIVIDE) {
if (value2 == 0.0)
print_var_error(FLERR,"Divide by 0 in variable formula",ivar);
print_var_error(FLERR,"Divide by 0 in variable formula",ivar,0);
argstack[nargstack++] = value1 / value2;
} else if (opprevious == MODULO) {
if (value2 == 0.0)
print_var_error(FLERR,"Modulo 0 in variable formula",ivar);
print_var_error(FLERR,"Modulo 0 in variable formula",ivar,0);
argstack[nargstack++] = fmod(value1,value2);
} else if (opprevious == CARAT) {
if (value2 == 0.0)
argstack[nargstack++] = 1.0;
else if ((value1 == 0.0) && (value2 < 0.0))
print_var_error(FLERR,"Invalid power expression in "
"variable formula",ivar);
"variable formula",ivar,0);
else argstack[nargstack++] = pow(value1,value2);
} else if (opprevious == UNARY) {
argstack[nargstack++] = -value2;
@ -3372,7 +3372,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
else {
if (value1 < 0.0)
print_var_error(FLERR,"Sqrt of negative value in "
"variable formula",ivar);
"variable formula",ivar,0);
argstack[nargstack++] = sqrt(value1);
}
@ -3388,7 +3388,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
else {
if (value1 <= 0.0)
print_var_error(FLERR,"Log of zero/negative value in "
"variable formula",ivar);
"variable formula",ivar,0);
argstack[nargstack++] = log(value1);
}
} else if (strcmp(word,"log") == 0) {
@ -3398,7 +3398,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
else {
if (value1 <= 0.0)
print_var_error(FLERR,"Log of zero/negative value in "
"variable formula",ivar);
"variable formula",ivar,0);
argstack[nargstack++] = log10(value1);
}
} else if (strcmp(word,"abs") == 0) {
@ -3429,7 +3429,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
if (tree) newtree->type = ASIN;
else {
if (value1 < -1.0 || value1 > 1.0)
print_var_error(FLERR,"Arcsin of invalid value in variable formula",ivar);
print_var_error(FLERR,"Arcsin of invalid value in variable formula",ivar,0);
argstack[nargstack++] = asin(value1);
}
} else if (strcmp(word,"acos") == 0) {
@ -3438,7 +3438,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
if (tree) newtree->type = ACOS;
else {
if (value1 < -1.0 || value1 > 1.0)
print_var_error(FLERR,"Arccos of invalid value in variable formula",ivar);
print_var_error(FLERR,"Arccos of invalid value in variable formula",ivar,0);
argstack[nargstack++] = acos(value1);
}
} else if (strcmp(word,"atan") == 0) {
@ -4032,7 +4032,7 @@ int Variable::special_function(char *word, char *contents, Tree **tree,
} else if (index && compute->array_flag) {
if (index > compute->size_array_cols)
print_var_error(FLERR,"Variable formula compute array "
"is accessed out-of-range",ivar);
"is accessed out-of-range",ivar,0);
if (update->whichflag == 0) {
if (compute->invoked_array != update->ntimestep)
print_var_error(FLERR,"Compute used in variable between runs "
@ -4652,14 +4652,22 @@ char *Variable::find_next_comma(char *str)
------------------------------------------------------------------------- */
void Variable::print_var_error(const char *srcfile, int lineno,
const char *errmsg, int ivar)
const char *errmsg, int ivar, int global)
{
if ((ivar >= 0) && (ivar < nvar)) {
char msg[128];
snprintf(msg,128,"Variable %s: %s",names[ivar],errmsg);
error->all(srcfile,lineno,msg);
} else error->all(srcfile,lineno,errmsg);
if (global)
error->all(srcfile,lineno,msg);
else
error->one(srcfile,lineno,msg);
} else {
if (global)
error->all(srcfile,lineno,errmsg);
else
error->one(srcfile,lineno,errmsg);
}
}
/* ----------------------------------------------------------------------

View File

@ -125,7 +125,7 @@ class Variable : protected Pointers {
double constant(char *);
int parse_args(char *, char **);
char *find_next_comma(char *);
void print_var_error(const char *, int, const char *, int);
void print_var_error(const char *, int, const char *, int, int global=1);
void print_tree(Tree *, int);
};