tweaks to code and doc page

This commit is contained in:
Steve Plimpton
2025-05-01 12:57:27 -06:00
parent 76d0ead245
commit a2a2c541b5
2 changed files with 16 additions and 16 deletions

View File

@ -177,7 +177,7 @@ simulation.
When an input script line is encountered that defines a variable of When an input script line is encountered that defines a variable of
style *equal* or *vector* or *atom* or *python* that contains a style *equal* or *vector* or *atom* or *python* that contains a
formula or links to Python code, the formula or Python code is NOT formula or links to Python code, the formula or Python code is NOT
immediately evaluated. Instead, it is evaulated aech time the immediately evaluated. Instead, it is evaluated each time the
variable is **used**. If you simply want to evaluate a formula in variable is **used**. If you simply want to evaluate a formula in
place you can use a so-called immediate variable. as described in place you can use a so-called immediate variable. as described in
the preceding note. Or see the section below about "Immediate the preceding note. Or see the section below about "Immediate
@ -568,7 +568,7 @@ references, fix references, and references to other variables.
+------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Feature functions | is_available(category,feature), is_active(category,feature), is_defined(category,id) | | Feature functions | is_available(category,feature), is_active(category,feature), is_defined(category,id) |
+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Python function wrappers | py_varname(x,y,z,...) | | Python func wrappers | py_varname(x,y,z,...) |
+------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Atom values | id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i] | | Atom values | id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i] |
+------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@ -1212,14 +1212,14 @@ input script:
variable foo python truncate variable foo python truncate
python truncate return v_foo input 1 v_pyarg1 format fi here """ python truncate return v_foo input 1 v_pyarg1 format fi here """
def truncate(x): def truncate(x):
return int(x) return int(x)
""" """
variable pyarg1 internal 0.0 variable pyarg1 internal 0.0
variable xtrunc atom py_foo(x) variable xtrunc atom py_foo(x)
variable ytrunc atom py_foo(y) variable ytrunc atom py_foo(y)
variable ztrunc atom py_foo(z) variable ztrunc atom py_foo(z)
dump 1 all custom 100 tmp.dump id x y z v_xtrunc v_ytrunc v_ztrunc dump 1 all custom 100 tmp.dump id x y z v_xtrunc v_ytrunc v_ztrunc
The first two commands define a python-style variable *foo* and couple The first two commands define a python-style variable *foo* and couple
it to the Python-coded function *truncate()* which takes a single it to the Python-coded function *truncate()* which takes a single

View File

@ -3534,7 +3534,7 @@ double Variable::eval_tree(Tree *tree, int i)
if (tree->type == SIGN) if (tree->type == SIGN)
return (eval_tree(tree->first,i) >= 0.0) ? 1.0 : -1.0; // sign(eval_tree(tree->first,i)); return (eval_tree(tree->first,i) >= 0.0) ? 1.0 : -1.0; // sign(eval_tree(tree->first,i));
if (tree->type == PYFUNCTION) { if (tree->type == PYFUNCTION) {
int narg = tree->argcount; int narg = tree->argcount;
for (int iarg = 0; iarg < narg; iarg++) { for (int iarg = 0; iarg < narg; iarg++) {
@ -3546,7 +3546,7 @@ double Variable::eval_tree(Tree *tree, int i)
arg = compute_equal(tree->pyvar); arg = compute_equal(tree->pyvar);
return arg; return arg;
} }
if (tree->type == GMASK) { if (tree->type == GMASK) {
if (atom->mask[i] & tree->ivalue) return 1.0; if (atom->mask[i] & tree->ivalue) return 1.0;
else return 0.0; else return 0.0;
@ -4137,7 +4137,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
double value = value1 + value2*(1.0-cos(omega*delta*update->dt)); double value = value1 + value2*(1.0-cos(omega*delta*update->dt));
argstack[nargstack++] = value; argstack[nargstack++] = value;
} }
} else if (strcmp(word,"sign") == 0) { } else if (strcmp(word,"sign") == 0) {
if (narg != 1) if (narg != 1)
print_var_error(FLERR,"Invalid math function in variable formula",ivar); print_var_error(FLERR,"Invalid math function in variable formula",ivar);
@ -4150,7 +4150,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
} else if (strstr(word,"py_") == word) { } else if (strstr(word,"py_") == word) {
// text following py_ = python-style variable name // text following py_ = python-style variable name
int pyvar = find(&word[3]); int pyvar = find(&word[3]);
if (style[pyvar] != PYTHON) if (style[pyvar] != PYTHON)
print_var_error(FLERR,"Invalid python function variable name",ivar); print_var_error(FLERR,"Invalid python function variable name",ivar);
@ -4160,7 +4160,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
int *jvars = new int[narg]; int *jvars = new int[narg];
char *internal_varname; char *internal_varname;
for (int iarg = 0; iarg < narg; iarg++) { for (int iarg = 0; iarg < narg; iarg++) {
internal_varname = utils::strdup(fmt::format("pyarg{}", iarg+1)); internal_varname = utils::strdup(fmt::format("pyarg{}", iarg+1));
jvars[iarg] = find(internal_varname); jvars[iarg] = find(internal_varname);
@ -4173,7 +4173,7 @@ int Variable::math_function(char *word, char *contents, Tree **tree, Tree **tree
// if tree: store python variable and arg info in tree for later eval // if tree: store python variable and arg info in tree for later eval
// else: one-time eval of python function now // else: one-time eval of python function now
if (tree) { if (tree) {
newtree->type = PYFUNCTION; newtree->type = PYFUNCTION;
newtree->pyvar = pyvar; newtree->pyvar = pyvar;