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:
@ -1352,7 +1352,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
if (index1 > compute->size_vector &&
|
if (index1 > compute->size_vector &&
|
||||||
compute->size_vector_variable == 0)
|
compute->size_vector_variable == 0)
|
||||||
print_var_error(FLERR,"Variable formula compute vector "
|
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 (update->whichflag == 0) {
|
||||||
if (compute->invoked_vector != update->ntimestep)
|
if (compute->invoked_vector != update->ntimestep)
|
||||||
print_var_error(FLERR,"Compute used in variable between runs "
|
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 &&
|
if (index1 > compute->size_array_rows &&
|
||||||
compute->size_array_rows_variable == 0)
|
compute->size_array_rows_variable == 0)
|
||||||
print_var_error(FLERR,"Variable formula compute array "
|
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)
|
if (index2 > compute->size_array_cols)
|
||||||
print_var_error(FLERR,"Variable formula compute array "
|
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 (update->whichflag == 0) {
|
||||||
if (compute->invoked_array != update->ntimestep)
|
if (compute->invoked_array != update->ntimestep)
|
||||||
print_var_error(FLERR,"Compute used in variable between runs "
|
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)
|
if (index2 > compute->size_peratom_cols)
|
||||||
print_var_error(FLERR,"Variable formula compute "
|
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 (update->whichflag == 0) {
|
||||||
if (compute->invoked_peratom != update->ntimestep)
|
if (compute->invoked_peratom != update->ntimestep)
|
||||||
print_var_error(FLERR,"Compute used in variable "
|
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);
|
"vector-style variable formula",ivar);
|
||||||
if (index1 > compute->size_peratom_cols)
|
if (index1 > compute->size_peratom_cols)
|
||||||
print_var_error(FLERR,"Variable formula compute array "
|
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 (update->whichflag == 0) {
|
||||||
if (compute->invoked_peratom != update->ntimestep)
|
if (compute->invoked_peratom != update->ntimestep)
|
||||||
print_var_error(FLERR,"Compute used in variable "
|
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 &&
|
if (index1 > fix->size_vector &&
|
||||||
fix->size_vector_variable == 0)
|
fix->size_vector_variable == 0)
|
||||||
print_var_error(FLERR,"Variable formula fix vector is "
|
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)
|
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
|
||||||
print_var_error(FLERR,"Fix in variable not computed "
|
print_var_error(FLERR,"Fix in variable not computed "
|
||||||
"at a compatible time",ivar);
|
"at a compatible time",ivar);
|
||||||
@ -1671,10 +1671,10 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
if (index1 > fix->size_array_rows &&
|
if (index1 > fix->size_array_rows &&
|
||||||
fix->size_array_rows_variable == 0)
|
fix->size_array_rows_variable == 0)
|
||||||
print_var_error(FLERR,"Variable formula fix array is "
|
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)
|
if (index2 > fix->size_array_cols)
|
||||||
print_var_error(FLERR,"Variable formula fix array is "
|
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)
|
if (update->whichflag > 0 && update->ntimestep % fix->global_freq)
|
||||||
print_var_error(FLERR,"Fix in variable not computed at a "
|
print_var_error(FLERR,"Fix in variable not computed at a "
|
||||||
"compatible time",ivar);
|
"compatible time",ivar);
|
||||||
@ -1775,7 +1775,7 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
|
|
||||||
if (index2 > fix->size_peratom_cols)
|
if (index2 > fix->size_peratom_cols)
|
||||||
print_var_error(FLERR,"Variable formula fix array is "
|
print_var_error(FLERR,"Variable formula fix array is "
|
||||||
"accessed out-of-range",ivar);
|
"accessed out-of-range",ivar,0);
|
||||||
if (update->whichflag > 0 &&
|
if (update->whichflag > 0 &&
|
||||||
update->ntimestep % fix->peratom_freq)
|
update->ntimestep % fix->peratom_freq)
|
||||||
print_var_error(FLERR,"Fix in variable not computed "
|
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);
|
"equal-style variable formula",ivar);
|
||||||
if (index1 > fix->size_peratom_cols)
|
if (index1 > fix->size_peratom_cols)
|
||||||
print_var_error(FLERR,"Variable formula fix array "
|
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 &&
|
if (update->whichflag > 0 &&
|
||||||
update->ntimestep % fix->peratom_freq)
|
update->ntimestep % fix->peratom_freq)
|
||||||
print_var_error(FLERR,"Fix in variable not computed at "
|
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;
|
argstack[nargstack++] = value1 * value2;
|
||||||
else if (opprevious == DIVIDE) {
|
else if (opprevious == DIVIDE) {
|
||||||
if (value2 == 0.0)
|
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;
|
argstack[nargstack++] = value1 / value2;
|
||||||
} else if (opprevious == MODULO) {
|
} else if (opprevious == MODULO) {
|
||||||
if (value2 == 0.0)
|
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);
|
argstack[nargstack++] = fmod(value1,value2);
|
||||||
} else if (opprevious == CARAT) {
|
} else if (opprevious == CARAT) {
|
||||||
if (value2 == 0.0)
|
if (value2 == 0.0)
|
||||||
argstack[nargstack++] = 1.0;
|
argstack[nargstack++] = 1.0;
|
||||||
else if ((value1 == 0.0) && (value2 < 0.0))
|
else if ((value1 == 0.0) && (value2 < 0.0))
|
||||||
print_var_error(FLERR,"Invalid power expression in "
|
print_var_error(FLERR,"Invalid power expression in "
|
||||||
"variable formula",ivar);
|
"variable formula",ivar,0);
|
||||||
else argstack[nargstack++] = pow(value1,value2);
|
else argstack[nargstack++] = pow(value1,value2);
|
||||||
} else if (opprevious == UNARY) {
|
} else if (opprevious == UNARY) {
|
||||||
argstack[nargstack++] = -value2;
|
argstack[nargstack++] = -value2;
|
||||||
@ -3372,7 +3372,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
|
|||||||
else {
|
else {
|
||||||
if (value1 < 0.0)
|
if (value1 < 0.0)
|
||||||
print_var_error(FLERR,"Sqrt of negative value in "
|
print_var_error(FLERR,"Sqrt of negative value in "
|
||||||
"variable formula",ivar);
|
"variable formula",ivar,0);
|
||||||
argstack[nargstack++] = sqrt(value1);
|
argstack[nargstack++] = sqrt(value1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3388,7 +3388,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
|
|||||||
else {
|
else {
|
||||||
if (value1 <= 0.0)
|
if (value1 <= 0.0)
|
||||||
print_var_error(FLERR,"Log of zero/negative value in "
|
print_var_error(FLERR,"Log of zero/negative value in "
|
||||||
"variable formula",ivar);
|
"variable formula",ivar,0);
|
||||||
argstack[nargstack++] = log(value1);
|
argstack[nargstack++] = log(value1);
|
||||||
}
|
}
|
||||||
} else if (strcmp(word,"log") == 0) {
|
} else if (strcmp(word,"log") == 0) {
|
||||||
@ -3398,7 +3398,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree,
|
|||||||
else {
|
else {
|
||||||
if (value1 <= 0.0)
|
if (value1 <= 0.0)
|
||||||
print_var_error(FLERR,"Log of zero/negative value in "
|
print_var_error(FLERR,"Log of zero/negative value in "
|
||||||
"variable formula",ivar);
|
"variable formula",ivar,0);
|
||||||
argstack[nargstack++] = log10(value1);
|
argstack[nargstack++] = log10(value1);
|
||||||
}
|
}
|
||||||
} else if (strcmp(word,"abs") == 0) {
|
} 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;
|
if (tree) newtree->type = ASIN;
|
||||||
else {
|
else {
|
||||||
if (value1 < -1.0 || value1 > 1.0)
|
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);
|
argstack[nargstack++] = asin(value1);
|
||||||
}
|
}
|
||||||
} else if (strcmp(word,"acos") == 0) {
|
} 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;
|
if (tree) newtree->type = ACOS;
|
||||||
else {
|
else {
|
||||||
if (value1 < -1.0 || value1 > 1.0)
|
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);
|
argstack[nargstack++] = acos(value1);
|
||||||
}
|
}
|
||||||
} else if (strcmp(word,"atan") == 0) {
|
} 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) {
|
} else if (index && compute->array_flag) {
|
||||||
if (index > compute->size_array_cols)
|
if (index > compute->size_array_cols)
|
||||||
print_var_error(FLERR,"Variable formula compute array "
|
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 (update->whichflag == 0) {
|
||||||
if (compute->invoked_array != update->ntimestep)
|
if (compute->invoked_array != update->ntimestep)
|
||||||
print_var_error(FLERR,"Compute used in variable between runs "
|
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,
|
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)) {
|
if ((ivar >= 0) && (ivar < nvar)) {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
|
|
||||||
snprintf(msg,128,"Variable %s: %s",names[ivar],errmsg);
|
snprintf(msg,128,"Variable %s: %s",names[ivar],errmsg);
|
||||||
error->all(srcfile,lineno,msg);
|
if (global)
|
||||||
} else error->all(srcfile,lineno,errmsg);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|||||||
@ -125,7 +125,7 @@ class Variable : protected Pointers {
|
|||||||
double constant(char *);
|
double constant(char *);
|
||||||
int parse_args(char *, char **);
|
int parse_args(char *, char **);
|
||||||
char *find_next_comma(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);
|
void print_tree(Tree *, int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user