# [lammps-users] Using compute in loops

Dear all,

i have an another question about using compute in loops... Now I tried to calculate a variable inside the loop using some computed value. Following is the part of the input including the loop part

I got error msg as /" Compute used in variable between runs is not current "/

Could you suggest me how to resolve this ?

Thanks a lot

Best
yi

=============== input file ====================

# ###########
# Relax the system
minimize 1e-10 0.0 1000 100000

# ###########

dump 2 all custom 1 dump_shear_* id type x y z c_CEpat c_CNAat fx fy fz

displace_atoms g_uppf move 1.0 0.0 0.0 units box

variable N equal count(g_free)
variable f atom sqrt(fx*fx+fy*fy+fz*fz)
compute Cmf g_free reduce sum v_f
variable m equal c_Cmf/N
minimize 1.0e-12 1.0e-10 1000 100000
# do the quasidynamics relaxaton
variable l loop 2
label loop
run 20
print " mean_gradient_force = \$m at loop = \$l"
if \$m < 1e-10 then "jump in_test-shear_displace break"
next l jump in_test-shear_displace loop
label break

================= end of the input file ===========================

variable m equal c_Cmf/N
shouldn’t it be
variable m equal c_Cmf/\$N

I am not sure if this is source of error. Try this out.

Hi, Vikas,

Thanks for reply. But changing from " variable m equal c_Cmf/N" to "variable m equal c_Cmf/\$N" or "variable m equal c_Cmf/v_N" gives me the same error mag...
Another issue, Does it matter that I put all these variable commends and compute commends either inside or outside the loop? I tried both, the result is same.

Vikas Varshney wrote:

The variable doc page discusses this, at the bottom,
in the section on Variable Accuracy.

Steve

Hi, Steve,

Suggested by the variable doc page, I've tried to put 'run 0' before using the variable, but still no luck with error msg "/Compute used in variable between runs is not current/". Maybe I misunderstood the doc page.... Could you please give me some advices? Attached is the input file where I introduced the variable and compute

Thanks a lot!

post as simple as possible a script which reproduces
the problem.

Steve

Sorry for the confusion,

Here is the input script

Your script is long and complicated and requires a data file
I don't have. I'm asking you to simplify it to something
small and concise that illustrates where LAMMPS is
having a problem, eliminating the extraneous stuff.

Steve

I see the problem in your script.

The \$m variable in the print statement
between runs invokes your c_Cmf compute.
Unless that compute was invoked on the last timestep
of the preceding run, it won't be "current" and LAMMPS
won't use it's value. You can insure it is evaluted
by outputting it with thermo output, e.g.

thermo_style custom step temp c_Cmf

Then the loop will run.
See the bottom of the varialble doc page for more
details.

Steve

Hi, Steve,

Thanks a lot for your suggestion and time!
It works perfectly now.

Best
yi

Steve Plimpton wrote: