diff -Naur lammps-31Mar08/doc/variable.html lammps-1Apr08/doc/variable.html --- lammps-31Mar08/doc/variable.html 2008-02-29 18:13:20.000000000 -0700 +++ lammps-1Apr08/doc/variable.html 2008-03-28 10:22:09.000000000 -0600 @@ -27,7 +27,7 @@ equal or atom args = one formula containing numbers, thermo keywords, math operations, group functions, atom values and vectors, compute/fix/variable references numbers = 0.0, 100, -5.4, 2.8e-4, etc thermo keywords = vol, ke, press, etc from thermo_style - math operations = (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x) + math operations = (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x), ceil(x), floor(x), round(x) group functions = count(group), mass(group), charge(group), xcm(group,dim), vcm(group,dim), fcm(group,dim), bound(group,xmin), gyration(group) @@ -213,7 +213,7 @@
- + @@ -245,7 +245,11 @@ subtraction. Parenthesis can be used to group one or more portions of a formula and enforce a desired order of operations. Additional math operations can be specified as keywords followed by a parenthesized -argument, e.g. sqrt(v_ke). +argument, e.g. sqrt(v_ke). The ceil(), floor(), and round() +operations are those in the C math library. Ceil() is the smallest +integer not less than its argument. Floor() if the largest integer +not greater than its argument. Round() is the nearest integer to its +argument.

Group functions take one or two arguments in a specific format. The first argument is the group-ID. The dim argument, if it exists, is diff -Naur lammps-31Mar08/doc/variable.txt lammps-1Apr08/doc/variable.txt --- lammps-31Mar08/doc/variable.txt 2008-02-29 18:13:20.000000000 -0700 +++ lammps-1Apr08/doc/variable.txt 2008-03-28 10:22:09.000000000 -0600 @@ -22,7 +22,7 @@ {equal} or {atom} args = one formula containing numbers, thermo keywords, math operations, group functions, atom values and vectors, compute/fix/variable references numbers = 0.0, 100, -5.4, 2.8e-4, etc thermo keywords = vol, ke, press, etc from "thermo_style"_thermo_style.html - math operations = (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x) + math operations = (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x), ceil(x), floor(x), round(x) group functions = count(group), mass(group), charge(group), xcm(group,dim), vcm(group,dim), fcm(group,dim), bound(group,xmin), gyration(group) @@ -206,7 +206,7 @@ Number: 0.2, 100, 1.0e20, -15.4, etc Thermo keywords: vol, pe, ebond, etc -Math operations: (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x) +Math operations: (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x), ceil(x), floor(x), round(x) Group functions: count(ID), mass(ID), charge(ID), xcm(ID,dim), \ vcm(ID,dim), fcm(ID,dim), bound(ID,dir), gyration(ID) Atom values: mass\[N\], x\[N\], y\[N\], z\[N\], \ @@ -240,7 +240,11 @@ subtraction. Parenthesis can be used to group one or more portions of a formula and enforce a desired order of operations. Additional math operations can be specified as keywords followed by a parenthesized -argument, e.g. sqrt(v_ke). +argument, e.g. sqrt(v_ke). The ceil(), floor(), and round() +operations are those in the C math library. Ceil() is the smallest +integer not less than its argument. Floor() if the largest integer +not greater than its argument. Round() is the nearest integer to its +argument. Group functions take one or two arguments in a specific format. The first argument is the group-ID. The {dim} argument, if it exists, is diff -Naur lammps-31Mar08/src/variable.cpp lammps-1Apr08/src/variable.cpp --- lammps-31Mar08/src/variable.cpp 2008-03-17 10:57:23.000000000 -0600 +++ lammps-1Apr08/src/variable.cpp 2008-03-28 10:22:54.000000000 -0600 @@ -38,7 +38,7 @@ enum{INDEX,LOOP,EQUAL,WORLD,UNIVERSE,ULOOP,ATOM}; enum{ARG,OP}; enum{DONE,ADD,SUBTRACT,MULTIPLY,DIVIDE,CARAT,UNARY, - SQRT,EXP,LN,VALUE,ATOMARRAY,TYPEARRAY}; + SQRT,EXP,LN,CEIL,FLOOR,ROUND,VALUE,ATOMARRAY,TYPEARRAY}; #define INVOKED_SCALAR 1 // same as in computes #define INVOKED_VECTOR 2 @@ -1100,6 +1100,7 @@ } if (tree->type == UNARY) return -eval_tree(tree->left,i); + if (tree->type == SQRT) { double arg = eval_tree(tree->left,i); if (arg < 0.0) error->all("Sqrt of negative in variable formula"); @@ -1112,6 +1113,12 @@ if (arg <= 0.0) error->all("Log of zero/negative in variable formula"); return log(arg); } + if (tree->type == CEIL) + return ceil(eval_tree(tree->left,i)); + if (tree->type == FLOOR) + return floor(eval_tree(tree->left,i)); + if (tree->type == ROUND) + return round(eval_tree(tree->left,i)); return 0.0; } @@ -1204,7 +1211,8 @@ { // word not a match to any math function - if (strcmp(word,"sqrt") && strcmp(word,"exp") && strcmp(word,"ln")) + if (strcmp(word,"sqrt") && strcmp(word,"exp") && strcmp(word,"ln") && + strcmp(word,"ceil") && strcmp(word,"floor") && strcmp(word,"round")) return 0; Tree *newtree; @@ -1236,11 +1244,22 @@ if (value <= 0.0) error->all("Log of zero/negative in variable formula"); argstack[nargstack++] = log(value); } + + } else if (strcmp(word,"ceil") == 0) { + if (tree) newtree->type = CEIL; + else argstack[nargstack++] = ceil(value); + + } else if (strcmp(word,"floor") == 0) { + if (tree) newtree->type = FLOOR; + else argstack[nargstack++] = floor(value); + + } else if (strcmp(word,"round") == 0) { + if (tree) newtree->type = ROUND; + else argstack[nargstack++] = round(value); } return 1; -} - +} /* ---------------------------------------------------------------------- process a group function in formula

Number 0.2, 100, 1.0e20, -15.4, etc
Thermo keywords vol, pe, ebond, etc
Math operations (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x)
Math operations (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x), ceil(x), floor(x), round(x)
Group functions count(ID), mass(ID), charge(ID), xcm(ID,dim), vcm(ID,dim), fcm(ID,dim), bound(ID,dir), gyration(ID)
Atom values mass[N], x[N], y[N], z[N], vx[N], vy[N], vz[N], fx[N], fy[N], fz[N]
Atom vectors mass[], x[], y[], z[], vx[], vy[], vz[], fx[], fy[], fz[]