Account for mass lost in tank overflow
This change addresses issue #769.
This commit is contained in:
@@ -7,7 +7,7 @@ Description: computes water quality reactions within pipes and tanks
|
|||||||
Authors: see AUTHORS
|
Authors: see AUTHORS
|
||||||
Copyright: see AUTHORS
|
Copyright: see AUTHORS
|
||||||
License: see LICENSE
|
License: see LICENSE
|
||||||
Last Updated: 05/15/2019
|
Last Updated: 03/12/2024
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -492,6 +492,13 @@ void tankmix1(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
seg->v += vnet;
|
seg->v += vnet;
|
||||||
seg->v = MAX(0.0, seg->v);
|
seg->v = MAX(0.0, seg->v);
|
||||||
tank->C = seg->c;
|
tank->C = seg->c;
|
||||||
|
|
||||||
|
// Account for mass lost in tank overflow
|
||||||
|
if (seg->v > tank->Vmax)
|
||||||
|
{
|
||||||
|
qual->MassBalance.outflow += ((seg->v) - tank->Vmax) * tank->C;
|
||||||
|
seg->v = tank->Vmax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -513,7 +520,8 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
|
|
||||||
int k;
|
int k;
|
||||||
double vt, // Transferred volume
|
double vt, // Transferred volume
|
||||||
vmz; // Full mixing zone volume
|
vmz, // Full mixing zone volume
|
||||||
|
vsz; // Full stagnant zone volume
|
||||||
Pseg mixzone, // Mixing zone segment
|
Pseg mixzone, // Mixing zone segment
|
||||||
stagzone; // Stagnant zone segment
|
stagzone; // Stagnant zone segment
|
||||||
Stank *tank = &pr->network.Tank[i];
|
Stank *tank = &pr->network.Tank[i];
|
||||||
@@ -559,8 +567,19 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
if (vt > 0.0)
|
if (vt > 0.0)
|
||||||
{
|
{
|
||||||
mixzone->v = vmz;
|
mixzone->v = vmz;
|
||||||
if (vnet > 0.0) stagzone->v += vt;
|
if (vnet > 0.0)
|
||||||
else stagzone->v = MAX(0.0, ((stagzone->v) - vt));
|
{
|
||||||
|
stagzone->v += vt;
|
||||||
|
|
||||||
|
// Account for mass lost in overflow from stagnant zone
|
||||||
|
vsz = (tank->Vmax) - vmz;
|
||||||
|
if (stagzone->v > vsz)
|
||||||
|
{
|
||||||
|
qual->MassBalance.outflow += ((stagzone->v) - vsz) * stagzone->c;
|
||||||
|
stagzone->v = vsz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else stagzone->v = MAX(0.0, ((stagzone->v) - vt));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -612,10 +631,13 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
else addseg(pr, k, vin, cin);
|
else addseg(pr, k, vin, cin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Withdraw flow from first segment
|
// Find volume leaving tank, adjusted so its volume doesn't exceed Vmax
|
||||||
|
vout = vin - vnet;
|
||||||
|
if (tank->V >= tank->Vmax && vnet > 0.0) vout = vin;
|
||||||
|
|
||||||
|
// Withdraw outflow from first segment
|
||||||
vsum = 0.0;
|
vsum = 0.0;
|
||||||
wsum = 0.0;
|
wsum = 0.0;
|
||||||
vout = vin - vnet;
|
|
||||||
while (vout > 0.0)
|
while (vout > 0.0)
|
||||||
{
|
{
|
||||||
seg = qual->FirstSeg[k];
|
seg = qual->FirstSeg[k];
|
||||||
@@ -643,6 +665,10 @@ void tankmix3(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
if (vsum > 0.0) tank->C = wsum / vsum;
|
if (vsum > 0.0) tank->C = wsum / vsum;
|
||||||
else if (qual->FirstSeg[k] == NULL) tank->C = 0.0;
|
else if (qual->FirstSeg[k] == NULL) tank->C = 0.0;
|
||||||
else tank->C = qual->FirstSeg[k]->c;
|
else tank->C = qual->FirstSeg[k]->c;
|
||||||
|
|
||||||
|
// Account for mass lost in overflow from 1st segment
|
||||||
|
if (tank->V >= tank->Vmax && vnet > 0.0)
|
||||||
|
qual->MassBalance.outflow += vnet * tank->C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -669,7 +695,7 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
k = net->Nlinks + i;
|
k = net->Nlinks + i;
|
||||||
if (qual->LastSeg[k] == NULL || qual->FirstSeg[k] == NULL) return;
|
if (qual->LastSeg[k] == NULL || qual->FirstSeg[k] == NULL) return;
|
||||||
|
|
||||||
// Find inflows & outflows
|
// Find inflow concentration
|
||||||
if (vin > 0.0) cin = win / vin;
|
if (vin > 0.0) cin = win / vin;
|
||||||
else cin = 0.0;
|
else cin = 0.0;
|
||||||
|
|
||||||
@@ -687,6 +713,33 @@ void tankmix4(Project *pr, int i, double vin, double win, double vnet)
|
|||||||
|
|
||||||
// Update reported tank quality
|
// Update reported tank quality
|
||||||
tank->C = qual->LastSeg[k]->c;
|
tank->C = qual->LastSeg[k]->c;
|
||||||
|
|
||||||
|
// If tank full then remove vnet from leading segments
|
||||||
|
if (tank->V >= tank->Vmax)
|
||||||
|
{
|
||||||
|
wsum = 0.0;
|
||||||
|
while (vnet > 0.0)
|
||||||
|
{
|
||||||
|
seg = qual->FirstSeg[k];
|
||||||
|
if (seg == NULL) break;
|
||||||
|
vseg = seg->v; // Flow volume from leading seg
|
||||||
|
vseg = MIN(vseg, vnet);
|
||||||
|
if (seg == qual->LastSeg[k]) vseg = vnet;
|
||||||
|
wsum += (seg->c) * vseg;
|
||||||
|
vnet -= vseg; // Remaining flow volume
|
||||||
|
if (vnet >= 0.0 && vseg >= seg->v) // Seg used up
|
||||||
|
{
|
||||||
|
if (seg->prev)
|
||||||
|
{
|
||||||
|
qual->FirstSeg[k] = seg->prev;
|
||||||
|
seg->prev = qual->FreeSeg;
|
||||||
|
qual->FreeSeg = seg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else seg->v -= vseg; // Remaining volume in segment
|
||||||
|
}
|
||||||
|
qual->MassBalance.outflow += wsum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If tank emptying then remove last segments until vnet consumed
|
// If tank emptying then remove last segments until vnet consumed
|
||||||
|
|||||||
Reference in New Issue
Block a user