Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96193883
variable.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Dec 23, 15:43
Size
9 KB
Mime Type
text/html
Expires
Wed, Dec 25, 15:43 (2 d)
Engine
blob
Format
Raw Data
Handle
23136358
Attached To
rLAMMPS lammps
variable.html
View Options
<HTML>
<CENTER><A HREF = "http://lammps.sandia.gov">LAMMPS WWW Site</A> - <A HREF = "Manual.html">LAMMPS Documentation</A> - <A HREF = "Section_commands.html#comm">LAMMPS Commands</A>
</CENTER>
<HR>
<H3>variable command
</H3>
<P><B>Syntax:</B>
</P>
<PRE>variable name style args ...
</PRE>
<UL><LI>name = single lower-case character, 'a' thru 'z'
<LI>style = <I>index</I> or <I>loop</I> or <I>equal</I> or <I>world</I> or <I>universe</I>
<PRE> <I>index</I> args = one or more strings
<I>loop</I> args = N = integer size of loop
<I>equal</I> args = one string containing functions, vectors, keywords, numbers
math functions = add(x,y), sub(x,y), mult(x,y), div(x,y),
neg(x), pow(x,y), exp(x), ln(x), sqrt(x)
group functions = mass(group), charge(group), xcm(group,dim),
vcm(group,dim), bounds(group,xmin), gyration(group)
vectors = x[5], y[12], z[17], vx[88], vy[19], vz[2],
fx[1], fy[2005], fz[1]
keywords = same keywords (mostly) as in <A HREF = "thermo_style.html">thermo_style custom</A> command
<I>world</I> args = one string for each partition of processors
<I>universe</I> args = one or more strings
</PRE>
</UL>
<P><B>Examples:</B>
</P>
<PRE>variable x index run1 run2 run3 run4 run5 run6 run7 run8
variable LoopVar loop 20
variable beta equal div(temp,3.0)
variable b1 equal add(x[234],mult(0.5,lx))
variable b equal xcm(mol1,x)
variable temp world 300.0 310.0 320.0 330.0
variable x universe 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
</PRE>
<P><B>Description:</B>
</P>
<P>This command assigns one or more values to a variable name so that the
variable can be used in subsequent input script commands. The "name"
of the variable is an arbitrary string. Each "value" is a string
which could be text or numbers, as in the examples above. As
explained in <A HREF = "Section_commands.html#3_2">this section</A>, occurrences of
the variable name in an input script line are replaced by the
variable's value. The variable name can be referenced in the input
script as $x if the name "x" is a single character, or as ${LoopVar}
if the name "LoopVar" is one or more characters.
</P>
<P>As described below, for variable styles <I>index</I>, <I>loop</I>, and
<I>universe</I>, the value assigned to a variable can be incremented via
the <A HREF = "next.html">next</A> command. When there are no more values to
assign, the variable is "exhausted" and a flag is set that causes the
next <A HREF = "jump.html">jump</A> 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 exited from.
</P>
<P>When a variable command is encountered for a variable that has already
been specified, the command is skipped. This is the case for all
variable styles except <I>equal</I>, so that <I>equal</I>-style variable names
can be re-used and re-defined anytime. Skipping allows you to loop
over the same input script many times without re-defining your
variables. When a variable is exhausted via the <A HREF = "next.html">next</A>
command, it is then available to be re-defined in a subsequent
variable command.
</P>
<P>For the <I>index</I> style, one or more strings are specified. Initially,
the 1st string is assigned to the variable. Each time a
<A HREF = "next.html">next</A> command is used with the variable name, the next
string is assigned. All processors assign the same string to the
variable. <I>Index</I>-style variables can also be set (with a single
value) by using the command-line switch -var; see <A HREF = "Section_start.html#2_4">this
section</A> for details.
</P>
<P>The <I>loop</I> style is identical to the <I>index</I> style except that the
strings are the integers from 1 to N. Initially, the string "1" is
assigned to the variable. Each time a <A HREF = "next.html">next</A> command is
used with the variable name, the next string ("2", "3", etc) is
assigned. All processors assign the same string to the variable.
</P>
<P>For the <I>equal</I> style, a single string is specified which represents
an equation that will be evaluated afresh each time the variable is
used. Thus the variable can take on different values at different
stages of the input script. For example, if the variable is used in a
<A HREF = "fix_print.html">fix print</A> command, it could print different values
each timestep it was invoked. The next command cannot be used with
<I>equal</I>-style variables, since there is only one value. Note that, as
with any other input script command, it is feasible to use another
variable in the <I>equal</I> variable's string, e.g. variable y equal
mult($x,2). However, $x will be replaced immediately by it's current
value when the command is first parsed, not each time that $y is
substituted for.
</P>
<P>The syntax of the equation assigned to <I>equal</I> variables is simple.
It can contain "functions", "vectors", "keywords", or "numbers" in any
combination.
</P>
<UL><LI>Function = a keyword followed by parenthesis with one or two arguments
<LI>Supported arithmetic functions = add(x,y), sub(x,y), mult(x,y), div(x,y), neg(x), pow(x,y), exp(x), ln(x), sqrt(x)
<LI>Supported group functions = mass(ID), charge(ID), xcm(ID,dim), vcm(ID,dim), bound(ID,dir), gyration(ID)
<LI>Example function usage = div(1.0e20,3.0), neg(x[34]), pow(lx,3.0), xcm(mol,x), bound(lower,zmin)
<LI>Vector = a keyword followed by square brackets containing an atom ID
<LI>Supported vectors = x, y, z, vx, vy, vz, fx, fy, fz
<LI>Example vector usage = x[123], fz[1000]
<LI>Keyword = keywords supported by the <A HREF = "thermo_style.html">thermo_style custom</A> command except cpu and pressure tensor components (pxx, pyy, etc)
<LI>Supported keywords = step, atoms, temp, press, pe, ke, eng, evdwl, ecoul, epair, ebond, eangle, edihed, eimp, emol, elong, vol, lx, ly, lz, gke, grot, t_ID
<LI>Example keyword usage = atoms, pow(vol,0.333), mult(elong,0.5)
<LI>Number = 0.2, 1.0e20, -15.4, etc
</UL>
<P>For the group functions, ID is a group-ID, dim is 'x' or 'y' or 'z',
and dir is one of 6 strings: "xmin", "xmax", "ymin", "ymax", "zmin",
or "zmax". The group functions mass() and charge() are the total mass
and charge of the group of atoms. Xcm() and vcm() return components
of the position and velocity of the center of mass of the group.
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 <A HREF = "fix_gyration.html">fix gyration</A> command for the
formula.
</P>
<P>Keywords have restrictions on when they can be assigned to variables.
For example, keywords that compute thermodynamic quantites can only be
invoked after the first simulation has begun. A warning is issued if
thermodyanmic keywords are invoked on timesteps when thermodynamic
information is not being printed to the screen, since the values
assigned to the variable may be out-of-date.
</P>
<P>The variable <I>equal</I> equation can also be nested in that function
arguments can be functions, vectors, keywords, or numbers. For
example, this is a valid equation:
</P>
<PRE>variable x equal div(add(pe,ke),pow(vol,div(1,3)))
</PRE>
<P>For the <I>world</I> style, one or more strings are specified. There must
be one string for each processor partition or "world". See <A HREF = "Section_start.html#2_4">this
section</A> of the manual for information on
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
next command cannot be used with <I>equal</I>-style variables, since there
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
<A HREF = "temper.html">temper</A> command), to assign different temperatures to
different partitions.
</P>
<P>For the <I>universe</I> style, one or more strings are specified. There
must be at least as many strings as there are processor partitions or
"worlds". See <A HREF = "Section_start.html#2_4">this page</A> for information on
running LAMMPS with multiple partitions via the "-partition"
command-line switch. This variable command initially assigns one
string to each world. When a <A HREF = "next.html">next</A> command is encountered
using this variable, the first processor partition to encounter it, is
assigned the next available value. This continues until all the
variable values are consumed. Thus, this command can be used to run
50 simulations on 8 processor partitions. The simulations will be run
one after the other on whatever partition becomes available, until
they are all finished. <I>Universe</I>-style variables are incremented
using the files "tmp.lammps.variable" and "tmp.lammps.variable.lock"
which you will see in your directory during such a LAMMPS run.
</P>
<P>If a variable command is encountered when the variable has already
been defined, the command is ignored. Thss allows an input script
with a variable command to be processed multiple times; see the
<A HREF = "jump.html">jump</A> or <A HREF = "include.html">include</A> commands. It also means
that the use of the command-line switch -var will override a
corresponding variable setting in the input script.
</P>
<P><B>Restrictions:</B>
</P>
<P>The use of atom vectors in <I>equal</I> style variables requires the atom
style to use a global mapping in order to look up the vector indices.
Only atom styles with molecular information create global maps.
</P>
<P><B>Related commands:</B>
</P>
<P><A HREF = "next.html">next</A>, <A HREF = "jump.html">jump</A>, <A HREF = "include.html">include</A>,
<A HREF = "temper.html">temper</A>, <A HREF = "fix_print.html">fix print</A>, <A HREF = "print.html">print</A>
</P>
<P><B>Default:</B> none
</P>
</HTML>
Event Timeline
Log In to Comment