not a bug but change variable evaluate local ivar to jvar to avoid code confusion
This commit is contained in:
@ -1977,12 +1977,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
|
|
||||||
} else if (strncmp(word,"v_",2) == 0) {
|
} else if (strncmp(word,"v_",2) == 0) {
|
||||||
|
|
||||||
int ivar = find(word+2);
|
int jvar = find(word+2);
|
||||||
if (ivar < 0)
|
if (jvar < 0)
|
||||||
print_var_error(FLERR,fmt::format("Invalid variable reference {} in variable formula",word),
|
print_var_error(FLERR,fmt::format("Invalid variable reference {} in variable formula",word),
|
||||||
ivar);
|
jvar);
|
||||||
if (eval_in_progress[ivar])
|
if (eval_in_progress[jvar])
|
||||||
print_var_error(FLERR,"has a circular dependency",ivar);
|
print_var_error(FLERR,"has a circular dependency",jvar);
|
||||||
|
|
||||||
// parse zero or one trailing brackets
|
// parse zero or one trailing brackets
|
||||||
// point i beyond last bracket
|
// point i beyond last bracket
|
||||||
@ -2006,9 +2006,9 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
// scalar from internal-style variable
|
// scalar from internal-style variable
|
||||||
// access value directly
|
// access value directly
|
||||||
|
|
||||||
if (style[ivar] == INTERNAL) {
|
if (style[jvar] == INTERNAL) {
|
||||||
|
|
||||||
value1 = dvalue[ivar];
|
value1 = dvalue[jvar];
|
||||||
if (tree) {
|
if (tree) {
|
||||||
auto newtree = new Tree();
|
auto newtree = new Tree();
|
||||||
newtree->type = VALUE;
|
newtree->type = VALUE;
|
||||||
@ -2019,13 +2019,13 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
// scalar from any style variable except VECTOR, ATOM, ATOMFILE
|
// scalar from any style variable except VECTOR, ATOM, ATOMFILE
|
||||||
// access value via retrieve()
|
// access value via retrieve()
|
||||||
|
|
||||||
} else if (style[ivar] != ATOM && style[ivar] != ATOMFILE && style[ivar] != VECTOR) {
|
} else if (style[jvar] != ATOM && style[jvar] != ATOMFILE && style[jvar] != VECTOR) {
|
||||||
|
|
||||||
char *var = retrieve(word+2);
|
char *var = retrieve(word+2);
|
||||||
if (var == nullptr)
|
if (var == nullptr)
|
||||||
print_var_error(FLERR,"Invalid variable evaluation in variable formula",ivar);
|
print_var_error(FLERR,"Invalid variable evaluation in variable formula",jvar);
|
||||||
if (!utils::is_double(var))
|
if (!utils::is_double(var))
|
||||||
print_var_error(FLERR,"Non-numeric variable value in variable formula",ivar);
|
print_var_error(FLERR,"Non-numeric variable value in variable formula",jvar);
|
||||||
if (tree) {
|
if (tree) {
|
||||||
auto newtree = new Tree();
|
auto newtree = new Tree();
|
||||||
newtree->type = VALUE;
|
newtree->type = VALUE;
|
||||||
@ -2036,15 +2036,15 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
// vector from vector-style variable
|
// vector from vector-style variable
|
||||||
// evaluate the vector-style variable, put result in newtree
|
// evaluate the vector-style variable, put result in newtree
|
||||||
|
|
||||||
} else if (style[ivar] == VECTOR) {
|
} else if (style[jvar] == VECTOR) {
|
||||||
|
|
||||||
if (tree == nullptr)
|
if (tree == nullptr)
|
||||||
print_var_error(FLERR,"Vector-style variable in equal-style variable formula",ivar);
|
print_var_error(FLERR,"Vector-style variable in equal-style variable formula",jvar);
|
||||||
if (treetype == ATOM)
|
if (treetype == ATOM)
|
||||||
print_var_error(FLERR,"Vector-style variable in atom-style variable formula",ivar);
|
print_var_error(FLERR,"Vector-style variable in atom-style variable formula",jvar);
|
||||||
|
|
||||||
double *vec;
|
double *vec;
|
||||||
int nvec = compute_vector(ivar,&vec);
|
int nvec = compute_vector(jvar,&vec);
|
||||||
|
|
||||||
auto newtree = new Tree();
|
auto newtree = new Tree();
|
||||||
newtree->type = VECTORARRAY;
|
newtree->type = VECTORARRAY;
|
||||||
@ -2056,36 +2056,36 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
// vector from atom-style variable
|
// vector from atom-style variable
|
||||||
// evaluate the atom-style variable as newtree
|
// evaluate the atom-style variable as newtree
|
||||||
|
|
||||||
} else if (style[ivar] == ATOM) {
|
} else if (style[jvar] == ATOM) {
|
||||||
|
|
||||||
if (tree == nullptr)
|
if (tree == nullptr)
|
||||||
print_var_error(FLERR,"Atom-style variable in equal-style variable formula",ivar);
|
print_var_error(FLERR,"Atom-style variable in equal-style variable formula",jvar);
|
||||||
if (treetype == VECTOR)
|
if (treetype == VECTOR)
|
||||||
print_var_error(FLERR,"Atom-style variable in vector-style variable formula",ivar);
|
print_var_error(FLERR,"Atom-style variable in vector-style variable formula",jvar);
|
||||||
|
|
||||||
Tree *newtree = nullptr;
|
Tree *newtree = nullptr;
|
||||||
evaluate(data[ivar][0],&newtree,ivar);
|
evaluate(data[jvar][0],&newtree,jvar);
|
||||||
treestack[ntreestack++] = newtree;
|
treestack[ntreestack++] = newtree;
|
||||||
|
|
||||||
// vector from atomfile-style variable
|
// vector from atomfile-style variable
|
||||||
// point to the values in FixStore instance
|
// point to the values in FixStore instance
|
||||||
|
|
||||||
} else if (style[ivar] == ATOMFILE) {
|
} else if (style[jvar] == ATOMFILE) {
|
||||||
|
|
||||||
if (tree == nullptr)
|
if (tree == nullptr)
|
||||||
print_var_error(FLERR,"Atomfile-style variable in equal-style variable formula",ivar);
|
print_var_error(FLERR,"Atomfile-style variable in equal-style variable formula",jvar);
|
||||||
if (treetype == VECTOR)
|
if (treetype == VECTOR)
|
||||||
print_var_error(FLERR,"Atomfile-style variable in vector-style variable formula",ivar);
|
print_var_error(FLERR,"Atomfile-style variable in vector-style variable formula",jvar);
|
||||||
|
|
||||||
auto newtree = new Tree();
|
auto newtree = new Tree();
|
||||||
newtree->type = ATOMARRAY;
|
newtree->type = ATOMARRAY;
|
||||||
newtree->array = reader[ivar]->fixstore->vstore;
|
newtree->array = reader[jvar]->fixstore->vstore;
|
||||||
newtree->nstride = 1;
|
newtree->nstride = 1;
|
||||||
treestack[ntreestack++] = newtree;
|
treestack[ntreestack++] = newtree;
|
||||||
|
|
||||||
// no other possibilities for variable with no bracket
|
// no other possibilities for variable with no bracket
|
||||||
|
|
||||||
} else print_var_error(FLERR,"Mismatched variable in variable formula",ivar);
|
} else print_var_error(FLERR,"Mismatched variable in variable formula",jvar);
|
||||||
|
|
||||||
// vname[i] with one bracket
|
// vname[i] with one bracket
|
||||||
|
|
||||||
@ -2094,12 +2094,12 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
// scalar from vector-style variable
|
// scalar from vector-style variable
|
||||||
// compute the vector-style variable, extract single value
|
// compute the vector-style variable, extract single value
|
||||||
|
|
||||||
if (style[ivar] == VECTOR) {
|
if (style[jvar] == VECTOR) {
|
||||||
|
|
||||||
double *vec;
|
double *vec;
|
||||||
int nvec = compute_vector(ivar,&vec);
|
int nvec = compute_vector(jvar,&vec);
|
||||||
if (index <= 0 || index > nvec)
|
if (index <= 0 || index > nvec)
|
||||||
print_var_error(FLERR,"Invalid index into vector-style variable",ivar);
|
print_var_error(FLERR,"Invalid index into vector-style variable",jvar);
|
||||||
int m = index; // convert from tagint to int
|
int m = index; // convert from tagint to int
|
||||||
|
|
||||||
if (tree) {
|
if (tree) {
|
||||||
@ -2113,25 +2113,25 @@ double Variable::evaluate(char *str, Tree **tree, int ivar)
|
|||||||
// compute the per-atom variable in result
|
// compute the per-atom variable in result
|
||||||
// use peratom2global to extract single value from result
|
// use peratom2global to extract single value from result
|
||||||
|
|
||||||
} else if (style[ivar] == ATOM) {
|
} else if (style[jvar] == ATOM) {
|
||||||
|
|
||||||
double *result;
|
double *result;
|
||||||
memory->create(result,atom->nlocal,"variable:result");
|
memory->create(result,atom->nlocal,"variable:result");
|
||||||
compute_atom(ivar,0,result,1,0);
|
compute_atom(jvar,0,result,1,0);
|
||||||
peratom2global(1,nullptr,result,1,index,tree,treestack,ntreestack,argstack,nargstack);
|
peratom2global(1,nullptr,result,1,index,tree,treestack,ntreestack,argstack,nargstack);
|
||||||
memory->destroy(result);
|
memory->destroy(result);
|
||||||
|
|
||||||
// scalar from atomfile-style variable
|
// scalar from atomfile-style variable
|
||||||
// use peratom2global to extract single value from FixStore instance
|
// use peratom2global to extract single value from FixStore instance
|
||||||
|
|
||||||
} else if (style[ivar] == ATOMFILE) {
|
} else if (style[jvar] == ATOMFILE) {
|
||||||
|
|
||||||
peratom2global(1,nullptr,reader[ivar]->fixstore->vstore,1,index,
|
peratom2global(1,nullptr,reader[jvar]->fixstore->vstore,1,index,
|
||||||
tree,treestack,ntreestack,argstack,nargstack);
|
tree,treestack,ntreestack,argstack,nargstack);
|
||||||
|
|
||||||
// no other possibilities for variable with one bracket
|
// no other possibilities for variable with one bracket
|
||||||
|
|
||||||
} else print_var_error(FLERR,"Mismatched variable in variable formula",ivar);
|
} else print_var_error(FLERR,"Mismatched variable in variable formula",jvar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user