Error: Fix pour polydisperse fractions do not sum to 1.0 <../fix_pour.cpp:980>

Hi there,

I use the following command to pour spheres with 4 different diameters:

region slab block 0 1 0 1 0.5 1 units box
fix ins1 all pour 500 1 12345 region slab diam poly 4 0.1 0.2 0.15 0.5 0.2 0.2 0.25 0.1

I got the error: Fix pour polydisperse fractions do not sum to 1.0 <../fix_pour.cpp:980>

But 0.5+0.2+0.2+0.1=1, absolutely.

What is the problem of LAMMPS here? Thanks.

Andy

Hi there,

I use the following command to pour spheres with 4 different diameters:

region slab block 0 1 0 1 0.5 1 units box
fix ins1 all pour 500 1 12345 region slab diam poly 4 0.1 0.2 0.15 0.5 0.2 0.2 0.25 0.1

I got the error: Fix pour polydisperse fractions do not sum to 1.0 <../fix_pour.cpp:980>

But 0.5+0.2+0.2+0.1=1, absolutely.

What is the problem of LAMMPS here? Thanks.

the problem is that the person who implemented this specific feature
apparently didn't know much about floating point math and not that
certain numbers cannot be represented exactly, that summing of numbers
is not associative and summing of numbers of different magnitude can
lead to truncation, or that because of all that you never compare
floating point numbers for exact identity . the following change to
fix pour will set this right.

axel.

diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp
index 662d466..65b2223 100644
--- a/src/GRANULAR/fix_pour.cpp
+++ b/src/GRANULAR/fix_pour.cpp
@@ -42,6 +42,7 @@ enum{ONE,RANGE,POLY};
enum{LAYOUT_UNIFORM,LAYOUT_NONUNIFORM,LAYOUT_TILED}; // several files

#define EPSILON 0.001
+#define SMALL 1.0e-10

/* ---------------------------------------------------------------------- */

@@ -976,7 +977,7 @@ void FixPour::options(int narg, char **arg)
         }
         double sum = 0.0;
         for (int i = 0; i < npoly; i++) sum += frac_poly[i];
- if (sum != 1.0)
+ if (fabs(sum - 1.0) > SMALL)
           error->all(FLERR,"Fix pour polydisperse fractions do not
sum to 1.0");
       } else error->all(FLERR,"Illegal fix pour command");

Thank you, Axel. I am a very newbie of LAMMPS.

So could you tell me how to set the numbers? I need to pour a set of spheres with different diameters distribution. How can I avoid this error in my lammps input script?

Andy

Thank you, Axel. I am a very newbie of LAMMPS.

So could you tell me how to set the numbers? I need to pour a set of spheres with different diameters distribution. How can I avoid this error in my lammps input script?

your input is correct. the issue is in the source code of LAMMPS. it
has to be modified as indicated in the patch i quoted (take out the
lines prefixed with '-' and insert those prefixed with '+'. or copy
the section to a text file and apply the patch via the patch program)
and then recompiled. the change will also be published in my
LAMMPS-ICMS tree later tonight and hopefully make it into the upstream
version in one of the next patches.

axel.

the problem is that the person who implemented this specific feature
apparently didn’t know much about floating point math

That would be me, duh. Good catch.

Since it’s a fairly recently added feature, I’ll attribute

it to loss of brain cells due to following the US presidential

election process too closely.

Steve