Multiple runs and fix deform

Dear Lammps users,

I’m having trouble preventing fix deform from resetting to the original box length when doing multiple runs.

I want to deform the box at rate which is constant within a run, but different between runs. Since the fix needs both box deformation length and velocity, I calculate the deformation length within a run from the velocity and the size of the box at the beginning of each run.

I first have the commands:

variable mylen equal lx # Get length of box in x direction
variable mylenstart equal ${mylen} # Record starting length (constant)

variable boxpos equal v_l0+(v_currenttime-v_t0)*v_boxvel #t0 is the time at the beginning of each run
fix boxstretch all deform 1 x variable v_boxpos v_boxvel units box remap none

and then I run with

run 100 start 0 stop 300 post no
variable l0 equal {mylen}-{mylenstart} # Length of the box at the end of the run
run 100 start 0 stop 300 pre no post no
variable l0 equal {mylen}-{mylenstart}
run 100 start 0 stop 300 pre no

but “mylen” gets reset to the original box length at the beginning of every run. I’ve tried this with the “every” command too (which would be more useful) with the same result. According to the manual page it should be possible to deform constantly over multiple runs, so I wonder what I’m missing?

Any advice is greatly appreciated.
Thank you.


The run command start/stop options are only used by the
various fix deform options like final, delta, etc (but not variable)

to set a time origin and elapsed time. To do something like

current value = lo value + elapsed time * (hi value - lo value)

But if you are using the variable option, you are replacing that
formula with your own, so you can do whatever you want.

I suggest you debug by printing out the values of your several
variables (and the box length) at every step with thermo output
for the 300 steps of your 3 runs. This should tell you how fix
deform is using the “change” it expects from the boxpos variable,
as explained on the fix deform doc page. Note that it is a change
in box length, not the box length itself, which is what your definition
of boxpos appears to be, since it includes l0. And your formula
does not eval to 0.0 on the first time step, as the doc page indicates
it should.