Compute the pressure and Stresses

Dear All,

I am using Lammps (lammps/29sep2021) to compute the stresses and the pressure:

I did the following:

variable          pr    equal press/10000
variable          sxx   equal pxx/(10000)
variable          syy   equal pyy/(10000)
variable          szz   equal pzz/(10000)
variable          sxy   equal pxy/(10000)
variable          sxz   equal pxz/(10000)
variable          syz   equal pyz/(10000)

velocity all create 300.0 1972
thermo          1     #output thermodynamics every 1000 timesteps
thermo_style    custom step temp pe press lx ly lz   density

fix statdump all print 1 "${st} ${tm} ${Et} ${Ep} ${Ek} ${tmp} ${pr} ${sxx} ${syy} ${szz} ${sxy} ${sxz} ${syz}" screen no file dump.stat
run 0

The result obtained at the end of the simulation reading the dump.stat is the following:

              average pressure (GPa): 27.46786
   average stresstensor xx xy xz (GPa):      31.0318      -0.0100      -0.0095 
   average stresstensor yx yy yz (GPa):      -0.0100      23.3890       0.0095 
   average stresstensor zx zy zz (GPa):      -0.0095       0.0095      27.9827 

I was expecting (31.0318 + 23.3890+27.9827 )/3=27.467833333333335 should be of the opposite sign with the average pressure.
It that correct? If yes, please, what could be the source of the mistake?
Thank you.

Why? The result you get is consistent with what you compute.
You define sxx as pxx/10000 and the other tensor elements similar and pr as press/10000. Since press is (pxx+pyy+pzz)/3.0 your averaged output is consistent with what you define. If you want sxx be the negative of pxx/10000 you have to change your variable definition accordingly.

Thank you for your answer.

Because of compute this :
peratom all stress/atom NULL
compute p all reduce sum c_peratom[1] c_peratom[2] c_peratom[3]
variable press equal -(c_p[1]+c_p[2]+c_p[3])/(3*vol)
thermo_style custom step temp etotal press v_press.

I have found it following the link compute stress/atom command — LAMMPS documentation

But there is no compute stress/atom in your input.