OpenWaterAnalytics / EPANET

The Water Distribution System Hydraulic and Water Quality Analysis Toolkit
MIT License
279 stars 204 forks source link

"Invalid floating point operation" error #666

Closed LRossman closed 2 years ago

LRossman commented 2 years ago

I recently received an "Invalid floating point operation" message when running a particular network under v2.2. I tracked the cause to the following line in the tanktimestep() function of hydraul.c:

        // Find time to fill/drain tank
        t = (long)ROUND(v / q);

where the ROUND macro is defined in types.h as:

#define ROUND(x) (((x)>=0) ? (int)((x)+.5) : (int)((x)-.5))

My guess is that the value of (v / q) became too large to convert to an integer (a check already exists to not evaluate t if |q| < 1.0e-6).

The proposed fix is:

        // Find time to fill/drain tank
        double xt = v / q;
        if (xt > *tstep + 1) continue;
        t = (long)(ROUND(xt));

where *tstep is the current estimate of the next hydraulic time step which won't be any larger than the user-supplied time step. After making this fix the network in question ran successfully.

samhatchett commented 2 years ago

closed as merged