Pressure evaluation in lammps

Dear Lammps Users,

I am confused about the calculation of pressure based on the virial theorem.
According to the virial theorem, macroscopic pressure can be calculated from temperature or kinetic energy, and the virial, which represents the pressure from interatomic forces among atoms.
As I see from the theorem, this virial need to be time or ensemble averaged. However, when I checked the code in compute_pressure. cpp, it seems that the virial is calculated as the instantaneous value.
I am curious about how pressure in lammps is averaged from microscopic pressure, or how does the pressure calculation in lammps works.

Thanks!

Xiao Jia

Dear Lammps Users,

I am confused about the calculation of pressure based on the virial
theorem.
According to the virial theorem, macroscopic pressure can be calculated
from temperature or kinetic energy, and the virial, which represents the
pressure from interatomic forces among atoms.
As I see from the theorem, this virial need to be time or ensemble
averaged. However, when I checked the code in compute_pressure. cpp, it
seems that the virial is calculated as the instantaneous value.

​it is the instantaneous value *of the entire system*, though (so averaged
over the ensemble).

I am curious about how pressure in lammps is averaged from microscopic

pressure, or how does the pressure calculation in lammps works.

​you can easily obtain time averaged values from averaging over the
instantaneous values printed in the thermodynamic output or you can define
a compute and run it through fix ave/time to averaging (per segment, per
window, or running).

for the most part, pressure is a diagnostic output, anyway.

​axel.​

Dear Axel,

Thanks for your answering.

Based on the description and the code, ensemble average is conducted by averaging the atomic virial throughout the volume as sum(virial) / V. Can you tell me if my understanding is correct?

With this method, I tried to calculate localized pressure in different cells like chunks.
In each cell, virials are summed from each atom belong to the cell, and averaged by dividing the cell volume.
I can get fluctuated pressure along the dimension, along which cells are defined.

I am wondering whether the relatively small atom number (10,000) in the cell can result in this situation.

Thanks!
Xiao Jia

Dear Axel,

Thanks for your answering.

Based on the description and the code, ensemble average is conducted by
averaging the atomic virial throughout the volume as sum(virial) / V. Can
you tell me if my understanding is correct?

yes, for the most part. LAMMPS used an optimized approach, if only the
global virial is required, but that yields the same stress tensor.

With this method, I tried to calculate localized pressure in different
cells like chunks.
In each cell, virials are summed from each atom belong to the cell, and
averaged by dividing the cell volume.
I can get fluctuated pressure along the dimension, along which cells are
defined.

*all* "macroscopic" thermodynamic properties fluctuate when computed on an
atomic scale. some more, some less. pressure fluctuates a *lot* for
condensed systems, since they are not very compressible and even more so,
the smaller the (sub)system is you are looking at.

I am wondering whether the relatively small atom number (10,000) in the
cell can result in this situation.

​this sounds like you need to do some more reading in your text books on
statistical thermodynamics beyond what you have already read. you are
obviously on the right path and are asking the right questions, but this
mailing list is not the place to discuss such matters. we like to focus on
issues that concern the usage of LAMMPS.

​axel.​

Dear Axel,

Thanks for your reply and advices.
I will do some more reading in the area of statistical thermodynamics.

Best,
Xiao Jia