Page MenuHomec4science

fix_controller.html
No OneTemporary

File Metadata

Created
Sat, Jul 13, 13:20

fix_controller.html

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>fix controller command &mdash; LAMMPS documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/sphinxcontrib-images/LightBox2/lightbox2/css/lightbox.css" type="text/css" />
<link rel="top" title="LAMMPS documentation" href="index.html"/>
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-nav-search">
<a href="Manual.html" class="icon icon-home"> LAMMPS
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="Section_intro.html">1. Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_start.html">2. Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_commands.html">3. Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_packages.html">4. Packages</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_accelerate.html">5. Accelerating LAMMPS performance</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_howto.html">6. How-to discussions</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_example.html">7. Example problems</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_perf.html">8. Performance &amp; scalability</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_tools.html">9. Additional tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_modify.html">10. Modifying &amp; extending LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_python.html">11. Python interface to LAMMPS</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_errors.html">12. Errors</a></li>
<li class="toctree-l1"><a class="reference internal" href="Section_history.html">13. Future and history</a></li>
</ul>
</div>
&nbsp;
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="Manual.html">LAMMPS</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="Manual.html">Docs</a> &raquo;</li>
<li>fix controller command</li>
<li class="wy-breadcrumbs-aside">
<a href="http://lammps.sandia.gov">Website</a>
<a href="Section_commands.html#comm">Commands</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="fix-controller-command">
<span id="index-0"></span><h1>fix controller command</h1>
<div class="section" id="syntax">
<h2>Syntax</h2>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">fix</span> <span class="n">ID</span> <span class="n">group</span><span class="o">-</span><span class="n">ID</span> <span class="n">controller</span> <span class="n">Nevery</span> <span class="n">alpha</span> <span class="n">Kp</span> <span class="n">Ki</span> <span class="n">Kd</span> <span class="n">pvar</span> <span class="n">setpoint</span> <span class="n">cvar</span>
</pre></div>
</div>
<ul class="simple">
<li>ID, group-ID are documented in <a class="reference internal" href="fix.html"><span class="doc">fix</span></a> command</li>
<li>controller = style name of this fix command</li>
<li>Nevery = invoke controller every this many timesteps</li>
<li>alpha = coupling constant for PID equation (see units discussion below)</li>
<li>Kp = proportional gain in PID equation (unitless)</li>
<li>Ki = integral gain in PID equation (unitless)</li>
<li>Kd = derivative gain in PID equation (unitless)</li>
<li>pvar = process variable of form c_ID, c_ID[I], f_ID, f_ID[I], or v_name</li>
</ul>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">c_ID</span> <span class="o">=</span> <span class="k">global</span> <span class="n">scalar</span> <span class="n">calculated</span> <span class="n">by</span> <span class="n">a</span> <span class="n">compute</span> <span class="k">with</span> <span class="n">ID</span>
<span class="n">c_ID</span><span class="p">[</span><span class="n">I</span><span class="p">]</span> <span class="o">=</span> <span class="n">Ith</span> <span class="n">component</span> <span class="n">of</span> <span class="k">global</span> <span class="n">vector</span> <span class="n">calculated</span> <span class="n">by</span> <span class="n">a</span> <span class="n">compute</span> <span class="k">with</span> <span class="n">ID</span>
<span class="n">f_ID</span> <span class="o">=</span> <span class="k">global</span> <span class="n">scalar</span> <span class="n">calculated</span> <span class="n">by</span> <span class="n">a</span> <span class="n">fix</span> <span class="k">with</span> <span class="n">ID</span>
<span class="n">f_ID</span><span class="p">[</span><span class="n">I</span><span class="p">]</span> <span class="o">=</span> <span class="n">Ith</span> <span class="n">component</span> <span class="n">of</span> <span class="k">global</span> <span class="n">vector</span> <span class="n">calculated</span> <span class="n">by</span> <span class="n">a</span> <span class="n">fix</span> <span class="k">with</span> <span class="n">ID</span>
<span class="n">v_name</span> <span class="o">=</span> <span class="n">value</span> <span class="n">calculated</span> <span class="n">by</span> <span class="n">an</span> <span class="n">equal</span><span class="o">-</span><span class="n">style</span> <span class="n">variable</span> <span class="k">with</span> <span class="n">name</span>
</pre></div>
</div>
<ul class="simple">
<li>setpoint = desired value of process variable (same units as process variable)</li>
<li>cvar = name of control variable</li>
</ul>
</div>
<div class="section" id="examples">
<h2>Examples</h2>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">fix</span> <span class="mi">1</span> <span class="nb">all</span> <span class="n">controller</span> <span class="mi">100</span> <span class="mf">1.0</span> <span class="mf">0.5</span> <span class="mf">0.0</span> <span class="mf">0.0</span> <span class="n">c_thermo_temp</span> <span class="mf">1.5</span> <span class="n">tcontrol</span>
<span class="n">fix</span> <span class="mi">1</span> <span class="nb">all</span> <span class="n">controller</span> <span class="mi">100</span> <span class="mf">0.2</span> <span class="mf">0.5</span> <span class="mi">0</span> <span class="mf">100.0</span> <span class="n">v_pxxwall</span> <span class="mf">1.01325</span> <span class="n">xwall</span>
<span class="n">fix</span> <span class="mi">1</span> <span class="nb">all</span> <span class="n">controller</span> <span class="mi">10000</span> <span class="mf">0.2</span> <span class="mf">0.5</span> <span class="mi">0</span> <span class="mi">2000</span> <span class="n">v_avpe</span> <span class="o">-</span><span class="mf">3.785</span> <span class="n">tcontrol</span>
</pre></div>
</div>
</div>
<div class="section" id="description">
<h2>Description</h2>
<p>This fix enables control of a LAMMPS simulation using a control loop
feedback mechanism known as a proportional-integral-derivative (PID)
controller. The basic idea is to define a &#8220;process variable&#8221; which is
a quantity that can be monitored during a running simulation. A
desired target value is chosen for the process variable. A &#8220;control
variable&#8221; is also defined which is an adjustable attribute of the
running simulation, which the process variable will respond to. The
PID controller continuously adjusts the control variable based on the
difference between the process variable and the target.</p>
<p>Here are examples of ways in which this fix can be used. The
examples/pid directory contains a script that implements the simple
thermostat.</p>
<table border="1" class="docutils">
<colgroup>
<col width="49%" />
<col width="25%" />
<col width="25%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Goal</td>
<td>process variable</td>
<td>control variable</td>
</tr>
<tr class="row-even"><td>Simple thermostat</td>
<td>instantaneous T</td>
<td>thermostat target T</td>
</tr>
<tr class="row-odd"><td>Find melting temperature</td>
<td>average PE per atom</td>
<td>thermostat target T</td>
</tr>
<tr class="row-even"><td>Control pressure in non-periodic system</td>
<td>force on wall</td>
<td>position of wall</td>
</tr>
<tr class="row-odd"><td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For this fix to work, the control variable must actually induce
a change in a running LAMMPS simulation. Typically this will only
occur if there is some other command (e.g. a thermostat fix) which
uses the control variable as an input parameter. This could be done
directly or indirectly, e.g. the other command uses a variable as
input whose formula uses the control variable. The other command
should alter its behavior dynamically as the variable changes.</p>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If there is a command you think could be used in this fashion,
but does not currently allow a variable as an input parameter, please
notify the LAMMPS developers. It is often not difficult to enable a
command to use a variable as an input parameter.</p>
</div>
<p>The group specified with this command is ignored. However, note that
the process variable may be defined by calculations performed by
computes and fixes which store their own &#8220;group&#8221; definitions.</p>
<p>The PID controller is invoked once each <em>Nevery</em> timesteps.</p>
<p>The PID controller is implemented as a discretized version of
the following dynamic equation:</p>
<img alt="_images/fix_controller1.jpg" class="align-center" src="_images/fix_controller1.jpg" />
<p>where <em>c</em> is the continuous time analog of the control variable,
<em>e</em>=<em>pvar</em>-<em>setpoint</em> is the error in the process variable, and
<em>alpha</em>, <em>Kp</em>, <em>Ki</em>, and <em>Kd</em> are constants set by the corresponding
keywords described above. The discretized version of this equation is:</p>
<img alt="_images/fix_controller2.jpg" class="align-center" src="_images/fix_controller2.jpg" />
<p>where <em>tau</em> = <em>Nevery</em> * <em>timestep</em> is the time interval between updates,
and the subscripted variables indicate the values of <em>c</em> and <em>e</em> at
successive updates.</p>
<p>From the first equation, it is clear that if the three gain values
<em>Kp</em>, <em>Ki</em>, <em>Kd</em> are dimensionless constants, then <em>alpha</em> must have
units of [unit <em>cvar</em>]/[unit <em>pvar</em>]/[unit time] e.g. [ eV/K/ps
]. The advantage of this unit scheme is that the value of the
constants should be invariant under a change of either the MD timestep
size or the value of <em>Nevery</em>. Similarly, if the LAMMPS <a class="reference internal" href="units.html"><span class="doc">unit style</span></a> is changed, it should only be necessary to change
the value of <em>alpha</em> to reflect this, while leaving <em>Kp</em>, <em>Ki</em>, and
<em>Kd</em> unaltered.</p>
<p>When choosing the values of the four constants, it is best to first
pick a value and sign for <em>alpha</em> that is consistent with the
magnitudes and signs of <em>pvar</em> and <em>cvar</em>. The magnitude of <em>Kp</em>
should then be tested over a large positive range keeping <em>Ki</em>=<em>Kd</em>=0.
A good value for <em>Kp</em> will produce a fast reponse in <em>pvar</em>, without
overshooting the <em>setpoint</em>. For many applications, proportional
feedback is sufficient, and so <em>Ki</em>=<em>Kd</em>=0 can be used. In cases where
there is a substantial lag time in the response of <em>pvar</em> to a change
in <em>cvar</em>, this can be counteracted by increasing <em>Kd</em>. In situations
where <em>pvar</em> plateaus without reaching <em>setpoint</em>, this can be
counteracted by increasing <em>Ki</em>. In the language of Charles Dickens,
<em>Kp</em> represents the error of the present, <em>Ki</em> the error of the past,
and <em>Kd</em> the error yet to come.</p>
<p>Because this fix updates <em>cvar</em>, but does not initialize its value,
the initial value is that assigned by the user in the input script via
the <a class="reference internal" href="variable.html"><span class="doc">internal-style variable</span></a> command. This value is
used (by the other LAMMPS command that used the variable) until this
fix performs its first update of <em>cvar</em> after <em>Nevery</em> timesteps. On
the first update, the value of the derivative term is set to zero,
because the value of <em>e_n-1</em> is not yet defined.</p>
<hr class="docutils" />
<p>The process variable <em>pvar</em> can be specified as the output of a
<a class="reference internal" href="compute.html"><span class="doc">compute</span></a> or <a class="reference internal" href="fix.html"><span class="doc">fix</span></a> or the evaluation of a
<a class="reference internal" href="variable.html"><span class="doc">variable</span></a>. In each case, the compute, fix, or variable
must produce a global quantity, not a per-atom or local quantity.</p>
<p>If <em>pvar</em> begins with &#8220;<a href="#id1"><span class="problematic" id="id2">c_</span></a>&#8221;, a compute ID must follow which has been
previously defined in the input script and which generates a global
scalar or vector. See the individual <a class="reference internal" href="compute.html"><span class="doc">compute</span></a> doc page
for details. If no bracketed integer is appended, the scalar
calculated by the compute is used. If a bracketed integer is
appended, the Ith value of the vector calculated by the compute is
used. Users can also write code for their own compute styles and <a class="reference internal" href="Section_modify.html"><span class="doc">add them to LAMMPS</span></a>.</p>
<p>If <em>pvar</em> begins with &#8220;<a href="#id3"><span class="problematic" id="id4">f_</span></a>&#8221;, a fix ID must follow which has been
previously defined in the input script and which generates a global
scalar or vector. See the individual <a class="reference internal" href="fix.html"><span class="doc">fix</span></a> doc page for
details. Note that some fixes only produce their values on certain
timesteps, which must be compatible with when fix controller
references the values, or else an error results. If no bracketed integer
is appended, the scalar calculated by the fix is used. If a bracketed
integer is appended, the Ith value of the vector calculated by the fix
is used. Users can also write code for their own fix style and <a class="reference internal" href="Section_modify.html"><span class="doc">add them to LAMMPS</span></a>.</p>
<p>If <em>pvar</em> begins with &#8220;<a href="#id5"><span class="problematic" id="id6">v_</span></a>&#8221;, a variable name must follow which has been
previously defined in the input script. Only equal-style variables
can be referenced. See the <a class="reference internal" href="variable.html"><span class="doc">variable</span></a> command for
details. Note that variables of style <em>equal</em> define a formula which
can reference individual atom properties or thermodynamic keywords, or
they can invoke other computes, fixes, or variables when they are
evaluated, so this is a very general means of specifying the process
variable.</p>
<p>The target value <em>setpoint</em> for the process variable must be a numeric
value, in whatever units <em>pvar</em> is defined for.</p>
<p>The control variable <em>cvar</em> must be the name of an <a class="reference internal" href="variable.html"><span class="doc">internal-style variable</span></a> previously defined in the input script. Note
that it is not specified with a &#8220;<a href="#id7"><span class="problematic" id="id8">v_</span></a>&#8221; prefix, just the name of the
variable. It must be an internal-style variable, because this fix
updates its value directly. Note that other commands can use an
equal-style versus internal-style variable interchangeably.</p>
</div>
<hr class="docutils" />
<div class="section" id="restart-fix-modify-output-run-start-stop-minimize-info">
<h2>Restart, fix_modify, output, run start/stop, minimize info</h2>
<p>Currenlty, no information about this fix is written to <a class="reference internal" href="restart.html"><span class="doc">binary restart files</span></a>. None of the <a class="reference internal" href="fix_modify.html"><span class="doc">fix_modify</span></a> options
are relevant to this fix.</p>
<p>This fix produces a global vector with 3 values which can be accessed
by various <a class="reference internal" href="Section_howto.html#howto-15"><span class="std std-ref">output commands</span></a>. The values
can be accessed on any timestep, though they are only updated on
timesteps that are a multiple of <em>Nevery</em>.</p>
<p>The three values are the most recent updates made to the control
variable by each of the 3 terms in the PID equation above. The first
value is the proportional term, the second is the integral term, the
third is the derivative term.</p>
<p>The units of the vector values will be whatever units the control
variable is in. The vector values calculated by this fix are
&#8220;extensive&#8221;.</p>
<p>No parameter of this fix can be used with the <em>start/stop</em> keywords of
the <a class="reference internal" href="run.html"><span class="doc">run</span></a> command. This fix is not invoked during <a class="reference internal" href="minimize.html"><span class="doc">energy minimization</span></a>.</p>
</div>
<div class="section" id="restrictions">
<h2>Restrictions</h2>
<blockquote>
<div>none</div></blockquote>
</div>
<div class="section" id="related-commands">
<h2>Related commands</h2>
<p><a class="reference internal" href="fix_adapt.html"><span class="doc">fix adapt</span></a></p>
<p><strong>Default:</strong> none</p>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2013 Sandia Corporation.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/sphinxcontrib-images/LightBox2/lightbox2/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="_static/sphinxcontrib-images/LightBox2/lightbox2/js/lightbox.min.js"></script>
<script type="text/javascript" src="_static/sphinxcontrib-images/LightBox2/lightbox2-customize/jquery-noconflict.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>

Event Timeline