git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@8078 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp
2012-05-17 21:40:06 +00:00
parent 2e841e3441
commit ccf0f9a1ac

View File

@ -455,9 +455,9 @@ char *Variable::retrieve(char *name)
strcpy(data[ivar][0],result); strcpy(data[ivar][0],result);
str = data[ivar][0]; str = data[ivar][0];
} else if (style[ivar] == EQUAL) { } else if (style[ivar] == EQUAL) {
char result[32]; char result[64];
double answer = evaluate(data[ivar][0],NULL); double answer = evaluate(data[ivar][0],NULL);
sprintf(result,"%.10g",answer); sprintf(result,"%.20g",answer);
int n = strlen(result) + 1; int n = strlen(result) + 1;
if (data[ivar][1]) delete [] data[ivar][1]; if (data[ivar][1]) delete [] data[ivar][1];
data[ivar][1] = new char[n]; data[ivar][1] = new char[n];
@ -1093,7 +1093,8 @@ double Variable::evaluate(char *str, Tree **tree)
strcpy(id,&word[2]); strcpy(id,&word[2]);
int ivar = find(id); int ivar = find(id);
if (ivar < 0) error->all(FLERR,"Invalid variable name in variable formula"); if (ivar < 0)
error->all(FLERR,"Invalid variable name in variable formula");
// parse zero or one trailing brackets // parse zero or one trailing brackets
// point i beyond last bracket // point i beyond last bracket
@ -1129,7 +1130,8 @@ double Variable::evaluate(char *str, Tree **tree)
} else if (nbracket == 0 && style[ivar] == ATOM) { } else if (nbracket == 0 && style[ivar] == ATOM) {
if (tree == NULL) if (tree == NULL)
error->all(FLERR,"Atom-style variable in equal-style variable formula"); error->all(FLERR,
"Atom-style variable in equal-style variable formula");
Tree *newtree; Tree *newtree;
evaluate(data[ivar][0],&newtree); evaluate(data[ivar][0],&newtree);
treestack[ntreestack++] = newtree; treestack[ntreestack++] = newtree;
@ -1183,7 +1185,8 @@ double Variable::evaluate(char *str, Tree **tree)
} else if (str[i] == '[') { } else if (str[i] == '[') {
if (domain->box_exist == 0) if (domain->box_exist == 0)
error->all(FLERR,"Variable evaluation before simulation box is defined"); error->all(FLERR,
"Variable evaluation before simulation box is defined");
ptr = &str[i]; ptr = &str[i];
int id = int_between_brackets(ptr); int id = int_between_brackets(ptr);
@ -1198,7 +1201,8 @@ double Variable::evaluate(char *str, Tree **tree)
} else if (is_atom_vector(word)) { } else if (is_atom_vector(word)) {
if (domain->box_exist == 0) if (domain->box_exist == 0)
error->all(FLERR,"Variable evaluation before simulation box is defined"); error->all(FLERR,
"Variable evaluation before simulation box is defined");
atom_vector(word,tree,treestack,ntreestack); atom_vector(word,tree,treestack,ntreestack);
@ -1222,10 +1226,12 @@ double Variable::evaluate(char *str, Tree **tree)
} else { } else {
if (domain->box_exist == 0) if (domain->box_exist == 0)
error->all(FLERR,"Variable evaluation before simulation box is defined"); error->all(FLERR,
"Variable evaluation before simulation box is defined");
int flag = output->thermo->evaluate_keyword(word,&value1); int flag = output->thermo->evaluate_keyword(word,&value1);
if (flag) error->all(FLERR,"Invalid thermo keyword in variable formula"); if (flag)
error->all(FLERR,"Invalid thermo keyword in variable formula");
if (tree) { if (tree) {
Tree *newtree = new Tree(); Tree *newtree = new Tree();
newtree->type = VALUE; newtree->type = VALUE;
@ -1249,7 +1255,8 @@ double Variable::evaluate(char *str, Tree **tree)
else if (onechar == '/') op = DIVIDE; else if (onechar == '/') op = DIVIDE;
else if (onechar == '^') op = CARAT; else if (onechar == '^') op = CARAT;
else if (onechar == '=') { else if (onechar == '=') {
if (str[i+1] != '=') error->all(FLERR,"Invalid syntax in variable formula"); if (str[i+1] != '=')
error->all(FLERR,"Invalid syntax in variable formula");
op = EQ; op = EQ;
i++; i++;
} else if (onechar == '!') { } else if (onechar == '!') {
@ -1270,11 +1277,13 @@ double Variable::evaluate(char *str, Tree **tree)
i++; i++;
} }
} else if (onechar == '&') { } else if (onechar == '&') {
if (str[i+1] != '&') error->all(FLERR,"Invalid syntax in variable formula"); if (str[i+1] != '&')
error->all(FLERR,"Invalid syntax in variable formula");
op = AND; op = AND;
i++; i++;
} else if (onechar == '|') { } else if (onechar == '|') {
if (str[i+1] != '|') error->all(FLERR,"Invalid syntax in variable formula"); if (str[i+1] != '|')
error->all(FLERR,"Invalid syntax in variable formula");
op = OR; op = OR;
i++; i++;
} else op = DONE; } else op = DONE;
@ -1324,10 +1333,12 @@ double Variable::evaluate(char *str, Tree **tree)
else if (opprevious == MULTIPLY) else if (opprevious == MULTIPLY)
argstack[nargstack++] = value1 * value2; argstack[nargstack++] = value1 * value2;
else if (opprevious == DIVIDE) { else if (opprevious == DIVIDE) {
if (value2 == 0.0) error->all(FLERR,"Divide by 0 in variable formula"); if (value2 == 0.0)
error->all(FLERR,"Divide by 0 in variable formula");
argstack[nargstack++] = value1 / value2; argstack[nargstack++] = value1 / value2;
} else if (opprevious == CARAT) { } else if (opprevious == CARAT) {
if (value2 == 0.0) error->all(FLERR,"Power by 0 in variable formula"); if (value2 == 0.0)
error->all(FLERR,"Power by 0 in variable formula");
argstack[nargstack++] = pow(value1,value2); argstack[nargstack++] = pow(value1,value2);
} else if (opprevious == UNARY) { } else if (opprevious == UNARY) {
argstack[nargstack++] = -value2; argstack[nargstack++] = -value2;