Weird repeated output when I use fix print command and loops

Greetings. I got a problem when I want to use ‘fix print’ to save data to files. Two repeated rows at same timestep come up in loops state. And I do not know why. The weird file is like below.

The problem is that this program runs successfully without error message. So how should I do to fix it? I attach relevant code below. Thank you!

P.S. The output file only repeats during loops. In realxtion it works well.

#compute the interaction force between block and substrate
compute interForce block group/group substrate
variable interFx equal c_interForce[1]
variable interFy equal c_interForce[2]
variable interFz equal c_interForce[3]
variable istep equal step
fix 4 all print 200 “{istep} {Temp} {IniCentX1} {IniCentY1} {IniCentZ1} {IniCentVX1} {IniCentVY1} {IniCentVZ1} {IniCentFX1} {IniCentFY1} {IniCentFZ1}" file screen no title "Step Temperature CentX1 CentY1 CentZ1 CentVX1 CentVY1 CentVZ1 CentFX1 CentFY1 CentFZ1" fix 5 all print 200 "{istep} {interFx} {interFy} ${interFz}” file screen no title “Step interFx interFy interFz”

---------------------------Impose Fn-----------------------------------

variable normolNum equal count(fn-area)
variable Fn equal -2000 #total normal force
variable fn equal v_Fn/v_normolNum
reset_timestep 0
dump normol all custom 100 dump.normol id type x y z vx vy vz fx fy fz
dump_modify normol sort id

label loopone
variable xx loop 50
variable forcen equal v_fn/50
fix normol fn-area addforce 0 0 v_forcen
run 200
next xx
jump SELF loopone

unfix normol
fix faxiang fn-area addforce 0 0 v_fn
undump normol


reset_timestep 0
dump chiyu all custom 1000 dump.chiyu id type x y z vx vy vz fx fy fz
dump_modify chiyu sort id
run 20000
undump chiyu

-------------------------------Impose Fx-----------------------------------------

variable lateralNum equal count(fx-area)
variable Fx equal 200 #total shear force
variable fx equal v_Fx/v_lateralNum
reset_timestep 0
dump lateral all custom 100 dump.lateral id type x y z vx vy vz fx fy fz
dump_modify lateral sort id

label looptwo
variable yy loop 50
variable forcex equal v_fx/50
fix lateral fx-area addforce v_forcex 0 0
run 200
next yy
jump SELF looptwo

unfix lateral
fix lateral fx-area addforce v_fx 0 0
undump lateral


It is a bit difficult to spot an issue here because your input is unnecessary long and complicated. It is much better to simplify it as much as you can before posting here: everything below “Relaxation” is irrelevant. Also you must always report your LAMMPS version.

Concerning what you call a weird behavior: you have a run of 200 steps inside a loop, so my guess is that LAMMPS prints information at the beginning of every new iteration of the loop. This looks like the expected behavior to me.



Quick tip that you can use triple back-dashes (```) to get scripts formatted in verbatim.

My guess is that fix print prints twice per loop: once because at the start of the loop it detects that step 800 (for example) is a multiple of 200, and again at the end of the loop it detects that 1000 is a multiple of 200. Your next run command picks up at step 1000, not step 1001 (this is why run 0 works, for example), and therefore fix print fires again at start and end.

You can replace fix print with a simple print command at the end of the loop (although computes might not be current). Alternatively, you can just postprocess your file with sed '2~2d' or awk 'NR == 1 || NR %2 == 0' to remove every other line after the first two.

1 Like

Thanks for your reply!
I do not know where I can see my LAMMPS version. Is this right?

Thanks for your detailed explanation! I will try to solve this.

Yes! 3Aug2022 would be the LAMMPS version.

Another tips get!
Thank you

In this case, what you are telling us is just (part of) the name of the folder that LAMMPS is installed in. It’s probably the correct version, but there is always the chance (especially if you didn’t compile it yourself) that someone named the folder differently from the actual version that was installed.

I’m not familiar with LAMMPS Shell but the LAMMPS version is always stated in the first line of a log file. You can also get it by running lmp -help as the documentation says (where lmp is supposed to be the name of the LAMMPS program file – it may again change depending on how it was installed).


This reminds me of when I was a kid:

There used to be mail catalogs from which you could order computer games on 3.5" floppy disks. Once, I found some blank floppy disks lying around near the computer, and I excitedly wrote a computer game name on the disk label. I was very disappointed to find out that doing so didn’t magically make the game appear inside the disk!


Thanks a lot for reminding me. I named the folder with the same name of actual version.

I found why the output would repeat in loops. It because simulation step in one cycle is 200. So it will repeat twice. If I change the simulation step to 100, then it will repeat when timestep is an integral multiple of 1000. So I finally change this value to 230. Therefore there is no repeated output.

Thanks again! By the way, your story is quite amusing