Merge pull request #624 from OpenWaterAnalytics/dev_tank_fix

Empty tank draining fix
This commit is contained in:
Lew Rossman
2021-04-16 17:23:07 -04:00
committed by GitHub
2 changed files with 17 additions and 32 deletions

View File

@@ -691,6 +691,8 @@ void pumpcoeff(Project *pr, int k)
hgrad; // Head loss gradient
Spump *pump;
double qstar;
// Use high resistance pipe if pump closed or cannot deliver head
setting = hyd->LinkSetting[k];
if (hyd->LinkStatus[k] <= CLOSED || setting == 0.0)
@@ -748,12 +750,14 @@ void pumpcoeff(Project *pr, int k)
if (hgrad > CBIG)
{
hgrad = CBIG;
hloss = -hgrad * hyd->LinkFlow[k];
qstar = sqrt(-r / hgrad);
hloss = (r / qstar) - hgrad * (qstar - q);
}
else if (hgrad < hyd->RQtol)
{
hgrad = hyd->RQtol;
hloss = -hgrad * hyd->LinkFlow[k];
qstar = sqrt(-r / hgrad);
hloss = (r / qstar) - hgrad * (qstar - q);
}
// ... otherwise compute head loss from pump curve
else

View File

@@ -413,7 +413,7 @@ void tankstatus(Project *pr, int k, int n1, int n2)
Hydraul *hyd = &pr->hydraul;
int i, n;
double h, q;
double q;
Stank *tank;
Slink *link = &net->Link[k];
@@ -437,40 +437,21 @@ void tankstatus(Project *pr, int k, int n1, int n2)
tank = &net->Tank[i];
if (tank->A == 0.0) return;
// Find head difference across link
h = hyd->NodeHead[n1] - hyd->NodeHead[n2];
// If tank is full, then prevent flow into it
if (hyd->NodeHead[n1] >= tank->Hmax - hyd->Htol && !tank->CanOverflow)
{
// Case 1: Link is a pump discharging into tank
if (link->Type == PUMP)
{
if (link->N2 == n1) hyd->LinkStatus[k] = TEMPCLOSED;
}
// Case 2: Downstream head > tank head
// (e.g., an open outflow check valve would close)
else if (cvstatus(pr, OPEN, h, q) == CLOSED)
// Can't add flow to a full tank
if (hyd->NodeHead[n1] >= tank->Hmax && !tank->CanOverflow)
{
if (link->Type == PUMP && link->N2 == n1)
hyd->LinkStatus[k] = TEMPCLOSED;
else if (q < 0.0)
hyd->LinkStatus[k] = TEMPCLOSED;
}
}
// If tank is empty, then prevent flow out of it
if (hyd->NodeHead[n1] <= tank->Hmin + hyd->Htol)
{
// Case 1: Link is a pump discharging from tank
if (link->Type == PUMP)
{
if (link->N1 == n1) hyd->LinkStatus[k] = TEMPCLOSED;
}
// Case 2: Tank head > downstream head
// (e.g., a closed outflow check valve would open)
else if (cvstatus(pr, CLOSED, h, q) == OPEN)
// Can't remove flow from an empty tank
if (hyd->NodeHead[n1] <= tank->Hmin)
{
if (link->Type == PUMP && link->N1 == n1)
hyd->LinkStatus[k] = TEMPCLOSED;
else if (q > 0.0)
hyd->LinkStatus[k] = TEMPCLOSED;
}
}
}