Problem with compute reduce sum

Hi all,

Currently I use the "compute reduce sum" command to calculate the total contact region between two different particle clusters using "compute voronoi/atom". Since the structure containing the free surface which may lead to some extreme large calculated values of surface area and volume for some atoms when calculated with "compute voronoi/atom" command. So only 0.1<surface area<50 and volume<20 are used for doing the contact area summation. The command is written as

compute DropletSurface Droplet voronoi/atom surface NveLayer face_threshold 1e-1
variable S atom ((c_DropletSurface[1]<=20)*(c_DropletSurface[3]>=1e-1)*(c_DropletSurface[3]<=50))*c_DropletSurface[3]
compute ContactRegion1 all reduce ave v_S
compute ContactRegion2 all reduce sum v_S

I also use the thermo_style to print this value to the screen using

thermo_style custom step lz c_ContactRegion1 c_ContactRegion2

The printed results on the screen are

Step Lz ContactR ContactR
0 408.69901 0.013069324 0.013069324

Since all the calculated values in atom-vector S >0 and I have also checked that some of the atoms have S>10, why the "compute reduce ave and sum" give the same results, not c_ContactRegion1 (ave of S)<c_ContactRegion2 (sum of S)?
Is there anyone know where is the problem? Thanks for your help in advance.


The best way to debug something like is take it one step at at time.

I suggest you write the cmopute voronoi/atom and per-atom variable values to a dump file
and examine them. If they are not what you expect then
write simpler versions of the per-atom formula and dump
those out. Then sum the values in the dump file by hand (e.g. a Python script)
and verify that you get the same answer as compute reduce sum/ave is