fix ave/spatial with region option bug ?

Hi developers,

Me again. I've been trying to track down this problem in the code and haven't been able to find it yet, but there seems to be a problem with the fix ave/spatial code, when used in combination with region.

I have modified the in.melt input file from the examples folder to give a minimal example of this problem.

Basically, calculating the density (or any other property in an homogeneous system) gives an inhomogeneous result. This is because atoms in the last bins, those with the largest coordinates in either the x or y directions, are mapped into the adjacent lower bins (this type of behaviour is mentioned to occur if say the box dimensions change during the simulation). So that the lower bins on the sides have double the density, and the bin on the corner gets 4 times the density.

This problem only occur if the region option is used and 2 dimensions are binned.

I am using the latest LAMMPS version.

INPUT FILE:
# 3d Lennard-Jones melt

units lj
atom_style atomic

lattice fcc 0.8442
region box block 0 10 0 10 0 10
create_box 1 box
create_atoms 1 box
mass 1 1.0

velocity all create 3.0 87287

pair_style lj/cut 2.5
pair_coeff 1 1 1.0 1.0 2.5

neighbor 0.3 bin
neigh_modify every 20 delay 0 check no

fix 1 all nve
thermo 50
run 250

region mid block INF INF INF INF 5 5.5
fix sig_prof all ave/spatial 1 10 100 x lower 0.25 y lower 0.25 density/number units reduced region mid ave running file sig.dat

run 100

SIG.DAT OUTPUT:
# Spatial-averaged data for fix sig_prof and group all
# Timestep Number-of-bins
# Bin Coord1 Coord2 Ncount density/number
300 16
   1 0.125 0.125 13 0.0438984
   2 0.125 0.375 12.3 0.0415346
   3 0.125 0.625 24.9 0.0840823
   4 0.125 0.875 0 0
   5 0.375 0.125 10.7 0.0361318
   6 0.375 0.375 14.2 0.0479506
   7 0.375 0.625 26.1 0.0881345
   8 0.375 0.875 0 0
   9 0.625 0.125 23.9 0.0807055
   10 0.625 0.375 25.1 0.0847577
   11 0.625 0.625 49.5 0.167152
   12 0.625 0.875 0 0
   13 0.875 0.125 0 0
   14 0.875 0.375 0 0
   15 0.875 0.625 0 0
   16 0.875 0.875 0 0

The denisty in each bin should be ~0.04.

Thanks, Mathieu