ERROR:Invalid variable reference v_b in variable formula


I got a problem when I tried to use a double loop to add force to particles. And I refer to the example in jump command — LAMMPS documentation, but I still got the error message:Invalid variable reference v_b in variable formula . Below is my code:

label loopstart
variable x loop 200
label loopone
variable b loop 200
variable force equal -2.5e-6*v_b
fix normol all addforce 0 v_force 0
run 1000
next b
jump SELF loopone
variable b delete
run 5500000
next x
jump SELF loopstart

I don’t know how to fix it. Any help will be appreciated! Thanks advance!

The best description of what LAMMPS is doing in a complicated situation like this is the log file. Can you provide that?

Your “fix addforce” command references the “force” variable which references the “b” variable.
After the inner loop is completed, you delete the “b” variable, but then run additional time steps without also doing “unfix normol”. Thus during the run the fix will evaluate “force” which wants to evaluate “b”, but cannot do so because it has been deleted.

Thanks! I will attach it next time.

Thanks you for your reply and the question is exactly you pointed out. Thank you again!

BTW: the inner loop is not really needed. You can easily construct a force value that is ramped up with the timesteps using the “ramp()” variable function.