write_restart causes "compute is not current" error

Hello all,

Let’s say I want to print some compute values after I minimize and write a restart file:

minimize 10e-8 10e-8 100000 100000
write_restart after_min
print “(c_compzcoord1-c_compzcoord2) (pe) $(c_compfrc)”

As you can test with the attachments, (I’m using lammps-7Aug19) this gives the error “Compute used in variable between runs is not current”.
However, the error goes away if you comment out the “write_restart command”!

I could put a “run 0” after write_restart, but I wanted to know why this is happening? Shouldn’t write_restart have no impact on the simulation and just write current state as they are?

Thanks in advance,
Jamal

data.dat (257 KB)

runfile (1.09 KB)

Hello all,

Let’s say I want to print some compute values after I minimize and write a restart file:

minimize 10e-8 10e-8 100000 100000
write_restart after_min
print “(c_compzcoord1-c_compzcoord2) (pe) $(c_compfrc)”

As you can test with the attachments, (I’m using lammps-7Aug19) this gives the error “Compute used in variable between runs is not current”.
However, the error goes away if you comment out the “write_restart command”!

I could put a “run 0” after write_restart, but I wanted to know why this is happening? Shouldn’t write_restart have no impact on the simulation and just write current state as they are?

write_restart will trigger the “init()” methods of various classes (this is needed to have a consistent internal state and because communication may be needed to exchange atoms between subdomains) and that will invalidate all compute data from previous runs. hence the behavior you see is expected and consistent with how write_restart is expected to work.
you may only access results from computes after a run, if there has been nothing else happening that modifies the state. or to put it differently, you can consider the results of compute styles a “fragile”.
otherwise you can cache the results of computes using one of the averaging fixes (when using nrepeat of 1 there is usually no averaging), which have persisting data.

axel.

Or swap the order of your print and write_restart commands.

Steve