LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
[lammps-users] Surprising difference between temperature calculated by "temp" themo-keyword and T= 2*ke/(3*kb*N)

# [lammps-users] Surprising difference between temperature calculated by "temp" themo-keyword and T= 2*ke/(3*kb*N)

 From: Bhanuday Sharma Date: Sat, 7 Oct 2017 20:27:55 +0530

Dear lammps-users,
For a simple simulation of Ar gas in a cubical box, I am getting small difference in temperature calculated by two identical methods. Lammps manual says that kinetic energy of all atoms is calculated by summing 0.5mvv for all atoms. And then this kinetic energy (ke) is used to calculated temperature using the formula [ ke = 3*kb*T*N/2 ]. So I defined a variable temp_manual as following and compared its values with output of "temp" thermo-keyword. But surprisingly found that these values differ by ~0.004. Which is not a small difference as lammps uses variable type 'double' for all these variables and double has an accuracy up to 15 digits. So theoretically we should get a difference after 14th digits. Round off error shouldn't be much as there is only 4 multiplications and one divisions being performed here.

variable   temp_manual   equal   2*ke/(3*v_kb*v_N)

where N= total number of gas particles from count(all) command. in my case N=10000
kb= 8.617343e-5  .
I picked this value of kb for 'metal' units from file 'update.cpp' in lammps code, so that I can make sure that I am using the same value of kb as lammps is using.

Simulation Details-
Gas Used -  Ar
Temperature -  600 K
boundary conditions - periodic at all boundaries
ensemble used - NVE
units - metal

Thermo commands used are as following-
thermo_style custom temp v_temp_manual
thermo_modify format float %25.20g

Please help me in resolving this issue as it is very essential for my simulations. Why this difference is occurring and how can we eliminate it?

Sample output from log.lammps file is as following-
 Temp temp_manual Difference = Temp - temp_manual 599.999999999998 599.995698924729 0.004301075268813 600.006928103531 600.002626978598 0.004301124932567
Bhanuday Sharma