[lammps-users] Good methods for replacing lost atoms


What is the best way to replace atoms when the are lost? I want the number of atoms in my simulation (1000) to remain constant at every time step (for NVE or NVT ensembles). The following script works as I expected for the variable C, but not J.

variable C equal count(CNTs)
fix extra2 all print 1 "C count $C" file Ccount.txt screen no
variable J equal 1000-$C
fix constC CNTs deposit $J 1 1 6 region wholebox near 3 attempt 5 units box
run 1000

C is evaluated every time step and written to a file. However, J, the number of lost atoms, is evaluated only once so my lost atoms aren't being replaced. What's the correct syntax? Thanks in advance for your advice.

Nicholas J. Lee

This variable will eval J afresh (with a current C value)
each time J is evaluated:

variable J equal 1000-v_C

Your form will substitute for C once (immediately).
See the variable doc page.