How can I calculate the Pressure_xx value for each chunk in LAMMPS

Based on various papers and manuals, I have calculated the pressure (P_xx) for each chunk.

But I’m not sure if the command I’ve written is correct because it calculates values on a much larger scale than what I expected

My scripts are as below

compute ch_id all chunk/atom bin/1d x lower 10 units box
compute stress all stress/atom NULL
variable press atom -(c_stress[1])
fix ave_stress all ave/chunk 1 100 200 ch_id v_press file ave_stress.out

I will explain the script line by line.

Line 1: Create chunks at intervals of 10 angstroms along the x-axis.
Line 2: Calculate stress for each atom.
Line 3: Set a variable to only take the value of stress[1] to calculate P_xx.
Line 4: Average the v_press variable for each chunk

Please check my script, and give me some advise.

Thanks,

Please have a look at the documentation for compute stress/atom. It has an example for computing a pressure profile. You only need to adapt it for your system and that you only want the xx component. What you have currently is not correct:

  • what compute stress/atom returns is in a stress * volume formulation; thus to get pressure you need to compute -\sum_{slice} \mathrm{stress}_{xx} / V_{slice}
  • You need to get the sum, not the average and then divide by the volume of the slice. This volume is well defined, the volume per atom not.
  • You need to do time averaging of the vector of per chunk stress results

Thank you for your comment.

Following your comments, I have made changes as follows

script

compute ch_id all chunk/atom bin/1d x lower 10 units box
varibale Ly equal ly
varialbe Lz equal lz
variable bin_volume equal {Ly}*{Lz}*10
compute stress all stress/atom NULL
variable press atom -(c_stress[1])/v_bin_volume
compute binpress all reduce/chunk ch_id sum v_press
fix avestress all ave/time 1 100 200 c_binpress mode vector file ave_stress.out

And I think it works.

Thanks,