Variable atom-style cannot express chunkID of each atom defined by compute chunk/atom

Hi all,

Command line ‘fix 1 all rigid/small custom v_’ requires an atom-style variable, and I hope the variable can represent the chunkID of each atom.

I don’t know why ‘variable chunkID atom c_ chunk’ cannot assign the chunkID of each atom but the total number of chunks to the variable.

However, in ‘fix ave/chunk’, c_chunk can represent the chunkID of each atom.

What does

compute chunk all chunk/atom [... settings ...]
variable chunkID atom c_chunk

do in your script? I would expect it to return a per-atom chunk ID variable as expected.

fix 1 groupID rigid custom v_chunkID

To set each chunk as a rigid body:

fix 1 groupID rigid custom v_chunkID

but failed.

Failed how?

Also, when reporting unexpected behavior, please always report which LAMMPS version you are using and what platform you are running on.

Here is a brief test in.file about variable chunkID atom c_Nchunk and the test results of the lammps-2022Jun23 compiled by Intel on a single processor on MobaXterm.

Obviously, the variable only assigns the total number of chunks to each atom instead of chunkID.
c_Nchunk is considered as a global scalar(total number of chunks) instead of per-atom vector(chunkID).

in.chunktest (869 Bytes)
CH.airebo (905.0 KB)
Si.sw (795 Bytes)
9-540Ncell_Sicore_9.5.data (356.0 KB)

chunktest.log (5.9 KB)
preNchunk.txt (552 Bytes)
System.data (356.0 KB)

Your analysis is incorrect. The problem is that you are connecting the atom style variable to the compute, but the compute is “non-current” in between runs and thus cannot be accessed and will produce inconsistent or random data.
You need a “cache” that makes the data properly permanent. Fix store/state can be used for that.

compute cluster Ncell cluster/atom 2.5
compute Nchunk Ncell chunk/atom c_cluster compress yes nchunk once ids once
fix storechunk all store/state 0 c_Nchunk
variable chunkID atom f_storechunk
run 0 post no

fix R Ncell rigid/nve custom v_chunkID
run 2 post no
write_dump all custom dump.chunk id v_chunkID

the same limitation doesn’t seem to apply to compute cluster/atom though:

compute cluster Ncell cluster/atom 2.5
compute chunk Ncell chunk/atom c_cluster #nchunk once ids once
fix storechunk all store/state 0 c_chunk
variable chunkID1 atom c_chunk
variable chunkID2 atom c_cluster
variable chunkID3 atom f_storechunk
compute cmin Ncell reduce min v_chunkID1 v_chunkID2 v_chunkID3
compute cmax Ncell reduce max v_chunkID1 v_chunkID2 v_chunkID3
thermo_style custom c_cmin[1] c_cmax[1] c_cmin[2] c_cmax[2] c_cmin[3] c_cmax[3]
# outputs 5657, 5657, 1, 5657, 1, 5657 for c_chunk, c_cluster, f_storechunk in order
run 0

It does. You are creating thermo output which is during a run, if you would add “c_cluster” to the write_dump command in my example, you will get:

ERROR: Compute used in dump between runs is not current (src/dump_custom.cpp:567)

And if you use the compute in a variable and add the variable to the write_dump line you get:

ERROR: Variable clusterID: Compute used in variable between runs is not current (src/variable.cpp:1571)

Using fix store/state can give you access to both with the example input changed as follows:

compute cluster Ncell cluster/atom 2.5
compute Nchunk Ncell chunk/atom c_cluster compress yes nchunk once ids once
fix storechunk all store/state 0 c_Nchunk c_cluster
variable chunkID atom f_storechunk[1]
variable clusterID atom f_storechunk[2]
run 0 post no

fix R Ncell rigid/nve custom v_chunkID
run 2 post no
write_dump all custom dump.chunk id v_chunkID f_storechunk[1] f_storechunk[2]

You mean that compute Nchunk only performs calculation at the 0 timestep and cannot be invoked at other timesteps, right? But even in timestep 0, the value of v_chunkID is also incorrect in preNchunk.txt.