OpenWaterAnalytics / EPANET

The Water Distribution System Hydraulic and Water Quality Analysis Toolkit
MIT License
272 stars 201 forks source link

Segment volume for overflowing tank #769

Closed Shang2000 closed 3 months ago

Shang2000 commented 4 months ago

I am not sure whether it is a known issue. I searched and did not find related information. When a tank is overflowing, the volume in Tank (STANK.V) is kept constant. However the WQ segment volume (Pseg->v) in the tankmix function keeps increasing, leading to very large volume used in tank water quality calculation. Should overflown volume be taken out of the segment volume?

LRossman commented 4 months ago

Yes, this should be corrected in the tankmix1function of qualreact.c as follows:

    if (seg)
    {
       vnew = seg->v + vin;
       if (vnew > 0.0) seg->c = (seg->c * seg->v + win) / vnew;
       seg->v += vnet;
       seg->v = MAX(0.0, seg->v);
       seg->v = MIN(seg->v, tank->Vmax);  // <--- new line
       tank->C = seg->c;        
    }

The chart below shows the tracer concentration in a 50-ft diameter tank receiving a constant 109.3 gpm inflow with 100 mg/L of tracer in it. The tank has a maximum depth of 20 ft and is initially filled to 18 ft with a tracer concentration of 50 mg/L. It takes 4 hours for the tank to become full after which it overflows. The original and corrected results are compared on the chart.

image

We see that because the corrected code limits the volume of the tank's single water quality segment the concentration from mixing its inflow with its current volume produces a larger concentration than the unrestricted volume from the original code since that segment volume (plus the inflow volume) appears in the denominator of the mixing equation.

A similar update should be added to tankmix2as follows:

    if (vt > 0.0)
    {
        mixzone->v = vmz;
        if (vnet > 0.0) stagzone->v += vt;
        else            stagzone->v = MAX(0.0, ((stagzone->v) - vt));
        stagzone->v = MIN(stagzone->v, ((tank->Vmax) - vmz));   //<--- new line
    }
Shang2000 commented 4 months ago

Thank you Lew. I would suggest adding the overflown mass into Massbalance.outflow. That will make the mass balance ratio to be 1.

if (seg)
{
   vnew = seg->v + vin;
   if (vnew > 0.0) seg->c = (seg->c * seg->v + win) / vnew;
   seg->v += vnet;
   seg->v = MAX(0.0, seg->v);

   pr->quality.MassBalance.outflow += (seg->v - MIN(seg->v, tank->Vmax)) * seg->c; //<--- newline
   seg->v = MIN(seg->v, tank->Vmax);    // <--- newline

   tank->C = seg->c;
}

================================ Water Quality Mass Balance (hrs)

Initial Mass: 0.00000e+00 Mass Inflow: 0.00000e+00 Mass Outflow: 9.76095e+06 Mass Reacted: -9.98979e+06 Final Mass: 2.28841e+05 Mass Ratio: 1.00000

LRossman commented 3 months ago

This issue has been addressed in PR #771 and can be closed.