Group of atoms don't move under set velocity (possible lammps bug?)

Dear Lammps Users,

Running a very simple simulation with strange results. I want to give particles from two groups an initial velocity so they move along the x-axis but in opposite directions. The “set velocity” command of lammps for groups of atoms does not appear to be working as nothing is really moving when I look at the dump files. However if I use “set velocity” for all particles, then they do move, but only along one direction, which is not what I want. Would appear that the “set velocity” for all particles works but “set velocity” for groups of particles does nothing. Copy of script below. Can someone please clue me in on what can be wrong with the script? Or is this a bug in lammps? Greatly appreciate it.

------------------------ INITIALIZATION ----------------------

clear
units lj

dimension 3
boundary f f f
comm_modify vel yes

----------------------- PARTICLE DEFINITION ----------------------

atom_style sphere

region whole block 0.0 100.0 0.0 50.0 0.0 50.0
create_box 2 whole

group red id 1
group blue id 2

create_atoms 1 single 40 25 25
create_atoms 1 single 40 10 10
create_atoms 2 single 50 25 25
create_atoms 2 single 50 10 10

set atom 1 diameter 4
set atom 1 mass 4

set atom 2 diameter 4
set atom 2 mass 4

#velocity all set 10 0 0
velocity red set 10 0 0
velocity blue set -10 0 0

----------------------- DEFINE SETTINGS -----------------------

pair_style dpd 0.0 5.0 1234
pair_coeff 1 2 -50 10
pair_coeff 1 1 40 0
pair_coeff 2 2 40 0

dump 1 all custom 100 dump.comp.* id type x y z

----------------- DEFINE THERMO ---------------------------------

thermo 10
thermo_style custom step temp pe ke

----------------- SETUP RUN ---------------------------------

reset_timestep 0
#timestep 0.0005

fix wall all wall/reflect xlo EDGE xhi EDGE ylo EDGE yhi EDGE zlo EDGE zhi EDGE
fix 1 all nve/sphere

variable natoms equal “count(all)”

----------------- PERFORM RUN ---------------------------------

run 1000

print “Number of atoms = ${natoms}”
print “All done”

Please look very carefully at your output in the log.lammps file. There is:

group red id 1
0 atoms in group red
group blue id 2
0 atoms in group blue

So when you use the velocity command, you set the velocities to empty groups.
The groups are empty because at the time when you create them, the atom IDs you have specified do not exist yet. You only create those atoms later. That will not update the group.

LAMMPS input script is processed like a bash script one line at a time and each line is executed immediately.

1 Like

Got it. Changed the ordering of commands in my script per your advice. That fixed the problem. Thanks for your help.