Compute ke vs "direct" dump file calculation

Hi all,

I am an undergraduate who has just started learning LAMMPS. I am currently trying to learn energy distribution in a boundary-driven granular mixture consisting of two particle species.

I am a bit confused about how LAMMPS calculates the kinetic energy when using the “compute ke” command. At a given timestep in my simulation, I will “directly” calculate the translational kinetic energy through a dump file as

\frac{1}{2}\cdot m \cdot \Sigma_i^N(v_{xi}^2+v_{yi}^2+v_{zi}^2)

where m_i is the particle mass, and the sum is of all particles in a specific group. However, the value I get here does not agree with the value of the compute ke command.

For example, for one snapshot(tstep) I will obtain approximately [Large= 144, Small= 18], whereas the log file reports [c_l_ke = 0.36014641, c_s_ke = 0.053549768]

I’ve looked around LAMMPS’ documentation as well as MATSCI discussions and haven’t been able to find an explanation. Is there something I am misunderstanding about compute ke?

This is the version of LAMMPS: Large-scale Atomic/Molecular Massively Parallel Simulator - 10 Sep 2025

Below is my script:

units      lj
atom_style  sphere
boundary    f f f
newton     off
comm_modify     vel yes
atom_modify     id yes

# --------------------
#Simulation Box
# --------------------
region     box block -7 7 -7 7 0 15
create_box  2 box


# --------------------
#Setting
# --------------------
pair_style      gran/hooke/history 20000.0 NULL 50.0 NULL 0.5 0
pair_coeff  * *
timestep    0.001
neighbor    0.02 bin
neigh_modify    delay 0
fix    1 all nve/sphere


# --------------------
# Start with stationary cylinder
# --------------------
fix    cylwall all wall/gran hooke/history 20000.0 NULL 50.0 NULL 0.5 0 zcylinder 5.0 #r=5
fix    zcap all wall/gran hooke/history 20000.0 NULL 50.0 NULL 0.5 0 zplane 0 10 #z=(0,10)


# --------------------
#Generate granular particles
# --------------------
group       large type 1
group       small type 2

region     spawn_region cylinder z 0 0 5 1 9 #center at (0,0), r=5, z in (1,9)
create_atoms    1 random 200 102983 spawn_region overlap 0.6 group large
create_atoms    2 random 200 492039 spawn_region overlap 0.6 group small


set         group large mass 1
set         group large diameter 1

set         group small mass 0.125
set         group small diameter 0.5

# --------------------
# System cooldown
# --------------------
fix        drag all viscous 0.1 # F=-gamma*v, gamma = 0.1

#Setup surveillance
compute    energy all ke
thermo_style    custom step atoms c_energy
thermo     5000

run        200000


# --------------------
# start injecting energy
# --------------------
unfix      drag
unfix       cylwall

#start rotating cylinder
fix        cylwall all wall/gran hooke/history 20000.0 NULL 50.0 NULL 0.5 0 zcylinder 5.0 shear x 1 #1 rotation every 10pi seconds

#give a kick in case the volume fraction is ever too low
velocity    all create 0.1 292939 dist gaussian mom yes rot yes 

# --------------------
# Second run for simulation
# --------------------
compute     l_ke large ke
compute     s_ke small ke
thermo_style        custom step atoms c_l_ke c_s_ke
thermo      100
log         test.log
dump        1 all custom 100 test.txt id x y z vx vy vz omegax omegay omegaz type radius mass
dump_modify     1 sort id time yes

run    3000000 

Thank you for your time and suggestions.

1 Like

You are using reduced units, which implies thermo_modify norm yes.

1 Like

Thank you for pointing that out. After using thermo_modify norm no, the values from compute ke now match up with my calculation using the dump files.

Thank you for your time and help.