Calculate change in scalar variables between timesteps

Hello!

I’m trying to simulate a packing in where a box filled with spherical particles with gran/hooke potential is isobarically compressed such that density is monotinically increasing, and average contact number/atom increases over time.

I can monitor the change in density and average number of contacts/atom through thermo_style, but I wish to implement an exit condition which monitors the change of these two variables between every N timesteps.

(To clarify: Exit condition should be that if the change of the two scalar values is smaller than a set tolerance, the script should exit.)

Is this possible?

It could probably be done using the fix vector command — LAMMPS documentation

That would allow you to store properties every N timesteps.
Then you just need an equal style variable that computes what index you have to use for a given timestep and then another that computes the difference between the fix vector item for that step and the previous item.

Thank you for the quick response. This worked great, had to add a variable handling a logical argument to ensure I didnt reach out of scope at first iteration. (1 and 1 instead of 0 and 1)