# Index of the Fix Command in LAMMPS

I am puzzled by the indices of the fix command in LAMMPS code. Taking the following command as an example.

fix hot all heat 1 100.0 region hot
fix cold all heat 1 -100.0 region cold
thermo_style custom step temp c_Thot c_Tcold
thermo 1000
compute ke all ke/atom
variable temp atom c_ke/1.5
compute layers all chunk/atom bin/1d z lower 0.05 units reduced
fix 2 all ave/chunk 10 100 1000 layers v_temp file profile.heat
variable tdiff equal f_2[11][3]-f_2[1][3]
thermo_style custom step temp v_tdiff f_ave
run 20000


I know the number '2' in f_2[11][3] indicates the group ID.

What is the meaning of the subscripts, [11] and [3], of the fix command mean here?

If I want to compute the temperature gradient, should I use the value of 'v_tdiff' or 'f_ave' to plot the temperature-distance figure and obtain the slope?

Would anyone please give me some suggestions/hints?

First, as a correction, the "2" in f_2[11][3] stands for the name of the fix, which is called "2" in the definition

fix 2 all ave/chunk [...]


Second, you are referring to the KAPPA example in the LAMMPS examples folder, which can be found here. It is useful to point out that in this example, a box is separated into 20 "chunks" in the Z-direction, the middle of which (chunk 11) is "cold" (heat is removed using fix heat) and the lowest one (chunk 1) is "hot" (heat is added). After some time equilibrating the temperature gradient, heat transfer is computed.

Now, let's break down the key commands:

compute ke all ke/atom
variable temp atom c_ke/1.5


Here, per-atom kinetic energies are calculated, and converted into "temperature" using , I assume, $$E = \frac{3}{2} kT$$ (we're in a Lennard-Jones system, so $$k = 1$$). Note that for every atom, we obtain a vector of length 3, with the three components of the kinetic energy.

compute layers all chunk/atom bin/1d z lower 0.05 units reduced


Here, the box is "chopped up" into 20 chunks along Z (each 0.05 box thick)

fix 2 all ave/chunk 10 100 1000 layers v_temp file profile.heat


Now, we average the values of v_temp for the atoms within each chunk, so we get average temperature per chunk. However, v_temp is a vector of length 3, so we actually get a temperature vector for every chunk.

Finally, we access the per-chunk averages. Normally, we access the property of chunk n through f_2[n]. So to subtract a value between chunk 1 and 11, we'd have f_2[11]-f_2[1]. However, we're still dealing with temperature vectors (for every component) and need to specify one index to get a scalar. Given that heat flux in the Z-direction is computed, we take the third component.

So we have:

• All values for all chunks: f_2
• The averaged quantity for chunk 1: f_2[1]
• If the quantity is a vector, one component: f_2[1][3]
• @Kristol Bal Thank you very much for the explanation. In other words, I should use the average temperature difference value, which is denoted by variable 'f_ave' in the example, to plot the temperature v.s. distance along z axis to obtain the slope (temperature gradient) value. Am I correct? Commented Apr 5 at 14:47
• @Kristol Bal Can I ask one more question? If the central region is not composed of the same atom; but composed of one benzene ring sandwiched by silicon rod on both side, can I still separate the box into several chunks and obtain the temperature gradient though calculating the average temperature difference for each chunk; just like the example above? I really appreciate that you could give me more suggestions. Commented Apr 5 at 15:00
• @Kieran, different questions should merit opening a new question and I'm not really familiar with heat conductance modeling). For your first question, note that you did not include the full input deck. Here, a fix ave/time is introduced, which computes a time average called f_ave. Commented Apr 8 at 7:54