Invoking a pressure compute

Hello LAMMPS users:

My goal is to have pressure data for each timestep of my simulation. I can accomplish this by having the following in my input file:

compute stress all pressure thermo_temp
thermo_style custom step temp pe ke pxx pyy pzz
thermo 1

The problem with this solution is that it’s a lot of I/O, which slows down my simulation. Instead, I’d like to make a buffer that will store a certain number (say 1000) of pressures for each timestep for a 1000 timesteps, and when the buffer is full, write (or append) to the data file. This way, I reduce I/O.

Now, if instead of having:

thermo 1

I have:

thermo 10

yet I still want to compute the pressure at every given timestep, how should I go about accomplishing it? Once I know how to invoke the pressure computation at each timestep and understand how to return a pointer to its data structure, figuring out the buffer situation would be relatively straightforward, I think. I’ve been trying to use the extract_lammps_compute library function, though I’ve had no luck with it, constantly obtaining segfaults. I’ve also tried to mess around with manually calling `compute_pressure’ and other similar compute/modify functions, though that was a no-go either, all returning segfaults.

I appreciate your help,

First, you do not need to define a pressure compute. LAMMPS
already does this. You can just use pxx, etc in the thermo_style command.

Second, you could try letting fix ave/time do the output for you, to a file,
instead of thermo output to the screen. You do not have to "average"
with fix ave/time, you can dump raw values, every step if you like. Though
if you will eventually average anyway, you could let fix ave/time do that
for you and output less often. Using fix ave/time will be a savings in
2 ways. You will only be computing (every step) exaclly what you want,
e.g. pxx, etc. And it will only write to a file, not to the screen, whcih
may be the source of your bottleneck.

If that still isn't fast enough, buffering would have to be added to
fix ave/time. That is do-able but not easy. Note that the OS already
does buffering of file writes. If you comment out the flush() line
in fix_ave_time.cpp then system buffering will occur. If that is
actually faster, then we could make the flush() invocation an option,
as we do for some other commands.