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.
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-
Difference = Temp - temp_manual