who are gas atoms in GCMC?

Dear Lammps developers,

I am trying to understand the code of fix-gcmc. To make it easy, I start from a system only Argon atoms (single-atom molecule) are included. I have tested it and it seems everything goes well. But when I artificially modified some Argon atom type from 1 to 2, I found something I can not understand.

According to my understanding, in the code of fix-gcmc, “gas atoms” refers to the atoms of gcmc type, i.e. the atoms to be inserted or deleted. My understanding comes from the following function:

int FixGCMC::pick_random_gas_atom()
{
int i = -1;
int iwhichglobal = static_cast (ngas*random_equal->uniform());
if ((iwhichglobal >= ngas_before) &&
(iwhichglobal < ngas_before + ngas_local)) {
int iwhichlocal = iwhichglobal - ngas_before;
i = local_gas_list[iwhichlocal];
}
return i;
}

By using this function, one atom is chosen for deletion or translation. So, I guess, here “ngas_local” is the number of gcmc type atoms in the current processor. This function is used to choose one of the “ngas_local” atoms.

However, in another function, void FixGCMC::update_gas_atoms_list(), it seems not only the gcmc type atoms are counted as “ngas_local” atoms (the meaning of “groupbit” is not clear to me yet). The related code is as follows:

for (int i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
local_gas_list[ngas_local] = i;
ngas_local++;
}
}

In my test run, I modified 20 Argon atom type from 1 to 2. I have found that the value of “atom->nlocal” is the same as that of “ngas_local”. That means, all local atoms (whether they are gcmc type or not) are also local gas atoms, and all local atoms can be chosen for GCMC exchange (in my simulation, atoms of type 1 is set as the gcmc type). I tried many ways but just could not find the origin of my puzzle.

In my test, the value of mask[i] for atoms of type 1 is 1 or 3, for atoms of type 2 is 5. The values for “groupbit” and “groupbitall” are both 1. That is the reason why both atoms of type 1 and 2 are chosen for “ngas_local”. But why they are both included?

Could someone help me? Thanks in advance!

All the best,

Yongbiao

Dear Lammps developers,

  I am trying to understand the code of fix-gcmc. To make it easy, I start
from a system only Argon atoms (single-atom molecule) are included. I have
tested it and it seems everything goes well. But when I artificially
modified some Argon atom type from 1 to 2, I found something I can not
understand.

  According to my understanding, in the code of fix-gcmc, "gas atoms"
refers to the atoms of gcmc type, i.e. the atoms to be inserted or deleted.
My understanding comes from the following function:

int FixGCMC::pick_random_gas_atom()
{
  int i = -1;
  int iwhichglobal = static_cast<int> (ngas*random_equal->uniform());
  if ((iwhichglobal >= ngas_before) &&
      (iwhichglobal < ngas_before + ngas_local)) {
    int iwhichlocal = iwhichglobal - ngas_before;
    i = local_gas_list[iwhichlocal];
  }
  return i;
}

By using this function, one atom is chosen for deletion or translation.
So, I guess, here "ngas_local" is the number of gcmc type atoms in the
current processor. This function is used to choose one of the "ngas_local"
atoms.

However, in another function, void FixGCMC::update_gas_atoms_list(),
it seems not only the gcmc type atoms are counted as "ngas_local" atoms
(the meaning of "groupbit" is not clear to me yet). The related code is as
follows:

    for (int i = 0; i < nlocal; i++) {
      if (mask[i] & groupbit) {
        local_gas_list[ngas_local] = i;
        ngas_local++;
      }
    }

In my test run, I modified 20 Argon atom type from 1 to 2. I have found
that the value of "atom->nlocal" is the same as that of "ngas_local". That
means, all local atoms (whether they are gcmc type or not) are also local
gas atoms, and all local atoms can be chosen for GCMC exchange (in my
simulation, atoms of type 1 is set as the gcmc type). I tried many ways but
just could not find the origin of my puzzle.

In my test, the value of mask[i] for atoms of type 1 is 1 or 3, for atoms
of type 2 is 5. The values for "groupbit" and "groupbitall" are both 1.
That is the reason why both atoms of type 1 and 2 are chosen for
"ngas_local". But why they are both included?

  Could someone help me? Thanks in advance!

​it looks to me, that you first need to improve the way how you analyze
code and how you deduce what code does. there are flaws in your arguments
and guesses, because you didn't try any research on the code that you don't
understand and because you are not paying enough attention to what the
documentation says and how those features of the fix are translated into
code.

for example, if i stick the three words "mask groupbit lammps" into google,
i get to see *several* good explanations within the first few hits.

secondly, your guesses are in conflict with the documentation. the gcmc
"type" applies to atoms that are *inserted*, but fix gcmc operates on all
atoms in the *group* that fix gcmc operates on. this is where "mask" and
groupbit come into play. didn't i advise you on the difference between a
bitmask and a logical and before?

also, you are reading the two functions you quote in the wrong order. the
second function (update...) is obviously first used to build the list of
eligible atoms and then the first function (pick...) is used to pick one
randomly (and do so reliably in parallel). it is not so difficult to
understand, but it requires using logic and imagination to understand why
things have to be done in such a complex way when running in parallel.
guessing is rarely a good approach in science in general and when trying to
understand code in particular.

axel.