Change group in run time (via fix)

Dear developers:

I have a moving sphere in runtime. The penetrable surface can separate the computational domain to inner region and outer region.

The particles have different properties (should apply different pair forces).

I wonder how I can change switch the groups in fix.

Looks like I should change atom->mask;

But I guess it may be something binary (mask[i] & groupbit)
Can anyone give me some guides about how to change the mask?

I’d like to know where are the key operations in the source codes when we assign dynamic groups, too.

Thanks in advances,

Dear developers:

I have a moving sphere in runtime. The penetrable surface can separate the computational domain to inner region and outer region.

The particles have different properties (should apply different pair forces).

I wonder how I can change switch the groups in fix.

Looks like I should change atom->mask;

NEVER change this property directly. this is done by the group commands already.

But I guess it may be something binary (mask[i] & groupbit)
Can anyone give me some guides about how to change the mask?

you don’t change it. it reflects the group assignments of atoms as it is. if you change the mask property, you will break lots of functionality in LAMMPS.

I’d like to know where are the key operations in the source codes when we assign dynamic groups, too.

sorry, there is no alternative to understanding this to carefully reading the source code, in this case the source of the group command (group.cpp group.h) and the internal fix GROUP (fix_group.cpp fix_group.h) which will facilitate the dynamic group updates.

that said, dynamic groups won’t help you here, because pair wise forces don’t change with a group: to have different forces, you need to have different atom types.
thus to have the interactions change, you could write a custom fix that changes the atom type depending on what region an atom is in.

axel.

Thanks a lot for Axel’s quick and useful replies!

I will stick on changing the groups.

I take a look at fix_group.cpp and group.cpp.

If I understand correctly. Below codes should do the job.
Would like to know any further advice.
Thanks in advance!

/////////////////////////////////////////////////////////////////////////////////////////////////////////

//have to define groups initially

//say I load in 2 switchable groups
igroup = group->find(grp);
if (igroup == -1) error->one(FLERR,“Group ID for group_inner does not exist”);
groupbit_inner = group->bitmask[igroup];
groupbit_inner_inverse = group->inversemask[group->find(igroup)];

igroup = group->find(grp);
if (igroup == -1) error->one(FLERR,“Group ID for group_solid does not exist”);
groupbit_outer = group->bitmask[igroup];
groupbit_outer_inverse = group->inversemask[group->find(igroup)];

//Switch group after moving positions
void FixSTH::post_integrate()
{
// only assign atoms to group on steps that are multiples of nevery
if (update->ntimestep % nevery == 0) set_group();
}

void FixSTH::set_group()
{
double **x = atom->x;
int *mask = atom->mask;
int inflag;
for (int i = 0; i < nlocal; i++) {
//f(x) a funtion depends on particle positions judges inside or outside
if (f(x)=in);{mask[i] |= groupbit_inner};
else {mask[i] &=groupbit_inner_inverse};

if (f(x)=out);{mask[i] |=groupbit_outer};
else {mask[i] &=groupbit_outer_inverse};
}
}

Changing the group does not change the pair wise forces. So this is a pointless exercise. Axel.