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
2008-10-07 22:45:58 +08:00
style = {delete} or {index} or {loop} or {world} or {universe} or {uloop} or {equal} or {atom} :l
{delete} = no args
2006-09-22 00:22:34 +08:00
{index} args = one or more strings
{loop} args = N = integer size of loop
2007-02-10 05:37:30 +08:00
{world} args = one string for each partition of processors
{universe} args = one or more strings
{uloop} args = N = integer size of loop
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
2007-02-10 05:37:30 +08:00
thermo keywords = vol, ke, press, etc from "thermo_style"_thermo_style.html
2008-05-16 04:32:10 +08:00
math operations = (), -x, x+y, x-y, x*y, x/y, x^y,
sqrt(x), exp(x), ln(x), log(x),
sin(x), cos(x), tan(x), asin(x), acos(x), atan(x),
ceil(x), floor(x), round(x)
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),
2009-04-29 03:50:15 +08:00
bound(group,xmin), gyration(group), ke(group)
region functions = count(group,region), mass(group,region), charge(group,region),
xcm(group,dim,region), vcm(group,dim,region), fcm(group,dim,region),
bound(group,xmin,region), gyration(group,region), ke(group,reigon)
2009-06-29 23:28:41 +08:00
atom value = mass\[N\], type\[N\], x\[N\], y\[N\], z\[N\],
2008-01-03 03:25:15 +08:00
vx\[N\], vy\[N\], vz\[N\], fx\[N\], fy\[N\], fz\[N\]
2009-06-29 23:28:41 +08:00
atom vector = mass\[\], type\[\], x\[\], y\[\], z\[\],
2008-01-03 03:25:15 +08:00
vx\[\], vy\[\], vz\[\], fx\[\], fy\[\], fz\[\]
2008-01-09 07:13:53 +08:00
compute references = c_ID, c_ID\[2\], c_ID\[N\], c_ID\[N\]\[2\], c_ID\[\], c_ID\[\]\[2\]
fix references = f_ID, f_ID\[2\], f_ID\[N\], f_ID\[N\]\[2\], f_ID\[\], f_ID\[\]\[2\]
2008-10-07 07:07:25 +08:00
variable references = v_abc, v_abc\[N\], v_abc\[\] :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
2008-10-07 22:45:58 +08:00
variable b atom x\[\]*y\[\]/vol
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
2008-10-07 22:45:58 +08:00
variable x uloop 15
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.
2007-02-21 08:18:01 +08:00
Variables can be used in several ways in LAMMPS. A variable can be
2008-01-03 03:25:15 +08:00
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
2009-01-06 06:26:31 +08:00
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
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
ave/time"_fix_ave/time 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
ave/spatial"_fix_ave_spatial.html and "fix ave/atom"_fix_ave_atom.html
commands).
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
2009-01-06 06:26:31 +08:00
IMPORTANT NOTE: When the input script line that defines a variable of
style {equal} or {atom} that contain a formula is encountered, the
formula is NOT immediately evaluated and the result stored. See the
discussion below about "Immediate Evaluation of Variables" if you want
to do this.
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
2008-01-03 03:25:15 +08:00
means that using the "command-line switch"_Section_start.html#2_6 -var
2008-10-07 07:07:25 +08:00
will override a corresponding index variable setting in the input
script.
2007-07-03 22:58:21 +08:00
There are two exceptions to this rule. First, variables of style
2008-01-03 03:25:15 +08:00
{equal} and {atom} ARE redefined each time the command is encountered.
2009-01-06 06:26:31 +08:00
This only changes their associated formula if the formula contains a
substitution for another variable, e.g. $x. But that can be useful,
for example, in a loop.
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
2007-02-21 09:05:23 +08:00
"This section"_Section_commands.html#3_2 of the manual explains how
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
2006-12-20 00:44:20 +08:00
As described below, for variable styles {index}, {loop}, {universe},
2007-07-03 22:58:21 +08:00
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
2008-01-03 03:25:15 +08:00
assign, the variable is exhausted and a flag is set that causes the
2006-09-22 00:22:34 +08:00
next "jump"_jump.html command encountered in the input script to be
skipped. This enables the construction of simple loops in the input
2008-01-03 03:25:15 +08:00
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"
2008-10-07 23:02:40 +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
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
section"_Section_start.html#2_6 for details.
2006-09-22 00:22:34 +08:00
The {loop} style is identical to the {index} style except that the
2007-02-21 08:18:01 +08:00
strings are the integers from 1 to N. This allows generation of a
long list of runs (e.g. 1000) without having to list N strings in the
2006-12-20 00:44:20 +08:00
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.
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
2007-02-10 05:37:30 +08:00
section"_Section_start.html#2_6 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
2007-02-10 05:37:30 +08:00
"worlds". See "this page"_Section_start.html#2_6 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 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
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
operations, group 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
2007-02-10 05:37:30 +08:00
Thermo keywords: vol, pe, ebond, etc
2008-05-16 04:32:10 +08:00
Math operations: (), -x, x+y, x-y, x*y, x/y, x^y, sqrt(x), exp(x), ln(x), log(x), sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), ceil(x), floor(x), round(x)
2008-01-03 03:25:15 +08:00
Group functions: count(ID), mass(ID), charge(ID), xcm(ID,dim), \
2009-04-29 03:50:15 +08:00
vcm(ID,dim), fcm(ID,dim), bound(ID,dir), gyration(ID), ke(ID)
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)
2009-06-29 23:28:41 +08:00
Atom values: mass\[N\], type\[N\], x\[N\], y\[N\], z\[N\], \
2008-01-03 03:25:15 +08:00
vx\[N\], vy\[N\], vz\[N\], fx\[N\], fy\[N\], fz\[N\]
2009-06-29 23:28:41 +08:00
Atom vectors: mass\[\], type\[\], x\[\], y\[\], z\[\], \
2008-01-03 03:25:15 +08:00
vx\[\], vy\[\], vz\[\], fx\[\], fy\[\], fz\[\]
2008-01-09 07:13:53 +08:00
Compute references: c_ID, c_ID\[2\], c_ID\[N\], c_ID\[N\]\[2\], c_ID\[\], c_ID\[\]\[2\]
Fix references: f_ID, f_ID\[2\], f_ID\[N\], f_ID\[N\]\[2\], f_ID\[\], f_ID\[\]\[2\]
Other variables: v_abc, v_abc\[N\], v_abc\[\] :tb(s=:)
Note that formula elements that contain empty brackets, such as an
atom vector, produce per-atom values. All other formula elements
produce a global value.
A formula for equal-style variables cannot use any formula element
that produces per-atom values. A formula for an atom-style variable
can use formula elements that produce either global values or per-atom
values.
2008-01-03 03:25:15 +08:00
The thermo keywords allowed in a formula are those defined by the
2009-01-06 06:26:31 +08:00
"thermo_style custom" 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 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 evaluated 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
Math operations are written in the usual way, where the "x" and "y" in
the examples above can be another section of the formula. Operators
are evaluated left to right and have the usual precedence: unary minus
2008-05-16 04:32:10 +08:00
before exponentiation ("^"), exponentiation before multiplication and
2008-01-03 03:25:15 +08:00
division, and multiplication and division before addition and
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
2008-05-16 04:32:10 +08:00
argument, e.g. sqrt(v_ke). Note that ln() is the natural log; log()
is the base 10 log. 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.
2008-01-03 03:25:15 +08:00
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
{x} or {y} or {z}. The {dir} argument, if it exists, is {xmin},
{xmax}, {ymin}, {ymax}, {zmin}, or {zmax}. 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 "fix
gyration"_fix_gyration.html command for a definition of the formula.
2009-04-29 03:50:15 +08:00
Region functions are exactly the same as group functions with 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.
2008-01-03 03:25:15 +08:00
Atom values take a single integer argument from 1-N, which is the
desired atom-ID, e.g. x\[243\]., which means use the x coordinate of
the atom with ID=243.
2008-01-09 07:13:53 +08:00
Atom vectors use empty brackets, i.e. they take no argument. They
generate one value per atom, so that a reference like x\[\] means the
x-coord of each atom will be used when evaluating the variable.
2008-01-03 03:25:15 +08:00
2008-01-09 07:13:53 +08:00
Compute references access one or more quantities calculated by a
2007-02-21 08:18:01 +08:00
"compute"_compute.html. The ID in the reference should be replaced by
the actual ID of the compute defined elsewhere in the input script.
2008-01-09 07:13:53 +08:00
See the doc pages for individual computes to see which ones calculate
global versus per-atom quantities. If the compute reference contains
empty brackets, then per-atom values calculated by the compute are
accessed. Otherwise a single value (global or per-atom) calculated by
2009-01-06 06:26:31 +08:00
the compute is accessed. If a variable containing a compute is
evaluated in an input script (not during a run), then the values
accessed by the compute must be current. See the discussion below
about "Variable Accuracy".
2008-01-09 07:13:53 +08:00
The different kinds of compute references are as follows. M is a
positive integer <= the number of vector values calculated by the
compute. N is a global atom ID (positive integer).
c_ID: scalar value of a global compute
c_ID\[2\]: vector component of a global compute
c_ID\[N\]: single atom's scalar value of a per-atom compute
c_ID\[N\]\[M\]: single atom's vector component of a per-atom compute
c_ID\[\]: per-atom scalar from a per-atom compute
c_ID\[\]\[M\]: per-atom vector component from a per-atom compute :tb(s=:)
Fix references access one or more quantities calculated by a
2008-10-07 07:07:25 +08:00
"fix"_fix.html. The ID in the reference should be replaced by the
actual ID of the fix defined elsewhere in the input script. See the
doc pages for individual computes to see which ones calculate global
versus per-atom quantities. If the fix reference contains empty
brackets, then per-atom values calculated by the fix are accessed.
2009-01-06 06:26:31 +08:00
Otherwise a single value (global or per-atom) calculated by the fix is
accessed.
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-01-06 06:26:31 +08:00
the doc pages for individual fix commands for details. If a variable
containing a fix is evaluated 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
The different kinds of fix references are exactly the same as the
compute references listed in the above table, where "c_" is replaced
by "f_", and the word "compute" is replaced by "fix".
2007-02-10 05:37:30 +08:00
The current values of other variables can be accessed by prepending a
2008-01-03 03:25:15 +08:00
"v_" to the variable name. This will cause that variable to be
2008-03-01 09:13:20 +08:00
evaluated. Atom-style variables generate per-atom values; all other
2008-01-09 07:13:53 +08:00
styles of variables generate a single scalar value.
The different kinds of variable references are as follows. N is a
global atom ID (positive integer).
v_ID: scalar value of a non atom-style variable
v_ID\[N\]: single atom's scalar value from an atom-style variable
v_ID\[\]: per-atom value from an atom-style variable :tb(s=:)
2008-01-03 03:25:15 +08:00
IMPORTANT NOTE: If you define variables in circular manner like this:
2007-02-10 05:37:30 +08:00
variable a equal v_b
variable b equal v_a
print $a :pre
2008-01-03 03:25:15 +08:00
then LAMMPS will run for a while when the print statement is invoked!
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
v_abc). The former can be used in any command, including a variable
command, to force the immediate evaluation of the referenced variable
and the substitution of its value into the command. The latter is a
required kind of argument to some commands (e.g. the "fix
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
use the variable "v" in some other command like "fix ave/time" 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
section"_Section_commands.html#3_2 on parsing input script commands),
and thus an error will occur when the formula for "vratio" is
evaluated later.
: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
the compute 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
(2) LAMMPS may not be able to evaluate the variable and generate an
2009-02-17 22:58:00 +08:00
error. For example, if the variable requires a quantity from a
"compute"_compute.html that is not current, LAMMPS will not do it.
This means, for example, that such a variable then the variable cannot
be evaluated before the first run has occurred.
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
used in a variable after the run.
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
(3) The variable may be evaluated incorrectly. And LAMMPS may have
no way to detect this has occurred. Consider the following sequence
of commands:
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