Region intersect

I was bugged by the behaviour of the region command in my reply to this post.

I believe there is a bug in LAMMPS (verified with versions 7 Feb 2024 - Update 1, 21Nov23, and 2Jun22) in the definition of regions and groups. This is a small example to reproduce the issue:

cube.in
# Check the region intersect command.
units metal
dimension 3
boundary p p p
atom_style atomic

# Define the simulation box
region sample block 0 20 0 20 0 20 units box
create_box 2 sample
lattice fcc 3.615
create_atoms 1 region sample

# Define atomic type and mass
mass 1 63.546
mass 2 63.546
pair_style eam/alloy
pair_coeff * * Cu_zhou.eam.alloy Cu Cu

# Thermodynamic output.
thermo 500
thermo_style custom step etotal epair pe ke temp press vol
thermo_modify flush yes
dump 1 all custom 20 Cu_bulk.dump id type x y z

# Relax the structure.
velocity        all create 300 68748
fix             NPT      all      npt temp 300. 300. 0.1 iso 0. 0. 1.
run             5000
unfix NPT

# Change the atom type on the outside of the cube.
region inner block 5 15 5 15 5 15 units box
group inner region inner
region side   intersect 2 sample inner
group side region side
set group side type 2

# Integrate only the atoms inside the cube.
fix             NVT      inner      nvt temp 300. 300. 0.1
run            5000

The inconsistencies begin with the definition of the inner and side regions. From the log:

create_atoms 1 region sample
Created 864 atoms

region inner block 5 15 5 15 5 15 units box
group inner region inner
103 atoms in group inner
region side   intersect 2 sample inner
group side region side
103 atoms in group side
set group side type 2
Setting atom values ...
  103 settings made for type

The inner group is correctly populated and should be of type 1. If I understand correctly the command region intersect, the side group should have 864-103=761 atoms of type 2, but LAMMPS reports only 103. However, the DUMP file has the following composition:

761 atoms of type 1 # side
103 atoms of type 2 # inner

with the atom types swapped and the group side having more atoms than reported in the log. The integration in fix nvt seems correct, except for the swapped atom types. Here is a rendering of the exploded sample:


The inner group is coloured in blue and has type 2 in the DUMP file.

Is this a bug?

No. The intersection of two regions is the volume that is occupied by both regions. Since the “inner” region is inside of the “sample” region, the intersection is the same as “inner”.

To explain, if you had

region left block 0 12 0 20 0 20
region right block 8 20 0 20 0 20

Then the following two should be the same:

region overlap intersect left right
region middle block 8 12 0 20 0 20

To get the “side” group you are looking for you should do:

group side subtract all inner
1 Like

Thanks for the explanation, Axel: I overlooked the interplay between the region and group commands.
Now the dump is consistent with the groups: