Change of variable accoring to old value on the last step

Submitted by ROAC on Tue, 12/04/2012 - 19:18

Hi, Christoph:

I am doing a simulation involving chemical reaction of particles. In the simulation, I have to update some material properties, such as Young's modulus, Poisson's Ratio, and friction coefficients.... These coefficients must be changed according to their early values (on the last time step), so that I can implement a calculation like:

S_new=S_old+1

When I do it by using the 'variable atom' commands, errors always take place. This algorithm is easy to implement in C++ or other languages. But, it becomes a wrong statement in Liggghts. Do you know why?

Best,

Andy

ckloss's picture

ckloss | Wed, 12/05/2012 - 18:45

Andy,

to answer your question, please provide more info how you implemented this.
Note that Young's modulus, Poisson's Ratio, and friction coefficients are PER-TYPE parameters and not per-particle parameters. If you want per-particle-parameters (eg via variables) you would have to change the pair style implementation (per-type is more efficient, so it's implemented this way).

Christoph

ROAC | Fri, 12/07/2012 - 21:08

Sorry for the unclear description. Here I give an example to show you what I did for the calculation of contour length:

#=====================================================
variable AV atom (vx*vx+vy*vy+vz*vz)^0.5 # per-atom absolute velocity
variable ds atom v_AV*${Dt} # per-atom distance traveled within Dt
variable S atom v_S+v_ds # per-atom contour length

dump dump1 all custom 100 test.dump id type x y z vx vy vz v_S
run 200
#======================================================

When I implement this, no data will be dumped. But, I can obtain data if I don't dump the value of S.
I don't know why it happened...

richti83's picture

richti83 | Fri, 12/07/2012 - 23:04

maybe it's a typo but:
variable S atom v_S+v_ds # per-atom contour length
can not work because of the recursive usage of v_S in my opinion

Maybe a compute can help:

Note that other atom attributes can be used as inputs to a variable by using the compute property/atom command and then specifying a quantity from that compute

and than using S atom c_whatever+c_somethingelse

just my 2 cents

I'm not an associate of DCS GmbH and not a core developer of LIGGGHTS®
ResearchGate | Contact

jorisheyman | Tue, 12/11/2012 - 13:18

I think andy wants to access the variable S at the last time step S_{i-1} to compute S at the next time step S_{i} recursively. I had a similar problem when trying to generate a time-correlated noise variable (e.g. with an auto-regressive process). I didn't find a way to do it inside of LIGGGHTS so I moved to a LIGGGHTS-python coupling.

ROAC | Wed, 12/12/2012 - 20:32

Someone told me that the fix "store/state" may do the recursive calculation of peratom variable. By using it, I can dump the data eventually. But, the peratom variable increases unreasonably fast and finally results in an infinite value....

jorisheyman | Thu, 12/13/2012 - 20:41

As I would potentially need this function too, I ask in the LAMMPS forum for advices.
Steve answered me this:

In general, no. Because variables are not even
evaluated unless they are needed on a specific timestep.
You could write a fix to do this and store whatever
you want from previous timesteps. That's not really
what fix store/state is designed for.
You could use a second variable to store the current
value of the first variable. If you used a loop (via the
jump command), it would be possible to have the
2nd variable store the value of the 1st variable on the
previous loop iteration, simply by assigning them at
the right point in the loop.

In other words, it is not possible yet.
I turned to python coupling to get, store, and compute the needed variables. I had to modify a litlle bit the makefiles to build a shared library of liggghts for python (according to last Lammps release). If you are interested I can share the modifications.

Cheers,
j