# Lammps command for derivative

Hi, Guys,

Is there any command for calculating the derivative of a variable in Lammps If this variable is a function of time? I tried fix ave/time, but the results appears to be not right. Thanks alot!

Bests,

Eric

Hi, Guys,

Is there any command for calculating the derivative of a variable in
Lammps If this variable is a function of time? I tried fix ave/time, but the
results appears to be not right. Thanks alot!

The derivative with respect to time? Of course, you could always
print out the value of the variable you are interested to a file
frequently using the "fix print" command. After the simulation is
finished you could compute the time derivative numerically. However I
suspect this is not what you want.

I don't know if there is a fix which forces LAMMPS to calculate a
variable at regular intervals without also writing that value of that
variable to a file. If so, then you could use it to calculate the
difference in the value of a compute at two successive timesteps (or
two nearby timesteps) and save the result in a variable. (Then you
could use "fix print" to print THAT variable to a file at
low-frequency intervals.)

This discussion looks relevant:
(It would be cool if there was a fix which would allow LAMMPS to
calculate the value of a variable at regular intervals and halt the
simulation when the value exceeds a threshold, but I don't want to
make Steve work on this.)

Please forgive me if I strayed from the topic of your original question.

Cheers
Andrew

You can write a variable formula that takes the difference of 2 other variables
and divides by some elapsed time. The question would be what
time delta you want and how to get the old value of a variable. If
it's a variable
you computed/stored at the beginning of a run, that's easy. If it's 1 timestep
ago, then that value would have to be stored someplace, like in a fix.

E.g. you could write a simple fix that keeps a running tally of the last
N values of a variable (or compute, etc) on the last N timesteps. Then
you could write a variable formula that computes your "derivative" based
on using those most recent N values.

Here's a poor man's version of a time derivative of temperature in a loop,

variable now equal temp
variable old equal temp
variable deriv equal (v_now-v_old)/10

variable a loop 5
label loop
run 10
print "DERIV = \{deriv\}&quot; variable old equal {now}
next a
jump SELF loop

Steve

(It would be cool if there was a fix which would allow LAMMPS to
calculate the value of a variable at regular intervals and halt the
simulation when the value exceeds a threshold, (It would be cool if there was a fix which would allow LAMMPS to
calculate the value of a variable at regular intervals and halt the
simulation when the value exceeds a threshold,

You can do something like this now by putting a command like

if "\$x > 100.0" then quit
or
if "\$x > 100.0" then jump SELF mylabel

in a loop that has a run command (for some increment)
or as the argument to a run every command.

Steve

Thanks for the two nice loop examples.