2006-09-22 00:22:34 +08:00
"LAMMPS WWW Site"_lws - "LAMMPS Documentation"_ld - "LAMMPS Commands"_lc :c
:link(lws,http://lammps.sandia.gov)
:link(ld,Manual.html)
:link(lc,Section_commands.html#comm)
:line
variable command :h3
[Syntax:]
variable name style args ... :pre
2006-09-28 03:12:31 +08:00
name = name of variable to define :ulb,l
2013-12-03 08:23:55 +08:00
style = {delete} or {index} or {loop} or {world} or {universe} or {uloop} or {string} or {format} or {getenv} or {file} or {atomfile} or {equal} or {atom} :l
2008-10-07 22:45:58 +08:00
{delete} = no args
2006-09-22 00:22:34 +08:00
{index} args = one or more strings
2010-10-07 00:29:13 +08:00
{loop} args = N
N = integer size of loop, loop from 1 to N inclusive
{loop} args = N pad
N = integer size of loop, loop from 1 to N inclusive
pad = all values will be same length, e.g. 001, 002, ..., 100
{loop} args = N1 N2
N1,N2 = loop from N1 to N2 inclusive
{loop} args = N1 N2 pad
N1,N2 = loop from N1 to N2 inclusive
pad = all values will be same length, e.g. 050, 051, ..., 100
2007-02-10 05:37:30 +08:00
{world} args = one string for each partition of processors
{universe} args = one or more strings
2010-10-07 00:29:13 +08:00
{uloop} args = N
N = integer size of loop
{uloop} args = N pad
N = integer size of loop
pad = all values will be same length, e.g. 001, 002, ..., 100
2010-05-12 04:04:33 +08:00
{string} arg = one string
2013-12-03 08:23:55 +08:00
{format} args = vname fstr
vname = name of equal-style variable to evaluate
fstr = C-style format string
2013-10-30 23:57:57 +08:00
{getenv} arg = one string
2012-11-10 09:17:45 +08:00
{file} arg = filename
2013-07-25 04:47:56 +08:00
{atomfile} arg = filename
2008-01-09 07:23:02 +08:00
{equal} or {atom} args = one formula containing numbers, thermo keywords, math operations, group functions, atom values and vectors, compute/fix/variable references
2008-01-09 07:13:53 +08:00
numbers = 0.0, 100, -5.4, 2.8e-4, etc
2010-10-13 01:58:24 +08:00
constants = PI
2007-02-10 05:37:30 +08:00
thermo keywords = vol, ke, press, etc from "thermo_style"_thermo_style.html
2010-04-24 04:00:32 +08:00
math operators = (), -x, x+y, x-y, x*y, x/y, x^y,
2010-11-19 02:30:31 +08:00
x==y, x!=y, x<y, x<=y, x>y, x>=y, x&&y, x||y, !x
2012-11-26 23:56:41 +08:00
math functions = sqrt(x), exp(x), ln(x), log(x), abs(x),
2010-09-10 08:07:24 +08:00
sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), atan2(y,x),
2010-10-13 01:58:24 +08:00
random(x,y,z), normal(x,y,z), ceil(x), floor(x), round(x)
2012-05-18 06:25:44 +08:00
ramp(x,y), stagger(x,y), logfreq(x,y,z), stride(x,y,z), vdisplace(x,y), swiggle(x,y,z), cwiggle(x,y,z)
2008-01-03 03:25:15 +08:00
group functions = count(group), mass(group), charge(group),
2007-03-23 01:05:12 +08:00
xcm(group,dim), vcm(group,dim), fcm(group,dim),
2010-05-19 08:15:34 +08:00
bound(group,xmin), gyration(group), ke(group),
2010-11-24 22:43:25 +08:00
angmom(group,dim), torque(group,dim),
inertia(group,dimdim), omega(group,dim)
2009-04-29 03:50:15 +08:00
region functions = count(group,region), mass(group,region), charge(group,region),
xcm(group,dim,region), vcm(group,dim,region), fcm(group,dim,region),
2010-05-19 08:15:34 +08:00
bound(group,xmin,region), gyration(group,region), ke(group,reigon),
2010-11-24 22:43:25 +08:00
angmom(group,dim,region), torque(group,dim,region),
inertia(group,dimdim,region), omega(group,dim,region)
2014-02-05 02:59:28 +08:00
special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x)
2014-01-09 05:21:23 +08:00
atom value = 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\]
atom vector = id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz
2009-12-10 05:20:59 +08:00
compute references = c_ID, c_ID\[i\], c_ID\[i\]\[j\]
fix references = f_ID, f_ID\[i\], f_ID\[i\]\[j\]
variable references = v_name, v_name\[i\] :pre
2006-09-22 00:22:34 +08:00
:ule
[Examples:]
variable x index run1 run2 run3 run4 run5 run6 run7 run8
2007-07-03 22:58:21 +08:00
variable LoopVar loop $n
2008-01-03 03:25:15 +08:00
variable beta equal temp/3.0
2008-01-19 07:12:55 +08:00
variable b1 equal x\[234\]+0.5*vol
2008-01-03 03:25:15 +08:00
variable b1 equal "x\[234\] + 0.5*vol"
variable b equal xcm(mol1,x)/2.0
variable b equal c_myTemp
2009-12-10 05:20:59 +08:00
variable b atom x*y/vol
2011-06-08 01:15:11 +08:00
variable foo string myfile
2012-11-10 09:17:45 +08:00
variable f file values.txt
2008-01-09 07:21:32 +08:00
variable temp world 300.0 310.0 320.0 $\{Tfinal\}
2006-12-20 00:44:20 +08:00
variable x universe 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
2010-10-07 00:29:13 +08:00
variable x uloop 15 pad
2013-12-03 08:23:55 +08:00
variable str format x %.6g
2008-10-07 22:45:58 +08:00
variable x delete :pre
2006-09-22 00:22:34 +08:00
[Description:]
2008-01-03 03:25:15 +08:00
This command assigns one or more strings to a variable name for
evaluation later in the input script or during a simulation.
2013-07-25 08:09:27 +08:00
Variables can thus be useful in several contexts. A variable can be
defined and then referenced elsewhere in an input script to become
part of a new input command. For variable styles that store multiple
strings, the "next"_next.html command can be used to increment which
string is assigned to the variable. Variables of style {equal} store
a formula which when evaluated produces a single numeric value which
can be output either directly (see the "print"_print.html, "fix
2009-01-06 06:26:31 +08:00
print"_fix_print.html, and "run every"_run.html commands) or as part
of thermodynamic output (see the "thermo_style"_thermo_style.html
command), or used as input to an averaging fix (see the "fix
2010-05-08 00:29:19 +08:00
ave/time"_fix_ave_time.html command). Variables of style {atom} store
a formula which when evaluated produces one numeric value per atom
which can be output to a dump file (see the "dump custom"_dump.html
command) or used as input to an averaging fix (see the "fix
2009-01-06 06:26:31 +08:00
ave/spatial"_fix_ave_spatial.html and "fix ave/atom"_fix_ave_atom.html
2013-07-25 05:27:24 +08:00
commands). Variables of style {atomfile} can be used anywhere in an
input script that atom-style variables are used; they get their
per-atom values from a file rather than from a formula.
2007-02-21 08:18:01 +08:00
In the discussion that follows, the "name" of the variable is the
arbitrary string that is the 1st argument in the variable command.
2008-01-03 03:25:15 +08:00
This name can only contain alphanumeric characters and underscores.
2007-07-03 22:58:21 +08:00
The "string" is one or more of the subsequent arguments. The "string"
can be simple text as in the 1st example above, it can contain other
2008-01-03 03:25:15 +08:00
variables as in the 2nd example, or it can be a formula as in the 3rd
example. The "value" is the numeric quantity resulting from
2007-07-03 22:58:21 +08:00
evaluation of the string. Note that the same string can generate
different values when it is evaluated at different times during a
simulation.
2007-02-21 08:18:01 +08:00
2013-02-19 01:23:22 +08:00
IMPORTANT NOTE: When the input script line is encountered that defines
a variable of style {equal} or {atom} that contains a formula, the
2009-01-06 06:26:31 +08:00
formula is NOT immediately evaluated and the result stored. See the
discussion below about "Immediate Evaluation of Variables" if you want
2013-12-03 08:23:55 +08:00
to do this. This is also true of the {format} style variable
since it evaluates another variable when it is invoked.
2009-01-06 06:26:31 +08:00
2007-02-21 08:18:01 +08:00
IMPORTANT NOTE: When a variable command is encountered in the input
script and the variable name has already been specified, the command
is ignored. This means variables can NOT be re-defined in an input
2007-07-03 22:58:21 +08:00
script (with 2 exceptions, read further). This is to allow an input
script to be processed multiple times without resetting the variables;
see the "jump"_jump.html or "include"_include.html commands. It also
2012-01-28 07:39:14 +08:00
means that using the "command-line switch"_Section_start.html#start_7
2011-08-26 00:46:23 +08:00
-var will override a corresponding index variable setting in the input
2008-10-07 07:07:25 +08:00
script.
2007-07-03 22:58:21 +08:00
There are two exceptions to this rule. First, variables of style
2013-10-30 23:57:57 +08:00
{string}, {getenv}, {equal} and {atom} ARE redefined each time the
command is encountered. This allows these style of variables to be
redefined multiple times in an input script. In a loop, this means
the formula associated with an {equal} or {atom} style variable can
2013-12-03 08:23:55 +08:00
change if it contains a substitution for another variable, e.g. $x or
v_x.
2007-07-03 22:58:21 +08:00
Second, as described below, if a variable is iterated on to the end of
its list of strings via the "next"_next.html command, it is removed
2008-03-01 09:13:20 +08:00
from the list of active variables, and is thus available to be
2009-03-17 23:41:12 +08:00
re-defined in a subsequent variable command. The {delete} style does
2008-10-07 22:45:58 +08:00
the same thing.
2007-02-10 05:37:30 +08:00
:line
2011-08-26 01:01:01 +08:00
"This section"_Section_commands.html#cmd_2 of the manual explains how
2007-02-21 09:05:23 +08:00
occurrences of a variable name in an input script line are replaced by
the variable's string. The variable name can be referenced as $x if
the name "x" is a single character, or as $\{LoopVar\} if the name
"LoopVar" is one or more characters.
2007-02-21 08:18:01 +08:00
2012-11-10 09:17:45 +08:00
As described below, for variable styles {index}, {loop}, {file},
{universe}, and {uloop}, which string is assigned to a variable can be
incremented via the "next"_next.html command. When there are no more
strings to assign, the variable is exhausted and a flag is set that
causes the next "jump"_jump.html command encountered in the input
script to be skipped. This enables the construction of simple loops
in the input script that are iterated over and then exited from.
2006-09-22 00:22:34 +08:00
2008-10-07 22:45:58 +08:00
As explained above, an exhausted variable can be re-used in an input
2009-03-17 23:41:12 +08:00
script. The {delete} style also removes the variable, the same as if
2008-10-07 22:45:58 +08:00
it were exhausted, allowing it to be redefined later in the input
script or when the input script is looped over. This can be useful
when breaking out of a loop via the "if"_if.html and "jump"_jump.html
commands before the variable would become exhausted. For example,
label loop
variable a loop 5
print "A = $a"
2011-04-12 03:49:41 +08:00
if "$a > 2" then "jump in.script break"
2008-10-07 22:45:58 +08:00
next a
2008-10-07 23:02:40 +08:00
jump in.script loop
2008-10-07 22:45:58 +08:00
label break
variable a delete :pre
2007-02-10 05:37:30 +08:00
:line
2014-01-10 02:28:49 +08:00
This section describes how various variable styles are defined and
what they store. Many of the styles store one or more strings. Note
that a single string can contain spaces (multiple words), if it is
enclosed in quotes in the variable command. When the variable is
substituted for in another input script command, its returned string
will then be interpreted as multiple arguments in the expanded
command.
2006-09-22 00:22:34 +08:00
For the {index} style, one or more strings are specified. Initially,
the 1st string is assigned to the variable. Each time a
"next"_next.html command is used with the variable name, the next
string is assigned. All processors assign the same string to the
2007-02-21 08:18:01 +08:00
variable.
2006-09-22 00:22:34 +08:00
2007-04-30 23:34:40 +08:00
{Index} style variables with a single string value can also be set by
using the command-line switch -var; see "this
2012-01-28 07:39:14 +08:00
section"_Section_start.html#start_7 for details.
2007-04-30 23:34:40 +08:00
2006-09-22 00:22:34 +08:00
The {loop} style is identical to the {index} style except that the
2010-06-29 02:11:30 +08:00
strings are the integers from 1 to N inclusive, if only one argument N
is specified. This allows generation of a long list of runs
(e.g. 1000) without having to list N strings in the input script.
Initially, the string "1" is assigned to the variable. Each time a
"next"_next.html command is used with the variable name, the next
string ("2", "3", etc) is assigned. All processors assign the same
string to the variable. The {loop} style can also be specified with
two arguments N1 and N2. In this case the loop runs from N1 to N2
inclusive, and the string N1 is initially assigned to the variable.
2012-06-13 22:06:14 +08:00
N1 <= N2 and N2 >= 0 is required.
2006-09-22 00:22:34 +08:00
For the {world} style, one or more strings are specified. There must
be one string for each processor partition or "world". See "this
2012-01-28 07:39:14 +08:00
section"_Section_start.html#start_7 of the manual for information on
2006-09-22 00:22:34 +08:00
running LAMMPS with multiple partitions via the "-partition"
command-line switch. This variable command assigns one string to each
world. All processors in the world are assigned the same string. The
2007-02-21 08:18:01 +08:00
next command cannot be used with {equal} style variables, since there
2006-09-22 00:22:34 +08:00
is only one value per world. This style of variable is useful when
you wish to run different simulations on different partitions, or when
performing a parallel tempering simulation (see the
"temper"_temper.html command), to assign different temperatures to
different partitions.
For the {universe} style, one or more strings are specified. There
must be at least as many strings as there are processor partitions or
2012-01-28 07:39:14 +08:00
"worlds". See "this page"_Section_start.html#start_7 for information
2011-08-26 00:46:23 +08:00
on running LAMMPS with multiple partitions via the "-partition"
2006-09-22 00:22:34 +08:00
command-line switch. This variable command initially assigns one
string to each world. When a "next"_next.html command is encountered
using this variable, the first processor partition to encounter it, is
2007-02-21 08:18:01 +08:00
assigned the next available string. This continues until all the
variable strings are consumed. Thus, this command can be used to run
2006-09-22 00:22:34 +08:00
50 simulations on 8 processor partitions. The simulations will be run
one after the other on whatever partition becomes available, until
2007-02-21 08:18:01 +08:00
they are all finished. {Universe} style variables are incremented
2006-09-22 00:22:34 +08:00
using the files "tmp.lammps.variable" and "tmp.lammps.variable.lock"
which you will see in your directory during such a LAMMPS run.
2006-12-20 00:44:20 +08:00
The {uloop} style is identical to the {universe} style except that the
2007-02-21 08:18:01 +08:00
strings are the integers from 1 to N. This allows generation of long
list of runs (e.g. 1000) without having to list N strings in the input
script.
2006-09-22 00:22:34 +08:00
2012-11-10 09:17:45 +08:00
For the {string} style, a single string is assigned to the variable.
The only difference between this and using the {index} style with a
single string is that a variable with {string} style can be redefined.
E.g. by another command later in the input script, or if the script is
read again in a loop.
2013-12-03 08:23:55 +08:00
For the {format} style, an equal-style variable is specified along
with a C-style format string, e.g. "%f" or "%.10g", which must be
appropriate for formatting a double-precision floating-point value.
This allows an equal-style variable to be formatted specifically for
output as a string, e.g. by the "print"_print.html command, if the
2013-12-03 23:23:25 +08:00
default format "%.15g" has too much precision.
2013-12-03 08:23:55 +08:00
2013-10-30 23:57:57 +08:00
For the {getenv} style, a single string is assigned to the variable
which should be the name of an environment variable. When the
variable is evaluated, it returns the value of the environment
variable, or an empty string if it not defined. This style of
variable can be used to adapt the behavior of LAMMPS input scripts via
environment variable settings, or to retrieve information that has
been previously stored with the "shell putenv"_shell.html command.
Note that because environment variable settings are stored by the
operating systems, they persist beyond a "clear"_clear.html command.
2012-11-10 09:17:45 +08:00
For the {file} style, a filename is provided which contains a list of
strings to assign to the variable, one per line. The strings can be
2013-07-25 04:47:56 +08:00
numeric values if desired. See the discussion of the next() function
2012-11-10 09:17:45 +08:00
below for equal-style variables, which will convert the string of a
file-style variable into a numeric value in a formula.
When a file-style variable is defined, the file is opened and the
string on the first line is read and stored with the variable. This
means the variable can then be evaluated as many times as desired and
will return that string. There are two ways to cause the next string
from the file to be read: use the "next"_next.html command or the
next() function in an equal- or atom-style variable, as discussed
below.
The rules for formatting the file are as follows. A comment character
"#" can be used anywhere on a line; text starting with the comment
character is stripped. Blank lines are skipped. The first "word" of
a non-blank line, delimited by white space, is the "string" assigned
to the variable.
2013-07-25 04:47:56 +08:00
For the {atomfile} style, a filename is provided which contains one or
more sets of values, to assign on a per-atom basis to the variable.
The format of the file is described below.
When an atomfile-style variable is defined, the file is opened and the
first set of per-atom values are read and stored with the variable.
This means the variable can then be evaluated as many times as desired
and will return those values. There are two ways to cause the next
set of per-atom values from the file to be read: use the
"next"_next.html command or the next() function in an atom-style
variable, as discussed below.
The rules for formatting the file are as follows. Each time a set of
per-atom values is read, a non-blank line is searched for in the file.
A comment character "#" can be used anywhere on a line; text starting
with the comment character is stripped. Blank lines are skipped. The
first "word" of a non-blank line, delimited by white space, is read as
the count N of per-atom lines to immediately follow. N can be be the
total number of atoms in the system, or only a subset. The next N
lines have the following format
ID value :pre
where ID is an atom ID and value is the per-atom numeric value that
will be assigned to that atom. IDs can be listed in any order.
IMPORTANT NOTE: Every time a set of per-atom lines is read, the value
for all atoms is first set to 0.0. Thus values for atoms whose ID
does not appear in the set, will remain 0.0.
2007-02-10 05:37:30 +08:00
:line
2007-02-21 08:18:01 +08:00
For the {equal} and {atom} styles, a single string is specified which
2008-01-03 03:25:15 +08:00
represents a formula that will be evaluated afresh each time the
variable is used. If you want spaces in the string, enclose it in
double quotes so the parser will treat it as a single argument. For
{equal} style variables the formula computes a scalar quantity, which
becomes the value of the variable whenever it is evaluated. For
{atom} style variables the formula computes one quantity for each
atom whenever it is evaluated.
2007-02-21 08:18:01 +08:00
Note that {equal} and {atom} variables can produce different values at
different stages of the input script or at different times during a
run. For example, if an {equal} variable is used in a "fix
print"_fix_print.html command, different values could be printed each
2009-01-06 06:26:31 +08:00
timestep it was invoked. If you want a variable to be evaluated
immediately, so that the result is stored by the variable instead of
the string, see the section below on "Immediate Evaluation of
Variables".
2007-02-21 08:18:01 +08:00
The next command cannot be used with {equal} or {atom} style
variables, since there is only one string.
2007-02-10 05:37:30 +08:00
2008-01-03 03:25:15 +08:00
The formula for an {equal} or {atom} variable can contain a variety
2007-02-21 08:18:01 +08:00
of quantities. The syntax for each kind of quantity is simple, but
2007-02-10 05:37:30 +08:00
multiple quantities can be nested and combined in various ways to
build up formulas of arbitrary complexity. For example, this is a
2008-01-03 03:25:15 +08:00
valid (though strange) variable formula:
2007-02-10 05:37:30 +08:00
2008-01-03 03:25:15 +08:00
variable x equal "pe + c_MyTemp / vol^(1/3)" :pre
2007-02-10 05:37:30 +08:00
2008-01-03 03:25:15 +08:00
Specifically, an formula can contain numbers, thermo keywords, math
2010-04-24 04:00:32 +08:00
operators, math functions, group functions, region functions, atom
values, atom vectors, compute references, fix references, and
references to other variables.
2007-02-10 05:37:30 +08:00
2008-01-09 07:13:53 +08:00
Number: 0.2, 100, 1.0e20, -15.4, etc
2010-10-13 01:58:24 +08:00
Constant: PI
2007-02-10 05:37:30 +08:00
Thermo keywords: vol, pe, ebond, etc
2010-11-19 02:30:31 +08:00
Math operators: (), -x, x+y, x-y, x*y, x/y, x^y, x==y, x!=y, x<y, x<=y, x>y, x>=y, x&&y, x||y, !x
2012-11-26 23:56:41 +08:00
Math functions: sqrt(x), exp(x), ln(x), log(x), abs(x), sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), atan2(y,x), random(x,y,z), normal(x,y,z), ceil(x), floor(x), round(x), ramp(x,y), stagger(x,y), logfreq(x,y,z), stride(x,y,z), vdisplace(x,y), swiggle(x,y,z), cwiggle(x,y,z)
2008-01-03 03:25:15 +08:00
Group functions: count(ID), mass(ID), charge(ID), xcm(ID,dim), \
2010-05-19 08:15:34 +08:00
vcm(ID,dim), fcm(ID,dim), bound(ID,dir), \
2010-11-24 22:43:25 +08:00
gyration(ID), ke(ID), angmom(ID,dim), torque(ID,dim), \
2010-05-29 00:45:33 +08:00
inertia(ID,dimdim), omega(ID,dim)
2010-05-19 08:15:34 +08:00
Region functions: count(ID,IDR), mass(ID,IDR), charge(ID,IDR), \
xcm(ID,dim,IDR), vcm(ID,dim,IDR), fcm(ID,dim,IDR), \
bound(ID,dir,IDR), gyration(ID,IDR), ke(ID,IDR), \
2010-11-24 22:43:25 +08:00
angmom(ID,dim,IDR), torque(ID,dim,IDR), \
inertia(ID,dimdim,IDR), omega(ID,dim,IDR)
2014-02-05 02:59:28 +08:00
Special functions: sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x)
2014-01-09 05:21:23 +08:00
Atom values: id\[i\], mass\[i\], type\[i\], mol\[i\], x\[i\], y\[i\], z\[i\], \
2009-12-10 05:20:59 +08:00
vx\[i\], vy\[i\], vz\[i\], fx\[i\], fy\[i\], fz\[i\]
2014-01-09 05:21:23 +08:00
Atom vectors: id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz
2009-12-10 05:20:59 +08:00
Compute references: c_ID, c_ID\[i\], c_ID\[i\]\[j\]
Fix references: f_ID, f_ID\[i\], f_ID\[i\]\[j\]
Other variables: v_name, v_name\[i\] :tb(s=:)
2010-08-18 05:58:29 +08:00
:line
2010-08-05 05:36:27 +08:00
Most of the formula elements produce a scalar value. A few produce a
per-atom vector of values. These are the atom vectors, compute
references that represent a per-atom vector, fix references that
represent a per-atom vector, and variables that are atom-style
variables. Math functions that operate on scalar values produce a
2010-08-18 05:58:29 +08:00
scalar value; math function that operate on per-atom vectors do so
element-by-element and produce a per-atom vector.
2008-01-09 07:13:53 +08:00
A formula for equal-style variables cannot use any formula element
2010-08-05 05:36:27 +08:00
that produces a per-atom vector. A formula for an atom-style variable
can use formula elements that produce either a scalar value or a
2011-06-22 21:15:24 +08:00
per-atom vector. Atom-style variables are evaluated by other commands
that define a "group"_group.html on which they operate, e.g. a
"dump"_dump.html or "compute"_compute.html or "fix"_fix.html command.
When they invoke the atom-style variable, only atoms in the group are
inlcuded in the formula evaluation. The variable evaluates to 0.0 for
atoms not in the group.
2008-01-03 03:25:15 +08:00
The thermo keywords allowed in a formula are those defined by the
2009-12-04 01:57:33 +08:00
"thermo_style custom"_thermo_style.html command. Thermo keywords that
require a "compute"_compute.html to calculate their values such as
"temp" or "press", use computes stored and invoked by the
"thermo_style"_thermo_style.html command. This means that you can
only use those keywords in a variable if the style you are using with
the thermo_style command (and the thermo keywords associated with that
style) also define and use the needed compute. Note that some thermo
keywords use a compute indirectly to calculate their value (e.g. the
enthalpy keyword uses temp, pe, and pressure). If a variable is
2009-12-10 05:20:59 +08:00
evaluated directly in an input script (not during a run), then the
values accessed by the thermo keyword must be current. See the
discussion below about "Variable Accuracy".
2008-01-03 03:25:15 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-10-13 01:58:24 +08:00
Math Operators :h4
2010-04-24 04:00:32 +08:00
Math operators are written in the usual way, where the "x" and "y" in
2010-08-05 05:36:27 +08:00
the examples can themselves be arbitrarily complex formulas, as in the
examples above. In this syntax, "x" and "y" can be scalar values or
per-atom vectors. For example, "ke/natoms" is the division of two
2010-10-07 02:12:34 +08:00
scalars, where "vy+vz" is the element-by-element sum of two per-atom
vectors of y and z velocities.
2010-08-05 05:36:27 +08:00
Operators are evaluated left to right and have the usual C-style
2010-11-19 02:30:31 +08:00
precedence: unary minus and unary logical NOT operator "!" have the
highest precedence, exponentiation "^" is next; multiplication and
division are next; addition and subtraction are next; the 4 relational
operators "<", "<=", ">", and ">=" are next; the two remaining
relational operators "==" and "!=" are next; then the logical AND
operator "&&"; and finally the logical OR operator "||" has the lowest
precedence. Parenthesis can be used to group one or more portions of
a formula and/or enforce a different order of evaluation than what
would occur with the default precedence.
2010-04-24 04:00:32 +08:00
2013-11-12 00:48:14 +08:00
IMPORTANT NOTE: Because a unary minus is higher precedence than
exponentiation, the formula "-2^2" will evaluate to 4, not -4. This
convention is compatible with some programming languages, but not
2013-11-20 23:14:48 +08:00
others. As mentioned, this behavior can be easily overridden with
parenthesis; the formula "-(2^2)" will evaluate to -4.
2013-11-12 00:48:14 +08:00
2010-04-24 04:00:32 +08:00
The 6 relational operators return either a 1.0 or 0.0 depending on
2010-11-19 02:30:31 +08:00
whether the relationship between x and y is TRUE or FALSE. For
2010-04-24 04:00:32 +08:00
example the expression x<10.0 in an atom-style variable formula will
return 1.0 for all atoms whose x-coordinate is less than 10.0, and 0.0
2010-11-19 01:28:36 +08:00
for the others. The logical AND operator will return 1.0 if both its
2010-11-19 02:30:31 +08:00
arguments are non-zero, else it returns 0.0. The logical OR operator
will return 1.0 if either of its arguments is non-zero, else it
returns 0.0. The logical NOT operator returns 1.0 if its argument is
0.0, else it returns 0.0.
These relational and logical operators can be used as a masking or
selection operation in a formula. For example, the number of atoms
2010-08-06 22:48:24 +08:00
whose properties satifsy one or more criteria could be calculated by
2010-04-24 04:18:34 +08:00
taking the returned per-atom vector of ones and zeroes and passing it
to the "compute reduce"_compute_reduce.html command.
2010-04-24 04:00:32 +08:00
2010-10-13 01:58:24 +08:00
:line
Math Functions :h4
2010-08-05 05:36:27 +08:00
Math functions are specified as keywords followed by one or more
2010-10-13 01:58:24 +08:00
parenthesized arguments "x", "y", "z", each of which can themselves be
2010-08-05 05:36:27 +08:00
arbitrarily complex formulas. In this syntax, the arguments can
2010-08-18 05:58:29 +08:00
represent scalar values or per-atom vectors. In the latter case, the
math operation is performed on each element of the vector. For
example, "sqrt(natoms)" is the sqrt() of a scalar, where "sqrt(y*z)"
yields a per-atom vector with each element being the sqrt() of the
product of one atom's y and z coordinates.
2010-08-05 05:36:27 +08:00
Most of the math functions perform obvious operations. The ln() is
2010-10-07 02:12:34 +08:00
the natural log; log() is the base 10 log.
2010-10-13 01:58:24 +08:00
The random(x,y,z) function takes 3 arguments: x = lo, y = hi, and z =
seed. It generates a uniform random number between lo and hi. The
normal(x,y,z) function also takes 3 arguments: x = mu, y = sigma, and
z = seed. It generates a Gaussian variate centered on mu with
variance sigma^2. In both cases the seed is used the first time the
internal random number generator is invoked, to initialize it. For
equal-style variables, every processor uses the same seed so that they
each generate the same sequence of random numbers. For atom-style
variables, a unique seed is created for each processor, based on the
specified seed. This effectively generates a different random number
for each atom being looped over in the atom-style variable.
IMPORTANT NOTE: Internally, there is just one random number generator
for all equal-style variables and one for all atom-style variables.
If you define multiple variables (of each style) which use the
random() or normal() math functions, then the internal random number
generators will only be initialized once, which means only one of the
specified seeds will determine the sequence of generated random
numbers.
2010-10-07 02:12:34 +08:00
The ceil(), floor(), and round() functions 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.
2010-10-13 01:58:24 +08:00
The ramp(x,y) function uses the current timestep to generate a value
linearly intepolated between the specified x,y values over the course
of a run, according to this formula:
value = x + (y-x) * (timestep-startstep) / (stopstep-startstep) :pre
The run begins on startstep and ends on stopstep. Startstep and
stopstep can span multiple runs, using the {start} and {stop} keywords
of the "run"_run.html command. See the "run"_run.html command for
details of how to do this.
The stagger(x,y) function uses the current timestep to generate a new
2012-05-18 06:25:44 +08:00
timestep. X,y > 0 and x > y are required. The generated timesteps
2010-10-13 01:58:24 +08:00
increase in a staggered fashion, as the sequence
x,x+y,2x,2x+y,3x,3x+y,etc. For any current timestep, the next
timestep in the sequence is returned. Thus if stagger(1000,100) is
used in a variable by the "dump_modify every"_dump_modify.html
command, it will generate the sequence of output timesteps:
100,1000,1100,2000,2100,3000,etc :pre
The logfreq(x,y,z) function uses the current timestep to generate a
2012-05-18 06:25:44 +08:00
new timestep. X,y,z > 0 and y < z are required. The generated
2010-10-13 01:58:24 +08:00
timesteps increase in a logarithmic fashion, as the sequence
x,2x,3x,...y*x,z*x,2*z*x,3*z*x,...y*z*x,z*z*x,2*z*x*x,etc. For any
current timestep, the next timestep in the sequence is returned. Thus
if logfreq(100,4,10) is used in a variable by the "dump_modify
every"_dump_modify.html command, it will generate the sequence of
output timesteps:
100,200,300,400,1000,2000,3000,4000,10000,20000,etc :pre
2012-05-18 06:25:44 +08:00
The stride(x,y,z) function uses the current timestep to generate a new
timestep. X,y >= 0 and z > 0 and x <= y are required. The generated
timesteps increase in increments of z, from x to y, I.e. it generates
the sequece x,x+z,x+2z,...,y. If y-x is not a multiple of z, then
similar to the way a for loop operates, the last value will be one
that does not exceed y. For any current timestep, the next timestep
in the sequence is returned. Thus if stagger(1000,2000,100) is used
in a variable by the "dump_modify every"_dump_modify.html command, it
will generate the sequence of output timesteps:
1000,1100,1200, ... ,1900,2000 :pre
2012-05-24 21:38:41 +08:00
The vdisplace(x,y) function takes 2 arguments: x = value0 and y =
velocity, and uses the elapsed time to change the value by a linear
displacement due to the applied velocity over the course of a run,
according to this formula:
2010-10-13 01:58:24 +08:00
2012-05-24 21:38:41 +08:00
value = value0 + velocity*(timestep-startstep)*dt :pre
2010-10-13 01:58:24 +08:00
where dt = the timestep size.
The run begins on startstep. Startstep can span multiple runs, using
the {start} keyword of the "run"_run.html command. See the
2010-10-29 08:17:32 +08:00
"run"_run.html command for details of how to do this. Note that the
"thermo_style"_thermo_style.html keyword elaplong =
timestep-startstep.
2010-10-13 01:58:24 +08:00
The swiggle(x,y,z) and cwiggle(x,y,z) functions each take 3 arguments:
2012-05-24 21:38:41 +08:00
x = value0, y = amplitude, z = period. They use the elapsed time to
oscillate the value by a sin() or cos() function over the course of a
run, according to one of these formulas, where omega = 2 PI / period:
2010-10-13 01:58:24 +08:00
2012-05-24 21:38:41 +08:00
value = value0 + Amplitude * sin(omega*(timestep-startstep)*dt)
value = value0 + Amplitude * (1 - cos(omega*(timestep-startstep)*dt)) :pre
2010-10-13 01:58:24 +08:00
where dt = the timestep size.
The run begins on startstep. Startstep can span multiple runs, using
the {start} keyword of the "run"_run.html command. See the
2010-10-29 08:17:32 +08:00
"run"_run.html command for details of how to do this. Note that the
"thermo_style"_thermo_style.html keyword elaplong =
timestep-startstep.
2008-01-03 03:25:15 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-08-06 07:19:40 +08:00
2010-10-13 01:58:24 +08:00
Group and Region Functions :h4
2010-08-05 05:36:27 +08:00
Group functions are specified as keywords followed by one or two
parenthesized arguments. The first argument is the group-ID. The
{dim} argument, if it exists, is {x} or {y} or {z}. The {dir}
argument, if it exists, is {xmin}, {xmax}, {ymin}, {ymax}, {zmin}, or
{zmax}. The {dimdim} argument, if it exists, is {xx} or {yy} or {zz}
or {xy} or {yz} or {xz}.
2010-05-29 00:45:33 +08:00
The group function count() is the number of atoms in the group. The
group functions mass() and charge() are the total mass and charge of
the group. Xcm() and vcm() return components of the position and
velocity of the center of mass of the group. Fcm() returns a
component of the total force on the group of atoms. Bound() returns
the min/max of a particular coordinate for all atoms in the group.
Gyration() computes the radius-of-gyration of the group of atoms. See
the "compute gyration"_compute_gyration.html command for a definition
of the formula. Angmom() returns components of the angular momentum
2010-11-24 22:43:25 +08:00
of the group of atoms around its center of mass. Torque() returns
components of the torque on the group of atoms around its center of
mass, based on current forces on the atoms. Inertia() returns one of
2012-11-27 22:41:21 +08:00
6 components of the symmetric inertia tensor of the group of atoms
around its center of mass, ordered as Ixx,Iyy,Izz,Ixy,Iyz,Ixz.
Omega() returns components of the angular velocity of the group of
atoms around its center of mass.
2008-01-03 03:25:15 +08:00
2010-08-05 05:36:27 +08:00
Region functions are specified exactly the same way as group functions
except they take an extra argument which is the region ID. The
function is computed for all atoms that are in both the group and the
region. If the group is "all", then the only criteria for atom
inclusion is that it be in the region.
2009-04-29 03:50:15 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-10-13 01:58:24 +08:00
Special Functions :h4
2010-08-18 05:58:29 +08:00
2010-10-13 01:58:24 +08:00
Special functions take specific kinds of arguments, meaning their
arguments cannot be formulas themselves.
2010-08-18 05:58:29 +08:00
2014-02-05 02:59:28 +08:00
The sum(x), min(x), max(x), ave(x), trap(x), and slope(x) functions
each take 1 argument which is of the form "c_ID" or "c_ID\[N\]" or
"f_ID" or "f_ID\[N\]". The first two are computes and the second two
are fixes; the ID in the reference should be replaced by the ID of a
compute or fix defined elsewhere in the input script. The compute or
fix must produce either a global vector or array. If it produces a
global vector, then the notation without "\[N\]" should be used. If
it produces a global array, then the notation with "\[N\]" should be
2010-08-18 05:58:29 +08:00
used, when N is an integer, to specify which column of the global
array is being referenced.
2010-10-13 23:00:13 +08:00
These functions operate on the global vector of inputs and reduce it
to a single scalar value. This is analagous to the operation of the
"compute reduce"_compute_reduce.html command, which invokes the same
functions on per-atom and local vectors.
2010-08-18 05:58:29 +08:00
The sum() function calculates the sum of all the vector elements. The
min() and max() functions find the minimum and maximum element
respectively. The ave() function is the same as sum() except that it
2014-02-05 02:59:28 +08:00
divides the result by the length of the vector.
The trap() function is the same as sum() except the first and last
elements are multiplied by a weighting factor of 1/2 when performing
the sum. This effectively implements an integration via the
trapezoidal rule on the global vector of data. I.e. consider a set of
points, equally spaced by 1 in their x coordinate: (1,V1), (2,V2),
..., (N,VN), where the Vi are the values in the global vector of
length N. The integral from 1 to N of these points is trap(). When
appropriately normalized by the timestep size, this function is useful
for calculating integrals of time-series data, like that generated by
the "fix ave/correlate"_fix_ave_correlate.html command.
The slope() function uses linear regression to fit a line to the set
of points, equally spaced by 1 in their x coordinate: (1,V1), (2,V2),
..., (N,VN), where the Vi are the values in the global vector of
length N. The returned value is the slope of the line. If the line
has a single point or is vertical, it returns 1.0e20.
2010-08-18 05:58:29 +08:00
2010-10-13 23:00:13 +08:00
The gmask(x) function takes 1 argument which is a group ID. It
can only be used in atom-style variables. It returns a 1 for
atoms that are in the group, and a 0 for atoms that are not.
The rmask(x) function takes 1 argument which is a region ID. It can
only be used in atom-style variables. It returns a 1 for atoms that
are in the geometric region, and a 0 for atoms that are not.
The grmask(x,y) function takes 2 arguments. The first is a group ID,
and the second is a region ID. It can only be used in atom-style
variables. It returns a 1 for atoms that are in both the group and
region, and a 0 for atoms that are not in both.
2012-11-10 09:17:45 +08:00
The next(x) function takes 1 argument which is a variable ID (not
2013-07-25 04:47:56 +08:00
"v_foo", just "foo"). It must be for a file-style or atomfile-style
variable. Each time the next() function is invoked (i.e. each time
the equal-style or atom-style variable is evaluated), the following
steps occur.
For file-style variables, the current string value stored by the
file-style variable is converted to a numeric value and returned by
the function. And the next string value in the file is read and
stored. Note that if the line previously read from the file was not a
numeric string, then it will typically evaluate to 0.0, which is
likely not what you want.
For atomfile-style variables, the current per-atom values stored by
the atomfile-style variable are returned by the function. And the
next set of per-atom values in the file is read and stored.
Since file-style and atomfile-style variables read and store the first
line of the file or first set of per-atoms values when they are
defined in the input script, these are the value(s) that will be
returned the first time the next() function is invoked. If next() is
invoked more times than there are lines or sets of lines in the file,
the variable is deleted, similar to how the "next"_next.html command
operates.
2012-11-10 09:17:45 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-10-13 01:58:24 +08:00
Atom Values and Vectors :h4
2009-12-10 05:20:59 +08:00
Atom values take a single integer argument I from 1 to N, where I is
the an atom-ID, e.g. x\[243\], which means use the x coordinate of the
atom with ID = 243.
2008-01-03 03:25:15 +08:00
2009-12-10 05:20:59 +08:00
Atom vectors generate one value per atom, so that a reference like
"vx" means the x-component of each atom's velocity will be used when
2014-01-09 05:21:23 +08:00
evaluating the variable.
The meaning of the different atom values and vectors is mostly
self-explanatory. Mol refernces the molecule ID of an atom, and is
only defined if an "atom_style"_atom_style.html is being used
that defines molecule IDs.
Note that many other atom attributes can be used as inputs to a
variable by using the "compute
2009-12-17 01:12:09 +08:00
property/atom"_compute_property_atom.html command and then specifying
a quantity from that compute.
2008-01-03 03:25:15 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-10-13 01:58:24 +08:00
Compute References :h4
2009-12-10 05:20:59 +08:00
Compute references access quantities calculated by a
2007-02-21 08:18:01 +08:00
"compute"_compute.html. The ID in the reference should be replaced by
2009-12-10 05:20:59 +08:00
the ID of a compute defined elsewhere in the input script. As
discussed in the doc page for the "compute"_compute.html command,
computes can produce global, per-atom, or local values. Only global
and per-atom values can be used in a variable. Computes can also
2010-08-11 22:30:24 +08:00
produce a scalar, vector, or array. An equal-style variable can only
use scalar values, which means a global scalar, or an element of a
global or per-atom vector or array. Atom-style variables can use the
same scalar values. They can also use per-atom vector values. A
vector value can be a per-atom vector itself, or a column of an
per-atom array. See the doc pages for individual computes to see what
kind of values they produce.
2009-12-10 05:20:59 +08:00
Examples of different kinds of compute references are as follows.
There is no ambiguity as to what a reference means, since computes
only produce global or per-atom quantities, never both.
c_ID: global scalar, or per-atom vector
c_ID\[I\]: Ith element of global vector, or atom I's value in per-atom vector, or Ith column from per-atom array
c_ID\[I\]\[J\]: I,J element of global array, or atom I's Jth value in per-atom array :tb(s=:)
If a variable containing a compute is evaluated
directly in an input script (not during a run), then the values
2009-01-06 06:26:31 +08:00
accessed by the compute must be current. See the discussion below
about "Variable Accuracy".
2008-01-09 07:13:53 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-10-13 01:58:24 +08:00
Fix References :h4
2009-12-10 05:20:59 +08:00
Fix references access quantities calculated by a "fix"_compute.html.
The ID in the reference should be replaced by the ID of a fix defined
elsewhere in the input script. As discussed in the doc page for the
"fix"_fix.html command, fixes can produce global, per-atom, or local
values. Only global and per-atom values can be used in a variable.
Fixes can also produce a scalar, vector, or array. An equal-style
2010-08-11 22:30:24 +08:00
variable can only use scalar values, which means a global scalar, or
an element of a global or per-atom vector or array. Atom-style
variables can use the same scalar values. They can also use per-atom
vector values. A vector value can be a per-atom vector itself, or a
column of an per-atom array. See the doc pages for individual fixes
to see what kind of values they produce.
2009-12-10 05:20:59 +08:00
The different kinds of fix references are exactly the same as the
compute references listed in the above table, where "c_" is replaced
2010-08-11 22:30:24 +08:00
by "f_". Again, there is no ambiguity as to what a reference means,
since fixes only produce global or per-atom quantities, never both.
2009-12-10 05:20:59 +08:00
f_ID: global scalar, or per-atom vector
f_ID\[I\]: Ith element of global vector, or atom I's value in per-atom vector, or Ith column from per-atom array
f_ID\[I\]\[J\]: I,J element of global array, or atom I's Jth value in per-atom array :tb(s=:)
If a variable containing a fix is evaluated directly in an input
script (not during a run), then the values accessed by the fix should
be current. See the discussion below about "Variable Accuracy".
2008-01-09 07:13:53 +08:00
Note that some fixes only generate quantities on certain timesteps.
If a variable attempts to access the fix on non-allowed timesteps, an
error is generated. For example, the "fix ave/time"_fix_ave_time.html
command may only generate averaged quantities every 100 steps. See
2009-12-10 05:20:59 +08:00
the doc pages for individual fix commands for details.
2007-02-10 05:37:30 +08:00
2010-08-18 05:58:29 +08:00
:line
2010-10-13 01:58:24 +08:00
Variable References :h4
2012-11-10 09:17:45 +08:00
Variable references access quantities stored or calculated by other
variables, which will cause those variables to be evaluated. The name
in the reference should be replaced by the name of a variable defined
elsewhere in the input script.
As discussed on this doc page, equal-style variables generate a global
2013-07-25 04:47:56 +08:00
scalar numeric value; atom-style and atomfile-style variables generate
a per-atom vector of numeric values; all other variables store a
string. The formula for an equal-style variable can use any style of
variable except an atom-style or atomfile-style (unless only a single
value from the variable is accessed via a subscript). If a
string-storing variable is used, the string is converted to a numeric
value. Note that this will typically produce a 0.0 if the string is
not a numeric string, which is likely not what you want. The formula
for an atom-style variable can use any style of variable, including
other atom-style or atomfile-style variables.
2008-01-09 07:13:53 +08:00
2009-12-10 05:20:59 +08:00
Examples of different kinds of variable references are as follows.
There is no ambiguity as to what a reference means, since variables
2012-11-10 09:17:45 +08:00
produce only a global scalar or a per-atom vector, never both.
2008-01-09 07:13:53 +08:00
2009-12-10 05:20:59 +08:00
v_name: scalar, or per-atom vector
v_name\[I\]: atom I's value in per-atom vector :tb(s=:)
2008-01-03 03:25:15 +08:00
2008-10-07 07:07:25 +08:00
:line
2009-01-06 06:27:48 +08:00
[Immediate Evaluation of Variables:]
2009-01-06 06:26:31 +08:00
There is a difference between referencing a variable with a leading $
sign (e.g. $x or $\{abc\}) versus with a leading "v_" (e.g. v_x or
2013-02-19 01:23:22 +08:00
v_abc). The former can be used in any input script command, including
a variable command. The input script parser evaluates the reference
variable immediately and substitutes its value into the command. As
explained in "Section commands 3.2"_Section_commands.html#3_2 for
"Parsing rules", you can also use un-named "immediate" variables for
this purpose. An variable reference such as
$((xlo+xhi)/2+sqrt(v_area)) evaluates the string between the
parenthesis as an equal-style variable.
Referencing a variable with a leading "v_" is an optional or required
kind of argument for some commands (e.g. the "fix
2009-01-06 06:26:31 +08:00
ave/spatial"_fix_ave_spatial.html or "dump custom"_dump.html or
"thermo_style"_thermo_style.html commands) if you wish it to evaluate
a variable periodically during a run. It can also be used in a
variable formula if you wish to reference a second variable. The
second variable will be evaluated whenever the first variable is
evaluated.
As an example, suppose you use this command in your input script to
define the variable "v" as
2008-10-07 07:07:25 +08:00
2009-01-06 06:26:31 +08:00
variable v equal vol :pre
2008-10-07 07:07:25 +08:00
2009-01-06 06:26:31 +08:00
before a run where the simulation box size changes. You might think
this will assign the initial volume to the variable "v". That is not
the case. Rather it assigns a formula which evaluates the volume
(using the thermo_style keyword "vol") to the variable "v". If you
2010-05-08 00:29:19 +08:00
use the variable "v" in some other command like "fix
ave/time"_fix_ave_time.html then the current volume of the box will be
evaluated continuously during the run.
2008-10-07 07:07:25 +08:00
2009-01-06 06:26:31 +08:00
If you want to store the initial volume of the system, you can do it
this way:
2008-01-03 03:25:15 +08:00
2009-01-06 06:26:31 +08:00
variable v equal vol
variable v0 equal $v :pre
2007-02-10 05:37:30 +08:00
2009-01-06 06:26:31 +08:00
The second command will force "v" to be evaluated (yielding the
initial volume) and assign that value to the variable "v0". Thus the
command
2007-02-10 05:37:30 +08:00
2009-01-06 06:26:31 +08:00
thermo_style custom step v_v v_v0 :pre
2007-02-10 05:37:30 +08:00
2009-01-06 06:26:31 +08:00
would print out both the current and initial volume periodically
during the run.
2007-02-10 05:37:30 +08:00
2009-01-06 06:26:31 +08:00
Note that it is a mistake to enclose a variable formula in double
quotes if it contains variables preceeded by $ signs. For example,
2007-02-10 05:37:30 +08:00
2009-01-06 06:26:31 +08:00
variable vratio equal "$\{vfinal\}/$\{v0\}" :pre
This is because the quotes prevent variable substitution (see "this
2011-08-26 01:01:01 +08:00
section"_Section_commands.html#cmd_2 on parsing input script
commands), and thus an error will occur when the formula for "vratio"
is evaluated later.
2009-01-06 06:26:31 +08:00
:line
2007-02-10 05:37:30 +08:00
2009-01-06 06:27:48 +08:00
[Variable Accuracy:]
2009-01-06 06:26:31 +08:00
Obviously, LAMMPS attempts to evaluate variables containing formulas
({equal} and {atom} style variables) accurately whenever the
evaluation is performed. Depending on what is included in the
formula, this may require invoking a "compute"_compute.html, either
directly or indirectly via a thermo keyword, or accessing a value
2009-02-17 22:58:00 +08:00
previously calculated by a compute, or accessing a value calculated
and stored by a "fix"_fix.html. If the compute is one that calculates
the pressure or energy of the system, then these quantities need to be
tallied during the evaluation of the interatomic potentials (pair,
bond, etc) on timesteps that the variable will need the values.
2009-01-06 06:26:31 +08:00
LAMMPS keeps track of all of this during a "run"_run.html or "energy
minimization"_minimize.html. An error will be generated if you
attempt to evaluate a variable on timesteps when it cannot produce
accurate values. For example, if a "thermo_style
custom"_thermo_style.html command prints a variable which accesses
values stored by a "fix ave/time"_fix_ave_time.html command and the
timesteps on which thermo output is generated are not multiples of the
2009-02-17 22:58:00 +08:00
averaging frequency used in the fix command, then an error will occur.
2009-01-06 06:26:31 +08:00
2009-02-17 22:58:00 +08:00
An input script can also request variables be evaluated before or
after or in between runs, e.g. by including them in a
"print"_print.html command. In this case, if a compute is needed to
evaluate a variable (either directly or indirectly), LAMMPS will not
invoke the compute, but it will use a value previously calculated by
2010-05-06 04:19:26 +08:00
the compute, and can do this only if it is current. Fixes will always
provide a quantity needed by a variable, but the quantity may or may
not be current. This leads to one of three kinds of behavior:
2009-01-06 06:26:31 +08:00
(1) The variable may be evaluated accurately. If it contains
2009-02-17 22:58:00 +08:00
references to a compute or fix, and these values were calculated on
the last timestep of a preceeding run, then they will be accessed and
used by the variable and the result will be accurate.
2009-01-06 06:26:31 +08:00
2012-08-28 23:27:10 +08:00
(2) LAMMPS may not be able to evaluate the variable and will generate
an error message stating so. For example, if the variable requires a
quantity from a "compute"_compute.html that is not current, LAMMPS
will generate an error. This means, for example, that such a variable
cannot be evaluated before the first run has occurred. Likewise, in
between runs, such a variable cannot be accessed unless it was
evaluated on the last timestep of the preceding run, e.g. by
thermodynamic output.
2009-02-17 22:58:00 +08:00
One way to get around this problem is to perform a 0-timestep run
2009-01-06 06:26:31 +08:00
before using the variable. For example, these commands
variable t equal temp
print "Initial temperature = $t"
run 1000 :pre
will generate an error if the run is the first run specified in the
input script, because generating a value for the "t" variable requires
a compute for calculating the temperature to be invoked.
However, this sequence of commands would be fine:
run 0
variable t equal temp
print "Initial temperature = $t"
run 1000 :pre
The 0-timestep run initializes and invokes various computes, including
the one for temperature, so that the value it stores is current and
can be accessed by the variable "t" after the run has completed. Note
that a 0-timestep run does not alter the state of the system, so it
does not change the input state for the 1000-timestep run that
2009-02-17 22:58:00 +08:00
follows. Also note that the 0-timestep run must actually use and
2009-01-06 06:26:31 +08:00
invoke the compute in question (e.g. via "thermo"_thermo_style.html or
"dump"_dump.html output) in order for it to enable the compute to be
2010-05-06 04:19:26 +08:00
used in a variable after the run. Thus if you are trying to print a
variable that uses a compute you have defined, you could insure it was
invoked on the last timestep of the preceding run by including it in
thermodynamic output.
2009-01-06 06:26:31 +08:00
2009-02-17 22:58:00 +08:00
Unlike computes, "fixes"_fix.html will never generate an error if
their values are accessed by a variable in between runs. They always
return some value to the variable. However, the value may not be what
you expect if the fix has not yet calculated the quantity of interest
or it is not current. For example, the "fix indent"_fix_indent.html
2009-01-06 06:26:31 +08:00
command stores the force on the indenter. But this is not computed
until a run is performed. Thus if a variable attempts to print this
2009-02-17 22:58:00 +08:00
value before the first run, zeroes will be output. Again, performing
a 0-timestep run before printing the variable has the desired effect.
2009-01-06 06:26:31 +08:00
2012-08-28 23:27:10 +08:00
(3) The variable may be evaluated incorrectly and LAMMPS may have no
way to detect this has occurred. Consider the following sequence of
commands:
2009-01-06 06:26:31 +08:00
pair_coeff 1 1 1.0 1.0
run 1000
pair_coeff 1 1 1.5 1.0
variable e equal pe
print "Final potential energy = $e" :pre
The first run is performed using one setting for the pairwise
potential defined by the "pair_style"_pair_style.html and
"pair_coeff"_pair_coeff.html commands. The potential energy is
evaluated on the final timestep and stored by the "compute
pe"_compute_pe.html compute (this is done by the
"thermo_style"_thermo_style.html command). Then a pair coefficient is
changed, altering the potential energy of the system. When the
potential energy is printed via the "e" variable, LAMMPS will use the
potential energy value stored by the "compute pe"_compute_pe.html
compute, thinking it is current. There are many other commands which
could alter the state of the system between runs, causing a variable
to evaluate incorrectly.
The solution to this issue is the same as for case (2) above, namely
2009-02-17 22:58:00 +08:00
perform a 0-timestep run before the variable is evaluated to insure
2009-01-06 06:26:31 +08:00
the system is up-to-date. For example, this sequence of commands
would print a potential energy that reflected the changed pairwise
coefficient:
pair_coeff 1 1 1.0 1.0
run 1000
pair_coeff 1 1 1.5 1.0
run 0
variable e equal pe
print "Final potential energy = $e" :pre
2007-02-10 05:37:30 +08:00
:line
2006-09-22 00:22:34 +08:00
[Restrictions:]
2008-01-09 07:13:53 +08:00
Indexing any formula element by global atom ID, such as an atom value,
requires the atom style to use a global mapping in order to look up
the vector indices. By default, only atom styles with molecular
information create global maps. The "atom_modify
map"_atom_modify.html command can override the default.
2006-09-22 00:22:34 +08:00
2008-01-03 03:25:15 +08:00
All {universe}- and {uloop}-style variables defined in an input script
must have the same number of values.
2007-06-20 20:56:17 +08:00
2006-09-22 00:22:34 +08:00
[Related commands:]
"next"_next.html, "jump"_jump.html, "include"_include.html,
"temper"_temper.html, "fix print"_fix_print.html, "print"_print.html
[Default:] none