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 eV per Kelvin .
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.
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?
Simulation Details-
boundary conditions - periodic at all boundaries ; ensemble used - NVE; units - metal Sample output from log.lammps file is as following-
Temp temp_manual Diff =Temp - temp_manual
599.9999999999 599.9956989247 0.0043010752
600.0069281035 0.002626978598 0.0043011249