Difference in water age calculated in EPANET and in Matlab using epanet-matlab toolkit

Hello everyone.

I am a complete newbie in the topic. I attempt to use KIOS Research Center EPANET-Matlab Toolkit (I looked through this https://github.com/KIOS-Research/CCWI2016 and this https://github.com/OpenWaterAnalytics/EPANET-Matlab-Toolkit)
In my test run, I am interested in water age. I set d.setQualityType(‘age’) and run hydraulic and quality d.getComputedHydraulicTimeSeries and d.getComputedQualityTimeSeries. Interestingly, when I compare the results from EPANET alone with the results from Matlab, they are different but only for some nodes.

Left column is the EPANET results, right column is the Matlab.

I’d greatly appreciate any advice why this is happening, and especially I’d be happy to hear suggestions what should I read to understand a little more how the toolkit works.

Thank you.

1 Like

Hi yloskvi4

I think the result in the matlab is correct, Epanet is rounding numbers.

It looks like both answers are identical except that EPANET is simply only presenting 2 significant figures (the default for the program) while Matlab is giving you all decimal places. If you rounded your Matlab results to two decimal places form the results you show, they would appear to be identical.

Pat Moore

not quite. look at the highlighted rows.

@karwan_eng and @InnovyzePatrick the screenshot in the original post is a bit deceiving. Click on it to see the entire image.

@yloskvi4 which DLL is Matlab using, which version? Are these nodes connected to closed links by any chance? I remember having some issues with those.

Good catch Elad. You definitely see the differences when you click on the whole picture better. Elad is correct that odd things can happen on nodes connected to junctions with no demand during periods where the flows through connecting pipes are zero. To calculate the junction concentration EPANET uses a weighted average based on the flows in all connected pipes, but if the flows in the pipes are near zero then even pipes with no flow can contribute to the junction concentration due to the numerical rounding error of pipes with flows all less than 2 decimal places. This can at times create short term spikes in the water age to occur in the junction water age to sometimes occur.

EPANET can also at times calculate unusual water age values on the suction node of pumps that are not running as well (It can make those have a water age of zero). Without seeing your system it’s difficult to tell if those are potentially contributing. These are at least two locations I know of where unusual water age results can occur in EPANET

However, I am not familiar with using Matlab and EPANET to tell you why there might be differences in the two methods as I have never used Matlab in that way.

The one other thing I would check is to make sure your water quality timestep is always at least 1/10th of your hydraulic timestep and that your hydraulic accuracy and water quality accuracy are generally not higher than 0.01 as that can begin to introduce error.

We have also noticed that to get the most accurate water age results you may need to reduce your hydraulic timestep to less than 1 hour. I always recommend that people check 1 hour - 30 minutes, 15 minutes, 10 minutes, and 5 minutes as the hydraulic timestep (in that order) and when the WQ results between the two runs remains within a reasonable tolerance, then use the larger of the two hydraulic timesteps in the comparison. In certain models this can impact results up to 10-20% or more by improving the pipe flow estimations the software uses to estimate transport times. This is often most significant if your model has multiple tanks near each other which can cause difficulties in the EPANET hydraulic solution and thus the water age.

Those are fairly easy things to check in your results to make sure that is not causing difficulties.

Hi Olya,

Which network have you been using? I’d like to replicate your results. Most probably it’s because the latest version of EPANET was used (2.1) which has small differences that might explain this.

The MATLAB Toolkit is not affecting the results, as these are produced from the EPANET DLL/executable (directly from the memory or through the binary output file).

So, we were able to reproduce the difference. We checked all DLLs and 2.0.12 (original EPA version, GitHub Release versions) and 2.1.0) as well as through the 2.0.12 GUI version.

  1. When we have a network with initial quality conditions in the pipes, and we set the quality to AGE using the toolkit, there are at least two changes occurring, the pipe quality and the tolerance.

If we restore these parameters (i.e. set pipe initial quality to zero) and tolerance to the previous numbers, the results are closer to the correct ones.

  1. When we modify the tank diameter, the Min Volume is not re-calculated. If we re-calculate it using its equation the results are close to the expected ones.

In any case, these are not MATLAB issues, but EPANET issues which we need to investigate this further @samhatchett, @eladsal

@demetrios are you sure that the Min Volume is not calculated? We have it in the code:
Tank[j].Vmin = tankvolume(j, Tank[j].Hmin);

I have just fixed a bug in ENsetqualtype. This fix may be related to this report issue.

@yloskvi4 can you please check?

I check this and its ok! But there are other “problems”:

Tank Diameter: 50.000000
Min Volume: 98174.773438
Tank Diameter: 34.000000
Min Volume: 98174.773438 // This is I think must be equal with [Min Volume = 45396.0138443725]
MinVolume = PIR^2MinWaterLevel

I use this inp file: net2-cl2.inp

Tolerance before ENsetqualtype: 0.010000
Initial quality type: 1
Tolerance after ENsetqualtype: 0.283170
After set quality type: 2 //to age

Yes, I this issue. Units of the quality tolerance should be updated. Will work on it.

When is this happening, after changing the tank diameter?

Yes, the min volume is the same when diameter=50 and when I change it to diameter=34 using ENsetnodevalue.

Quality tolerance error fixed in 5eead5a.

Issue was in ENsetqualtype where the quality conversion factor was changed.


For topics that appear to be bugs in the engine, please post an issue on GitHub. That way we can better track them and their resolutions.

1 Like