dynamomd / DynamO

An event-driven particle simulator and visualisation code. Please see the website below for more information.
http://DynamOMD.com
GNU General Public License v3.0
56 stars 36 forks source link

Andersen Thermostat gives non-zero momentum for multi-component systems #29

Closed zhang10 closed 11 years ago

zhang10 commented 11 years ago

my input/output is the following: dynamod -m1 -C 10 --s1 1,1.05,1,1,.5:.9,1.05,.729,1,.5 -T 1 -o BinarySW.startconfig.xml dynarun BinarySW.startconfig.xml -c 10000000 BinarySW.eqconfig.xml

After running, the average system momentum in my output file is significantly nonzero.

I tried running a configuration file without the "-T 1" andersen thermostat. That run gave an effectively zero net momentum.

Thus, I conclude that the Andersen thermostat is broken for multicomponent systems

toastedcrumpets commented 11 years ago

Hi, Thanks for taking the time to report a bug, but I don't think that this is one.

I've simulated the system you've given and I've gotten these results for the momentum:

<SystemMomentum>
  <Current x="-1.08893035757427" y="116.72463234306" z="-35.2584754115088"/>
  <Average x="3.52165337998153" y="5.79806413491709" z="2.0840805982459"/>
</SystemMomentum>

If you check the output plugin reference documentation, you'll see that this is the average momentum of the system. In this system you have 4000 particles, so your average momentum per particle is actually (0.00088,0.0014,0.00052), giving an average magnitude of 0.00093.

We can check if this is a reasonable deviation from zero. The total number of thermostat events is

<Entry Type="System" Name="Thermostat" Event="GAUSSIAN" Count="494657"/>

Each Andersen thermostat event only thermostats one particle. So we have something like 124 thermostat events per particle. The average momentum per particle doesn't seem so bad in this context, so I don't think this is a bug in the simulator. To double check, I've run the simulation 4x longer to see what happens to the deviation. The results are:

    <SystemMomentum>
      <Current x="-65.0688680708049" y="-45.305217256979" z="-63.4630915853946"/>
      <Average x="3.38092098238895" y="0.312460480315974" z="-2.02639299092048"/>
    </SystemMomentum>

This gives an average per particle of (0.00085,0.000078,-0.00050) with an average magnitude of 0.00048. This is roughly half of the previous value, as expected from a sqrt(N_coll) scaling of sampling from a Gaussian.

To obtain an accurate estimate of the predicted error, we could try assuming that each thermostat is a direct sampling of a Gaussian, and use this to estimate the variance of the sample mean but this is difficult as we don't resample all velocities at once.

Hopefully this clarifies the operation of the thermostat, and gives you a little more confidence in its operation. I'll close this issue as its not a bug but the expected behaviour of the system, but please comment again if you think I've missed something or if its still not clear. Marcus