Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about minimum volume for new segments - performance implications #813

Open
samhatchett opened this issue Aug 6, 2024 · 6 comments

Comments

@samhatchett
Copy link
Member

When the quality engine is looking at node outflows, the following logic is used in determining if new segments are produced.

In short, the volume of a new segment must be greater than 0.0 and its quality value has to be outside of Ctol - otherwise no new segment is produced.

EPANET/src/qualroute.c

Lines 341 to 357 in fbd005d

v = fabs(LINKFLOW(k)) * tstep;
if (v == 0.0) return;
// Release flow and mass into upstream end of the link
// ... case where link has a last (most upstream) segment
seg = qual->LastSeg[k];
if (seg)
{
// ... if node quality close to segment quality then mix
// the nodal outflow volume with the segment's volume
if (fabs(seg->c - c) < qual->Ctol)
{
seg->c = (seg->c*seg->v + c*v) / (seg->v + v);
seg->v += v;
}

This approach has some pretty severe performance impacts on large networks, run for long times, that have dead-end pipes. After a while, even with large tolerance values, the number of segments skyrockets because the volume of these new segments, while greater than 0.0, is still vanishingly small.

I'm wondering about the introduction of a "volume tolerance" term here to skip new segment creation when the volume of the new segment would be negligible in the eyes of the user.

@LRossman
Copy link
Collaborator

LRossman commented Aug 6, 2024

The segment explosion occurs mainly for Water Age simulations, yes? Instead of a volume tolerance, which may be difficult to have an intuitive feel for, what about a flow tolerance. Because EPANET's hydraulic solver can't allow a flow to be exactly 0, pipes downstream of a closed pipe or on the path to a dead end with no demand will always see some small amount of flow which I believe contributes to segment growth. The program already has an optional Flow Tolerance (FlowChangeLimit) used to determine hydraulic convergence. Maybe we can also use it to limit WQ segment growth as shown below:

    // ... case where link has a last (most upstream) segment
    seg = qual->LastSeg[k];
    if (seg)
    {
        // ... if node quality close to segment quality or inflow is negligible
        //    then mix the nodal outflow volume with the segment's volume
        if (fabs(seg->c - c) < qual->Ctol ||
            (hyd->FlowChangeLimit > 0.0 && fabs(LINKFLOW(k)) < hyd->FlowChangeLimit))
        {
            seg->c = (seg->c*seg->v + c*v) / (seg->v + v);
            seg->v += v;
        }

It would be easy to try out since only one line of code needs to be added.

@samhatchett
Copy link
Member Author

that's a really good point, to lean on a convention that's already in use. I'll see if I can benchmark this kind of change in my worst case scenario - thanks for the feedback.

@jamesuber
Copy link
Member

jamesuber commented Aug 7, 2024 via email

@LRossman
Copy link
Collaborator

LRossman commented Aug 7, 2024

I agree with @jamesuber 's point. Using the existing hydraulic flow tolerance for water quality as well is just an easy way to test if it is effective in limiting WQ segment growth without sacrificing accuracy. To add a separate new WQ flow tolerance option requires making changes to 8 different files (which doesn't speak well for the overall design of the code base -- but that's a separate issue). We can do so if testing shows that a WQ flow tolerance is worthwhile.

P.S. Another option is to add a user-specified maximum segment limit for pipes. This was present in EPANET 1.x which used an Eulerian scheme for WQ routing, where each pipe was divided into a fixed number of equal size segments with each new flow solution.

@LRossman
Copy link
Collaborator

LRossman commented Aug 9, 2024

I just found something interesting when simulating water age. If you set the Quality Tolerance to the reporting time step you can significantly reduce the number of segments used without affecting the reported results. I tested this on a 5,000 pipe network with a 72 hour duration. With a 1-hr reporting step there was a 10-fold decrease in segments as compared to the default tolerance of 0.01 hrs. With a 15-minute reporting step there was a 4-fold decrease. In both cases I couldn't see any difference in the time series of water age at selected nodes.

@jamesuber
Copy link
Member

jamesuber commented Aug 9, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants