[lammps-users] 'Variable' change for 'fix' for different 'run'

Dear All,

I am dividing a ‘nve run’ into two parts as I want to change one of the variables in ‘fix’ after one run is performed. I notice that the value of the variable is reassigned after run 1 but for run 2 the value of the variable is not taken into consideration by the ‘fix’ command.

Script:
variable a equal 1000

fix integrate all nve

fix f33 all ordern diffusivity {Ndiff} {Nwrite} c_positions start $a file diffnew.$a.dat onsagnew.$a.dat

run 1000 start 0 stop 10000
print “A1 = $a”
variable a equal 2000
run 9000 start 0 stop 10000
print “A2 = $a”

In the output file, I see the variable a=2000 using the print command (print A2). In the second run, I expect the files diffnew.2000.dat and onsagnew.2000.dat to be generated but I do not get them (I only get the output files: diffnew.1000.dat, onsagnew.1000.dat)

I request you to help me resolve this issue.

Further: Once I overcome this I would actually like to use ‘run 10000 every 1000 “next a”’, (where variable a index 1000 2000 …). LAMMPS is not accepting next in this case. I get an error:
Invalid variable ‘a’ in next command

Thank you very much.

Regards,
Kunal Mavani

please always report which version of LAMMPS you are using and what platform you are running on.

variable access in LAMMPS can be done in two ways: 1) via immediate expansion or 2) via variable references.

immediate expansion is when you use {name} in the input script. the variable will be expanded as part of the input file processing and after that there is no indication what was entered directly or taken from a variable. you can see the input file expansion in the log file. variable references are usually referenced with v_name (notable exceptions are the "print" and "fix print" commands that use the syntax). in that case the variable is expanded by the command and in the case of fix print multiple times during a run.

thus for you “fix ordern” command to recognize the new value of the variable “a” you have to unfix the fix and create a new instance of the fix that will then expand $a to its then current value. this is also quite logical, since how should the fix command know that you have changed a variable and thus want it to close its files and then open them under a new name. that would be very counterintuitive.

as for your use of “next”. i have no problem with the following minimal input.

region box block 0 1 0 1 0 1
create_box 1 box
mass * 1.0
variable a index 1000 2000 3000 4000 5000
fix 1 all print 1000 “a=$a”
run 5000 pre no post no every 1000 ‘next a’

but there would be an error message (albeit a different one with the current version of LAMMPS), if you are requesting “next a”, but there are no more values left and that error would be justified in that case.

axel.

Dear Axel,

I figured out my previous question. I assigned the fix ID as variable name itself.

Thank you very much.

Regards,
Kunal Mavani

Dear Axel,

Thank you for your reply. With ‘unfix’ and again using ‘fix’, I am able to do it. Actually, I was interested in not unfixing the old fix (as I want to continue writing data to that file as well). Is there a way to create a new ‘fix’ without unfixing the old one? One way would be that I manually create all the fixes (for my simulation I would require about 15-20 fix). I was interested if there’s a dynamic way?

LAMMPS version: 22nd Aug 2018

Regards,
Kunal Mavani.